mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 18:30:09 +00:00
reworked the .runtime feature detection (now Electron works, though with an odd bug)...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
9a0649a9b1
commit
6b16ce2cc3
@ -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
|
||||
|
||||
@ -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: [
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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')
|
||||
}
|
||||
|
||||
|
||||
@ -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,
|
||||
})
|
||||
|
||||
@ -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(..)???
|
||||
|
||||
@ -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,
|
||||
|
||||
|
||||
@ -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,
|
||||
|
||||
|
||||
@ -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: [
|
||||
|
||||
@ -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...
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user