Commit 02759e63 authored by carlosperate's avatar carlosperate

Electron: Cherry-pick boilerplate updates (~30 commits).

Synchronised up to version d00f37c724a8c94ff619a04af3381289afa36a40
"Simplify author field logic"
released on the 23rd December 2015 https://github.com/szwacz/electron-boilerplate/commit/d00f37c724a8c94ff619a04af3381289afa36a40

Main things left out have been the ES6 import convention.
parent 77683d42
...@@ -6,13 +6,15 @@ ...@@ -6,13 +6,15 @@
* *
* @fileoverview Generates the application menu bar. * @fileoverview Generates the application menu bar.
*/ */
var app = require('app'); const electron = require('electron');
var Menu = require('menu'); const app = electron.app;
var shell = require('shell'); const Menu = electron.Menu;
var dialog = require('dialog'); const shell = electron.shell;
var MenuItem = require('menu-item'); const dialog = electron.dialog;
var server = require('./servermgr.js'); const MenuItem = electron.MenuItem;
var BrowserWindow = require('browser-window'); const BrowserWindow = electron.BrowserWindow;
const server = require('./servermgr.js');
module.exports.setArdublocklyMenu = function(devMode) { module.exports.setArdublocklyMenu = function(devMode) {
if (typeof(devMode)==='undefined') devMode = false; if (typeof(devMode)==='undefined') devMode = false;
...@@ -380,7 +382,7 @@ var getDevMenuData = function() { ...@@ -380,7 +382,7 @@ var getDevMenuData = function() {
label: 'Reload', label: 'Reload',
accelerator: 'CmdOrCtrl+F5', accelerator: 'CmdOrCtrl+F5',
click: function() { click: function() {
BrowserWindow.getFocusedWindow().reloadIgnoringCache(); BrowserWindow.getFocusedWindow().webContents.reloadIgnoringCache();
} }
}, { }, {
label: 'Toggle DevTools', label: 'Toggle DevTools',
......
...@@ -7,16 +7,19 @@ ...@@ -7,16 +7,19 @@
* @fileoverview Electron entry point continues here. Creates windows and * @fileoverview Electron entry point continues here. Creates windows and
* handles system events. * handles system events.
*/ */
var app = require('app'); const electron = require('electron');
var winston = require('winston'); const app = electron.app;
var appMenu = require('./appmenu.js'); const BrowserWindow = electron.BrowserWindow;
var server = require('./servermgr.js');
var BrowserWindow = require('browser-window');
var projectLocator = require('./projectlocator.js');
var env = require('./vendor/electron_boilerplate/env_config');
var windowStateKeeper = require('./vendor/electron_boilerplate/window_state');
var tag = '[Ardublockly Electron] '; const winston = require('winston');
const appMenu = require('./appmenu.js');
const server = require('./servermgr.js');
const projectLocator = require('./projectlocator.js');
const windowStateKeeper = require('./vendor/electron_boilerplate/window_state');
const env = require('fs-jetpack').cwd(app.getAppPath()).read('package.json', 'json').env;
const tag = '[Ardublockly Electron] ';
// Global reference of the window object must be maintain, or the window will // Global reference of the window object must be maintain, or the window will
// be closed automatically when the JavaScript object is garbage collected. // be closed automatically when the JavaScript object is garbage collected.
...@@ -114,7 +117,7 @@ app.on('ready', function() { ...@@ -114,7 +117,7 @@ app.on('ready', function() {
mainWindow.webContents.session.setDownloadPath( mainWindow.webContents.session.setDownloadPath(
process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME']); process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME']);
mainWindow.loadUrl('http://localhost:8000/ardublockly'); mainWindow.loadURL('http://localhost:8000/ardublockly');
mainWindow.on('close', function() { mainWindow.on('close', function() {
mainWindowState.saveState(mainWindow); mainWindowState.saveState(mainWindow);
...@@ -147,6 +150,6 @@ function createSplashWindow() { ...@@ -147,6 +150,6 @@ function createSplashWindow() {
'skip-taskbar': true, 'skip-taskbar': true,
'use-content-size': true 'use-content-size': true
}); });
splashWindow.loadUrl(imagePath); splashWindow.loadURL(imagePath);
} }
} }
...@@ -7,11 +7,8 @@ ...@@ -7,11 +7,8 @@
"author": "carlosperate", "author": "carlosperate",
"homepage": "http://ardublockly.embeddedlog.com/", "homepage": "http://ardublockly.embeddedlog.com/",
"main": "main.js", "main": "main.js",
"config": {
"target": "development"
},
"dependencies": { "dependencies": {
"fs-jetpack": "^0.7.0", "fs-jetpack": "^0.7.1",
"winston": "^1.0.1" "winston": "^1.0.1"
}, },
"repository" : { "repository" : {
......
...@@ -6,17 +6,16 @@ ...@@ -6,17 +6,16 @@
* *
* @fileoverview Finds the Ardublockly Project directory and files. * @fileoverview Finds the Ardublockly Project directory and files.
*/ */
var jetpack = require('fs-jetpack'); const jetpack = require('fs-jetpack');
var env = require('./vendor/electron_boilerplate/env_config');
// Name of the folder containing the electron executable, needs to be synced // Name of the folder containing the electron executable, needs to be synced
// with the name set in the Python server and Electron build files. // with the name set in the Python server and Electron build files.
var execFolderName = 'arduexec'; const execFolderName = 'arduexec';
var serverExecFolderName = 'server'; const serverExecFolderName = 'server';
var serverExecName = 'start'; const serverExecName = 'start';
module.exports.ardublocklyExecFolderName = execFolderName; module.exports.ardublocklyExecFolderName = execFolderName;
var tag = '[Project Root Locator] '; const tag = '[Project Root Locator] ';
var ardublocklyRootDir = null; var ardublocklyRootDir = null;
...@@ -33,11 +32,6 @@ function ardublocklyNotFound(working_dir) { ...@@ -33,11 +32,6 @@ function ardublocklyNotFound(working_dir) {
module.exports.getProjectRootJetpack = function() { module.exports.getProjectRootJetpack = function() {
if (ardublocklyRootDir === null) { if (ardublocklyRootDir === null) {
// First, work out the project root directory
if (env.name === 'development') {
// In dev mode the file cwd is on the project/package/electron dir
ardublocklyRootDir = jetpack.dir('../../');
} else {
// Cannot use relative paths in build, so let's try to find the // Cannot use relative paths in build, so let's try to find the
// ardublockly folder in a node from the executable file path tree // ardublockly folder in a node from the executable file path tree
ardublocklyRootDir = jetpack.dir(__dirname); ardublocklyRootDir = jetpack.dir(__dirname);
...@@ -58,8 +52,6 @@ module.exports.getProjectRootJetpack = function() { ...@@ -58,8 +52,6 @@ module.exports.getProjectRootJetpack = function() {
ardublocklyNotFound(ardublocklyRootDir.path('.')); ardublocklyNotFound(ardublocklyRootDir.path('.'));
} }
} }
}
return ardublocklyRootDir; return ardublocklyRootDir;
}; };
......
...@@ -6,11 +6,12 @@ ...@@ -6,11 +6,12 @@
* *
* @fileoverview Manages the Ardublockly server. * @fileoverview Manages the Ardublockly server.
*/ */
var winston = require('winston'); const winston = require('winston');
var childProcess = require('child_process'); const childProcess = require('child_process');
var projectLocator = require('./projectlocator.js');
var tag = '[Server mgr] ' const projectLocator = require('./projectlocator.js');
const tag = '[Server mgr] '
var serverProcess = null; var serverProcess = null;
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
(function () { (function () {
'use strict'; 'use strict';
var remote = require('remote'); var remote = require('electron').remote;
var Menu = remote.require('menu'); var Menu = remote.Menu;
var MenuItem = remote.require('menu-item'); var MenuItem = remote.MenuItem;
var cut = new MenuItem({ var cut = new MenuItem({
label: "Cut", label: "Cut",
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
textMenu.append(copy); textMenu.append(copy);
textMenu.append(paste); textMenu.append(paste);
document.addEventListener('contextmenu', function(e) { document.addEventListener('contextmenu', function (e) {
switch (e.target.nodeName) { switch (e.target.nodeName) {
case 'TEXTAREA': case 'TEXTAREA':
......
// Loads config/env_XXX.json file and puts it
// in proper place for given Electron context.
'use strict';
(function () {
var jetpack = require('fs-jetpack');
if (typeof window === 'object') {
// Web browser context, __dirname points to folder where app.html file is.
window.env = jetpack.read(__dirname + '/env_config.json', 'json');
} else {
// Node context
module.exports = jetpack.read(__dirname + '/../../env_config.json', 'json');
}
}());
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
(function () { (function () {
'use strict'; 'use strict';
var shell = require('shell'); var shell = require('electron').shell;
var supportExternalLinks = function (e) { var supportExternalLinks = function (e) {
var href; var href;
......
{ {
"devDependencies": { "devDependencies": {
"asar": "^0.7.2", "asar": "^0.7.2",
"electron-prebuilt": "^0.34.0", "electron-prebuilt": "^0.35.1",
"fs-jetpack": "^0.7.0", "fs-jetpack": "^0.7.0",
"gulp": "^3.9.0", "gulp": "^3.9.0",
"gulp-less": "^3.0.3", "gulp-less": "^3.0.3",
"gulp-util": "^3.0.6", "gulp-util": "^3.0.6",
"q": "^1.4.1", "q": "^1.4.1",
"rollup": "^0.16.1", "rollup": "^0.21.0",
"tree-kill": "^0.1.1", "tree-kill": "^0.1.1",
"yargs": "^3.15.0" "yargs": "^3.15.0"
}, },
...@@ -16,8 +16,7 @@ ...@@ -16,8 +16,7 @@
"rcedit": "^0.3.0" "rcedit": "^0.3.0"
}, },
"scripts": { "scripts": {
"postinstall": "node ./tasks/app_npm_install", "postinstall": "cd app && npm install",
"app-install": "node ./tasks/app_npm_install",
"build": "gulp build", "build": "gulp build",
"release": "gulp release --env=production", "release": "gulp release --env=production",
"start": "node ./tasks/start" "start": "node ./tasks/start"
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
!define src "{{src}}" !define src "{{src}}"
!define name "{{name}}" !define name "{{name}}"
!define productName "{{productName}}" !define productName "{{productName}}"
!define author "{{author}}"
!define version "{{version}}" !define version "{{version}}"
!define icon "{{icon}}" !define icon "{{icon}}"
!define setupIcon "{{setupIcon}}" !define setupIcon "{{setupIcon}}"
...@@ -90,6 +91,8 @@ Section "Install" ...@@ -90,6 +91,8 @@ Section "Install"
WriteRegStr HKLM "${uninstkey}" "DisplayName" "${productName}" WriteRegStr HKLM "${uninstkey}" "DisplayName" "${productName}"
WriteRegStr HKLM "${uninstkey}" "DisplayIcon" '"$INSTDIR\icon.ico"' WriteRegStr HKLM "${uninstkey}" "DisplayIcon" '"$INSTDIR\icon.ico"'
WriteRegStr HKLM "${uninstkey}" "UninstallString" '"$INSTDIR\${uninstaller}"' WriteRegStr HKLM "${uninstkey}" "UninstallString" '"$INSTDIR\${uninstaller}"'
WriteRegStr HKLM "${uninstkey}" "Publisher" "${author}"
WriteRegStr HKLM "${uninstkey}" "DisplayVersion" "${version}"
; Remove all application files copied by previous installation ; Remove all application files copied by previous installation
RMDir /r "$INSTDIR" RMDir /r "$INSTDIR"
...@@ -100,6 +103,7 @@ Section "Install" ...@@ -100,6 +103,7 @@ Section "Install"
File /r "${src}\*" File /r "${src}\*"
; Create start menu shortcut ; Create start menu shortcut
SetShellVarContext all
CreateShortCut "$SMPROGRAMS\${productName}.lnk" "$INSTDIR\${exec}" "" "$INSTDIR\icon.ico" CreateShortCut "$SMPROGRAMS\${productName}.lnk" "$INSTDIR\${exec}" "" "$INSTDIR\icon.ico"
WriteUninstaller "${uninstaller}" WriteUninstaller "${uninstaller}"
...@@ -149,6 +153,7 @@ Section "Uninstall" ...@@ -149,6 +153,7 @@ Section "Uninstall"
DeleteRegKey HKLM "${uninstkey}" DeleteRegKey HKLM "${uninstkey}"
DeleteRegKey HKLM "${regkey}" DeleteRegKey HKLM "${regkey}"
SetShellVarContext all
Delete "$SMPROGRAMS\${productName}.lnk" Delete "$SMPROGRAMS\${productName}.lnk"
; Remove whole directory from Program Files ; Remove whole directory from Program Files
......
// This script allows you to install native modules (those which have
// to be compiled) for your Electron app.
// The problem is that 'npm install' compiles them against node.js you have
// installed on your computer, NOT against node.js used inside Electron.
// To compile them agains Electron we need to tell npm it explicitly (and
// that's what this script does).
'use strict';
var childProcess = require('child_process');
var jetpack = require('fs-jetpack');
var argv = require('yargs').argv;
var utils = require('./utils');
var electronVersion = utils.getElectronVersion();
var nodeModulesDir = jetpack.cwd(__dirname + '/../app/node_modules')
var dependenciesCompiledAgainst = nodeModulesDir.read('electron_version');
// When you raise version of Electron used in your project, the safest
// thing to do is remove all installed dependencies and install them
// once again (so they compile against new version if you use any
// native package).
if (electronVersion !== dependenciesCompiledAgainst) {
nodeModulesDir.dir('.', { empty: true });
// Save the version string in file next to all installed modules so we know
// in the future what version of Electron has been used to compile them.
nodeModulesDir.write('electron_version', electronVersion);
}
// Tell the 'npm install' that we want to compile for Electron.
process.env.npm_config_disturl = "https://atom.io/download/atom-shell";
process.env.npm_config_target = electronVersion;
var params = ['install'];
// Maybe there was name of package user wants to install passed
// as a parameter to this script.
if (argv._.length > 0) {
params.push(argv._[0]);
params.push('--save');
}
var installCommand;
if (process.platform === 'win32') {
installCommand = 'npm.cmd'
} else {
installCommand = 'npm'
}
var install = childProcess.spawn(installCommand, params, {
cwd: __dirname + '/../app',
env: process.env,
stdio: 'inherit'
});
...@@ -15,11 +15,9 @@ var destDir = projectDir.cwd('./build'); ...@@ -15,11 +15,9 @@ var destDir = projectDir.cwd('./build');
var paths = { var paths = {
copyFromAppDir: [ copyFromAppDir: [
'./main.js', // maybe need to remove this one too
'./*.js',
'./node_modules/**', './node_modules/**',
'./vendor/**', './vendor/**',
'./**/*.html' './*.js'
], ],
} }
...@@ -27,7 +25,7 @@ var paths = { ...@@ -27,7 +25,7 @@ var paths = {
// Tasks // Tasks
// ------------------------------------- // -------------------------------------
gulp.task('clean', function(callback) { gulp.task('clean', function (callback) {
return destDir.dirAsync('.', { empty: true }); return destDir.dirAsync('.', { empty: true });
}); });
...@@ -46,7 +44,7 @@ var bundle = function (src, dest) { ...@@ -46,7 +44,7 @@ var bundle = function (src, dest) {
var deferred = Q.defer(); var deferred = Q.defer();
rollup.rollup({ rollup.rollup({
entry: src entry: src,
}).then(function (bundle) { }).then(function (bundle) {
var jsFile = pathUtil.basename(dest); var jsFile = pathUtil.basename(dest);
var result = bundle.generate({ var result = bundle.generate({
...@@ -54,14 +52,17 @@ var bundle = function (src, dest) { ...@@ -54,14 +52,17 @@ var bundle = function (src, dest) {
sourceMap: true, sourceMap: true,
sourceMapFile: jsFile, sourceMapFile: jsFile,
}); });
// Wrap code in self invoking function so the variables don't
// pollute the global namespace.
var isolatedCode = '(function () {' + result.code + '}());';
return Q.all([ return Q.all([
destDir.writeAsync(dest, result.code + '\n//# sourceMappingURL=' + jsFile + '.map'), destDir.writeAsync(dest, isolatedCode + '\n//# sourceMappingURL=' + jsFile + '.map'),
destDir.writeAsync(dest + '.map', result.map.toString()), destDir.writeAsync(dest + '.map', result.map.toString()),
]); ]);
}).then(function () { }).then(function () {
deferred.resolve(); deferred.resolve();
}).catch(function (err) { }).catch(function (err) {
console.error(err); console.error('Build: Error during rollup', err.stack);
}); });
return deferred.promise; return deferred.promise;
...@@ -81,17 +82,9 @@ gulp.task('bundle', ['clean'], bundleTask); ...@@ -81,17 +82,9 @@ gulp.task('bundle', ['clean'], bundleTask);
gulp.task('bundle-watch', bundleTask); gulp.task('bundle-watch', bundleTask);
var lessTask = function () {
return gulp.src('app/stylesheets/main.less')
.pipe(less())
.pipe(gulp.dest(destDir.path('stylesheets')));
};
gulp.task('less', ['clean'], lessTask);
gulp.task('less-watch', lessTask);
gulp.task('finalize', ['clean'], function () { gulp.task('finalize', ['clean'], function () {
var manifest = srcDir.read('package.json', 'json'); var manifest = srcDir.read('package.json', 'json');
// Add "dev" or "test" suffix to name, so Electron will write all data // Add "dev" or "test" suffix to name, so Electron will write all data
// like cookies and localStorage in separate places for each environment. // like cookies and localStorage in separate places for each environment.
switch (utils.getEnvName()) { switch (utils.getEnvName()) {
...@@ -103,10 +96,13 @@ gulp.task('finalize', ['clean'], function () { ...@@ -103,10 +96,13 @@ gulp.task('finalize', ['clean'], function () {
throw "test build has been removed"; throw "test build has been removed";
break; break;
} }
destDir.write('package.json', manifest);
var configFilePath = projectDir.path('config/env_' + utils.getEnvName() + '.json'); // Copy environment variables to package.json file for easy use
destDir.copy(configFilePath, 'env_config.json'); // in the running application. This is not official way of doing
// things, but also isn't prohibited ;)
manifest.env = projectDir.read('config/env_' + utils.getEnvName() + '.json', 'json');
destDir.write('package.json', manifest);
}); });
...@@ -117,4 +113,4 @@ gulp.task('watch', function () { ...@@ -117,4 +113,4 @@ gulp.task('watch', function () {
}); });
gulp.task('build', ['bundle', 'less', 'copy', 'finalize']); gulp.task('build', ['bundle', 'copy', 'finalize']);
...@@ -82,9 +82,11 @@ var createInstaller = function () { ...@@ -82,9 +82,11 @@ var createInstaller = function () {
var finalPackageName = manifest.name + '_' + manifest.version + '.exe'; var finalPackageName = manifest.name + '_' + manifest.version + '.exe';
var installScript = projectDir.read('resources/windows/installer.nsi'); var installScript = projectDir.read('resources/windows/installer.nsi');
installScript = utils.replace(installScript, { installScript = utils.replace(installScript, {
name: manifest.name, name: manifest.name,
productName: manifest.productName, productName: manifest.productName,
author: manifest.author,
version: manifest.version, version: manifest.version,
src: readyAppDir.path(), src: readyAppDir.path(),
dest: releasesDir.path(finalPackageName), dest: releasesDir.path(finalPackageName),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment