Skip to content
This repository has been archived by the owner on Sep 30, 2022. It is now read-only.

Commit

Permalink
* Changes to support electron-builder Squirrel compilation.
Browse files Browse the repository at this point in the history
  • Loading branch information
dannya committed Jun 28, 2016
1 parent 3e70c5b commit a4142db
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 46 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/app/node_modules
/screenshots
/.idea
/node_modules
/config_editable.js
/dist
/node_modules
File renamed without changes.
44 changes: 44 additions & 0 deletions app/config_editable.js
Original file line number Diff line number Diff line change
@@ -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;
74 changes: 69 additions & 5 deletions main.js → app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,74 @@ const electron = require('electron'),
fs = require('fs'),
os = require('os'),
mime = require('mime'),
spawn = require('child_process').spawn,
io = require('socket.io');


// define module shorthand names
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;

Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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';
Expand All @@ -254,9 +321,6 @@ var server = http

break;

case '.json':
contentType = 'application/json';
break;
case '.svg':
contentType = 'image/svg+xml';
break;
Expand Down
43 changes: 43 additions & 0 deletions app/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
17 changes: 11 additions & 6 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('.'));
}
Expand Down Expand Up @@ -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
}
Expand All @@ -192,7 +197,7 @@ gulp.task(
runSequence(
'clean',
'default',
'create_config',
'transfer_config',
callback
);
}
Expand Down
50 changes: 17 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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
}
}
}

0 comments on commit a4142db

Please sign in to comment.