Skip to content

Commit

Permalink
always restore a minimized prefs window
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Promislow <epromislow@suse.com>
  • Loading branch information
ericpromislow committed May 7, 2021
1 parent 4907b87 commit 26822d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
12 changes: 5 additions & 7 deletions background.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Console } from 'console';
import fs from 'fs';
import path from 'path';
import process from 'process';
import os from 'os';
import { URL } from 'url';
import Electron from 'electron';
Expand All @@ -24,9 +23,8 @@ let cfg: settings.Settings;
let tray: Tray;
let gone = false; // when true indicates app is shutting down
let lastBuildDirectory = '';
const singleInstanceLock = Electron.app.requestSingleInstanceLock();

if (!singleInstanceLock) {
if (!Electron.app.requestSingleInstanceLock()) {
gone = true;
process.exit(201);
}
Expand All @@ -47,7 +45,7 @@ Electron.app.whenReady().then(async() => {
return;
}
tray.on('window-preferences', () => {
window.openPreferences(true);
window.openPreferences();
Electron.app.dock?.show();
});

Expand Down Expand Up @@ -119,7 +117,7 @@ Electron.app.whenReady().then(async() => {
}
callback(result);
});
window.openPreferences(false);
window.openPreferences();

imageManager.on('kim-process-output', (data: string, isStderr: boolean) => {
window.send('kim-process-output', data, isStderr);
Expand All @@ -129,7 +127,7 @@ Electron.app.whenReady().then(async() => {
Electron.app.on('second-instance', () => {
// Someone tried to run another instance of Rancher Desktop,
// reveal and focus this window instead.
window.openPreferences(true);
window.openPreferences();
});

Electron.app.on('before-quit', async(event) => {
Expand Down Expand Up @@ -161,7 +159,7 @@ Electron.app.on('window-all-closed', () => {
Electron.app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
window.openPreferences(false);
window.openPreferences();
});

Electron.ipcMain.on('settings-read', (event) => {
Expand Down
11 changes: 4 additions & 7 deletions src/window/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@ const windowMapping = {};
* Open a given window; if it is already open, focus it.
* @param {string} name The window identifier; this controls window re-use.
* @param {string} url The URL to load into the window.
* @param {Boolean} restoreMinimizedWindow If it's minimized, restore it.
* This is for when the user tries to run a second instance, and that instance
* focuses this one and shuts itself down.
* @param {Electron.WebPreferences} prefs Options to control the new window.
*/
function createWindow(name, url, restoreMinimizedWindow, prefs, restoreWindow=false) {
function createWindow(name, url, prefs) {
let window = (name in windowMapping) ? BrowserWindow.fromId(windowMapping[name]) : null;

if (window) {
if (!window.isFocused()) {
if (restoreMinimizedWindow && window.isMinimized()) {
if (window.isMinimized()) {
window.restore();
}
window.show();
Expand All @@ -43,13 +40,13 @@ function createWindow(name, url, restoreMinimizedWindow, prefs, restoreWindow=fa
* Open the preferences window; if it is already open, focus it.
* @param {boolean} restoreMinimizedWindow Whether to unminimize a minimized window.
*/
function openPreferences(restoreMinimizedWindow) {
function openPreferences() {
let url = 'app://./index.html';

if (/^dev/i.test(process.env.NODE_ENV)) {
url = 'http://localhost:8888/';
}
createWindow('preferences', url, restoreMinimizedWindow, { nodeIntegration: true });
createWindow('preferences', url, { nodeIntegration: true });
}

/**
Expand Down

0 comments on commit 26822d8

Please sign in to comment.