mirror of
https://github.com/keeweb/keeweb.git
synced 2024-06-22 07:16:38 +02:00
Fixed Minimize to tray #7
This commit is contained in:
parent
dda8dd7190
commit
333e326bd2
|
@ -6,11 +6,16 @@
|
|||
var app = require('app'),
|
||||
BrowserWindow = require('browser-window'),
|
||||
path = require('path'),
|
||||
fs = require('fs');
|
||||
fs = require('fs'),
|
||||
Tray = require('tray'),
|
||||
Menu = require('menu');
|
||||
|
||||
var mainWindow = null,
|
||||
openFile = process.argv.filter(function(arg) { return /\.kdbx$/i.test(arg); })[0],
|
||||
ready = false;
|
||||
ready = false,
|
||||
appIcon = null,
|
||||
quiting = false,
|
||||
firstTray = true;
|
||||
|
||||
app.on('window-all-closed', function() { app.quit(); });
|
||||
app.on('ready', function() {
|
||||
|
@ -33,13 +38,49 @@ app.on('ready', function() {
|
|||
notifyOpenFile();
|
||||
});
|
||||
mainWindow.on('closed', function() { mainWindow = null; });
|
||||
|
||||
mainWindow.on('close', function(e) {
|
||||
if (!quiting) {
|
||||
e.preventDefault();
|
||||
mainWindow.minimize();
|
||||
mainWindow.setSkipTaskbar(true)
|
||||
if (firstTray) {
|
||||
appIcon.displayBalloon({title: 'KeeWeb', content: 'Application minimized to tray!'});
|
||||
firstTray = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
appIcon = new Tray(path.join(__dirname, 'icon.png'));
|
||||
var contextMenu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: 'Open KeeWeb',
|
||||
click: restoreMainWindow
|
||||
},
|
||||
{
|
||||
label: 'Quit KeeWeb',
|
||||
click: function() {
|
||||
quiting = true;
|
||||
mainWindow.close();
|
||||
}
|
||||
}
|
||||
]);
|
||||
appIcon.on('clicked', restoreMainWindow)
|
||||
appIcon.setContextMenu(contextMenu);
|
||||
appIcon.setToolTip('KeeWeb Desktop');
|
||||
});
|
||||
|
||||
app.on('open-file', function(e, path) {
|
||||
e.preventDefault();
|
||||
openFile = path;
|
||||
notifyOpenFile();
|
||||
});
|
||||
|
||||
function restoreMainWindow() {
|
||||
mainWindow.restore();
|
||||
mainWindow.setSkipTaskbar(false);
|
||||
}
|
||||
|
||||
function notifyOpenFile() {
|
||||
if (ready && openFile && mainWindow) {
|
||||
openFile = openFile.replace(/"/g, '\\"').replace(/\\/g, '\\\\');
|
||||
|
|
Loading…
Reference in New Issue
Block a user