| 
									
										
										
										
											2017-07-26 21:10:28 +03:00
										 |  |  | #!/usr/bin/env node
 | 
					
						
							|  |  |  | /********************************************************************** | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * ImageGrid.Viewer Electron entry point... | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2020-12-11 06:24:22 +03:00
										 |  |  | * NOTE: this is kept as simple as possible to speed up initial loading. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2017-07-26 21:10:28 +03:00
										 |  |  | **********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-14 20:06:58 +03:00
										 |  |  | // Global scope pollution test...
 | 
					
						
							| 
									
										
										
										
											2020-12-15 05:08:06 +03:00
										 |  |  | if(process.env.IMAGEGRID_DEBUG){ | 
					
						
							|  |  |  | 	global.__global = {...global} | 
					
						
							|  |  |  | 	global.scopeDiff = function(cur=global, base=__global){ | 
					
						
							|  |  |  | 		return Object.keys(cur) | 
					
						
							|  |  |  | 			.filter(function(k){ return base[k] !== cur[k] }) | 
					
						
							|  |  |  | 			.reduce(function(res, k){ | 
					
						
							|  |  |  | 				res[k] = cur[k] | 
					
						
							|  |  |  | 				return res }, {})} } | 
					
						
							| 
									
										
										
										
											2020-12-14 20:06:58 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-29 04:59:50 +03:00
										 |  |  | //require('v8-compile-cache')
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-26 21:10:28 +03:00
										 |  |  | var electron = require('electron') | 
					
						
							|  |  |  | var path = require('path') | 
					
						
							|  |  |  | var url = require('url') | 
					
						
							| 
									
										
										
										
											2020-08-27 17:09:04 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-13 08:33:03 +03:00
										 |  |  | var VERSION = require('./version').version | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-26 21:10:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-12 09:29:57 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-01 04:53:36 +03:00
										 |  |  | //---------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-11 06:24:22 +03:00
										 |  |  | var app = electron.app | 
					
						
							|  |  |  | var BrowserWindow = electron.BrowserWindow | 
					
						
							| 
									
										
										
										
											2020-06-20 03:48:18 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-13 04:12:12 +03:00
										 |  |  | // 
 | 
					
						
							|  |  |  | global.ELECTRON_PACKAGED = app.isPackaged | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // used to let e.js know that the CLI wants to start the GUI..
 | 
					
						
							|  |  |  | global.START_GUI = false | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-20 03:48:18 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-26 21:10:28 +03:00
										 |  |  | /*********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-12 09:29:57 +03:00
										 |  |  | // Splash window...
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2020-12-11 06:24:22 +03:00
										 |  |  | // XXX might be nice to show load progress on splash...
 | 
					
						
							| 
									
										
										
										
											2019-01-15 02:25:00 +03:00
										 |  |  | function createSplash(){ | 
					
						
							| 
									
										
										
										
											2019-01-13 08:04:29 +03:00
										 |  |  | 	// NOTE: this is done here as this does not depend on code loading, 
 | 
					
						
							|  |  |  | 	// 		thus showing the splash significantly faster...
 | 
					
						
							| 
									
										
										
										
											2019-01-13 07:09:00 +03:00
										 |  |  | 	var splash = global.splash = new BrowserWindow({ | 
					
						
							|  |  |  | 		// let the window to get ready before we show it to the user...
 | 
					
						
							|  |  |  | 		show: false, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		transparent: true, | 
					
						
							|  |  |  | 		frame: false, | 
					
						
							|  |  |  | 		center: true, | 
					
						
							| 
									
										
										
										
											2019-05-04 17:08:40 +03:00
										 |  |  | 		width: 840,  | 
					
						
							|  |  |  | 		height: 540, | 
					
						
							| 
									
										
										
										
											2019-01-13 07:09:00 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		alwaysOnTop: true, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		resizable: false, | 
					
						
							|  |  |  | 		movable: false, | 
					
						
							|  |  |  | 		minimizable: false, | 
					
						
							|  |  |  | 		maximizable: false, | 
					
						
							|  |  |  | 		fullscreenable: false, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		autoHideMenuBar: true, | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | 	splash.loadURL(url.format({ | 
					
						
							|  |  |  | 		pathname: path.join(__dirname, 'splash.html'), | 
					
						
							|  |  |  | 		protocol: 'file:', | 
					
						
							|  |  |  | 		slashes: true | 
					
						
							|  |  |  | 	})) | 
					
						
							|  |  |  | 	splash.once('ready-to-show', function(){ | 
					
						
							| 
									
										
										
										
											2019-01-13 08:04:29 +03:00
										 |  |  | 		this.webContents | 
					
						
							|  |  |  | 			// see if the splash screen is disabled...
 | 
					
						
							|  |  |  | 			.executeJavaScript('localStorage.disableSplashScreen') | 
					
						
							|  |  |  | 			.then(function(disabled){ | 
					
						
							| 
									
										
										
										
											2019-01-14 10:17:58 +03:00
										 |  |  | 				// update version...
 | 
					
						
							|  |  |  | 				disabled | 
					
						
							|  |  |  | 					|| splash.webContents | 
					
						
							|  |  |  | 						.executeJavaScript( | 
					
						
							|  |  |  | 							`document.getElementById("version").innerText = "${VERSION}"`) | 
					
						
							|  |  |  | 				// show/destroy..
 | 
					
						
							| 
									
										
										
										
											2019-01-13 08:04:29 +03:00
										 |  |  | 				disabled ? | 
					
						
							|  |  |  | 					splash.destroy() | 
					
						
							|  |  |  | 					: splash.show() }) }) | 
					
						
							| 
									
										
										
										
											2020-12-11 06:24:22 +03:00
										 |  |  | 	return splash } | 
					
						
							| 
									
										
										
										
											2019-01-13 07:09:00 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-12 09:29:57 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Create main window...
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2020-12-11 06:24:22 +03:00
										 |  |  | // XXX get initial settings from config...
 | 
					
						
							| 
									
										
										
										
											2020-12-12 09:29:57 +03:00
										 |  |  | var WIN | 
					
						
							| 
									
										
										
										
											2019-01-15 02:25:00 +03:00
										 |  |  | function createWindow(){ | 
					
						
							| 
									
										
										
										
											2017-07-26 21:10:28 +03:00
										 |  |  | 	// Create the browser window.
 | 
					
						
							| 
									
										
										
										
											2020-12-12 09:29:57 +03:00
										 |  |  | 	WIN = new BrowserWindow({ | 
					
						
							| 
									
										
										
										
											2019-01-14 20:52:27 +03:00
										 |  |  | 		webPreferences: { | 
					
						
							|  |  |  | 			nodeIntegration: true, | 
					
						
							| 
									
										
										
										
											2020-12-15 05:36:37 +03:00
										 |  |  | 			nodeIntegrationInWorker: true, | 
					
						
							| 
									
										
										
										
											2020-08-30 19:55:01 +03:00
										 |  |  | 			contextIsolation: false, | 
					
						
							| 
									
										
										
										
											2020-08-31 00:02:33 +03:00
										 |  |  | 			enableRemoteModule: true, | 
					
						
							| 
									
										
										
										
											2019-01-14 20:52:27 +03:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-11 06:24:22 +03:00
										 |  |  | 		// let the window get ready before we show it to the user...
 | 
					
						
							| 
									
										
										
										
											2017-11-03 02:12:38 +03:00
										 |  |  | 		show: false, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-06 18:32:29 +03:00
										 |  |  | 		backgroundColor: '#333333', | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-04 17:07:22 +03:00
										 |  |  | 		width: 800,  | 
					
						
							|  |  |  | 		height: 600, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		fullscreenable: true, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 02:12:38 +03:00
										 |  |  | 		//autoHideMenuBar: true,
 | 
					
						
							| 
									
										
										
										
											2017-10-04 17:07:22 +03:00
										 |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2017-11-03 02:12:38 +03:00
										 |  |  | 	// disable default menu...
 | 
					
						
							| 
									
										
										
										
											2020-12-12 09:29:57 +03:00
										 |  |  | 	WIN.setMenu(null) | 
					
						
							|  |  |  | 	WIN.loadURL(url.format({ | 
					
						
							| 
									
										
										
										
											2020-12-11 06:24:22 +03:00
										 |  |  | 		pathname: path.join(__dirname, 'index.html'), | 
					
						
							| 
									
										
										
										
											2017-07-26 21:10:28 +03:00
										 |  |  | 		protocol: 'file:', | 
					
						
							| 
									
										
										
										
											2020-12-12 22:41:49 +03:00
										 |  |  | 		slashes: true, | 
					
						
							| 
									
										
										
										
											2017-07-26 21:10:28 +03:00
										 |  |  | 	})) | 
					
						
							| 
									
										
										
										
											2020-12-11 06:24:22 +03:00
										 |  |  | 	// XXX HACK: pass this in a formal way... (???)
 | 
					
						
							| 
									
										
										
										
											2020-12-12 09:29:57 +03:00
										 |  |  | 	WIN.once('ready-to-show',  | 
					
						
							| 
									
										
										
										
											2020-12-11 06:24:22 +03:00
										 |  |  | 		function(){ global.readyToShow = true }) | 
					
						
							| 
									
										
										
										
											2020-12-12 09:29:57 +03:00
										 |  |  | 	WIN.on('closed',  | 
					
						
							|  |  |  | 		function(){ WIN = null }) | 
					
						
							| 
									
										
										
										
											2017-07-26 21:10:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-11 06:24:22 +03:00
										 |  |  | 	// devtools for different windows...
 | 
					
						
							| 
									
										
										
										
											2021-10-13 23:27:42 +03:00
										 |  |  | 	process.env.IMAGEGRID_DEBUG | 
					
						
							|  |  |  | 		&& WIN.openDevTools({mode: 'undocked'}) | 
					
						
							| 
									
										
										
										
											2021-05-02 23:27:09 +03:00
										 |  |  | 	//WIN.webContents.openDevTools({mode: 'undocked'})
 | 
					
						
							| 
									
										
										
										
											2020-12-12 09:29:57 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return WIN } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-26 21:10:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-12 09:29:57 +03:00
										 |  |  | // Start the app...
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | function start(){ | 
					
						
							|  |  |  | 	var _start = function(){ | 
					
						
							|  |  |  | 		createSplash() | 
					
						
							|  |  |  | 		createWindow() } | 
					
						
							| 
									
										
										
										
											2020-12-20 06:12:47 +03:00
										 |  |  | 	// NOTE: by this time (arg parsing and stuff) the app may already 
 | 
					
						
							|  |  |  | 	//		be ready...
 | 
					
						
							| 
									
										
										
										
											2020-12-12 09:29:57 +03:00
										 |  |  | 	app.isReady() ? | 
					
						
							|  |  |  | 		_start() | 
					
						
							|  |  |  | 		: app.on('ready', _start) } | 
					
						
							| 
									
										
										
										
											2017-07-26 21:10:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 03:22:02 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //---------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-12 09:29:57 +03:00
										 |  |  | // On macOS it's common to re-create a window in the app when the
 | 
					
						
							|  |  |  | // dock icon is clicked and there are no other windows open.
 | 
					
						
							|  |  |  | app.on('activate', function(){ | 
					
						
							|  |  |  | 	WIN === null | 
					
						
							|  |  |  | 		&& createWindow() })  | 
					
						
							| 
									
										
										
										
											2017-07-26 21:10:28 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Quit when all windows are closed.
 | 
					
						
							| 
									
										
										
										
											2019-01-15 02:25:00 +03:00
										 |  |  | // On macOS it is common for applications and their menu bar
 | 
					
						
							|  |  |  | // to stay active until the user quits explicitly with Cmd + Q
 | 
					
						
							|  |  |  | app.on('window-all-closed', function(){ | 
					
						
							| 
									
										
										
										
											2017-07-26 21:10:28 +03:00
										 |  |  | 	process.platform !== 'darwin' | 
					
						
							| 
									
										
										
										
											2020-09-02 01:40:26 +03:00
										 |  |  | 		&& app.quit() }) | 
					
						
							| 
									
										
										
										
											2017-07-26 21:10:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-12 09:29:57 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //---------------------------------------------------------------------
 | 
					
						
							|  |  |  | // start things up...
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-13 04:12:12 +03:00
										 |  |  | ;(ELECTRON_PACKAGED ?  | 
					
						
							|  |  |  | 		process.argv.length > 1  | 
					
						
							|  |  |  | 		: process.argv.length > 2) ? | 
					
						
							|  |  |  | 	// got some arguments -- delegate to ig.js...
 | 
					
						
							| 
									
										
										
										
											2020-12-12 09:29:57 +03:00
										 |  |  | 	(require('./ig')  | 
					
						
							|  |  |  | 		&& global.START_GUI  | 
					
						
							|  |  |  | 		&& start()) | 
					
						
							|  |  |  | 	// start the viewer...
 | 
					
						
							|  |  |  | 	: start() | 
					
						
							| 
									
										
										
										
											2017-07-26 21:10:28 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-11 06:24:22 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-26 21:10:28 +03:00
										 |  |  | /********************************************************************** | 
					
						
							|  |  |  | * vim:set ts=4 sw=4 :                                                */ |