Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
Merge branch 'master' into next61
zadam9e9fb2979fe0
diff --cc src/public/app/services/open.jsindex 6c79d94177,177db64593..29da3bac2e--- a/src/public/app/services/open.js+++ b/src/public/app/services/open.js@@@ -35,70 -24,92 +35,75 @@@ function downloadFileNote(noteId)download(url);}-async function openNoteExternally(noteId, mime) {- if (utils.isElectron()) {- const resp = await server.post(`notes/${noteId}/save-to-tmp-dir`);+function downloadAttachment(attachmentId) {+ const url = `${getFileUrl('attachments', attachmentId)}?${Date.now()}`; // don't use cache- const electron = utils.dynamicRequire('electron');- const res = await electron.shell.openPath(resp.tmpFilePath);-- if (res) {- // fallback in case there's no default application for this file- open(getFileUrl(noteId), {url: true});- }- }- else {- // allow browser to handle opening common file- if (mime === "application/pdf" || mime.startsWith("image") || mime.startsWith("audio") || mime.startsWith("video")){- window.open(getOpenFileUrl(noteId));- }- else {- window.location.href = getFileUrl(noteId);- }- }+ download(url);}- async function openNoteCustom(noteId, mime) {- if (utils.isElectron()) {- const resp = await server.post(`notes/${noteId}/save-to-tmp-dir`);- const filePath = resp.tmpFilePath;- const { exec } = utils.dynamicRequire('child_process');- const platform = process.platform;- if (platform === 'linux') {- const terminals = ['gnome-terminal', 'konsole', 'xterm', 'xfce4-terminal', 'mate-terminal', 'rxvt', 'terminator', 'terminology'];+ async function openNoteCustom(noteId) {+ if (!utils.isElectron() || utils.isMac()) {+ return;+ }++ const resp = await server.post(`notes/${noteId}/save-to-tmp-dir`);+ let filePath = resp.tmpFilePath;+ const {exec} = utils.dynamicRequire('child_process');+ const platform = process.platform;++ if (platform === 'linux') {+ // we don't know which terminal is available, try in succession+ const terminals = ['x-terminal-emulator', 'gnome-terminal', 'konsole', 'xterm', 'xfce4-terminal', 'mate-terminal', 'rxvt', 'terminator', 'terminology'];const openFileWithTerminal = (terminal) => {- const command = `${terminal} -e 'mimeopen -d "${filePath}"'`;- console.log(`Open Note custom: ${command} `);- exec(command, (error, stdout, stderr) => {- if (error) {- console.error(`Open Note custom: Failed to open file with ${terminal}: ${error}`);- searchTerminal(terminals.indexOf(terminal) + 1);- } else {- console.log(`Open Note custom: File opened with ${terminal}. ${stdout}`);- }- });+ const command = `${terminal} -e 'mimeopen -d "${filePath}"'`;+ console.log(`Open Note custom: ${command} `);+ exec(command, (error, stdout, stderr) => {+ if (error) {+ console.error(`Open Note custom: Failed to open file with ${terminal}: ${error}`);+ searchTerminal(terminals.indexOf(terminal) + 1);+ } else {+ console.log(`Open Note custom: File opened with ${terminal}: ${stdout}`);+ }+ });};+const searchTerminal = (index) => {- const terminal = terminals[index];- if (!terminal) {- console.error('Open Note custom: No terminal found!');- open(getFileUrl(noteId), { url: true });- return;- }- exec(`which ${terminal}`, (error, stdout, stderr) => {- if (stdout.trim()) {- openFileWithTerminal(terminal);- } else {- searchTerminal(index + 1);+ const terminal = terminals[index];+ if (!terminal) {+ console.error('Open Note custom: No terminal found!');+ open(getFileUrl(noteId), {url: true});+ return;}- });+ exec(`which ${terminal}`, (error, stdout, stderr) => {+ if (stdout.trim()) {+ openFileWithTerminal(terminal);+ } else {+ searchTerminal(index + 1);+ }+ });};searchTerminal(0);- } else if (platform === 'win32') {+ } else if (platform === 'win32') {if (filePath.indexOf("/") !== -1) {- //Note that the path separator must be \ instead of /- filePath = filePath.replace(/\//g, "\\");+ // Note that the path separator must be \ instead of /+ filePath = filePath.replace(/\//g, "\\");}const command = `rundll32.exe shell32.dll,OpenAs_RunDLL ` + filePath;exec(command, (err, stdout, stderr) => {- if (err) {- console.error("Open Note custom: ", err);- open(getFileUrl(noteId), { url: true });- return;- }+ if (err) {+ console.error("Open Note custom: ", err);+ open(getFileUrl(noteId), {url: true});+ return;+ }});- } else {+ } else {console.log('Currently "Open Note custom" only supports linux and windows systems');- open(getFileUrl(noteId), { url: true });- }+ open(getFileUrl(noteId), {url: true});}- }+ }function downloadNoteRevision(noteId, noteRevisionId) {- const url = getUrlForDownload(`api/notes/${noteId}/revisions/${noteRevisionId}/download`);+ const url = getUrlForDownload(`api/revisions/${noteRevisionId}/download`);download(url);}diff --cc src/public/app/widgets/buttons/note_actions.jsindex ac552f4b55,b660c7da2c..3f6bbf8435--- a/src/public/app/widgets/buttons/note_actions.js+++ b/src/public/app/widgets/buttons/note_actions.js@@@ -34,13 -28,8 +34,13 @@@ const TPL =<a data-trigger-command="renderActiveNote" class="dropdown-item render-note-button"><kbd data-command="renderActiveNote"></kbd> Re-render note</a><a data-trigger-command="findInText" class="dropdown-item find-in-text-button">Search in note <kbd data-command="findInText"></a><a data-trigger-command="showNoteSource" class="dropdown-item show-source-button"><kbd data-command="showNoteSource"></kbd> Note source</a>- <a data-trigger-command="openNoteExternally" class="dropdown-item open-note-externally-button"><kbd data-command="openNoteExternally"></kbd> Open note externally</a>+ <a data-trigger-command="showAttachments" class="dropdown-item"><kbd data-command="showAttachments"></kbd> Note attachments</a>+ <a data-trigger-command="openNoteExternally" class="dropdown-item open-note-externally-button"+ title="File will be open in an external application and watched for changes. You'll then be able to upload the modified version back to Trilium.">+ <kbd data-command="openNoteExternally"></kbd>+ Open note externally+ </a>- <a data-trigger-command="openNoteCustom" class="dropdown-item open-note-custom-button"><kbd data-command="openNoteCustom"></kbd> Open note custom (beta)</a>+ <a data-trigger-command="openNoteCustom" class="dropdown-item open-note-custom-button"><kbd data-command="openNoteCustom"></kbd> Open note custom</a><a class="dropdown-item import-files-button">Import files</a><a class="dropdown-item export-note-button">Export note</a><a class="dropdown-item delete-note-button">Delete note</a>@@@ -104,31 -90,9 +104,31 @@@ export default class NoteActionsWidgetthis.$renderNoteButton.toggle(note.type === 'render');this.$openNoteExternallyButton.toggle(utils.isElectron());- this.$openNoteCustomButton.toggle(utils.isElectron());+ this.$openNoteCustomButton.toggle(utils.isElectron() && !utils.isMac()); // no implementation for Mac yet}+ async convertNoteIntoAttachmentCommand() {+ if (!await dialogService.confirm(`Are you sure you want to convert note '${this.note.title}' into an attachment of the parent note?`)) {+ return;+ }++ const {attachment: newAttachment} = await server.post(`notes/${this.noteId}/convert-to-attachment`);++ if (!newAttachment) {+ toastService.showMessage(`Converting note '${this.note.title}' failed.`);+ return;+ }++ toastService.showMessage(`Note '${newAttachment.title}' has been converted to attachment.`);+ await ws.waitForMaxKnownEntityChangeId();+ await appContext.tabManager.getActiveContext().setNote(newAttachment.parentId, {+ viewScope: {+ viewMode: 'attachments',+ attachmentId: newAttachment.attachmentId+ }+ });+ }+toggleDisabled($el, enable) {if (enable) {$el.removeAttr('disabled');diff --cc src/services/options.jsindex 480b1e1429,d2b1404fdb..8620d0c213--- a/src/services/options.js+++ b/src/services/options.js@@@ -27,15 -25,19 +27,19 @@@ function getOption(name)}/**- * @returns {number}+ * @returns {integer}*/- function getOptionInt(name) {+ function getOptionInt(name, defaultValue = undefined) {const val = getOption(name);const intVal = parseInt(val);if (isNaN(intVal)) {- throw new Error(`Could not parse '${val}' into integer for option '${name}'`);+ if (defaultValue === undefined) {- throw new Error(`Could not parse "${val}" into integer for option "${name}"`);++ throw new Error(`Could not parse '${val}' into integer for option '${name}'`);+ } else {+ return defaultValue;+ }}return intVal;