new electron-builder

This commit is contained in:
antelle 2016-04-16 23:34:16 +03:00
parent eef6e3aca6
commit 9ee20331ee
10 changed files with 290 additions and 133 deletions

View File

@ -16,9 +16,9 @@ module.exports = function(grunt) {
var webpack = require('webpack');
var pkg = require('./package.json');
var dt = new Date().toISOString().replace(/T.*/, '');
var electronVersion = '0.37.4';
var minElectronVersionForUpdate = '0.32.0';
var zipCommentPlaceholder = 'zip_comment_placeholder_that_will_be_replaced_with_hash';
var electronVersion = pkg.devDependencies['electron-prebuilt'].replace(/^\D/, '');
while (zipCommentPlaceholder.length < 512) {
zipCommentPlaceholder += '.';
@ -98,12 +98,12 @@ module.exports = function(grunt) {
nonull: true
},
'desktop_osx': {
src: 'tmp/desktop/KeeWeb.dmg',
src: 'tmp/desktop/KeeWeb-darwin-x64/KeeWeb-' + pkg.version + '.dmg',
dest: 'dist/desktop/KeeWeb.mac.dmg',
nonull: true
},
'desktop_win': {
src: 'tmp/desktop/KeeWeb Setup.exe',
src: 'tmp/desktop/win/KeeWebSetup-' + pkg.version + '-ia32.exe',
dest: 'dist/desktop/KeeWeb.win32.exe',
nonull: true
},
@ -299,13 +299,6 @@ module.exports = function(grunt) {
'app-version': pkg.version,
'build-version': '<%= gitinfo.local.branch.current.shortSHA %>'
},
osx: {
options: {
platform: 'darwin',
arch: 'x64',
icon: 'graphics/app.icns'
}
},
linux64: {
options: {
platform: 'linux',
@ -319,58 +312,40 @@ module.exports = function(grunt) {
arch: 'ia32',
icon: 'graphics/app.ico'
}
},
win32: {
options: {
platform: 'win32',
arch: 'ia32',
icon: 'graphics/app.ico',
'version-string': {
CompanyName: 'antelle.github.io',
LegalCopyright: 'Antelle, MIT license',
FileDescription: 'KeeWeb Desktop',
OriginalFilename: 'KeeWeb.exe',
FileVersion: pkg.version,
ProductVersion: pkg.version,
ProductName: 'KeeWeb',
InternalName: 'KeeWeb'
}
}
}
},
'electron-builder': {
options: {
out: path.join(__dirname, 'tmp/desktop'),
basePath: __dirname,
config: {
osx: {
title: 'KeeWeb',
background: path.join(__dirname, 'graphics/dmg-bg.png'),
icon: path.join(__dirname, 'graphics/app.icns'),
'icon-size': 80,
contents: [
{'x': 438, 'y': 344, 'type': 'link', 'path': '/Applications'},
{'x': 192, 'y': 344, 'type': 'file'}
]
},
win: {
title: 'KeeWeb',
icon: path.join(__dirname, 'graphics/app.ico')
}
}
publish: 'never',
dist: false,
projectDir: __dirname,
appDir: 'tmp/desktop/app',
sign: false
},
osx: {
options: {
platform: 'osx',
appPath: path.join(__dirname, 'tmp/desktop/KeeWeb-darwin-x64/KeeWeb.app')
platforms: ['osx'],
arch: 'x64'
}
},
win: {
options: {
platform: 'win32',
appPath: path.join(__dirname, 'tmp/desktop/KeeWeb-win32-ia32')
platform: ['win32'],
arch: 'ia32'
}
}
// linux64: {
// options: {
// platform: ['linux'],
// arch: 'x64'
// }
// },
// linux32: {
// options: {
// platform: ['linux'],
// arch: 'ia32'
// }
// }
},
compress: {
linux64: {
@ -478,7 +453,7 @@ module.exports = function(grunt) {
]);
grunt.registerTask('desktop', [
'default',
// 'default',
'gitinfo',
'clean:desktop_tmp',
'clean:desktop_dist',
@ -488,7 +463,8 @@ module.exports = function(grunt) {
'sign-archive:desktop_update',
'validate-desktop-update',
'electron',
'electron-builder',
'electron-builder:osx',
'electron-builder:win',
'compress:linux64',
'compress:linux32',
'deb:linux64',

View File

@ -3,7 +3,7 @@
"authors": [
"Antelle <dmitryvit@gmail.com>"
],
"description": "KeePass web app",
"description": "Free cross-platform password manager compatible with KeePass",
"main": "app/index.html",
"moduleType": [
"amd"

View File

@ -13,7 +13,7 @@ var app = require('app'),
var mainWindow = null,
appIcon = null,
openFile = process.argv.filter(function(arg) { return /\.kdbx$/i.test(arg); })[0],
openFile = process.argv.filter(function (arg) { return /\.kdbx$/i.test(arg); })[0],
ready = false,
restartPending = false,
htmlPath = path.join(__dirname, 'index.html'),
@ -21,77 +21,81 @@ var mainWindow = null,
updateMainWindowPositionTimeout = null,
windowPositionFileName = path.join(app.getPath('userData'), 'window-position.json');
process.argv.forEach(function(arg) {
if (arg.lastIndexOf('--htmlpath=', 0) === 0) {
htmlPath = path.resolve(arg.replace('--htmlpath=', ''), 'index.html');
}
});
if (!handleStartupSquirrelEvent()) {
process.argv.forEach(function (arg) {
if (arg.lastIndexOf('--htmlpath=', 0) === 0) {
htmlPath = path.resolve(arg.replace('--htmlpath=', ''), 'index.html');
}
});
app.on('window-all-closed', function() {
if (restartPending) {
// unbind all handlers, load new app.js module and pass control to it
globalShortcut.unregisterAll();
app.removeAllListeners('window-all-closed');
app.removeAllListeners('ready');
app.removeAllListeners('open-file');
app.removeAllListeners('activate');
var userDataAppFile = path.join(app.getPath('userData'), 'app.js');
delete require.cache[require.resolve('./app.js')];
require(userDataAppFile);
app.emit('ready');
} else {
if (process.platform !== 'darwin') {
app.quit();
app.on('window-all-closed', function () {
if (restartPending) {
// unbind all handlers, load new app.js module and pass control to it
globalShortcut.unregisterAll();
app.removeAllListeners('window-all-closed');
app.removeAllListeners('ready');
app.removeAllListeners('open-file');
app.removeAllListeners('activate');
var userDataAppFile = path.join(app.getPath('userData'), 'app.js');
delete require.cache[require.resolve('./app.js')];
require(userDataAppFile);
app.emit('ready');
} else {
if (process.platform !== 'darwin') {
app.quit();
}
}
}
});
app.on('ready', function() {
if (!checkSingleInstance()) {
setAppOptions();
createMainWindow();
setGlobalShortcuts();
}
});
app.on('open-file', function(e, path) {
e.preventDefault();
openFile = path;
notifyOpenFile();
});
app.on('activate', function() {
if (process.platform === 'darwin') {
if (!mainWindow) {
});
app.on('ready', function () {
if (!checkSingleInstance()) {
setAppOptions();
createMainWindow();
setGlobalShortcuts();
}
}
});
app.on('will-quit', function() {
globalShortcut.unregisterAll();
});
app.restartApp = function() {
restartPending = true;
mainWindow.close();
setTimeout(function() { restartPending = false; }, 1000);
};
app.openWindow = function(opts) {
return new BrowserWindow(opts);
};
app.minimizeApp = function() {
if (process.platform !== 'darwin') {
mainWindow.minimize();
mainWindow.setSkipTaskbar(true);
appIcon = new Tray(path.join(__dirname, 'icon.png'));
appIcon.on('click', restoreMainWindow);
var contextMenu = Menu.buildFromTemplate([
{ label: 'Open KeeWeb', click: restoreMainWindow },
{ label: 'Quit KeeWeb', click: closeMainWindow }
]);
appIcon.setContextMenu(contextMenu);
appIcon.setToolTip('KeeWeb');
}
};
app.getMainWindow = function() {
return mainWindow;
};
});
app.on('open-file', function (e, path) {
e.preventDefault();
openFile = path;
notifyOpenFile();
});
app.on('activate', function () {
if (process.platform === 'darwin') {
if (!mainWindow) {
createMainWindow();
}
}
});
app.on('will-quit', function () {
globalShortcut.unregisterAll();
});
app.restartApp = function () {
restartPending = true;
mainWindow.close();
setTimeout(function () {
restartPending = false;
}, 1000);
};
app.openWindow = function (opts) {
return new BrowserWindow(opts);
};
app.minimizeApp = function () {
if (process.platform !== 'darwin') {
mainWindow.minimize();
mainWindow.setSkipTaskbar(true);
appIcon = new Tray(path.join(__dirname, 'icon.png'));
appIcon.on('click', restoreMainWindow);
var contextMenu = Menu.buildFromTemplate([
{label: 'Open KeeWeb', click: restoreMainWindow},
{label: 'Quit KeeWeb', click: closeMainWindow}
]);
appIcon.setContextMenu(contextMenu);
appIcon.setToolTip('KeeWeb');
}
};
app.getMainWindow = function () {
return mainWindow;
};
}
function checkSingleInstance() {
var shouldQuit = app.makeSingleInstance(function(/*commandLine, workingDirectory*/) {
@ -286,3 +290,11 @@ function setGlobalShortcuts() {
} catch (e) {}
});
}
function handleStartupSquirrelEvent() {
if (process.platform !== 'win32') {
return false;
}
var handleSquirrelArg = require('./squirrel-handler');
return handleSquirrelArg();
}

View File

@ -1,10 +1,14 @@
{
"name": "KeeWeb",
"version": "1.1.2",
"description": "KeePass web app",
"description": "Free cross-platform password manager compatible with KeePass",
"main": "main.js",
"repository": "https://github.com/antelle/keeweb",
"author": "Antelle",
"repository": { "type": "git", "url": "https://github.com/antelle/keeweb" },
"author": {
"name": "Antelle",
"email": "antelle.net@gmail.com",
"url": "http://antelle.net"
},
"license": "MIT",
"readme": "../README.md",
"dependencies": {

View File

@ -0,0 +1,121 @@
'use strict';
// Portions copyright (C) GitHub, Atom project, MIT license https://github.com/atom/atom/blob/master/LICENSE.md
// https://github.com/atom/atom/blob/master/src/browser/squirrel-update.coffee
/* jshint node:true */
/* jshint browser:false */
var app = require('app'),
fs = require('fs'),
path = require('path'),
spawn = require('child_process').spawn;
var Reg = {
FileKey: 'HKCU\\Software\\Classes\\*\\shell\\KeeWeb',
ApplicationsKey: 'HKCU\\Software\\Classes\\Applications\\keeweb.exe'
};
var regPath = process.env.SystemRoot ? path.join(process.env.SystemRoot, 'System32', 'reg.exe') : 'reg.exe',
appFolder = path.resolve(process.execPath, '..'),
rootAppFolder = path.resolve(appFolder, '..'),
updateDotExe = path.join(rootAppFolder, 'Update.exe');
function handleSquirrelArg() {
var squirrelCommand = process.argv[1];
switch (squirrelCommand) {
case '--squirrel-install':
createShortcuts(function() {
app.quit(); // installContextMenu(app.quit);
});
return true;
case '--squirrel-updated':
updateShortcuts(function() {
app.quit(); // installContextMenu(app.quit);
});
return true;
case '--squirrel-uninstall':
removeShortcuts(function() {
app.quit(); // uninstallContextMenu(app.quit);
});
return true;
case '--squirrel-obsolete':
app.quit();
return true;
default:
return false;
}
}
function createShortcuts(callback) {
spawnUpdate(['--createShortcut', path.basename(process.execPath)], callback);
}
function updateShortcuts(callback) {
var homeDirectory = fs.getHomeDirectory();
if (homeDirectory) {
var desktopShortcutPath = path.join(homeDirectory, 'Desktop', 'KeeWeb.lnk');
fs.exists(desktopShortcutPath, function(exists) {
createShortcuts(function() {
if (exists) {
callback();
} else {
fs.unlink(desktopShortcutPath, callback);
}
});
});
} else {
createShortcuts(callback);
}
}
function removeShortcuts(callback) {
spawnUpdate(['--removeShortcut', path.basename(process.execPath)], callback);
}
function installContextMenu(callback) {
var addToRegistry, installFileHandler, installMenu;
addToRegistry = function(args, callback) {
args.unshift('add');
args.push('/f');
return spawnReg(args, callback);
};
installFileHandler = function(callback) {
var args;
args = [Reg.ApplicationsKey + '\\shell\\open\\command', '/ve', '/d', '"' + process.execPath + '" "%1"'];
return addToRegistry(args, callback);
};
installMenu = function(keyPath, arg, callback) {
var args;
args = [keyPath, '/ve', '/d', 'Open with KeeWeb'];
return addToRegistry(args, function() {
args = [keyPath, '/v', 'Icon', '/d', '"' + process.execPath + '"'];
return addToRegistry(args, function() {
args = [keyPath + '\\command', '/ve', '/d', '"' + process.execPath + '" "' + arg + '"'];
return addToRegistry(args, callback);
});
});
};
return installMenu(Reg.FileKey, '%1', function() {
return installFileHandler(callback);
});
}
function uninstallContextMenu(callback) {
var deleteFromRegistry = function(keyPath, callback) {
return spawnReg(['delete', keyPath, '/f'], callback);
};
return deleteFromRegistry(Reg.FileKey, function() {
return deleteFromRegistry(Reg.ApplicationsKey, callback);
});
}
function spawnUpdate(args) {
spawn(updateDotExe, args, { detached: true }).on('close', app.quit);
}
function spawnReg(args, callback) {
return spawn(regPath, args, callback);
}
module.exports = handleSquirrelArg;

View File

Before

Width:  |  Height:  |  Size: 182 KiB

After

Width:  |  Height:  |  Size: 182 KiB

View File

Before

Width:  |  Height:  |  Size: 361 KiB

After

Width:  |  Height:  |  Size: 361 KiB

View File

@ -1,16 +1,38 @@
'use strict';
var builder = require('electron-builder').init();
var builder = require('electron-builder');
var macPackager = require('electron-builder/out/macPackager');
var platformPackager = require('electron-builder/out/platformPackager');
var linuxPackager = require('electron-builder/out/linuxPackager');
var version;
// workaround for https://github.com/electron-userland/electron-builder/issues/322
macPackager.default.prototype.zipMacApp = function() {
return Promise.resolve();
};
// workaround for https://github.com/electron-userland/electron-builder/issues/323
platformPackager.PlatformPackager.prototype.computeBuildNumber = function() {
this.devMetadata.build['build-version'] = version;
return version;
};
// we don't have 512x512 icon
var createFromIcns = linuxPackager.LinuxPackager.prototype.createFromIcns;
linuxPackager.LinuxPackager.prototype.createFromIcns = function() {
return createFromIcns.apply(this, arguments).then(function(res) {
return res.filter(function(item) { return item.indexOf('512x512') < 0; });
});
};
module.exports = function (grunt) {
grunt.registerMultiTask('electron-builder', 'Create app installer with electron-builder', function () {
version = grunt.config.get('gitinfo.local.branch.current.shortSHA');
console.log();
var done = this.async();
builder.build(this.options(), function(err) {
if (err) {
grunt.warn(err);
return;
}
done();
});
builder.build(this.options())
.then(function () { done(); })
.catch(function (err) { grunt.warn(err || 'electron-builder error'); });
});
};

View File

@ -12,7 +12,8 @@
"devDependencies": {
"base64-loader": "^1.0.0",
"cssnano": "^3.3.2",
"electron-builder": "=2.1.1",
"electron-builder": "^3.5.2",
"electron-prebuilt": "^0.37.4",
"exports-loader": "^0.6.2",
"get-folder-size": "^1.0.0",
"grunt": "^0.4.5",
@ -21,8 +22,8 @@
"grunt-contrib-compress": "^1.2.0",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-deb": "github:antelle/grunt-contrib-deb#ddb2ef4",
"grunt-contrib-jshint": "^1.0.0",
"grunt-contrib-htmlmin": "^1.2.0",
"grunt-contrib-jshint": "^1.0.0",
"grunt-contrib-uglify": "^1.0.1",
"grunt-contrib-watch": "^1.0.0",
"grunt-electron": "^2.0.1",
@ -55,6 +56,27 @@
"email": "antelle.net@gmail.com",
"url": "http://antelle.net"
},
"build": {
"app-bundle-id": "net.antelle.keeweb",
"app-category-type": "public.app-category.productivity",
"iconUrl": "https://raw.githubusercontent.com/antelle/keeweb/master/graphics/icon.ico",
"compression": "maximum",
"asar": false,
"osx": {
"contents": [
{ "x": 438, "y": 344, "type": "link", "path": "/Applications" },
{ "x": 192, "y": 344, "type": "file" }
],
"icon-size": 80
},
"win": {
"loadingGif": "graphics/background.png"
}
},
"directories": {
"buildResources": "graphics",
"output": "tmp/desktop"
},
"license": "MIT",
"readme": "README.md"
}