migrated to nw.js v0.13.x

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2016-04-09 18:39:01 +03:00
parent 31656e0203
commit 7041714454
5 changed files with 69 additions and 54 deletions

View File

@ -11,6 +11,8 @@
APP_NAME=ImageGrid.Viewer APP_NAME=ImageGrid.Viewer
NODE_VERSION=v5.10.0
# process LESS files to CSS... # process LESS files to CSS...
%.css: %.less %.css: %.less
@ -120,6 +122,10 @@ zip: $(APP_ZIP)
node-deps: node-deps:
npm install npm install
sharp: node-deps
cd node_modules/sharp/
node-gyp --target=$(NODE_VERSION) rebuild
css: $(CSS_FILES) css: $(CSS_FILES)
dev: css dev: css

View File

@ -10,6 +10,7 @@ define(function(require){ var module = {}
var actions = require('lib/actions') var actions = require('lib/actions')
var features = require('lib/features') var features = require('lib/features')
var toggler = require('lib/toggler')
var core = require('features/core') var core = require('features/core')
var base = require('features/base') var base = require('features/base')
@ -31,12 +32,11 @@ var AppControlActions = actions.Actions({
storeWindowGeometry: ['- Interface/Store window state', storeWindowGeometry: ['- Interface/Store window state',
function(){ function(){
// store window parameters (size, state)... // store window parameters (size, state)...
var gui = requirejs('nw.gui') var win = nw.Window.get()
var win = gui.Window.get()
// fullscreen... // fullscreen...
// ...avoid overwriting size... // ...avoid overwriting size...
if(win.isFullscreen){ if(this.toggleFullScreen('?') == 'on'){
this.config.window = this.config.window || {} this.config.window = this.config.window || {}
this.config.window.fullscreen = true this.config.window.fullscreen = true
this.config.window.zoom = win.zoomLevel this.config.window.zoom = win.zoomLevel
@ -56,8 +56,7 @@ var AppControlActions = actions.Actions({
function(){ function(){
// or global.window.nwDispatcher.requireNwGui() // or global.window.nwDispatcher.requireNwGui()
// (see: https://github.com/rogerwang/node-webkit/issues/707) // (see: https://github.com/rogerwang/node-webkit/issues/707)
var gui = requirejs('nw.gui') var win = nw.Window.get()
var win = gui.Window.get()
// XXX move this into .restoreWindowGeometry(..) // XXX move this into .restoreWindowGeometry(..)
// get window state from config and load it... // get window state from config and load it...
@ -92,7 +91,7 @@ var AppControlActions = actions.Actions({
// XXX check if we are full screen... // XXX check if we are full screen...
if(cfg != null && cfg.fullscreen && !win.isFullscreen){ if(cfg != null && cfg.fullscreen && !win.isFullscreen){
this.toggleFullScreen() this.toggleFullScreen('on')
} }
/* XXX still buggy.... /* XXX still buggy....
@ -102,18 +101,27 @@ var AppControlActions = actions.Actions({
|| this.toggleInterfaceScale('??')[0]) || this.toggleInterfaceScale('??')[0])
*/ */
}], }],
toggleFullScreen: ['Interface/Toggle full screen mode', toggleFullScreen: ['Interface/Toggle full screen mode',
function(){ toggler.CSSClassToggler(
function(){ return document.body },
'.full-screen-mode',
function(action){
var that = this var that = this
var w = nw.Window.get()
// change the state only if the target state is not the same
// as the current state...
if((w.isFullscreen() ? 'on' : 'off') != action){
this.ribbons.preventTransitions() this.ribbons.preventTransitions()
// hide the viewer to hide any animation crimes... // hide the viewer to hide any animation crimes...
this.ribbons.viewer[0].style.visibility = 'hidden' this.ribbons.viewer[0].style.visibility = 'hidden'
// XXX where should toggleFullscreenMode(..) be defined... // XXX async...
// ...this also toggles a fullscreen css class on body... // ...this complicates things as we need to do the next
toggleFullscreenMode() // bit AFTER the resize is done...
//requirejs('nw.gui').Window.get().toggleFullscreen() w.toggleFullscreen()
setTimeout(function(){ setTimeout(function(){
that that
@ -123,13 +131,18 @@ var AppControlActions = actions.Actions({
.restoreTransitions() .restoreTransitions()
that.ribbons.viewer[0].style.visibility = '' that.ribbons.viewer[0].style.visibility = ''
}, 0) }, 100)
}], }
// NOTE: we delay this to account for window animation...
setTimeout(function(){
that.storeWindowGeometry()
}, 500)
})],
showDevTools: ['Interface|Development/Show Dev Tools', showDevTools: ['Interface|Development/Show Dev Tools',
function(){ function(){
if(window.showDevTools != null){ nw.Window.get().showDevTools &&
showDevTools() nw.Window.get().showDevTools()
}
}], }],
}) })
@ -174,8 +187,7 @@ module.AppControl = core.ImageGridFeatures.Feature({
function(){ this.storeWindowGeometry() }], function(){ this.storeWindowGeometry() }],
['focusImage', ['focusImage',
function(){ function(){
var gui = requirejs('nw.gui') var win = nw.Window.get()
var win = gui.Window.get()
if(this.images){ if(this.images){
var img = this.images[this.current] var img = this.images[this.current]

View File

@ -119,7 +119,7 @@ module.CLI = core.ImageGridFeatures.Feature({
// ig lf sm lf // ig lf sm lf
// ...this will print the list of features before // ...this will print the list of features before
// and after setup... // and after setup...
.option('sm, --setup-minimal', 'setup minimap features', function(){ .option('sm, --setup-minimal', 'setup minimal features', function(){
// load features we might need... // load features we might need...
// XXX require js loads these at the root... // XXX require js loads these at the root...
var location = require('features/location') var location = require('features/location')

View File

@ -51,25 +51,27 @@ var ImageGridFeatures =
module.ImageGridFeatures = Object.create(features.FeatureSet) module.ImageGridFeatures = Object.create(features.FeatureSet)
// setup exit... // nw or node...
if(typeof(process) != 'undefined'){ if(typeof(process) != 'undefined'){
// NOTE: if this passes it is async while when fails it's sync, this // nw.js 0.13+
// is why we set .runtime to 'nw' optimistically in advance so if(typeof(nw) != 'undefined'){
// as not to wait if all goes well and set it to 'node' in the
// callback that if fails will fail right away...
ImageGridFeatures.runtime = 'nw' ImageGridFeatures.runtime = 'nw'
requirejs(['nw.gui'],
// OK: nw.js // node...
function(){}, } else {
// ERR: pure node.js... ImageGridFeatures.runtime = 'node'
function(){ ImageGridFeatures.runtime = 'node' }) }
// browser... // 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'){ } else if(typeof(window) != 'undefined'){
ImageGridFeatures.runtime = 'browser' ImageGridFeatures.runtime = 'browser'
// unknown... // unknown...
// XXX do we need to detect chrome app???
} else { } else {
ImageGridFeatures.runtime = 'unknown' ImageGridFeatures.runtime = 'unknown'
} }
@ -101,8 +103,6 @@ var LifeCycleActions = actions.Actions({
// nw.js... // nw.js...
if(runtime == 'nw'){ if(runtime == 'nw'){
var gui = requirejs('nw.gui')
// this handles both reload and close... // this handles both reload and close...
$(window).on('beforeunload', stop) $(window).on('beforeunload', stop)
@ -117,7 +117,9 @@ var LifeCycleActions = actions.Actions({
// wait till ALL the handlers finish before // wait till ALL the handlers finish before
// exiting... // exiting...
.on('stop.post', function(){ .on('stop.post', function(){
w.close(true) // XXX might be broken in nw13 -- test!!!
//w.close(true)
nw.App.quit()
}) })
.stop() .stop()
@ -127,8 +129,7 @@ var LifeCycleActions = actions.Actions({
this.close(true) this.close(true)
} }
} }
gui.Window.get().on('close', this.__nw_stop_handler) nw.Window.get().on('close', this.__nw_stop_handler)
// node.js... // node.js...
} else if(runtime == 'node'){ } else if(runtime == 'node'){
@ -154,8 +155,7 @@ var LifeCycleActions = actions.Actions({
// nw... // nw...
if(this.__nw_stop_handler && this.runtime == 'nw'){ if(this.__nw_stop_handler && this.runtime == 'nw'){
var gui = requirejs('nw.gui') //nw.Window.get().off('close', this.__nw_stop_handler)
//gui.Window.get().off('close', this.__nw_stop_handler)
delete this.__nw_stop_handler delete this.__nw_stop_handler
} }

View File

@ -5,9 +5,6 @@
**********************************************************************/ **********************************************************************/
if(window.nodejs != null){ if(window.nodejs != null){
// node-webkit specific modules...
var gui = require('nw.gui')
define(function(require){ var module = {} define(function(require){ var module = {}
var toggler = require('lib/toggler') var toggler = require('lib/toggler')
@ -29,20 +26,20 @@ module.toggleFullscreenMode = toggler.CSSClassToggler(
document.body, document.body,
'.full-screen-mode', '.full-screen-mode',
function(action){ function(action){
gui.Window.get().toggleFullscreen() nw.Window.get().toggleFullscreen()
}) })
window.showDevTools = window.showDevTools =
module.showDevTools = function(){ module.showDevTools = function(){
gui.Window.get().showDevTools() nw.Window.get().showDevTools()
} }
window.setWindowTitle = window.setWindowTitle =
module.setWindowTitle = function(text){ module.setWindowTitle = function(text){
browser.setWindowTitle(test) browser.setWindowTitle(test)
gui.Window.get().title = title nw.Window.get().title = title
} }