diff --git a/app/scripts/app.js b/app/scripts/app.js index 4d75bb8d..a85461db 100644 --- a/app/scripts/app.js +++ b/app/scripts/app.js @@ -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(); } diff --git a/app/scripts/comp/launcher-electron.js b/app/scripts/comp/launcher-electron.js index 10dfe18c..979d990c 100644 --- a/app/scripts/comp/launcher-electron.js +++ b/app/scripts/comp/launcher-electron.js @@ -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; diff --git a/app/scripts/models/app-model.js b/app/scripts/models/app-model.js index d68a618d..2b35afe5 100644 --- a/app/scripts/models/app-model.js +++ b/app/scripts/models/app-model.js @@ -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(), diff --git a/app/scripts/views/app-view.js b/app/scripts/views/app-view.js index 0255ab4b..712a83e8 100644 --- a/app/scripts/views/app-view.js +++ b/app/scripts/views/app-view.js @@ -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); } }, diff --git a/app/scripts/views/open-view.js b/app/scripts/views/open-view.js index bd6f3c4e..4d467eb6 100644 --- a/app/scripts/views/open-view.js +++ b/app/scripts/views/open-view.js @@ -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() { diff --git a/desktop/app.js b/desktop/app.js index 9ba77f18..1e340649 100644 --- a/desktop/app.js +++ b/desktop/app.js @@ -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 = { diff --git a/release-notes.md b/release-notes.md index 2b9c3049..cc03de2a 100644 --- a/release-notes.md +++ b/release-notes.md @@ -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