From 31f357a0ba024b2dc42bd7b250ea5979ea8e236f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=E2=80=A2=C3=98=E2=80=A2R=E2=80=A2=C3=9C=E2=80=A2S?= Date: Thu, 13 May 2021 01:04:16 +0400 Subject: [PATCH] Fixed some redundant code (#5577) * Fixed some redundant code, index.ts (Check line 210) Also prefixed 'event' in line 226 and 232 with _ since they are unused * Fixed a wrongful autoimport * Removed a finished FIXME * Name the function and fix typo Co-authored-by: Labhansh Agrawal --- app/index.ts | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/app/index.ts b/app/index.ts index 3f20dbef..b9adc620 100644 --- a/app/index.ts +++ b/app/index.ts @@ -206,11 +206,12 @@ app.on('ready', () => }) ); -app.on('open-file', (event, path) => { +/** + * Get last focused BrowserWindow or create new if none and callback + * @param callback Function to call with the BrowserWindow + */ +function GetWindow(callback: (win: BrowserWindow) => void) { const lastWindow = app.getLastFocusedWindow(); - const callback = (win: BrowserWindow) => { - win.rpc.emit('open file', {path}); - }; if (lastWindow) { callback(lastWindow); } else if (!lastWindow && {}.hasOwnProperty.call(app, 'createWindow')) { @@ -220,20 +221,16 @@ app.on('open-file', (event, path) => { // sets his callback to an app.windowCallback property. app.windowCallback = callback; } +} + +app.on('open-file', (_event, path) => { + GetWindow((win: BrowserWindow) => { + win.rpc.emit('open file', {path}); + }); }); -app.on('open-url', (event, sshUrl) => { - const lastWindow = app.getLastFocusedWindow(); - const callback = (win: BrowserWindow) => { +app.on('open-url', (_event, sshUrl) => { + GetWindow((win: BrowserWindow) => { win.rpc.emit('open ssh', sshUrl); - }; - if (lastWindow) { - callback(lastWindow); - } else if (!lastWindow && {}.hasOwnProperty.call(app, 'createWindow')) { - app.createWindow(callback); - } else { - // If createWindow doesn't exist yet ('ready' event was not fired), - // sets his callback to an app.windowCallback property. - app.windowCallback = callback; - } + }); });