From 1ef859573e08be7c87f12037bd5187e6a991672a Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Fri, 28 Jan 2022 21:41:06 +0300 Subject: [PATCH] now version can be set in package.json and is propagated automatically... Signed-off-by: Alex A. Naanou --- Viewer/Makefile | 11 ++++++-- Viewer/cfg/requirejs.js | 5 ++-- Viewer/doc/HACKS | 6 +---- Viewer/e.js | 57 +++++++++++++++++++++++++--------------- Viewer/features/base.js | 7 ++--- Viewer/ig.js | 1 + Viewer/package-lock.json | 4 +-- Viewer/package.json | 2 +- Viewer/version.js | 22 +++++++++------- Viewer/version.js.tpl | 27 +++++++++++++++++++ 10 files changed, 96 insertions(+), 46 deletions(-) create mode 100644 Viewer/version.js.tpl diff --git a/Viewer/Makefile b/Viewer/Makefile index 52fc76c2..3d9b6caf 100755 --- a/Viewer/Makefile +++ b/Viewer/Makefile @@ -152,7 +152,7 @@ VERSION_FALLBACK ?= 4.0.0a # NOTE: we are not using './ig --version 2> /dev/null' because it will # not work before we do 'npm install'... VERSION := $(strip $(shell \ - echo 'console.log(require("./version").version)' | node - \ + echo 'console.log(require("./package.json").version)' | node - \ || echo $(VERSION_FALLBACK))) DATE := $(strip $(shell date "+%Y%m%d%H%M")) COMMIT := $(strip $(shell git rev-parse HEAD)) @@ -293,7 +293,7 @@ PROJECT_FILES = package.json # replace .less with .css making them build targets... CSS_FILES := $(patsubst %.less,%.css,$(wildcard css/*.less)) HTML_FILES := $(wildcard *.html) -ROOT_JS_FILES := $(wildcard *.js) +ROOT_JS_FILES := $(wildcard *.js) version.js # NOTE: this is only used for make change/dependency tracking checking... JS_FILES := $(ROOT_JS_FILES) \ $(wildcard $(DOMAIN_DIR)/*.js) \ @@ -379,6 +379,7 @@ version: @echo $(VERSION) + # XXX might be a good idea to print the generated env... #env: @@ -621,6 +622,12 @@ $(BUILD_INFO): $(CSS_FILES) $(NODE_DIR) $(PROJECT_FILES) \ @echo "electron: $(ELECTRON_VERSION)" | tee -a "$@" +version.js: package.json + cat version.js.tpl \ + | sed 's/\$$VERSION/$(VERSION)/' \ + > version.js + + %.css: %.less $(LESSC) $< > $@ diff --git a/Viewer/cfg/requirejs.js b/Viewer/cfg/requirejs.js index 1cb9dcd6..d6c7b4c4 100644 --- a/Viewer/cfg/requirejs.js +++ b/Viewer/cfg/requirejs.js @@ -26,8 +26,9 @@ var setup = function(require, root){ var requirejs = _requirejs var requirejs_cfg = { - // NOTE: this is really odd: running electron as a packed binary breaks - // requirejs' paths... + // XXX under electron the path seems to be one level above the + // actual base URL, i.e. one level above the $0, hence the + // need to correct this... baseUrl: root ? root : typeof(process) != 'undefined' diff --git a/Viewer/doc/HACKS b/Viewer/doc/HACKS index a40d6232..89d883cd 100644 --- a/Viewer/doc/HACKS +++ b/Viewer/doc/HACKS @@ -3,17 +3,13 @@ Hacks and fixes =============== 20220126: -- node_modules/requirejs/bin/r,js +node_modules/requirejs/bin/r,js Under Electron v14+ requirejs breaks with a SyntaxError on the first char of r.js ('#!/...') -- a hackish way to fix this is to comment it out, not yet sure why is this happening... STUB: patched by: make node_modules -- cfg/requirejs.js (FIXED) - .baseUrl calculation under U*IX systems needs a '/' prefixed... - - 20210122: diff --git a/Viewer/e.js b/Viewer/e.js index 57e2edad..48cdc180 100644 --- a/Viewer/e.js +++ b/Viewer/e.js @@ -54,7 +54,11 @@ global.START_GUI = false // // XXX might be nice to show load progress on splash... var SPLASH -function createSplash(){ +function createSplash(force=false){ + // singleton window... + if(!force && SPLASH){ + return SPLASH } + // NOTE: this is done here as this does not depend on code loading, // thus showing the splash significantly faster... SPLASH = new BrowserWindow({ @@ -111,12 +115,18 @@ function createSplash(){ // Create main window... // -// XXX get initial settings from config... +// NOTE: initial window metrics are loaded by the app feature... +// XXX should this be done here??? +// // XXX handle maximize corretly... // ...currently it does not differ visually from fullscreen -- either // make them the same or keep them separate visually... var WIN -function createWindow(){ +function createWindow(force=false){ + // singleton window... + if(!force && WIN){ + return WIN } + // Create the browser window. WIN = new BrowserWindow({ webPreferences: { @@ -186,6 +196,9 @@ function createWindow(){ return WIN } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // Start the app... // function start(){ @@ -201,23 +214,7 @@ function start(){ //--------------------------------------------------------------------- - -// 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 test... -app.on('activate', function(){ - WIN || createWindow() }) - -// Quit when all windows are closed. -// On macOS it is common for applications and their menu bar -// to stay active until the user quits explicitly with Cmd + Q -app.on('window-all-closed', function(){ - process.platform !== 'darwin' - && app.quit() }) - - - -//--------------------------------------------------------------------- +// Event handlers... // Window states... ipcMain.on('show', @@ -245,7 +242,7 @@ ipcMain.on('openSplashScreen', ipcMain.on('closeSplashScreen', function(){ SPLASH && SPLASH.destroy() }) -// devtools... +// DevTools... // XXX need to focus devtools here... // see: webContents.getAllWebContents() ipcMain.on('openDevTools', @@ -260,6 +257,24 @@ ipcMain.on('closeDevTools', +//--------------------------------------------------------------------- +// Event handlers (macOS)... + +// 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 test... +app.on('activate', function(){ + WIN || createWindow() }) + +// Quit when all windows are closed. +// On macOS it is common for applications and their menu bar +// to stay active until the user quits explicitly with Cmd + Q +app.on('window-all-closed', function(){ + process.platform !== 'darwin' + && app.quit() }) + + + //--------------------------------------------------------------------- // start things up... diff --git a/Viewer/features/base.js b/Viewer/features/base.js index f63b9686..ab4acce4 100755 --- a/Viewer/features/base.js +++ b/Viewer/features/base.js @@ -42,7 +42,8 @@ actions.Actions({ config: { // XXX should this be here??? // ...where should this be stored??? - version: version.version || '4.0.0a', + version: version.version + || '4.0.0a', 'default-direction': 'right', @@ -71,9 +72,9 @@ actions.Actions({ }, - // XXX get version(){ - return this.config.version }, + return version.version + || '4.0.0a' }, // basic state... // NOTE: the setters in the following use the appropriate actions diff --git a/Viewer/ig.js b/Viewer/ig.js index 6d050e67..64509bd7 100755 --- a/Viewer/ig.js +++ b/Viewer/ig.js @@ -19,6 +19,7 @@ if(process.env.IMAGEGRID_DEBUG){ return res }, {})} } + /*********************************************************************/ require('v8-compile-cache') diff --git a/Viewer/package-lock.json b/Viewer/package-lock.json index e23d6b54..9a0687af 100755 --- a/Viewer/package-lock.json +++ b/Viewer/package-lock.json @@ -1,12 +1,12 @@ { "name": "ImageGrid.Viewer.g4", - "version": "4.0.0a", + "version": "4.0.1a", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "ImageGrid.Viewer.g4", - "version": "4.0.0a", + "version": "4.0.1a", "dependencies": { "app-module-path": "^1.0.6", "async-json": "0.0.2", diff --git a/Viewer/package.json b/Viewer/package.json index 7f3f57c9..57fe6108 100755 --- a/Viewer/package.json +++ b/Viewer/package.json @@ -1,7 +1,7 @@ { "name": "ImageGrid.Viewer.g4", "main": "index.html", - "version": "4.0.0a", + "version": "4.0.1a", "author": "Alex A. Naanou (https://github.com/flynx)", "contributors": [], "repository": "github:flynx/ImageGrid", diff --git a/Viewer/version.js b/Viewer/version.js index 804364ca..ed5ee2df 100644 --- a/Viewer/version.js +++ b/Viewer/version.js @@ -1,5 +1,8 @@ /********************************************************************** * +* NOTE: version.js is generated automatically by Makefile from a template +* do not edit directly. +* Edit version.js.tpl instead. * * **********************************************************************/ @@ -7,17 +10,16 @@ (function(require){ var module={} // make module AMD/node compatible... /*********************************************************************/ -// XXX need to figure out a way to get the version from package.json and -// do it in: -// - bare nodejs -// > node version.js -// - browser + requirejs + file:// -// - browser + requirejs + http* -var VERSION = '4.0.1a' +// The version lives in package.json +// +// We need to be able to read the correct version in the folowing +// contexts: +// - nodejs/electron - can load JSON directly +// - browser (remote) - can load json via the require('json!package.json') +// - browser (local) - can't get access to .json files +// Thus the only way around this is to generate this file from a template. -//console.log(VERSION) - -module.version = VERSION +module.version = '4.0.1a-202201282135-el' diff --git a/Viewer/version.js.tpl b/Viewer/version.js.tpl new file mode 100644 index 00000000..4715bd7e --- /dev/null +++ b/Viewer/version.js.tpl @@ -0,0 +1,27 @@ +/********************************************************************** +* +* NOTE: version.js is generated automatically by Makefile from a template +* do not edit directly. +* Edit version.js.tpl instead. +* +* +**********************************************************************/ +((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define) +(function(require){ var module={} // make module AMD/node compatible... +/*********************************************************************/ + +// The version lives in package.json +// +// We need to be able to read the correct version in the folowing +// contexts: +// - nodejs/electron - can load JSON directly +// - browser (remote) - can load json via the require('json!package.json') +// - browser (local) - can't get access to .json files +// Thus the only way around this is to generate this file from a template. + +module.version = '$VERSION' + + + +/********************************************************************** +* vim:set ts=4 sw=4 : */ return module })