| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | import utils from "./utils.js"; | 
					
						
							| 
									
										
										
										
											2019-11-21 21:12:07 +01:00
										 |  |  | import dateNoteService from "./date_notes.js"; | 
					
						
							| 
									
										
										
										
											2019-11-23 23:06:25 +01:00
										 |  |  | import hoistedNoteService from "./hoisted_note.js"; | 
					
						
							| 
									
										
										
										
											2019-12-20 20:13:21 +01:00
										 |  |  | import server from "./server.js"; | 
					
						
							| 
									
										
										
										
											2020-01-12 11:15:23 +01:00
										 |  |  | import appContext from "./app_context.js"; | 
					
						
							| 
									
										
										
										
											2020-01-21 22:54:16 +01:00
										 |  |  | import Component from "../widgets/component.js"; | 
					
						
							| 
									
										
										
										
											2020-02-28 00:11:34 +01:00
										 |  |  | import toastService from "./toast.js"; | 
					
						
							| 
									
										
										
										
											2020-03-01 11:53:02 +01:00
										 |  |  | import noteCreateService from "./note_create.js"; | 
					
						
							| 
									
										
										
										
											2020-03-17 21:39:26 +01:00
										 |  |  | import ws from "./ws.js"; | 
					
						
							| 
									
										
										
										
											2020-05-05 23:58:52 +02:00
										 |  |  | import bundleService from "./bundle.js"; | 
					
						
							| 
									
										
										
										
											2019-08-20 21:40:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 22:54:16 +01:00
										 |  |  | export default class Entrypoints extends Component { | 
					
						
							| 
									
										
										
										
											2020-02-27 10:03:14 +01:00
										 |  |  |     constructor() { | 
					
						
							|  |  |  |         super(); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-01 11:04:42 +01:00
										 |  |  |         if (jQuery.hotkeys) { | 
					
						
							|  |  |  |             // hot keys are active also inside inputs and content editables
 | 
					
						
							|  |  |  |             jQuery.hotkeys.options.filterInputAcceptingElements = false; | 
					
						
							|  |  |  |             jQuery.hotkeys.options.filterContentEditable = false; | 
					
						
							|  |  |  |             jQuery.hotkeys.options.filterTextInputs = false; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-02-09 19:25:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 22:54:16 +01:00
										 |  |  |         $(document).on('click', "a[data-action='note-revision']", async event => { | 
					
						
							|  |  |  |             const linkEl = $(event.target); | 
					
						
							|  |  |  |             const noteId = linkEl.attr('data-note-path'); | 
					
						
							|  |  |  |             const noteRevisionId = linkEl.attr('data-note-revision-id'); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 22:54:16 +01:00
										 |  |  |             const attributesDialog = await import("../dialogs/note_revisions.js"); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 22:54:16 +01:00
										 |  |  |             attributesDialog.showNoteRevisionsDialog(noteId, noteRevisionId); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return false; | 
					
						
							| 
									
										
										
										
											2019-11-20 22:48:32 +01:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2018-12-10 20:44:50 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-28 21:52:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-16 19:54:11 +01:00
										 |  |  |     openDevToolsCommand() { | 
					
						
							| 
									
										
										
										
											2020-01-21 22:54:16 +01:00
										 |  |  |         if (utils.isElectron()) { | 
					
						
							| 
									
										
										
										
											2020-04-12 14:22:51 +02:00
										 |  |  |             utils.dynamicRequire('electron').remote.getCurrentWindow().toggleDevTools(); | 
					
						
							| 
									
										
										
										
											2020-01-21 22:54:16 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-06-02 13:02:20 -04:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-10-10 20:00:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-16 19:54:11 +01:00
										 |  |  |     findInTextCommand() { | 
					
						
							| 
									
										
										
										
											2020-01-22 20:48:56 +01:00
										 |  |  |         if (!utils.isElectron()) { | 
					
						
							|  |  |  |             return; | 
					
						
							| 
									
										
										
										
											2020-01-21 22:54:16 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-01-22 20:48:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-12 14:22:51 +02:00
										 |  |  |         const {remote} = utils.dynamicRequire('electron'); | 
					
						
							|  |  |  |         const {FindInPage} = utils.dynamicRequire('electron-find'); | 
					
						
							| 
									
										
										
										
											2020-01-22 20:48:56 +01:00
										 |  |  |         const findInPage = new FindInPage(remote.getCurrentWebContents(), { | 
					
						
							|  |  |  |             offsetTop: 10, | 
					
						
							|  |  |  |             offsetRight: 10, | 
					
						
							|  |  |  |             boxBgColor: 'var(--main-background-color)', | 
					
						
							|  |  |  |             boxShadowColor: '#000', | 
					
						
							|  |  |  |             inputColor: 'var(--input-text-color)', | 
					
						
							|  |  |  |             inputBgColor: 'var(--input-background-color)', | 
					
						
							|  |  |  |             inputFocusColor: '#555', | 
					
						
							|  |  |  |             textColor: 'var(--main-text-color)', | 
					
						
							|  |  |  |             textHoverBgColor: '#555', | 
					
						
							|  |  |  |             caseSelectedColor: 'var(--main-border-color)' | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2020-03-16 22:14:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         findInPage.openFindWindow(); | 
					
						
							| 
									
										
										
										
											2020-01-21 22:54:16 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-10-10 20:00:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-16 19:54:11 +01:00
										 |  |  |     async createNoteIntoDayNoteCommand() { | 
					
						
							| 
									
										
										
										
											2019-11-24 21:40:50 +01:00
										 |  |  |         const todayNote = await dateNoteService.getTodayNote(); | 
					
						
							| 
									
										
										
										
											2019-11-19 20:53:04 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-18 10:08:16 +01:00
										 |  |  |         const {note} = await server.post(`notes/${todayNote.noteId}/children?target=into`, { | 
					
						
							| 
									
										
										
										
											2020-03-17 21:39:26 +01:00
										 |  |  |             title: 'new note', | 
					
						
							| 
									
										
										
										
											2020-03-18 10:08:16 +01:00
										 |  |  |             content: '', | 
					
						
							|  |  |  |             type: 'text', | 
					
						
							|  |  |  |             isProtected: todayNote.isProtected | 
					
						
							| 
									
										
										
										
											2019-11-21 21:12:07 +01:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2019-11-24 21:40:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-17 21:39:26 +01:00
										 |  |  |         await ws.waitForMaxKnownSyncId(); | 
					
						
							| 
									
										
										
										
											2019-12-20 20:13:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-18 10:08:16 +01:00
										 |  |  |         await appContext.tabManager.openTabWithNote(note.noteId, true); | 
					
						
							| 
									
										
										
										
											2019-12-28 10:28:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-17 21:39:26 +01:00
										 |  |  |         appContext.triggerEvent('focusAndSelectTitle'); | 
					
						
							| 
									
										
										
										
											2020-01-21 22:54:16 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-11-23 23:06:25 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-16 19:54:11 +01:00
										 |  |  |     async toggleNoteHoistingCommand() { | 
					
						
							| 
									
										
										
										
											2020-02-07 21:08:55 +01:00
										 |  |  |         const note = appContext.tabManager.getActiveTabNote(); | 
					
						
							| 
									
										
										
										
											2019-11-23 23:06:25 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-10 20:57:56 +01:00
										 |  |  |         const hoistedNoteId = hoistedNoteService.getHoistedNoteId(); | 
					
						
							|  |  |  |         if (note.noteId === hoistedNoteId) { | 
					
						
							|  |  |  |             hoistedNoteService.unhoist(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-03-15 22:11:42 +01:00
										 |  |  |         else if (note.type !== 'search') { | 
					
						
							|  |  |  |             hoistedNoteService.setHoistedNoteId(note.noteId); | 
					
						
							| 
									
										
										
										
											2020-02-10 20:57:56 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-01-21 22:54:16 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-11-19 23:02:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-16 19:54:11 +01:00
										 |  |  |     copyWithoutFormattingCommand() { | 
					
						
							| 
									
										
										
										
											2020-01-21 22:54:16 +01:00
										 |  |  |         utils.copySelectionToClipboard(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-01-22 19:41:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-16 19:54:11 +01:00
										 |  |  |     toggleFullscreenCommand() { | 
					
						
							| 
									
										
										
										
											2020-01-22 19:41:19 +01:00
										 |  |  |         if (utils.isElectron()) { | 
					
						
							| 
									
										
										
										
											2020-04-12 14:22:51 +02:00
										 |  |  |             const win = utils.dynamicRequire('electron').remote.getCurrentWindow(); | 
					
						
							| 
									
										
										
										
											2020-01-22 19:41:19 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if (win.isFullScreenable()) { | 
					
						
							|  |  |  |                 win.setFullScreen(!win.isFullScreen()); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             // outside of electron this is handled by the browser
 | 
					
						
							|  |  |  |             this.$widget.find(".toggle-fullscreen-button").hide(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-16 19:54:11 +01:00
										 |  |  |     toggleZenModeCommand() { | 
					
						
							| 
									
										
										
										
											2020-01-22 19:41:19 +01:00
										 |  |  |         if (!this.zenModeActive) { | 
					
						
							|  |  |  |             $(".hide-in-zen-mode,.gutter").addClass("hidden-by-zen-mode"); | 
					
						
							| 
									
										
										
										
											2020-03-01 19:16:30 +01:00
										 |  |  |             $("#root-widget").addClass("zen-mode"); | 
					
						
							| 
									
										
										
										
											2020-01-22 19:41:19 +01:00
										 |  |  |             this.zenModeActive = true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             // not hiding / showing explicitly since element might be hidden also for other reasons
 | 
					
						
							|  |  |  |             $(".hide-in-zen-mode,.gutter").removeClass("hidden-by-zen-mode"); | 
					
						
							| 
									
										
										
										
											2020-03-01 19:16:30 +01:00
										 |  |  |             $("#root-widget").removeClass("zen-mode"); | 
					
						
							| 
									
										
										
										
											2020-01-22 19:41:19 +01:00
										 |  |  |             this.zenModeActive = false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-16 19:54:11 +01:00
										 |  |  |     reloadFrontendAppCommand() { | 
					
						
							| 
									
										
										
										
											2020-01-22 19:41:19 +01:00
										 |  |  |         utils.reloadApp(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-16 19:54:11 +01:00
										 |  |  |     logoutCommand() { | 
					
						
							| 
									
										
										
										
											2020-01-22 19:41:19 +01:00
										 |  |  |         const $logoutForm = $('<form action="logout" method="POST">') | 
					
						
							|  |  |  |             .append($(`<input type="hidden" name="_csrf" value="${glob.csrfToken}"/>`)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $("body").append($logoutForm); | 
					
						
							|  |  |  |         $logoutForm.trigger('submit'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-16 19:54:11 +01:00
										 |  |  |     backInNoteHistoryCommand() { | 
					
						
							| 
									
										
										
										
											2020-03-17 21:15:57 +01:00
										 |  |  |         if (utils.isElectron()) { | 
					
						
							| 
									
										
										
										
											2020-03-17 21:39:26 +01:00
										 |  |  |             // standard JS version does not work completely correctly in electron
 | 
					
						
							| 
									
										
										
										
											2020-04-12 14:22:51 +02:00
										 |  |  |             const webContents = utils.dynamicRequire('electron').remote.getCurrentWebContents(); | 
					
						
							| 
									
										
										
										
											2020-03-17 21:15:57 +01:00
										 |  |  |             const activeIndex = parseInt(webContents.getActiveIndex()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             webContents.goToIndex(activeIndex - 1); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             window.history.back(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-01-22 19:41:19 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-08 17:17:18 +01:00
										 |  |  |     forwardInNoteHistoryCommand() { | 
					
						
							| 
									
										
										
										
											2020-03-17 21:15:57 +01:00
										 |  |  |         if (utils.isElectron()) { | 
					
						
							| 
									
										
										
										
											2020-03-17 21:39:26 +01:00
										 |  |  |             // standard JS version does not work completely correctly in electron
 | 
					
						
							| 
									
										
										
										
											2020-04-12 14:22:51 +02:00
										 |  |  |             const webContents = utils.dynamicRequire('electron').remote.getCurrentWebContents(); | 
					
						
							| 
									
										
										
										
											2020-03-17 21:15:57 +01:00
										 |  |  |             const activeIndex = parseInt(webContents.getActiveIndex()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             webContents.goToIndex(activeIndex + 1); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             window.history.forward(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-01-22 19:41:19 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-02-28 00:11:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     async searchForResultsCommand({searchText}) { | 
					
						
							|  |  |  |         const response = await server.get('search/' + encodeURIComponent(searchText)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!response.success) { | 
					
						
							|  |  |  |             toastService.showError("Search failed.", 3000); | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.triggerEvent('searchResults', {results: response.results}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // have at least some feedback which is good especially in situations
 | 
					
						
							|  |  |  |         // when the result list does not change with a query
 | 
					
						
							|  |  |  |         toastService.showMessage("Search finished successfully."); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-03-01 11:53:02 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     async switchToDesktopVersionCommand() { | 
					
						
							|  |  |  |         utils.setCookie('trilium-device', 'desktop'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         utils.reloadApp(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     createTopLevelNoteCommand() { noteCreateService.createNewTopLevelNote(); } | 
					
						
							| 
									
										
										
										
											2020-05-05 19:30:03 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     async openInWindowCommand({notePath}) { | 
					
						
							|  |  |  |         if (utils.isElectron()) { | 
					
						
							|  |  |  |             const {ipcRenderer} = utils.dynamicRequire('electron'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             ipcRenderer.send('create-extra-window', {notePath}); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             const url = window.location.protocol + '//' + window.location.host + window.location.pathname + '?extra=1#' + notePath; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             window.open(url, '', 'width=1000,height=800'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async openNewWindowCommand() { | 
					
						
							|  |  |  |         this.openInWindowCommand({notePath: ''}); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-05-05 23:58:52 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     async runActiveNoteCommand() { | 
					
						
							|  |  |  |         const note = appContext.tabManager.getActiveTabNote(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // ctrl+enter is also used elsewhere so make sure we're running only when appropriate
 | 
					
						
							|  |  |  |         if (!note || note.type !== 'code') { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (note.mime.endsWith("env=frontend")) { | 
					
						
							|  |  |  |             await bundleService.getAndExecuteBundle(note.noteId); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (note.mime.endsWith("env=backend")) { | 
					
						
							|  |  |  |             await server.post('script/run/' + note.noteId); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         toastService.showMessage("Note executed"); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-01-22 19:41:19 +01:00
										 |  |  | } |