open directory

This commit is contained in:
SiriusXT 2024-09-04 11:08:04 +00:00
parent bc4444d132
commit e66b865cd6
2 changed files with 27 additions and 3 deletions

View File

@ -72,7 +72,7 @@ async function openCustom(type, entityId, mime) {
const terminal = terminals[index];
if (!terminal) {
console.error('Open Note custom: No terminal found!');
open(getFileUrl(entityId), {url: true});
open(getFileUrl(type, entityId), {url: true});
return;
}
exec(`which ${terminal}`, (error, stdout, stderr) => {
@ -166,6 +166,26 @@ function getHost() {
return `${url.protocol}//${url.hostname}:${url.port}`;
}
async function openDirectory(directory) {
try {
if (utils.isElectron()) {
const electron = utils.dynamicRequire('electron');
const res = await electron.shell.openPath(directory);
if (res) {
console.error('Failed to open directory:', res);
} else {
console.log('Directory opened successfully.');
}
} else {
console.error('Not running in an Electron environment.');
}
} catch (err) {
// Handle file system errors (e.g. path does not exist or is inaccessible)
console.error('Error:', err.message);
}
}
export default {
download,
downloadFileNote,
@ -176,4 +196,5 @@ export default {
openAttachmentExternally,
openNoteCustom,
openAttachmentCustom,
openDirectory
}

View File

@ -2,6 +2,8 @@ import server from "../../services/server.js";
import utils from "../../services/utils.js";
import { t } from "../../services/i18n.js";
import BasicWidget from "../basic_widget.js";
import openService from "../../services/open.js";
const TPL = `
<div class="about-dialog modal fade mx-auto" tabindex="-1" role="dialog">
@ -74,10 +76,11 @@ export default class AboutDialog extends BasicWidget {
this.$buildRevision.attr('href', `https://github.com/TriliumNext/Notes/commit/${appInfo.buildRevision}`);
if (utils.isElectron()) {
this.$dataDirectory.html($('<a></a>', {
href: 'file:///' + appInfo.dataDirectory,
text: appInfo.dataDirectory,
target: '_blank'
}));
this.$dataDirectory.find("a").on('click', () => {
openService.openDirectory(appInfo.dataDirectory);
})
} else {
this.$dataDirectory.text(appInfo.dataDirectory);
}