diff --git a/.gitignore b/.gitignore index 313e904..f90da99 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ +/app/node_modules /screenshots /.idea -/node_modules -/config_editable.js \ No newline at end of file +/dist +/node_modules \ No newline at end of file diff --git a/config.js b/app/config.js similarity index 100% rename from config.js rename to app/config.js diff --git a/app/config_editable.js b/app/config_editable.js new file mode 100644 index 0000000..90bfaf4 --- /dev/null +++ b/app/config_editable.js @@ -0,0 +1,44 @@ + +var powerplandisplay = { + config: { + port: 5555, + notOnTop: false, + showWindow: true, + webInspector: false, + theme: 'full', + refresh: 5, + frame: true, + updateUrl: 'https://github.com/dannyakakong/powerplandisplay/blob/master/package.json' + }, + + hiddenPowerPlans: [ + ], + + themes: { + full: { + name: 'Full', + frame: { + width: 654, + height: 450 + }, + noframe: { + width: 650, + height: 412 + } + }, + + compact: { + name: 'Compact', + frame: { + width: 350, + height: 198 + }, + noframe: { + width: 346, + height: 160 + } + } + } +}; + +module.exports = powerplandisplay; \ No newline at end of file diff --git a/main.js b/app/main.js similarity index 85% rename from main.js rename to app/main.js index d00f6c3..4d45cbb 100644 --- a/main.js +++ b/app/main.js @@ -21,6 +21,7 @@ const electron = require('electron'), fs = require('fs'), os = require('os'), mime = require('mime'), + spawn = require('child_process').spawn, io = require('socket.io'); @@ -28,6 +29,66 @@ const electron = require('electron'), const app = electron.app; +// determine if running in Squirrel or Electron context +const context = ((process.execPath.indexOf('electron')) === -1) ? 'squirrel' : 'electron'; + + +// process squirrel events? +if (context === 'squirrel') { + var runSquirrelCmd = function(args, done) { + spawn( + path.resolve( + path.dirname(process.execPath), '..', 'Update.exe' + ), + args, + { + detached: true + } + + ).on('close', done); + }; + + var handleStartupEvent = function() { + if (process.platform !== 'win32') { + return false; + } + + var target = path.basename(process.execPath); + var squirrelCommand = process.argv[1]; + + switch (squirrelCommand) { + case '--squirrel-install': + case '--squirrel-updated': + // install desktop / start menu shortcuts + runSquirrelCmd( + ['--createShortcut=' + target + ''], + app.quit + ); + + return true; + + case '--squirrel-uninstall': + // undo anything done in --squirrel-install and --squirrel-updated handlers + runSquirrelCmd( + ['--removeShortcut=' + target + ''], + app.quit + ); + + return true; + + case '--squirrel-obsolete': + app.quit(); + + return true; + } + }; + + if (handleStartupEvent()) { + return; + } +} + + // keep a global reference of certain objects to stop them getting garbage collected let win, powersave; @@ -65,7 +126,7 @@ powerplandisplay.sys = { // define function to get full / minified file based on debug flag powerplandisplay.path = function (pathItems, injectMin, alwaysInjectMin) { pathItems.unshift( - powerplandisplay.sys.rootDir, 'app' + powerplandisplay.sys.rootDir ); // inject '.min' into filename? @@ -231,7 +292,13 @@ var server = http filepath = '/index.html'; } - filepath = './app' + filepath; + if (context === 'squirrel') { + filepath = './resources/app' + filepath; + } else { + filepath = './app' + filepath; + } + + console.log(filepath); var extname = path.extname(filepath), contentType = 'text/html'; @@ -254,9 +321,6 @@ var server = http break; - case '.json': - contentType = 'application/json'; - break; case '.svg': contentType = 'image/svg+xml'; break; diff --git a/app/package.json b/app/package.json new file mode 100644 index 0000000..4837b30 --- /dev/null +++ b/app/package.json @@ -0,0 +1,43 @@ +{ + "name": "PowerPlanDisplay", + "version": "1.0.0", + "license": "GPL-3.0", + "description": "PowerPlanDisplay", + "main": "main.js", + "keywords": [ + "powerplan", + "Power Plan", + "Windows" + ], + "author": { + "name": "Danny Allen / Wonderscore Ltd", + "email": "me@dannya.com", + "url": "http://dannya.com/" + }, + "homepage": "https://github.com/dannyakakong/powerplandisplay", + "bugs": { + "url": "https://github.com/dannyakakong/powerplandisplay/issues" + }, + "repository": { + "type": "git", + "url": "https://github.com/dannyakakong/powerplandisplay.git" + }, + "os": [ + "win32" + ], + "scripts": { + "start": "electron --enable-logging main.js", + "debug": "electron --enable-logging main.js -d", + "development": "npm run debug" + }, + "dependencies": { + "bluebird": "^3.4.1", + "electron-squirrel-startup": "^1.0.0", + "mime": "^1.3.4", + "nomnom": "dannyakakong/nomnom", + "repeat": "0.0.6", + "socket.io": "^1.4.5", + "traverse": "^0.6.6", + "trim-character": "^2.0.1" + } +} diff --git a/gulpfile.js b/gulpfile.js index 88e5977..cebccbd 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -117,15 +117,14 @@ gulp.task('transfer_pages', function () { .pipe(gulp.dest('app')); }); - -gulp.task('create_config', function () { +gulp.task('transfer_config', function () { // create editable config (if doesn't already exist) if (!fs.existsSync('config_editable.js')) { gulp - .src('config.js') + .src('app/config.js') .pipe(strip()) .pipe( - rename('config_editable.js') + rename('app/config_editable.js') ) .pipe(gulp.dest('.')); } @@ -177,7 +176,13 @@ gulp.task( function () { return gulp .src( - 'app', + [ + 'app/css', + 'app/img', + 'app/js', + 'app/favicon.ico', + 'app/index.html' + ], { read: false } @@ -192,7 +197,7 @@ gulp.task( runSequence( 'clean', 'default', - 'create_config', + 'transfer_config', callback ); } diff --git a/package.json b/package.json index 54b13ff..64a6c7e 100644 --- a/package.json +++ b/package.json @@ -1,47 +1,22 @@ { - "name": "PowerPlanDisplay", - "version": "1.0.0", - "license": "GPL-3.0", - "description": "Shows your active Windows powerplan in a window containing all the available powerplans, and allows you to change powerplan with a single click", - "main": "main.js", "scripts": { - "prepublish": "gulp release", - "start": "electron --enable-logging main.js", - "debug": "electron --enable-logging main.js -d", - "development": "npm run debug" + "prepublish": "cd app && npm install && cd .. && gulp release", + "start": "electron ./app", + "debug": "electron --enable-logging ./app -d", + "pack": "build --dir", + "dist": "npm run prepublish && build --win", + "release": "npm run prepublish && build --win" }, "repository": { "type": "git", "url": "https://github.com/dannyakakong/powerplandisplay.git" }, - "keywords": [ - "powerplan", - "Power Plan", - "Windows" - ], - "author": { - "name": "Danny Allen / Wonderscore Ltd", - "email": "me@dannya.com", - "url": "http://dannya.com/" - }, - "homepage": "https://github.com/dannyakakong/powerplandisplay", - "bugs": { - "url": "https://github.com/dannyakakong/powerplandisplay/issues" - }, "os": [ "win32" ], - "dependencies": { - "bluebird": "^3.4.1", - "electron-prebuilt": "^1.2.5", - "mime": "^1.3.4", - "nomnom": "^1.8.1", - "repeat": "0.0.6", - "socket.io": "^1.4.5", - "traverse": "^0.6.6", - "trim-character": "^2.0.1" - }, "devDependencies": { + "electron-builder": "^5.10.1", + "electron-prebuilt": "^1.2.5", "gulp": "~3.9.0", "gulp-autoprefixer": "^2.3.1", "gulp-clean": "^0.3.1", @@ -58,5 +33,14 @@ "jeet": "6.1.2", "run-sequence": "^1.1.5", "yargs": "^4.2.0" + }, + "build": { + "appId": "uk.ltd.wonderscore.powerplandisplay", + "asar": false, + "win": { + "icon": "src/img/icon.ico", + "iconUrl": "https://raw.githubusercontent.com/dannyakakong/PowerPlanDisplay/master/src/img/icon.ico", + "msi": true + } } }