fix #731: option to open keyfile from command line

This commit is contained in:
antelle 2017-12-03 20:31:54 +01:00
parent b7013c548e
commit 04958db14d
6 changed files with 38 additions and 12 deletions

View File

@ -1,3 +1,4 @@
const Backbone = require('backbone');
const AppModel = require('./models/app-model');
const AppView = require('./views/app-view');
const AppSettingsModel = require('./models/app-settings-model');
@ -142,6 +143,7 @@ ready(() => {
function showView() {
appModel.prepare();
new AppView({ model: appModel }).render();
Backbone.trigger('app-ready');
logStartupTime();
}

View File

@ -253,6 +253,20 @@ const Launcher = {
}
return ps;
},
checkOpenFiles() {
this.readyToOpenFiles = true;
if (this.pendingFileToOpen) {
this.openFile(this.pendingFileToOpen);
delete this.pendingFileToOpen;
}
},
openFile(file) {
if (this.readyToOpenFiles) {
Backbone.trigger('launcher-open-file', file);
} else {
this.pendingFileToOpen = file;
}
},
getCookies(callback) {
this.electron().remote.session.defaultSession.cookies.get({}, callback);
},
@ -270,13 +284,12 @@ Backbone.on('launcher-exit-request', () => {
setTimeout(() => Launcher.exit(), 0);
});
Backbone.on('launcher-minimize', () => setTimeout(() => Backbone.trigger('app-minimized'), 0));
window.launcherOpen = function(path) {
Backbone.trigger('launcher-open-file', path);
};
window.launcherOpen = file => Launcher.openFile(file);
if (window.launcherOpenedFile) {
logger.info('Open file request', window.launcherOpenedFile);
Backbone.trigger('launcher-open-file', window.launcherOpenedFile);
Launcher.openFile(window.launcherOpenedFile);
delete window.launcherOpenedFile;
}
Backbone.on('app-ready', () => setTimeout(() => Launcher.checkOpenFiles(), 0));
module.exports = Launcher;

View File

@ -167,10 +167,10 @@ const AppView = Backbone.View.extend({
}
},
launcherOpenFile: function(path) {
if (path && /\.kdbx$/i.test(path)) {
launcherOpenFile: function(file) {
if (file && file.data && /\.kdbx$/i.test(file.data)) {
this.showOpenFile();
this.views.open.showOpenLocalFile(path);
this.views.open.showOpenLocalFile(file.data, file.key);
}
},

View File

@ -270,7 +270,7 @@ const OpenView = Backbone.View.extend({
displayOpenKeyFile: function() {
this.$el.toggleClass('open--key-file', !!this.params.keyFileName);
this.$el.find('.open__settings-key-file-name').text(this.params.keyFilePath || this.params.keyFileName || Locale.openKeyFile);
this.$el.find('.open__settings-key-file-name').text(this.params.keyFileName || this.params.keyFilePath || Locale.openKeyFile);
this.focusInput();
},
@ -531,7 +531,7 @@ const OpenView = Backbone.View.extend({
this.displayOpenKeyFile();
},
showOpenLocalFile: function(path) {
showOpenLocalFile: function(path, keyFilePath) {
if (this.busy) {
return;
}
@ -542,6 +542,13 @@ const OpenView = Backbone.View.extend({
this.params.rev = null;
this.params.fileData = null;
this.displayOpenFile();
if (keyFilePath) {
const parsed = Launcher.parsePath(keyFilePath);
this.params.keyFileName = parsed.file;
this.params.keyFilePath = keyFilePath;
this.params.keyFileData = null;
this.displayOpenKeyFile();
}
},
createDemo: function() {

View File

@ -331,13 +331,16 @@ function onContextMenu(e, props) {
function notifyOpenFile() {
if (ready && openFile && mainWindow) {
openFile = openFile.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
mainWindow.webContents.executeJavaScript('if (window.launcherOpen) { window.launcherOpen("' + openFile + '"); } ' +
' else { window.launcherOpenedFile="' + openFile + '"; }');
const openKeyfile = process.argv.filter(arg => arg.startsWith('--keyfile=')).map(arg => arg.replace('--keyfile=', ''))[0];
const fileInfo = JSON.stringify({ data: openFile, key: openKeyfile });
mainWindow.webContents.executeJavaScript('if (window.launcherOpen) { window.launcherOpen(' + fileInfo + '); } ' +
' else { window.launcherOpenedFile=' + fileInfo + '; }');
openFile = null;
}
}
function setGlobalShortcuts() {
const shortcutModifiers = process.platform === 'darwin' ? 'Ctrl+Alt+' : 'Shift+Alt+';
const shortcuts = {

View File

@ -4,6 +4,7 @@ Release notes
`-` fixed color flash on startup
`+` downgrading desktop app
`-` fixed calendar colors
`+` option to open keyfile from command line
##### v1.6.3 (2017-12-11)
`-` fixed Windows installer upgrade issue