diff --git a/src/public/app/components/root_command_executor.js b/src/public/app/components/root_command_executor.js index 63d86ae46..2f46e0bb7 100644 --- a/src/public/app/components/root_command_executor.js +++ b/src/public/app/components/root_command_executor.js @@ -54,13 +54,11 @@ export default class RootCommandExecutor extends Component { openService.openNoteExternally(noteId, mime); } } - + openNoteCustomCommand() { const noteId = appContext.tabManager.getActiveContextNoteId(); - const mime = appContext.tabManager.getActiveContextNoteMime() - if (noteId) { - openService.openNoteCustom(noteId, mime); + openService.openNoteCustom(noteId); } } diff --git a/src/public/app/services/open.js b/src/public/app/services/open.js index 9d6f3c931..177db6459 100644 --- a/src/public/app/services/open.js +++ b/src/public/app/services/open.js @@ -47,61 +47,66 @@ async function openNoteExternally(noteId, mime) { } } -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`); diff --git a/src/public/app/widgets/buttons/note_actions.js b/src/public/app/widgets/buttons/note_actions.js index de2ad33f9..b660c7da2 100644 --- a/src/public/app/widgets/buttons/note_actions.js +++ b/src/public/app/widgets/buttons/note_actions.js @@ -29,7 +29,7 @@ const TPL = ` Search in note Note source Open note externally - Open note custom (beta) + Open note custom Import files Export note Delete note @@ -90,7 +90,7 @@ export default class NoteActionsWidget extends NoteContextAwareWidget { this.$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 } toggleDisabled($el, enable) {