split electron app to launcher, content and data

This commit is contained in:
Antelle 2015-11-14 10:46:53 +03:00
parent bfb337b499
commit 876148e953
4 changed files with 53 additions and 14 deletions

View File

@ -6,15 +6,18 @@
var app = require('app'),
BrowserWindow = require('browser-window'),
path = require('path'),
fs = require('fs'),
Menu = require('menu');
var mainWindow = null,
openFile = process.argv.filter(function(arg) { return /\.kdbx$/i.test(arg); })[0],
ready = false,
htmlPath = path.join(app.getPath('userData'), 'index.html');
htmlPath = path.join(__dirname, 'index.html');
htmlPath = path.join(__dirname, '../tmp/index.html');
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() { app.quit(); });
app.on('ready', function() {
@ -24,14 +27,10 @@ app.on('ready', function() {
icon: path.join(__dirname, 'icon.png')
});
setMenu();
if (fs.existsSync(htmlPath)) {
mainWindow.loadUrl('file://' + htmlPath);
}
mainWindow.show(); // remove
mainWindow.openDevTools();
mainWindow.loadUrl('file://' + htmlPath);
mainWindow.webContents.on('dom-ready', function() {
setTimeout(function() {
//mainWindow.show();
mainWindow.show();
ready = true;
notifyOpenFile();
}, 50);

31
electron/launcher.js Normal file
View File

@ -0,0 +1,31 @@
'use strict';
/* jshint node:true */
/* jshint browser:false */
var app = require('app'),
path = require('path'),
fs = require('fs');
var userDataDir = app.getPath('userData'),
appPathUserData = path.join(userDataDir, 'app.js'),
appPath = path.join(__dirname, 'app.js');
if (fs.existsSync(appPathUserData)) {
var versionLocal = require('./package.json').version;
try {
var versionUserData = require(path.join(userDataDir, 'package.json')).version;
versionLocal = versionLocal.split('.');
versionUserData = versionUserData.split('.');
for (var i = 0; i < versionLocal.length; i++) {
if (+versionUserData[i] > +versionLocal[i]) {
appPath = appPathUserData;
}
}
}
catch (e) {
console.error('Error reading user file version', e);
}
}
require(appPath);

View File

@ -1,5 +1,13 @@
{
"name": "KeeWeb",
"version": "0.2.1",
"main": "main.js"
"description": "KeePass web app",
"main": "launcher.js",
"repository": "https://github.com/antelle/keeweb",
"author": "Antelle",
"license": "MIT",
"readme": "../README.md",
"dependencies": {
"node-stream-zip": "^1.2.1"
}
}

View File

@ -31,13 +31,14 @@
"string-replace-webpack-plugin": "0.0.2",
"time-grunt": "^1.2.1",
"uglify-loader": "^1.2.0",
"webpack": "^1.11.0",
"webpack-dev-server": "^1.10.1"
"webpack": "^1.11.0"
},
"scripts": {
"start": "grunt",
"test": "grunt test"
"test": "grunt test",
"postinstall": "npm install --prefix electron"
},
"author": "Antelle",
"license": "MIT"
"license": "MIT",
"readme": "README.md"
}