cleaned up app entry points...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-12-12 09:29:57 +03:00
parent af6f9e535f
commit 6659614212
6 changed files with 130 additions and 80 deletions

View File

@ -5,18 +5,16 @@
**********************************************************************/ **********************************************************************/
var requirejs_cfg = { var requirejs_cfg = {
baseUrl: // NOTE: this is really odd: running electron as a packed binary breaks
// electron... // requirejs' paths...
// NOTE: on electron v7+ the default seems to be '../', a bug? baseUrl: typeof(process) != 'undefined'
typeof(process) != 'undefined' && 'electron' in process.versions ? && process.versions.electron ?
document.baseURI (require.main ?
.replace(/^[a-zA-Z]+:\/\/\/?/, '') require.main.filename.split(/[\\\/]/g).slice(0, -1).join('/')
.split(/[#&]/)[0].split(/[\\\/]/g).slice(0, -1).join('/') : document.baseURI
// node... .replace(/^[a-zA-Z]+:\/\/\/?/, '')
: typeof(process) != 'undefined' ? .split(/[#&]/)[0].split(/[\\\/]/g).slice(0, -1).join('/'))
process.argv[1].split(/[\\\/]/g).slice(0, -1).join('/') : '.',
// everything else...
: './',
// XXX this does not work on direct filesystem access... // XXX this does not work on direct filesystem access...
//urlArgs: 'bust='+Date.now(), //urlArgs: 'bust='+Date.now(),
@ -62,20 +60,19 @@ var requirejs_cfg = {
if(typeof(require) != 'undefined'){ if(typeof(require) != 'undefined'){
requirejs_cfg.nodeRequire = require requirejs_cfg.nodeRequire = require }
//requirejs_cfg.baseUrl = __dirname
}
// XXX revise... // XXX revise...
if(typeof(require) != 'undefined' && typeof(global) != 'undefined'){ if(typeof(require) != 'undefined' && typeof(global) != 'undefined'){
global.requirejs = global.requirejs || require('requirejs') global.nodeRequire = require
} global.requirejs = global.requirejs || require('requirejs') }
requirejs.config(requirejs_cfg) requirejs.config(requirejs_cfg)
/********************************************************************** /**********************************************************************
* vim:set ts=4 sw=4 : */ * vim:set ts=4 sw=4 : */

View File

@ -18,6 +18,7 @@ var url = require('url')
var VERSION = require('./version').version var VERSION = require('./version').version
//--------------------------------------------------------------------- //---------------------------------------------------------------------
var app = electron.app var app = electron.app
@ -27,8 +28,9 @@ var BrowserWindow = electron.BrowserWindow
/*********************************************************************/ /*********************************************************************/
var win
// Splash window...
//
// XXX might be nice to show load progress on splash... // XXX might be nice to show load progress on splash...
function createSplash(){ function createSplash(){
// NOTE: this is done here as this does not depend on code loading, // NOTE: this is done here as this does not depend on code loading,
@ -74,11 +76,14 @@ function createSplash(){
: splash.show() }) }) : splash.show() }) })
return splash } return splash }
// Create main window...
//
// XXX get initial settings from config... // XXX get initial settings from config...
// XXX unify index.html and electron.html var WIN
function createWindow(){ function createWindow(){
// Create the browser window. // Create the browser window.
win = new BrowserWindow({ WIN = new BrowserWindow({
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
contextIsolation: false, contextIsolation: false,
@ -98,35 +103,46 @@ function createWindow(){
//autoHideMenuBar: true, //autoHideMenuBar: true,
}) })
// disable default menu... // disable default menu...
win.setMenu(null) WIN.setMenu(null)
win.loadURL(url.format({ WIN.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'), pathname: path.join(__dirname, 'index.html'),
//pathname: path.join(__dirname, 'electron.html'), //pathname: path.join(__dirname, 'electron.html'),
protocol: 'file:', protocol: 'file:',
slashes: true slashes: true
})) }))
// XXX HACK: pass this in a formal way... (???) // XXX HACK: pass this in a formal way... (???)
win.once('ready-to-show', WIN.once('ready-to-show',
function(){ global.readyToShow = true }) function(){ global.readyToShow = true })
win.on('closed', WIN.on('closed',
function(){ win = null }) function(){ WIN = null })
// devtools for different windows... // devtools for different windows...
//win.webContents.openDevTools() //WIN.webContents.openDevTools()
//win.openDevTools() //WIN.openDevTools()
return win } return WIN }
// Start the app...
//
function start(){
var _start = function(){
createSplash()
createWindow() }
// NOTE: by this time (arg parsing and stuff) the app may already be ready...
app.isReady() ?
_start()
: app.on('ready', _start) }
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// This will be called when Electron has finished initialization and is // On macOS it's common to re-create a window in the app when the
// ready to create browser windows. // dock icon is clicked and there are no other windows open.
// Some APIs can only be used after this event occurs. app.on('activate', function(){
app.on('ready', function(){ WIN === null
createSplash() && createWindow() })
createWindow() })
// Quit when all windows are closed. // Quit when all windows are closed.
// On macOS it is common for applications and their menu bar // On macOS it is common for applications and their menu bar
@ -135,12 +151,25 @@ app.on('window-all-closed', function(){
process.platform !== 'darwin' process.platform !== 'darwin'
&& app.quit() }) && app.quit() })
// 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.
// XXX needs testing... //---------------------------------------------------------------------
app.on('activate', function(){ // start things up...
win === null
&& createWindow() }) global.START_GUI = false
var argv1 = process.argv[1]
&& path.resolve(process.cwd(), process.argv[1])
;(process.argv.length > 2
|| (argv1 && argv1 != require.main.filename)) ?
// got some arguments -- trigger ig.js...
// XXX BUG: when running in a built app this will break with a require error...
(require('./ig')
&& global.START_GUI
&& start())
// start the viewer...
: start()

View File

@ -211,25 +211,28 @@ var CLIActions = actions.Actions({
}) })
.on('exit', function(){ .on('exit', function(){
that.stop() }) }], that.stop() }) }],
// XXX this is the wrong strategy...
// XXX move this to a feature that requires electron... // XXX move this to a feature that requires electron...
// ...and move electron to an optional dependency... // ...and move electron to an optional dependency...
// XXX should we require electron or npx electron???
startGUI: ['- System/Start viewer GUI', startGUI: ['- System/Start viewer GUI',
core.doc`
NOTE: this will not wait for the viewer to exit.`,
{cli: '@gui'}, {cli: '@gui'},
function(){ function(){
requirejs('child_process') // already in electron...
.spawn(requirejs('electron'), [ if(process.versions.electron){
pathlib.join( // XXX this feels hackish...
global.START_GUI = true
// launch gui...
} else {
requirejs('child_process')
.spawn(requirejs('electron'),
[ pathlib.join(
pathlib.dirname(nodeRequire.main.filename), pathlib.dirname(nodeRequire.main.filename),
'e.js') ]) 'e.js') ],
// XXX need to stop the process iff nothing { detached: true, }) } }],
// else is running, like repl...
// XXX feels hackish...
.on('exit', function(){
(!global.ig
|| global.ig.isStopped())
&& process.exit() })
this.__keep_running = true }],
/*/ XXX /*/ XXX
startWorker: ['- System/Start as worker', startWorker: ['- System/Start as worker',
{cli: '-worker'}, {cli: '-worker'},
@ -538,7 +541,6 @@ module.CLI = core.ImageGridFeatures.Feature({
// XXX // XXX
})() })()
// XXX not all promises in the system resolve strictly // XXX not all promises in the system resolve strictly
// after all the work is done, some resolve before that // after all the work is done, some resolve before that
// point and this calling process.exit() will interrupt // point and this calling process.exit() will interrupt

View File

@ -142,7 +142,9 @@ if(typeof(process) != 'undefined'){
runtime.node = true runtime.node = true
// Electron... // Electron...
if(process.versions['electron'] != null){ if(process.versions['electron'] != null
// node mode...
&& typeof(document) != 'undefined'){
runtime.electron = true runtime.electron = true
runtime.desktop = true runtime.desktop = true

View File

@ -572,9 +572,9 @@
"integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=" "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4="
}, },
"core-js": { "core-js": {
"version": "3.7.0", "version": "3.8.1",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.7.0.tgz", "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.8.1.tgz",
"integrity": "sha512-NwS7fI5M5B85EwpWuIwJN4i/fbisQUwLwiSNUWeXlkAZ0sbBjLEvLvFLf1uzAUV66PcEPt4xCGCmOZSxVf3xzA==", "integrity": "sha512-9Id2xHY1W7m8hCl8NkhQn5CufmF/WuR30BTRewvCXc1aZd3kMECwNZ69ndLbekKfakw9Rf2Xyc+QR6E7Gg+obg==",
"optional": true "optional": true
}, },
"core-util-is": { "core-util-is": {
@ -679,9 +679,9 @@
} }
}, },
"electron": { "electron": {
"version": "9.3.5", "version": "9.4.0",
"resolved": "https://registry.npmjs.org/electron/-/electron-9.3.5.tgz", "resolved": "https://registry.npmjs.org/electron/-/electron-9.4.0.tgz",
"integrity": "sha512-EPmDsp7sO0UPtw7nLD1ufse/nBskP+ifXzBgUg9psCUlapkzuwYi6pmLAzKLW/bVjwgyUKwh1OKWILWfOeLGcQ==", "integrity": "sha512-hOC4q0jkb+UDYZRy8vrZ1IANnq+jznZnbkD62OEo06nU+hIbp2IrwDRBNuSLmQ3cwZMVir0WSIA1qEVK0PkzGA==",
"requires": { "requires": {
"@electron/get": "^1.0.1", "@electron/get": "^1.0.1",
"@types/node": "^12.0.12", "@types/node": "^12.0.12",
@ -689,9 +689,9 @@
}, },
"dependencies": { "dependencies": {
"@types/node": { "@types/node": {
"version": "12.19.6", "version": "12.19.8",
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.6.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.8.tgz",
"integrity": "sha512-U2VopDdmBoYBmtm8Rz340mvvSz34VgX/K9+XCuckvcLGMkt3rbMX8soqFOikIPlPBc5lmw8By9NUK7bEFSBFlQ==" "integrity": "sha512-D4k2kNi0URNBxIRCb1khTnkWNHv8KSL1owPmS/K5e5t8B2GzMReY7AsJIY1BnP5KdlgC4rj9jk2IkDMasIE7xg=="
} }
} }
}, },
@ -990,10 +990,13 @@
}, },
"dependencies": { "dependencies": {
"semver": { "semver": {
"version": "7.3.2", "version": "7.3.4",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz", "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.4.tgz",
"integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==", "integrity": "sha512-tCfb2WLjqFAtXn4KEdxIhalnRtoKFN7nAwj0B3ZXCbQloV2tq5eDbcTmT68JJD3nRJq24/XgxtQKFIpQdtvmVw==",
"optional": true "optional": true,
"requires": {
"lru-cache": "^6.0.0"
}
} }
} }
}, },
@ -1124,9 +1127,9 @@
} }
}, },
"ig-argv": { "ig-argv": {
"version": "2.16.0", "version": "2.16.1",
"resolved": "https://registry.npmjs.org/ig-argv/-/ig-argv-2.16.0.tgz", "resolved": "https://registry.npmjs.org/ig-argv/-/ig-argv-2.16.1.tgz",
"integrity": "sha512-lWgUthK4CBpYJlaFaRmfaCVlZW4u4n/9QZAcTnutDAe5wT5UJ6nD+X/OJLgqU1suLP2H5OThGJtdDBNqwEPGOA==", "integrity": "sha512-fSgX86zTSRuMFaxGvbHK97/ASWgrYAnqLK/q32skXuZ8eDM2ZyM84kHbdgMqd3FrZS4DoyY5fA2TXD9AfWcE/w==",
"requires": { "requires": {
"ig-object": "^5.2.6" "ig-object": "^5.2.6"
} }
@ -1288,9 +1291,9 @@
} }
}, },
"less": { "less": {
"version": "3.12.2", "version": "3.13.0",
"resolved": "https://registry.npmjs.org/less/-/less-3.12.2.tgz", "resolved": "https://registry.npmjs.org/less/-/less-3.13.0.tgz",
"integrity": "sha512-+1V2PCMFkL+OIj2/HrtrvZw0BC0sYLMICJfbQjuj/K8CEnlrFX6R5cKKgzzttsZDHyxQNL1jqMREjKN3ja/E3Q==", "integrity": "sha512-uPhr9uoSGVKKYVGz0rXcYBK1zjwcIWRGcbnSgNt66XuIZYrYPaQiS+LeUOvqedBwrwdBYYaLqSff5ytGYuT7rA==",
"dev": true, "dev": true,
"requires": { "requires": {
"errno": "^0.1.1", "errno": "^0.1.1",
@ -1339,6 +1342,23 @@
"resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-1.0.1.tgz", "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-1.0.1.tgz",
"integrity": "sha512-G2Lj61tXDnVFFOi8VZds+SoQjtQC3dgokKdDG2mTm1tx4m50NUHBOZSBwQQHyy0V12A0JTG4icfZQH+xPyh8VA==" "integrity": "sha512-G2Lj61tXDnVFFOi8VZds+SoQjtQC3dgokKdDG2mTm1tx4m50NUHBOZSBwQQHyy0V12A0JTG4icfZQH+xPyh8VA=="
}, },
"lru-cache": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
"optional": true,
"requires": {
"yallist": "^4.0.0"
},
"dependencies": {
"yallist": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
"optional": true
}
}
},
"make-dir": { "make-dir": {
"version": "2.1.0", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-2.1.0.tgz", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-2.1.0.tgz",
@ -1484,9 +1504,9 @@
"integrity": "sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg==" "integrity": "sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg=="
}, },
"native-request": { "native-request": {
"version": "1.0.7", "version": "1.0.8",
"resolved": "https://registry.npmjs.org/native-request/-/native-request-1.0.7.tgz", "resolved": "https://registry.npmjs.org/native-request/-/native-request-1.0.8.tgz",
"integrity": "sha512-9nRjinI9bmz+S7dgNtf4A70+/vPhnd+2krGpy4SUlADuOuSa24IDkNaZ+R/QT1wQ6S8jBdi6wE7fLekFZNfUpQ==", "integrity": "sha512-vU2JojJVelUGp6jRcLwToPoWGxSx23z/0iX+I77J3Ht17rf2INGjrhOoQnjVo60nQd8wVsgzKkPfRXBiVdD2ag==",
"dev": true, "dev": true,
"optional": true "optional": true
}, },

View File

@ -22,7 +22,7 @@
"async-json": "0.0.2", "async-json": "0.0.2",
"cli-progress": "^3.8.2", "cli-progress": "^3.8.2",
"colors": "^1.4.0", "colors": "^1.4.0",
"electron": "^9.3.5", "electron": "^9.4.0",
"exif-reader": "^1.0.3", "exif-reader": "^1.0.3",
"exiftool": "^0.0.3", "exiftool": "^0.0.3",
"fs-extra": "^7.0.1", "fs-extra": "^7.0.1",
@ -31,7 +31,7 @@
"glob": "^7.1.6", "glob": "^7.1.6",
"guarantee-events": "^1.0.0", "guarantee-events": "^1.0.0",
"ig-actions": "^3.24.22", "ig-actions": "^3.24.22",
"ig-argv": "^2.16.0", "ig-argv": "^2.16.1",
"ig-features": "^3.4.2", "ig-features": "^3.4.2",
"ig-object": "^5.4.12", "ig-object": "^5.4.12",
"ig-types": "^5.0.40", "ig-types": "^5.0.40",
@ -55,7 +55,7 @@
"devDependencies": { "devDependencies": {
"asar": "^3.0.1", "asar": "^3.0.1",
"electron-rebuild": "^1.11.0", "electron-rebuild": "^1.11.0",
"less": "^3.12.2" "less": "^3.13.0"
}, },
"bin": { "bin": {
"ig": "ig.js" "ig": "ig.js"