Last active
November 27, 2024 19:23
-
-
Save laundmo/de1f386fac9f9e797fd77022d63967c9 to your computer and use it in GitHub Desktop.
Trilium widget to open italicized file paths. Only works in Desktop app. Add as "JS Frontend" note and make sure it has the #widget property.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* License: MIT https://opensource.org/licenses/MIT | |
* Made by: GEOsens GmbH 2023 | |
* | |
* Usage: Italicize the file path. The italicized file or folder can be opened with a double click. | |
* | |
* Note: there is not indication that a path is clickable, thanks ckeditor. | |
*/ | |
async function onClickOpenPath(event) { | |
// check if event was on Italicised | |
if (event.target.tagName == "I") { | |
var path = event.target.innerText; | |
// check if content is path (rudimentary) | |
if (/[a-zA-Z]:.*|\\\\\w.*?\\\w/.test(path)) { | |
// use backend to open file from path | |
await document.PathLinkerApi.runOnBackend(async (path) => { | |
const shell = require('electron').shell; | |
await shell.openPath(path); | |
return; | |
}, [path]); | |
} | |
} | |
} | |
const TEMPLATE = ` | |
<div style="padding: 10px; border-top: 1px solid var(--main-border-color); contain: none;"> | |
<script> | |
${onClickOpenPath.toString()} | |
document.addEventListener('dblclick', onClickOpenPath); | |
</script> | |
</div>`; | |
class PathLinkerWidget extends api.NoteContextAwareWidget { | |
constructor(...args) { | |
super(...args); | |
this.balloonEditorCreate = null; | |
} | |
get position() { | |
// higher value means position towards the bottom/right | |
return 100; | |
} | |
get parentWidget() { return 'center-pane'; } | |
doRender() { | |
this.$widget = $(TEMPLATE); | |
this.$widget.hide(); | |
// store API in document to access it from callback | |
document.PathLinkerApi = api; | |
return this.$widget; | |
} | |
} | |
let widget = new PathLinkerWidget(); | |
console.log("Loaded PathLinkerWidget"); | |
module.exports = widget; |
same here. seems like an update of electron broke it? tried to debug but my skills aren´t good enough
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm unable to get either of these working. I get an error about "require" not being defined, using Trilium Next 0.90.7