diff --git a/ui (gen4)/e.js b/ui (gen4)/e.js index 351d5254..5b6fec0b 100644 --- a/ui (gen4)/e.js +++ b/ui (gen4)/e.js @@ -20,12 +20,13 @@ var url = require('url') var win -function createWindow () { +function createWindow() { // Create the browser window. win = new BrowserWindow({width: 800, height: 600}) // and load the index.html of the app. win.loadURL(url.format({ + // XXX for some reason the system is loaded twice... pathname: path.join(__dirname, 'index.html'), protocol: 'file:', slashes: true diff --git a/ui (gen4)/features/app.js b/ui (gen4)/features/app.js index d2e36c7e..49e0b258 100755 --- a/ui (gen4)/features/app.js +++ b/ui (gen4)/features/app.js @@ -197,7 +197,7 @@ module.AppControl = core.ImageGridFeatures.Feature({ // - chrome app // - nw // - mobile - isApplicable: function(){ return this.runtime == 'nw' }, + isApplicable: function(){ return this.runtime.nw }, // XXX show main window... handlers: [ diff --git a/ui (gen4)/features/cli.js b/ui (gen4)/features/cli.js index 9874e2f4..dc3a0d9c 100755 --- a/ui (gen4)/features/cli.js +++ b/ui (gen4)/features/cli.js @@ -91,8 +91,9 @@ module.CLI = core.ImageGridFeatures.Feature({ 'lifecycle' ], + // XXX should this be ONLY node??? isApplicable: function(){ - return this.runtime == 'node' /*|| this.runtime == 'nw'*/ }, + return this.runtime.node && !this.runtime.browser }, actions: CLIActions, @@ -101,7 +102,7 @@ module.CLI = core.ImageGridFeatures.Feature({ function(){ var that = this // get the arguments... - if(this.runtime == 'nw'){ + if(this.runtime.nw){ var argv = nw.App.argv // XXX appears to have a stray '--help' lodged in @@ -109,7 +110,7 @@ module.CLI = core.ImageGridFeatures.Feature({ // ...need to test this with a packed exec... console.log('>>>>', argv) - } else if(this.runtime == 'node'){ + } else if(this.runtime.node){ var argv = process.argv } diff --git a/ui (gen4)/features/core.js b/ui (gen4)/features/core.js index ecaf7a6c..983251c9 100755 --- a/ui (gen4)/features/core.js +++ b/ui (gen4)/features/core.js @@ -162,17 +162,27 @@ ImageGridFeatures.__actions__ = //--------------------------------------------------------------------- // Setup runtime info... +// XXX add test if chrome-app... +// XXX add test if cordova... +// XXX add test if mobile... + +// XXX should this contain feature versions??? +var runtime = ImageGridFeatures.runtime = {} // nw or node... if(typeof(process) != 'undefined'){ + // node... + runtime.node = true // Electron... if(process.versions['electron'] != null){ - ImageGridFeatures.runtime = 'electron' + runtime.electron = true + runtime.desktop = true // nw.js 0.13+ } else if(typeof(nw) != 'undefined'){ - ImageGridFeatures.runtime = 'nw' + runtime.nw = true + runtime.desktop = true // NOTE: jli is patching the Date object and with two separate // instances we'll need to sync things up... @@ -187,25 +197,19 @@ if(typeof(process) != 'undefined'){ // node... } else { - ImageGridFeatures.runtime = 'node' - // XXX patch Date... // XXX this will not work directly as we will need to explicitly // require jli... //patchDate(global.Date) } +} // browser... // NOTE: we're avoiding detecting browser specifics for as long as possible, // this will minimize the headaches of supporting several non-standard // versions of code... -} else if(typeof(window) != 'undefined'){ - ImageGridFeatures.runtime = 'browser' - -// unknown... -// XXX do we need to detect chrome app??? -} else { - ImageGridFeatures.runtime = 'unknown' +if(typeof(window) != 'undefined'){ + runtime.browser = true } @@ -353,7 +357,7 @@ var LifeCycleActions = actions.Actions({ var runtime = this.runtime = ImageGridFeatures.runtime // nw.js... - if(runtime == 'nw'){ + if(runtime.nw){ // this handles both reload and close... $(window).on('beforeunload', stop) @@ -386,12 +390,12 @@ var LifeCycleActions = actions.Actions({ nw.Window.get().on('close', this.__nw_stop_handler) - // node.js... - } else if(runtime == 'node'){ + // node... + } else if(runtime.node){ process.on('exit', stop) // browser... - } else if(runtime == 'browser'){ + } else if(runtime.browser){ $(window).on('beforeunload', stop) // other... @@ -400,17 +404,11 @@ var LifeCycleActions = actions.Actions({ console.warn('Unknown runtime:', runtime) } - // handler ready event... + // handle ready event... // ...if no one requested to do it. if(this.__ready_announce_requested == null || this.__ready_announce_requested <= 0){ - if(runtime == 'nw'){ - $(function(){ that.declareReady() }) - - } else if(runtime == 'node'){ - this.declareReady() - - } else if(runtime == 'browser'){ + if(runtime.browser){ $(function(){ that.declareReady() }) } else { @@ -503,20 +501,19 @@ var LifeCycleActions = actions.Actions({ handlers can run cleanly. `, function(){ - // browser & nw... - if(this.__stop_handler - && (this.runtime == 'browser' || this.runtime == 'nw')){ + // browser... + if(this.__stop_handler && this.runtime.browser){ $(window).off('beforeunload', this.__stop_handler) } // nw... - if(this.__nw_stop_handler && this.runtime == 'nw'){ + if(this.__nw_stop_handler && this.runtime.nw){ nw.Window.get().removeAllListeners('close') delete this.__nw_stop_handler } // node... - if(this.__stop_handler && this.runtime == 'node'){ + if(this.__stop_handler && this.runtime.node){ process.removeAllListeners('exit') } diff --git a/ui (gen4)/features/external-editor.js b/ui (gen4)/features/external-editor.js index 6dcabb85..b7b0d000 100755 --- a/ui (gen4)/features/external-editor.js +++ b/ui (gen4)/features/external-editor.js @@ -122,8 +122,7 @@ module.ExternalEditor = core.ImageGridFeatures.Feature({ 'ui-external-editor', ], - isApplicable: function(){ - return this.runtime == 'nw' || this.runtime == 'node' }, + isApplicable: function(){ return this.runtime.node }, actions: ExternalEditorActions, }) diff --git a/ui (gen4)/features/filesystem.js b/ui (gen4)/features/filesystem.js index ab0fe48e..b590d945 100755 --- a/ui (gen4)/features/filesystem.js +++ b/ui (gen4)/features/filesystem.js @@ -215,8 +215,7 @@ module.FileSystemInfo = core.ImageGridFeatures.Feature({ actions: FileSystemInfoActions, - isApplicable: function(){ - return this.runtime == 'node' || this.runtime == 'nw' }, + isApplicable: function(){ return this.runtime.node }, }) @@ -762,8 +761,7 @@ module.FileSystemLoader = core.ImageGridFeatures.Feature({ actions: FileSystemLoaderActions, - isApplicable: function(){ - return this.runtime == 'node' || this.runtime == 'nw' }, + isApplicable: function(){ return this.runtime.node }, handlers: [ // clear changes when loading an index... @@ -2085,8 +2083,7 @@ module.FileSystemWriter = core.ImageGridFeatures.Feature({ actions: FileSystemWriterActions, - isApplicable: function(){ - return this.runtime == 'node' || this.runtime == 'nw' }, + isApplicable: function(){ return this.runtime.node }, // monitor changes... // XXX should we use .load(..) to trigger changes instead of .loadURLs(..)??? diff --git a/ui (gen4)/features/metadata.js b/ui (gen4)/features/metadata.js index b3f5858d..b5aeec26 100755 --- a/ui (gen4)/features/metadata.js +++ b/ui (gen4)/features/metadata.js @@ -212,8 +212,7 @@ module.MetadataReader = core.ImageGridFeatures.Feature({ 'metadata', ], - isApplicable: function(){ - return this.runtime == 'nw' || this.runtime == 'node' }, + isApplicable: function(){ return this.runtime.node }, actions: MetadataReaderActions, diff --git a/ui (gen4)/features/peer.js b/ui (gen4)/features/peer.js index 11f1e208..ca729296 100755 --- a/ui (gen4)/features/peer.js +++ b/ui (gen4)/features/peer.js @@ -372,8 +372,7 @@ module.ChildProcessPeer = core.ImageGridFeatures.Feature({ 'peer', ], - isApplicable: function(){ - return this.runtime == 'nw' || this.runtime == 'node' }, + isApplicable: function(){ return this.runtime.node }, actions: ChildProcessPeerActions, diff --git a/ui (gen4)/features/ui-chrome.js b/ui (gen4)/features/ui-chrome.js index 6350f531..e2aae49e 100755 --- a/ui (gen4)/features/ui-chrome.js +++ b/ui (gen4)/features/ui-chrome.js @@ -619,9 +619,9 @@ module.UIScale = core.ImageGridFeatures.Feature({ // XXX test if in: // - chrome app - // - nw + // - desktop // - mobile - isApplicable: function(){ return this.runtime == 'nw' }, + isApplicable: function(){ return this.runtime.desktop }, // XXX show main window... handlers: [ diff --git a/ui (gen4)/features/ui.js b/ui (gen4)/features/ui.js index d7dafc0e..51045e44 100755 --- a/ui (gen4)/features/ui.js +++ b/ui (gen4)/features/ui.js @@ -708,7 +708,7 @@ module.Viewer = core.ImageGridFeatures.Feature({ // check if we are running in a UI context... // NOTE: this will prevent loading of any features dependant on the // UI in a non UI context... - isApplicable: function(){ return typeof(window) == typeof({}) }, + isApplicable: function(){ return this.runtime.browser }, handlers: [ ['start', @@ -976,7 +976,7 @@ module.URLHash = core.ImageGridFeatures.Feature({ //isApplicable: function(){ // return typeof(location) != 'undefined' && location.hash != null }, - isApplicable: function(){ return this.runtime == 'browser' }, + isApplicable: function(){ return this.runtime.browser }, handlers: [ // hanlde window.onhashchange event...