asar packaging

pull/811/head
antelle 2017-12-02 20:38:13 +01:00
parent fd11c3011e
commit 2aadc27db8
10 changed files with 43 additions and 54 deletions

View File

@ -190,8 +190,8 @@ module.exports = function(grunt) {
nonull: true
},
'desktop-update': {
cwd: 'tmp/desktop/app/',
src: ['**', '!package-lock.json'],
cwd: 'tmp/desktop/KeeWeb-darwin-x64/KeeWeb.app/Contents/Resources/',
src: 'app.asar',
dest: 'tmp/desktop/update/',
expand: true,
nonull: true
@ -203,23 +203,23 @@ module.exports = function(grunt) {
},
'desktop-windows-helper-ia32': {
src: 'helper/win32/KeeWebHelper.exe',
dest: 'tmp/desktop/KeeWeb-win32-ia32/resources/app/',
dest: 'tmp/desktop/KeeWeb-win32-ia32/Resources/',
nonull: true
},
'desktop-windows-helper-x64': {
src: 'helper/win32/KeeWebHelper.exe',
dest: 'tmp/desktop/KeeWeb-win32-x64/resources/app/',
dest: 'tmp/desktop/KeeWeb-win32-x64/Resources/',
nonull: true
},
'desktop-darwin-helper-x64': {
src: 'helper/darwin/KeeWebHelper',
dest: 'tmp/desktop/KeeWeb-darwin-x64/KeeWeb.app/Contents/Resources/app/',
dest: 'tmp/desktop/KeeWeb-darwin-x64/KeeWeb.app/Contents/Resources/',
nonull: true,
options: { mode: '0755' }
},
'desktop-darwin-installer': {
cwd: 'package/osx/KeeWeb Installer.app',
dest: 'tmp/desktop/KeeWeb-darwin-x64/KeeWeb.app/Contents/Helpers/KeeWeb Installer.app',
dest: 'tmp/desktop/KeeWeb-darwin-x64/KeeWeb.app/Contents/Installer/KeeWeb Installer.app',
src: '**',
expand: true,
nonull: true,
@ -362,6 +362,7 @@ module.exports = function(grunt) {
out: 'tmp/desktop',
electronVersion: electronVersion,
overwrite: true,
asar: true,
'appCopyright': `Copyright © ${year} Antelle`,
'appVersion': pkg.version,
'buildVersion': '<%= gitinfo.local.branch.current.shortSHA %>'
@ -566,12 +567,11 @@ module.exports = function(grunt) {
options: {
file: 'dist/desktop/UpdateDesktop.zip',
expected: [
'main.js', 'app.js', 'index.html', 'package.json', 'icon.png',
'node_modules/node-stream-zip/node_stream_zip.js',
'app.asar',
'helper/darwin/KeeWebHelper',
'helper/win32/KeeWebHelper.exe'
],
expectedCount: 16,
expectedCount: 7,
publicKey: 'app/resources/public-key.pem'
}
}
@ -752,8 +752,8 @@ module.exports = function(grunt) {
'gitinfo',
'clean:desktop',
'build-desktop-app-content',
'build-desktop-update',
'build-desktop-executables',
'build-desktop-update',
'build-desktop-archives',
'build-desktop-dist',
'sign-dist'

View File

@ -9,26 +9,8 @@ const AutoTypeNativeHelper = {
return this._helperPath;
}
const ext = process.platform === 'win32' ? '.exe' : '';
const part = `helper/${process.platform}/KeeWebHelper${ext}`;
const possiblePaths = [
Launcher.getAppPath(part),
Launcher.getUserDataPath(part),
Launcher.getWorkDirPath(part)
];
let helperPath;
const helperCTime = -1;
possiblePaths.forEach(possiblePath => {
try {
const ctime = Launcher.statFileSync(possiblePath).ctime;
if (ctime > helperCTime) {
helperPath = possiblePath;
}
} catch (e) {}
});
if (!helperPath) {
logger.error('Helper not found. Searched paths:', possiblePaths.join(', '));
throw 'Helper not found';
}
const helperRelPath = `helper/${process.platform}/KeeWebHelper${ext}`;
const helperPath = Launcher.getAppPath(helperRelPath);
Launcher.ensureRunnable(helperPath);
logger.debug('Using auto-type helper', helperPath);
this._helperPath = helperPath;

View File

@ -54,7 +54,7 @@ const AppRightsChecker = {
runInstaller() {
Launcher.spawn({
cmd: this.AppPath + '/Contents/Helpers/KeeWeb\ Installer.app/Contents/MacOS/applet',
cmd: this.AppPath + '/Contents/Installer/KeeWeb\ Installer.app/Contents/MacOS/applet',
complete: () => {
this.needRunInstaller(needRun => {
if (this.alert && !needRun) {

View File

@ -81,9 +81,6 @@ const Launcher = {
}, err => callback(undefined, err));
}, err => callback(undefined, err));
},
statFileSync: function(path) {
this.req('fs').statSync(path);
},
mkdir: function(dir, callback) {
const basePath = this.getDataPath().join('/');
const createDir = (dirEntry, path, callback) => {

View File

@ -55,7 +55,9 @@ const Launcher = {
return this.joinPath(this.remoteApp().getPath('documents'), fileName || '');
},
getAppPath: function(fileName) {
return this.joinPath(this.remoteApp().getAppPath(), fileName || '');
const dirname = this.req('path').dirname;
const appPath = __dirname.endsWith('app.asar') ? __dirname : this.remoteApp().getAppPath();
return this.joinPath(dirname(appPath), fileName || '');
},
getWorkDirPath: function(fileName) {
return this.joinPath(process.cwd(), fileName || '');
@ -81,9 +83,6 @@ const Launcher = {
statFile: function(path, callback) {
this.req('fs').stat(path, (err, stats) => callback(stats, err));
},
statFileSync: function(path) {
return this.req('fs').statSync(path);
},
mkdir: function(dir, callback) {
const fs = this.req('fs');
const path = this.req('path');

View File

@ -15,7 +15,7 @@ const Updater = {
UpdateInterval: 1000 * 60 * 60 * 24,
MinUpdateTimeout: 500,
MinUpdateSize: 10000,
UpdateCheckFiles: ['index.html', 'app.js'],
UpdateCheckFiles: ['app.asar'],
nextCheckTimeout: null,
updateCheckDate: new Date(0),
enabled: Launcher && Launcher.updaterEnabled(),
@ -188,6 +188,7 @@ const Updater = {
const expectedFiles = this.UpdateCheckFiles;
const appPath = Launcher.getUserDataPath();
const StreamZip = Launcher.req('node-stream-zip');
StreamZip.setFs(Launcher.req('original-fs'));
const zip = new StreamZip({ file: updateFile, storeEntries: true });
zip.on('error', cb);
zip.on('ready', () => {

View File

@ -11,7 +11,7 @@ let appReady = false;
let restartPending = false;
let mainWindowPosition = {};
let updateMainWindowPositionTimeout = null;
const userDataDir = app.getPath('userData');
const userDataDir = app.getPath('userData').replace(/[\\/]temp[\\/]\d+\.\d+[\\/]?$/, '');
const windowPositionFileName = path.join(userDataDir, 'window-position.json');
const appSettingsFileName = path.join(userDataDir, 'app-settings.json');
const tempUserDataPath = path.join(userDataDir, 'temp');
@ -24,6 +24,7 @@ if (!htmlPath) {
}
app.setPath('userData', path.join(tempUserDataPath, tempUserDataPathRand));
setEnv();
app.on('window-all-closed', () => {
@ -40,7 +41,7 @@ app.on('window-all-closed', () => {
electron.systemPreferences.unsubscribeNotification(id);
}
systemNotificationIds.length = 0;
const userDataAppFile = path.join(userDataDir, 'app.js');
const userDataAppFile = path.join(userDataDir, 'app.asar/app.js');
delete require.cache[require.resolve('./app.js')];
require(userDataAppFile);
app.emit('ready');
@ -376,6 +377,9 @@ function setEnv() {
}
function deleteOldTempFiles() {
if (app.oldTempFilesDeleted) {
return;
}
setTimeout(() => {
for (const dir of fs.readdirSync(tempUserDataPath)) {
if (dir !== tempUserDataPathRand) {
@ -384,6 +388,7 @@ function deleteOldTempFiles() {
} catch (e) {}
}
}
app.oldTempFilesDeleted = true; // this is added to prevent file deletion on restart
}, 1000);
}

View File

@ -11,20 +11,20 @@ const path = require('path');
const fs = require('fs');
const userDataDir = app.getPath('userData');
const appPathUserData = path.join(userDataDir, 'app.js');
let appPath = path.join(__dirname, 'app.js');
const userDataAppArchivePath = path.join(userDataDir, 'app.asar');
let entryPointDir = __dirname;
if (fs.existsSync(appPathUserData)) {
if (fs.existsSync(userDataAppArchivePath)) {
let versionLocal = require('./package.json').version;
try {
let versionUserData = require(path.join(userDataDir, 'package.json')).version;
let versionUserData = require(path.join(userDataAppArchivePath, 'package.json')).version;
versionLocal = versionLocal.split('.');
versionUserData = versionUserData.split('.');
for (let i = 0; i < versionLocal.length; i++) {
if (+versionUserData[i] > +versionLocal[i]) {
appPath = appPathUserData;
entryPointDir = userDataAppArchivePath;
try {
validateSignature(path);
validateSignature(userDataDir);
} catch (e) {
exitWithError('Error validating signatures: ' + e);
}
@ -40,9 +40,10 @@ if (fs.existsSync(appPathUserData)) {
}
function validateSignature(appPath) {
const fs = require('original-fs');
const signatures = JSON.parse(fs.readFileSync(path.join(appPath, 'signatures.json')));
const selfSignature = signatures.kwResSelf;
if (!selfSignature || !signatures['app.js']) {
if (!selfSignature || !signatures['app.asar']) {
exitWithError('Invalid signature file');
}
delete signatures.kwResSelf;
@ -72,4 +73,5 @@ function exitWithError(err) {
process.exit(1);
}
require(appPath);
const entryPointFile = path.join(entryPointDir, 'app.js');
require(entryPointFile);

View File

@ -1,13 +1,14 @@
{
"name": "KeeWeb",
"version": "1.5.6",
"version": "1.6.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"node-stream-zip": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/node-stream-zip/-/node-stream-zip-1.4.1.tgz",
"integrity": "sha512-QYjWTLRNUqYwcHGu3JTcT8TF7PDX5P4SCISBzb3/t8Si4FVedVFagSm8GuOErZcxfg974DniSkr6Dg1XilTQmQ=="
"version": "1.4.2",
"resolved": "https://registry.npmjs.org/node-stream-zip/-/node-stream-zip-1.4.2.tgz",
"integrity": "sha512-9WbviH8qi0HgHmHbQleydUZToH3vNlN83CyOrhrwGaPzmBPH1SUYUkFyHjWl6GWMMODlM81qgycZEfWm267gKA==",
"dev": true
}
}
}

View File

@ -16,6 +16,8 @@
"license": "MIT",
"readme": "../README.md",
"dependencies": {
"node-stream-zip": "1.4.1"
"node-stream-zip": "^1.4.2"
},
"devDependencies": {
}
}