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