| 
									
										
										
										
											2017-10-20 23:43:20 -04:00
										 |  |  | 'use strict'; | 
					
						
							| 
									
										
										
										
											2018-01-28 22:18:14 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-20 23:43:20 -04:00
										 |  |  | const electron = require('electron'); | 
					
						
							| 
									
										
										
										
											2017-10-21 00:19:13 -04:00
										 |  |  | const path = require('path'); | 
					
						
							| 
									
										
										
										
											2018-01-31 08:03:25 -05:00
										 |  |  | const config = require('./src/services/config'); | 
					
						
							| 
									
										
										
										
											2018-01-12 20:05:17 -05:00
										 |  |  | const url = require("url"); | 
					
						
							| 
									
										
										
										
											2017-10-20 23:43:20 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | const app = electron.app; | 
					
						
							| 
									
										
										
										
											2018-02-12 23:53:00 -05:00
										 |  |  | const globalShortcut = electron.globalShortcut; | 
					
						
							|  |  |  | const clipboard = electron.clipboard; | 
					
						
							| 
									
										
										
										
											2017-10-20 23:43:20 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Adds debug features like hotkeys for triggering dev tools and reload
 | 
					
						
							|  |  |  | require('electron-debug')(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Prevent window being garbage collected
 | 
					
						
							|  |  |  | let mainWindow; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function onClosed() { | 
					
						
							|  |  |  |     // Dereference the window
 | 
					
						
							|  |  |  |     // For multiple windows store them in an array
 | 
					
						
							|  |  |  |     mainWindow = null; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function createMainWindow() { | 
					
						
							|  |  |  |     const win = new electron.BrowserWindow({ | 
					
						
							|  |  |  |         width: 1200, | 
					
						
							| 
									
										
										
										
											2017-10-21 00:19:13 -04:00
										 |  |  |         height: 900, | 
					
						
							| 
									
										
										
										
											2017-12-27 17:39:41 -05:00
										 |  |  |         title: 'Trilium Notes', | 
					
						
							| 
									
										
										
										
											2018-01-31 22:39:30 -05:00
										 |  |  |         icon: path.join(__dirname, 'src/public/images/app-icons/png/256x256.png') | 
					
						
							| 
									
										
										
										
											2017-10-20 23:43:20 -04:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-20 19:59:42 -05:00
										 |  |  |     const port = config['Network']['port'] || '3000'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-20 23:43:20 -04:00
										 |  |  |     win.setMenu(null); | 
					
						
							| 
									
										
										
										
											2017-11-20 19:59:42 -05:00
										 |  |  |     win.loadURL('http://localhost:' + port); | 
					
						
							| 
									
										
										
										
											2017-10-20 23:43:20 -04:00
										 |  |  |     win.on('closed', onClosed); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     win.webContents.on('new-window', (e, url) => { | 
					
						
							|  |  |  |         if (url !== mainWindow.webContents.getURL()) { | 
					
						
							|  |  |  |             e.preventDefault(); | 
					
						
							|  |  |  |             require('electron').shell.openExternal(url); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-12 18:42:00 -05:00
										 |  |  |     // prevent drag & drop to navigate away from trilium
 | 
					
						
							| 
									
										
										
										
											2018-01-12 20:05:17 -05:00
										 |  |  |     win.webContents.on('will-navigate', (ev, targetUrl) => { | 
					
						
							|  |  |  |         const parsedUrl = url.parse(targetUrl); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // we still need to allow internal redirects from setup and migration pages
 | 
					
						
							|  |  |  |         if (parsedUrl.hostname !== 'localhost' || (parsedUrl.path && parsedUrl.path !== '/')) { | 
					
						
							|  |  |  |             ev.preventDefault(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-01-12 18:42:00 -05:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-20 23:43:20 -04:00
										 |  |  |     return win; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | app.on('window-all-closed', () => { | 
					
						
							|  |  |  |     if (process.platform !== 'darwin') { | 
					
						
							|  |  |  |         app.quit(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | app.on('activate', () => { | 
					
						
							|  |  |  |     if (!mainWindow) { | 
					
						
							|  |  |  |         mainWindow = createMainWindow(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | app.on('ready', () => { | 
					
						
							|  |  |  |     mainWindow = createMainWindow(); | 
					
						
							| 
									
										
										
										
											2018-02-12 23:53:00 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const date_notes = require('./src/services/date_notes'); | 
					
						
							|  |  |  |     const utils = require('./src/services/utils'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     globalShortcut.register('CommandOrControl+Alt+P', async () => { | 
					
						
							|  |  |  |         const parentNoteId = await date_notes.getDateNoteId(utils.nowDate()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // window may be hidden / not in focus
 | 
					
						
							|  |  |  |         mainWindow.focus(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         mainWindow.webContents.send('create-sub-note', JSON.stringify({ | 
					
						
							|  |  |  |             parentNoteId: parentNoteId, | 
					
						
							|  |  |  |             content: '' | 
					
						
							|  |  |  |         })); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     globalShortcut.register('CommandOrControl+Alt+C', async () => { | 
					
						
							|  |  |  |         const parentNoteId = await date_notes.getDateNoteId(utils.nowDate()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // window may be hidden / not in focus
 | 
					
						
							|  |  |  |         mainWindow.focus(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         let content = clipboard.readText(); | 
					
						
							|  |  |  |         content = content.replace(/(\r\n|\n)/g, "<p>"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         mainWindow.webContents.send('create-sub-note', JSON.stringify({ | 
					
						
							|  |  |  |             parentNoteId: parentNoteId, | 
					
						
							|  |  |  |             content: content | 
					
						
							|  |  |  |         })); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | app.on('will-quit', () => { | 
					
						
							|  |  |  |     globalShortcut.unregisterAll(); | 
					
						
							| 
									
										
										
										
											2017-10-20 23:43:20 -04:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-31 08:03:25 -05:00
										 |  |  | require('./src/www'); |