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 @@
*
* @fileoverview Generates the application menu bar.
*/
var app = require('app');
var Menu = require('menu');
var shell = require('shell');
var dialog = require('dialog');
var MenuItem = require('menu-item');
var server = require('./servermgr.js');
var BrowserWindow = require('browser-window');
const electron = require('electron');
const app = electron.app;
const Menu = electron.Menu;
const shell = electron.shell;
const dialog = electron.dialog;
const MenuItem = electron.MenuItem;
const BrowserWindow = electron.BrowserWindow;
const server = require('./servermgr.js');
module.exports.setArdublocklyMenu = function(devMode) {
if (typeof(devMode)==='undefined') devMode = false;
......@@ -380,7 +382,7 @@ var getDevMenuData = function() {
label: 'Reload',
accelerator: 'CmdOrCtrl+F5',
click: function() {
BrowserWindow.getFocusedWindow().reloadIgnoringCache();
BrowserWindow.getFocusedWindow().webContents.reloadIgnoringCache();
}
}, {
label: 'Toggle DevTools',
......
......@@ -7,16 +7,19 @@
* @fileoverview Electron entry point continues here. Creates windows and
* handles system events.
*/
var app = require('app');
var winston = require('winston');
var appMenu = require('./appmenu.js');
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');
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
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
// be closed automatically when the JavaScript object is garbage collected.
......@@ -114,7 +117,7 @@ app.on('ready', function() {
mainWindow.webContents.session.setDownloadPath(
process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME']);
mainWindow.loadUrl('http://localhost:8000/ardublockly');
mainWindow.loadURL('http://localhost:8000/ardublockly');
mainWindow.on('close', function() {
mainWindowState.saveState(mainWindow);
......@@ -147,6 +150,6 @@ function createSplashWindow() {
'skip-taskbar': true,
'use-content-size': true
});
splashWindow.loadUrl(imagePath);
splashWindow.loadURL(imagePath);
}
}
......@@ -7,11 +7,8 @@
"author": "carlosperate",
"homepage": "http://ardublockly.embeddedlog.com/",
"main": "main.js",
"config": {
"target": "development"
},
"dependencies": {
"fs-jetpack": "^0.7.0",
"fs-jetpack": "^0.7.1",
"winston": "^1.0.1"
},
"repository" : {
......
......@@ -6,17 +6,16 @@
*
* @fileoverview Finds the Ardublockly Project directory and files.
*/
var jetpack = require('fs-jetpack');
var env = require('./vendor/electron_boilerplate/env_config');
const jetpack = require('fs-jetpack');
// Name of the folder containing the electron executable, needs to be synced
// with the name set in the Python server and Electron build files.
var execFolderName = 'arduexec';
var serverExecFolderName = 'server';
var serverExecName = 'start';
const execFolderName = 'arduexec';
const serverExecFolderName = 'server';
const serverExecName = 'start';
module.exports.ardublocklyExecFolderName = execFolderName;
var tag = '[Project Root Locator] ';
const tag = '[Project Root Locator] ';
var ardublocklyRootDir = null;
......@@ -33,32 +32,25 @@ function ardublocklyNotFound(working_dir) {
module.exports.getProjectRootJetpack = function() {
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
// ardublockly folder in a node from the executable file path tree
ardublocklyRootDir = jetpack.dir(__dirname);
var oldArdublocklyRootDir = '';
while (ardublocklyRootDir.path() != oldArdublocklyRootDir) {
// Check if /ardublokly/index.html exists within current path
if (jetpack.exists(
ardublocklyRootDir.path('ardublockly', 'index.html'))) {
// Found the right folder, break with this dir loaded
break;
}
oldArdublocklyRootDir = ardublocklyRootDir.path();
ardublocklyRootDir = ardublocklyRootDir.dir('../');
// Cannot use relative paths in build, so let's try to find the
// ardublockly folder in a node from the executable file path tree
ardublocklyRootDir = jetpack.dir(__dirname);
var oldArdublocklyRootDir = '';
while (ardublocklyRootDir.path() != oldArdublocklyRootDir) {
// Check if /ardublokly/index.html exists within current path
if (jetpack.exists(
ardublocklyRootDir.path('ardublockly', 'index.html'))) {
// Found the right folder, break with this dir loaded
break;
}
oldArdublocklyRootDir = ardublocklyRootDir.path();
ardublocklyRootDir = ardublocklyRootDir.dir('../');
}
if (ardublocklyRootDir.path() == oldArdublocklyRootDir) {
ardublocklyRootDir = jetpack.dir('.');
ardublocklyNotFound(ardublocklyRootDir.path('.'));
}
if (ardublocklyRootDir.path() == oldArdublocklyRootDir) {
ardublocklyRootDir = jetpack.dir('.');
ardublocklyNotFound(ardublocklyRootDir.path('.'));
}
}
return ardublocklyRootDir;
};
......
......@@ -6,11 +6,12 @@
*
* @fileoverview Manages the Ardublockly server.
*/
var winston = require('winston');
var childProcess = require('child_process');
var projectLocator = require('./projectlocator.js');
const winston = require('winston');
const childProcess = require('child_process');
var tag = '[Server mgr] '
const projectLocator = require('./projectlocator.js');
const tag = '[Server mgr] '
var serverProcess = null;
......
......@@ -4,9 +4,9 @@
(function () {
'use strict';
var remote = require('remote');
var Menu = remote.require('menu');
var MenuItem = remote.require('menu-item');
var remote = require('electron').remote;
var Menu = remote.Menu;
var MenuItem = remote.MenuItem;
var cut = new MenuItem({
label: "Cut",
......@@ -34,7 +34,7 @@
textMenu.append(copy);
textMenu.append(paste);
document.addEventListener('contextmenu', function(e) {
document.addEventListener('contextmenu', function (e) {
switch (e.target.nodeName) {
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 @@
(function () {
'use strict';
var shell = require('shell');
var shell = require('electron').shell;
var supportExternalLinks = function (e) {
var href;
......
{
"devDependencies": {
"asar": "^0.7.2",
"electron-prebuilt": "^0.34.0",
"electron-prebuilt": "^0.35.1",
"fs-jetpack": "^0.7.0",
"gulp": "^3.9.0",
"gulp-less": "^3.0.3",
"gulp-util": "^3.0.6",
"q": "^1.4.1",
"rollup": "^0.16.1",
"rollup": "^0.21.0",
"tree-kill": "^0.1.1",
"yargs": "^3.15.0"
},
......@@ -16,8 +16,7 @@
"rcedit": "^0.3.0"
},
"scripts": {
"postinstall": "node ./tasks/app_npm_install",
"app-install": "node ./tasks/app_npm_install",
"postinstall": "cd app && npm install",
"build": "gulp build",
"release": "gulp release --env=production",
"start": "node ./tasks/start"
......
......@@ -12,6 +12,7 @@
!define src "{{src}}"
!define name "{{name}}"
!define productName "{{productName}}"
!define author "{{author}}"
!define version "{{version}}"
!define icon "{{icon}}"
!define setupIcon "{{setupIcon}}"
......@@ -90,6 +91,8 @@ Section "Install"
WriteRegStr HKLM "${uninstkey}" "DisplayName" "${productName}"
WriteRegStr HKLM "${uninstkey}" "DisplayIcon" '"$INSTDIR\icon.ico"'
WriteRegStr HKLM "${uninstkey}" "UninstallString" '"$INSTDIR\${uninstaller}"'
WriteRegStr HKLM "${uninstkey}" "Publisher" "${author}"
WriteRegStr HKLM "${uninstkey}" "DisplayVersion" "${version}"
; Remove all application files copied by previous installation
RMDir /r "$INSTDIR"
......@@ -100,6 +103,7 @@ Section "Install"
File /r "${src}\*"
; Create start menu shortcut
SetShellVarContext all
CreateShortCut "$SMPROGRAMS\${productName}.lnk" "$INSTDIR\${exec}" "" "$INSTDIR\icon.ico"
WriteUninstaller "${uninstaller}"
......@@ -149,6 +153,7 @@ Section "Uninstall"
DeleteRegKey HKLM "${uninstkey}"
DeleteRegKey HKLM "${regkey}"
SetShellVarContext all
Delete "$SMPROGRAMS\${productName}.lnk"
; 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');
var paths = {
copyFromAppDir: [
'./main.js', // maybe need to remove this one too
'./*.js',
'./node_modules/**',
'./vendor/**',
'./**/*.html'
'./*.js'
],
}
......@@ -27,7 +25,7 @@ var paths = {
// Tasks
// -------------------------------------
gulp.task('clean', function(callback) {
gulp.task('clean', function (callback) {
return destDir.dirAsync('.', { empty: true });
});
......@@ -46,7 +44,7 @@ var bundle = function (src, dest) {
var deferred = Q.defer();
rollup.rollup({
entry: src
entry: src,
}).then(function (bundle) {
var jsFile = pathUtil.basename(dest);
var result = bundle.generate({
......@@ -54,14 +52,17 @@ var bundle = function (src, dest) {
sourceMap: true,
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([
destDir.writeAsync(dest, result.code + '\n//# sourceMappingURL=' + jsFile + '.map'),
destDir.writeAsync(dest, isolatedCode + '\n//# sourceMappingURL=' + jsFile + '.map'),
destDir.writeAsync(dest + '.map', result.map.toString()),
]);
}).then(function () {
deferred.resolve();
}).catch(function (err) {
console.error(err);
console.error('Build: Error during rollup', err.stack);
});
return deferred.promise;
......@@ -81,17 +82,9 @@ gulp.task('bundle', ['clean'], 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 () {
var manifest = srcDir.read('package.json', 'json');
// Add "dev" or "test" suffix to name, so Electron will write all data
// like cookies and localStorage in separate places for each environment.
switch (utils.getEnvName()) {
......@@ -103,10 +96,13 @@ gulp.task('finalize', ['clean'], function () {
throw "test build has been removed";
break;
}
destDir.write('package.json', manifest);
var configFilePath = projectDir.path('config/env_' + utils.getEnvName() + '.json');
destDir.copy(configFilePath, 'env_config.json');
// Copy environment variables to package.json file for easy use
// 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 () {
});
gulp.task('build', ['bundle', 'less', 'copy', 'finalize']);
gulp.task('build', ['bundle', 'copy', 'finalize']);
......@@ -82,9 +82,11 @@ var createInstaller = function () {
var finalPackageName = manifest.name + '_' + manifest.version + '.exe';
var installScript = projectDir.read('resources/windows/installer.nsi');
installScript = utils.replace(installScript, {
name: manifest.name,
productName: manifest.productName,
author: manifest.author,
version: manifest.version,
src: readyAppDir.path(),
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