mirror of https://github.com/keeweb/keeweb.git
fix #3: desktop app close handler
This commit is contained in:
parent
c40d516b6d
commit
290fe195b6
|
@ -8,6 +8,9 @@ if (window.process && window.process.versions && window.process.versions.electro
|
|||
name: 'electron',
|
||||
version: window.process.versions.electron,
|
||||
req: window.require,
|
||||
remReq: function(mod) {
|
||||
return this.req('remote').require(mod);
|
||||
},
|
||||
openLink: function(href) {
|
||||
this.req('shell').openExternal(href);
|
||||
},
|
||||
|
@ -16,12 +19,11 @@ if (window.process && window.process.versions && window.process.versions.electro
|
|||
this.req('remote').getCurrentWindow().openDevTools();
|
||||
},
|
||||
getSaveFileName: function(defaultPath, cb) {
|
||||
var remote = this.req('remote');
|
||||
if (defaultPath) {
|
||||
var homePath = remote.require('app').getPath('userDesktop');
|
||||
var homePath = this.remReq('app').getPath('userDesktop');
|
||||
defaultPath = this.req('path').join(homePath, defaultPath);
|
||||
}
|
||||
remote.require('dialog').showSaveDialog({
|
||||
this.remReq('dialog').showSaveDialog({
|
||||
title: 'Save Passwords Database',
|
||||
defaultPath: defaultPath,
|
||||
filters: [{ name: 'KeePass files', extensions: ['kdbx'] }]
|
||||
|
@ -35,6 +37,10 @@ if (window.process && window.process.versions && window.process.versions.electro
|
|||
},
|
||||
fileExists: function(path) {
|
||||
return this.req('fs').existsSync(path);
|
||||
},
|
||||
exit: function() {
|
||||
Launcher.exitRequested = true;
|
||||
this.remReq('app').quit();
|
||||
}
|
||||
};
|
||||
window.launcherOpen = function(path) {
|
||||
|
|
|
@ -186,8 +186,20 @@ var AppView = Backbone.View.extend({
|
|||
}
|
||||
},
|
||||
|
||||
beforeUnload: function() {
|
||||
beforeUnload: function(e) {
|
||||
if (this.model.files.hasUnsavedFiles()) {
|
||||
if (Launcher && !Launcher.exitRequested) {
|
||||
Alerts.yesno({
|
||||
header: 'Unsaved changes!',
|
||||
body: 'You have unsaved files, all changes will be lost.',
|
||||
buttons: [{result: 'yes', title: 'Exit and discard unsaved changes'}, {result: '', title: 'Don\'t exit'}],
|
||||
success: function() {
|
||||
Launcher.exit();
|
||||
}
|
||||
});
|
||||
e.returnValue = false;
|
||||
return false;
|
||||
}
|
||||
return 'You have unsaved files, all changes will be lost.';
|
||||
}
|
||||
},
|
||||
|
|
|
@ -16,6 +16,7 @@ var mainWindow = null,
|
|||
app.on('window-all-closed', function() { app.quit(); });
|
||||
app.on('ready', function() {
|
||||
var htmlPath = path.join(app.getPath('userData'), 'index.html');
|
||||
htmlPath = path.join(__dirname, '../tmp/index.html');
|
||||
|
||||
mainWindow = new BrowserWindow({
|
||||
show: false,
|
||||
|
|
Loading…
Reference in New Issue