mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-11-02 13:03:22 +00:00
Merge pull request #179 from zulip/window-close-fix
Fixed window close/hide logic + keep app running in background on close
This commit is contained in:
@@ -19,6 +19,8 @@ const conf = new Configstore();
|
||||
// Prevent window being garbage collected
|
||||
let mainWindow;
|
||||
|
||||
let isQuitting = false;
|
||||
|
||||
// Load this url in main window
|
||||
const mainURL = 'file://' + path.join(__dirname, '../renderer', 'main.html');
|
||||
|
||||
@@ -46,12 +48,6 @@ const iconPath = () => {
|
||||
return APP_ICON + (process.platform === 'win32' ? '.ico' : '.png');
|
||||
};
|
||||
|
||||
function onClosed() {
|
||||
// Dereference the window
|
||||
// For multiple windows, store them in an array
|
||||
mainWindow = null;
|
||||
}
|
||||
|
||||
function createMainWindow() {
|
||||
const win = new electron.BrowserWindow({
|
||||
// This settings needs to be saved in config
|
||||
@@ -79,7 +75,19 @@ function createMainWindow() {
|
||||
|
||||
win.loadURL(mainURL);
|
||||
|
||||
win.on('closed', onClosed);
|
||||
// Keep the app running in background on close event
|
||||
win.on('close', e => {
|
||||
if (!isQuitting) {
|
||||
e.preventDefault();
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
app.hide();
|
||||
} else {
|
||||
win.hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
win.setTitle('Zulip');
|
||||
|
||||
// Let's save browser window position
|
||||
@@ -136,9 +144,6 @@ app.on('certificate-error', (event, webContents, url, error, certificate, callba
|
||||
app.on('window-all-closed', () => {
|
||||
// Unregister all the shortcuts so that they don't interfare with other apps
|
||||
electronLocalshortcut.unregisterAll(mainWindow);
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
app.on('activate', () => {
|
||||
@@ -150,7 +155,6 @@ app.on('activate', () => {
|
||||
app.on('ready', () => {
|
||||
electron.Menu.setApplicationMenu(appMenu);
|
||||
mainWindow = createMainWindow();
|
||||
// Not using for now // tray.create();
|
||||
|
||||
const page = mainWindow.webContents;
|
||||
|
||||
@@ -185,6 +189,14 @@ app.on('ready', () => {
|
||||
mainWindow.webContents.send('destroytray');
|
||||
});
|
||||
|
||||
ipc.on('focus-app', () => {
|
||||
mainWindow.show();
|
||||
});
|
||||
|
||||
ipc.on('quit-app', () => {
|
||||
app.quit();
|
||||
});
|
||||
|
||||
ipc.on('reload-main', () => {
|
||||
page.reload();
|
||||
});
|
||||
@@ -201,3 +213,7 @@ app.on('will-quit', () => {
|
||||
// Unregister all the shortcuts so that they don't interfare with other apps
|
||||
electronLocalshortcut.unregisterAll(mainWindow);
|
||||
});
|
||||
|
||||
app.on('before-quit', () => {
|
||||
isQuitting = true;
|
||||
});
|
||||
|
||||
@@ -123,6 +123,15 @@ const createTray = function () {
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Focus',
|
||||
click() {
|
||||
ipcRenderer.send('focus-app');
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Manage Zulip servers',
|
||||
click() {
|
||||
@@ -144,7 +153,7 @@ const createTray = function () {
|
||||
{
|
||||
label: 'Quit',
|
||||
click() {
|
||||
remote.getCurrentWindow().close();
|
||||
ipcRenderer.send('quit-app');
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user