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

View File

@ -18,6 +18,7 @@ var url = require('url')
var VERSION = require('./version').version
//---------------------------------------------------------------------
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...
function createSplash(){
// NOTE: this is done here as this does not depend on code loading,
@ -74,11 +76,14 @@ function createSplash(){
: splash.show() }) })
return splash }
// Create main window...
//
// XXX get initial settings from config...
// XXX unify index.html and electron.html
var WIN
function createWindow(){
// Create the browser window.
win = new BrowserWindow({
WIN = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
@ -98,35 +103,46 @@ function createWindow(){
//autoHideMenuBar: true,
})
// disable default menu...
win.setMenu(null)
win.loadURL(url.format({
WIN.setMenu(null)
WIN.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
//pathname: path.join(__dirname, 'electron.html'),
protocol: 'file:',
slashes: true
}))
// XXX HACK: pass this in a formal way... (???)
win.once('ready-to-show',
WIN.once('ready-to-show',
function(){ global.readyToShow = true })
win.on('closed',
function(){ win = null })
WIN.on('closed',
function(){ WIN = null })
// devtools for different windows...
//win.webContents.openDevTools()
//win.openDevTools()
//WIN.webContents.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
// ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', function(){
createSplash()
createWindow() })
// 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() })
// Quit when all windows are closed.
// On macOS it is common for applications and their menu bar
@ -135,12 +151,25 @@ app.on('window-all-closed', function(){
process.platform !== 'darwin'
&& 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(){
win === null
&& createWindow() })
//---------------------------------------------------------------------
// start things up...
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(){
that.stop() }) }],
// XXX this is the wrong strategy...
// XXX move this to a feature that requires electron...
// ...and move electron to an optional dependency...
// XXX should we require electron or npx electron???
startGUI: ['- System/Start viewer GUI',
core.doc`
NOTE: this will not wait for the viewer to exit.`,
{cli: '@gui'},
function(){
requirejs('child_process')
.spawn(requirejs('electron'), [
pathlib.join(
// already in electron...
if(process.versions.electron){
// XXX this feels hackish...
global.START_GUI = true
// launch gui...
} else {
requirejs('child_process')
.spawn(requirejs('electron'),
[ pathlib.join(
pathlib.dirname(nodeRequire.main.filename),
'e.js') ])
// XXX need to stop the process iff nothing
// else is running, like repl...
// XXX feels hackish...
.on('exit', function(){
(!global.ig
|| global.ig.isStopped())
&& process.exit() })
this.__keep_running = true }],
'e.js') ],
{ detached: true, }) } }],
/*/ XXX
startWorker: ['- System/Start as worker',
{cli: '-worker'},
@ -538,7 +541,6 @@ module.CLI = core.ImageGridFeatures.Feature({
// XXX
})()
// XXX not all promises in the system resolve strictly
// after all the work is done, some resolve before that
// point and this calling process.exit() will interrupt

View File

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

View File

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

View File

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