mirror of https://github.com/keeweb/keeweb
fix #731: option to open keyfile from command line
parent
c063cd3461
commit
a4d5963620
|
@ -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');
|
||||
|
@ -140,6 +141,7 @@ ready(() => {
|
|||
function showView() {
|
||||
appModel.prepare();
|
||||
new AppView({ model: appModel }).render();
|
||||
Backbone.trigger('app-ready');
|
||||
logStartupTime();
|
||||
}
|
||||
|
||||
|
|
|
@ -252,6 +252,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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -259,13 +273,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;
|
||||
|
|
|
@ -500,6 +500,8 @@ const AppModel = Backbone.Model.extend({
|
|||
needLoadKeyFile = true;
|
||||
}
|
||||
}
|
||||
} else if (!params.keyFileData && !fileInfo) {
|
||||
needLoadKeyFile = true;
|
||||
}
|
||||
const file = new FileModel({
|
||||
id: fileInfo ? fileInfo.id : IdGenerator.uuid(),
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -260,7 +260,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();
|
||||
},
|
||||
|
||||
|
@ -490,7 +490,7 @@ const OpenView = Backbone.View.extend({
|
|||
this.displayOpenKeyFile();
|
||||
},
|
||||
|
||||
showOpenLocalFile: function(path) {
|
||||
showOpenLocalFile: function(path, keyFilePath) {
|
||||
if (this.busy) {
|
||||
return;
|
||||
}
|
||||
|
@ -501,6 +501,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() {
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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.1 (2017-12-03)
|
||||
`-` fixed white screen on startup
|
||||
|
|
Loading…
Reference in New Issue