keeweb/electron/main.js

51 lines
1.5 KiB
JavaScript
Raw Normal View History

2015-10-21 22:32:02 +02:00
'use strict';
2015-10-25 08:29:31 +01:00
/* jshint node:true */
/* jshint browser:false */
2015-10-21 22:32:02 +02:00
var app = require('app'),
BrowserWindow = require('browser-window'),
path = require('path'),
fs = require('fs');
2015-10-24 21:06:44 +02:00
var mainWindow = null,
2015-10-25 08:29:31 +01:00
openFile = process.argv.filter(function(arg) { return /\.kdbx$/i.test(arg); })[0],
2015-10-24 21:06:44 +02:00
ready = false;
2015-10-21 22:32:02 +02:00
app.on('window-all-closed', function() { app.quit(); });
app.on('ready', function() {
var htmlPath = path.join(app.getPath('userData'), 'index.html');
mainWindow = new BrowserWindow({
2015-10-24 21:06:44 +02:00
show: false,
2015-10-21 23:10:36 +02:00
width: 1000, height: 700, 'min-width': 600, 'min-height': 300,
2015-10-21 22:32:02 +02:00
icon: path.join(__dirname, 'icon.png')
});
mainWindow.setMenu(null);
if (fs.existsSync(htmlPath)) {
mainWindow.loadUrl('file://' + htmlPath);
} else {
mainWindow.loadUrl('https://antelle.github.io/keeweb/index.html');
}
2015-10-24 21:06:44 +02:00
mainWindow.webContents.on('dom-ready', function() {
mainWindow.show();
ready = true;
notifyOpenFile();
});
2015-10-21 22:32:02 +02:00
mainWindow.on('closed', function() { mainWindow = null; });
});
2015-10-24 21:06:44 +02:00
app.on('open-file', function(e, path) {
e.preventDefault();
2015-10-25 08:53:05 +01:00
openFile = path;
2015-10-24 21:06:44 +02:00
notifyOpenFile();
});
function notifyOpenFile() {
if (ready && openFile && mainWindow) {
2015-10-25 08:53:05 +01:00
openFile = openFile.replace(/"/g, '\\"').replace(/\\/g, '\\\\');
2015-10-24 21:06:44 +02:00
mainWindow.webContents.executeJavaScript('if (window.launcherOpen) { window.launcherOpen("' + openFile + '"); } ' +
' else { window.launcherOpenedFile="' + openFile + '"; }');
2015-10-25 08:53:05 +01:00
openFile = null;
2015-10-24 21:06:44 +02:00
}
}