From 81d3510fde9ce2593491563811b394119dfbda31 Mon Sep 17 00:00:00 2001 From: JBudny Date: Wed, 11 Dec 2019 21:39:34 +0100 Subject: [PATCH 1/5] Fix the 'Show Tray Icon' option from the preferencesSubmenu. --- source/menu.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/source/menu.ts b/source/menu.ts index ec91c80a3..393d7e142 100644 --- a/source/menu.ts +++ b/source/menu.ts @@ -1,6 +1,6 @@ import * as path from 'path'; import {existsSync, writeFileSync} from 'fs'; -import {app, shell, Menu, MenuItemConstructorOptions, BrowserWindow, dialog} from 'electron'; +import {app, shell, Menu, MenuItemConstructorOptions, dialog} from 'electron'; import { is, appMenu, @@ -10,10 +10,11 @@ import { debugInfo } from 'electron-util'; import config from './config'; -import {sendAction, showRestartDialog} from './util'; +import {sendAction, showRestartDialog, getWindow} from './util'; import {generateSubmenu as generateEmojiSubmenu} from './emoji'; import {toggleMenuBarMode} from './menu-bar-mode'; import {caprineIconPath} from './constants'; +import tray from './tray'; export default async function updateMenu(): Promise { const newConversationItem: MenuItemConstructorOptions = { @@ -272,9 +273,7 @@ Press Command/Ctrl+R in Caprine to see your changes. checked: config.get('menuBarMode'), click() { config.set('menuBarMode', !config.get('menuBarMode')); - - const [win] = BrowserWindow.getAllWindows(); - toggleMenuBarMode(win); + toggleMenuBarMode(getWindow()); } }, { @@ -335,7 +334,7 @@ Press Command/Ctrl+R in Caprine to see your changes. checked: config.get('showTrayIcon'), click() { config.set('showTrayIcon', !config.get('showTrayIcon')); - sendAction('toggle-tray-icon'); + config.get('showTrayIcon')? tray.create(getWindow()) : tray.destroy(); } }, { From 2c696e83765724c4fd9420572412a17fac913816 Mon Sep 17 00:00:00 2001 From: JBudny Date: Wed, 8 Jan 2020 00:47:03 +0100 Subject: [PATCH 2/5] Move toggle tray icon logic into a function --- source/menu.ts | 6 ++---- source/util.ts | 6 ++++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/source/menu.ts b/source/menu.ts index 393d7e142..8c88678e9 100644 --- a/source/menu.ts +++ b/source/menu.ts @@ -10,11 +10,10 @@ import { debugInfo } from 'electron-util'; import config from './config'; -import {sendAction, showRestartDialog, getWindow} from './util'; +import {sendAction, showRestartDialog, getWindow, toggleTrayIcon} from './util'; import {generateSubmenu as generateEmojiSubmenu} from './emoji'; import {toggleMenuBarMode} from './menu-bar-mode'; import {caprineIconPath} from './constants'; -import tray from './tray'; export default async function updateMenu(): Promise { const newConversationItem: MenuItemConstructorOptions = { @@ -333,8 +332,7 @@ Press Command/Ctrl+R in Caprine to see your changes. enabled: is.linux || is.windows, checked: config.get('showTrayIcon'), click() { - config.set('showTrayIcon', !config.get('showTrayIcon')); - config.get('showTrayIcon')? tray.create(getWindow()) : tray.destroy(); + toggleTrayIcon(); } }, { diff --git a/source/util.ts b/source/util.ts index 13cc31eba..f7fc97c17 100644 --- a/source/util.ts +++ b/source/util.ts @@ -1,6 +1,7 @@ import {app, BrowserWindow, dialog} from 'electron'; import {is} from 'electron-util'; import config from './config'; +import tray from './tray'; export function getWindow(): BrowserWindow { const [win] = BrowserWindow.getAllWindows(); @@ -49,3 +50,8 @@ export function stripTrackingFromUrl(url: string): string { return url; } + +export const toggleTrayIcon = (): void => { + config.set('showTrayIcon', !config.get('showTrayIcon')); + config.get('showTrayIcon') ? tray.create(getWindow()) : tray.destroy(); +}; From 2d12a35c8d373f0a412a1635cb5baa2704073e99 Mon Sep 17 00:00:00 2001 From: JBudny Date: Thu, 12 Dec 2019 19:48:47 +0100 Subject: [PATCH 3/5] Handle Launch Minimized option --- source/config.ts | 2 +- source/menu.ts | 8 ++++---- source/util.ts | 28 +++++++++++++++++++++++++++- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/source/config.ts b/source/config.ts index 2be59c9bb..06715d4b7 100644 --- a/source/config.ts +++ b/source/config.ts @@ -1,7 +1,7 @@ import Store = require('electron-store'); import {is} from 'electron-util'; -type StoreType = { +export type StoreType = { followSystemAppearance: boolean; darkMode: boolean; privateMode: boolean; diff --git a/source/menu.ts b/source/menu.ts index 8c88678e9..70def8468 100644 --- a/source/menu.ts +++ b/source/menu.ts @@ -10,7 +10,7 @@ import { debugInfo } from 'electron-util'; import config from './config'; -import {sendAction, showRestartDialog, getWindow, toggleTrayIcon} from './util'; +import {sendAction, showRestartDialog, getWindow, toggleTrayIcon, toggleLaunchMinimized} from './util'; import {generateSubmenu as generateEmojiSubmenu} from './emoji'; import {toggleMenuBarMode} from './menu-bar-mode'; import {caprineIconPath} from './constants'; @@ -327,9 +327,10 @@ Press Command/Ctrl+R in Caprine to see your changes. } }, { + id: 'showTrayIcon', label: 'Show Tray Icon', type: 'checkbox', - enabled: is.linux || is.windows, + enabled: (is.linux || is.windows) && !config.get('launchMinimized'), checked: config.get('showTrayIcon'), click() { toggleTrayIcon(); @@ -341,8 +342,7 @@ Press Command/Ctrl+R in Caprine to see your changes. visible: !is.macos, checked: config.get('launchMinimized'), click() { - config.set('launchMinimized', !config.get('launchMinimized')); - sendAction('toggle-tray-icon'); + toggleLaunchMinimized(menu); } }, { diff --git a/source/util.ts b/source/util.ts index f7fc97c17..f410d1230 100644 --- a/source/util.ts +++ b/source/util.ts @@ -1,4 +1,4 @@ -import {app, BrowserWindow, dialog} from 'electron'; +import {app, BrowserWindow, dialog, Menu} from 'electron'; import {is} from 'electron-util'; import config from './config'; import tray from './tray'; @@ -55,3 +55,29 @@ export const toggleTrayIcon = (): void => { config.set('showTrayIcon', !config.get('showTrayIcon')); config.get('showTrayIcon') ? tray.create(getWindow()) : tray.destroy(); }; + +export const toggleLaunchMinimized = (menu: Menu): void => { + config.set('launchMinimized', !config.get('launchMinimized')); + const showTrayIconItem = menu.getMenuItemById('showTrayIcon'); + + if (config.get('launchMinimized')) { + if (!config.get('showTrayIcon')) { + toggleTrayIcon(); + } + + disableMenuItem(showTrayIconItem, true); + + dialog.showMessageBox({ + type: 'info', + message: 'Show Tray Icon option has been locked on enabled due to enabled Launch Minimized option.', + buttons: ['OK'] + }); + } else { + showTrayIconItem.enabled = true; + } +}; + +const disableMenuItem = (menuItem: Electron.MenuItem, checked: boolean): void => { + menuItem.enabled = false; + menuItem.checked = checked; +}; From fd83279dd09c5d21f7476e7b534dffd26742e429 Mon Sep 17 00:00:00 2001 From: Jakub Budny <32987100+JBudny@users.noreply.github.com> Date: Fri, 17 Jan 2020 16:16:41 +0100 Subject: [PATCH 4/5] Update source/util.ts Co-Authored-By: Sindre Sorhus --- source/util.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/util.ts b/source/util.ts index f410d1230..679b08667 100644 --- a/source/util.ts +++ b/source/util.ts @@ -69,7 +69,7 @@ export const toggleLaunchMinimized = (menu: Menu): void => { dialog.showMessageBox({ type: 'info', - message: 'Show Tray Icon option has been locked on enabled due to enabled Launch Minimized option.', + message: 'The “Show Tray Icon” setting is force-enabled while the “Launch Minimized” setting is enabled.', buttons: ['OK'] }); } else { From 53f9ae67be843fedf13054d3f1dd415874f6b6dc Mon Sep 17 00:00:00 2001 From: JBudny Date: Tue, 28 Jan 2020 00:23:50 +0100 Subject: [PATCH 5/5] Apply requested changes --- source/config.ts | 2 +- source/util.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/source/config.ts b/source/config.ts index 06715d4b7..2be59c9bb 100644 --- a/source/config.ts +++ b/source/config.ts @@ -1,7 +1,7 @@ import Store = require('electron-store'); import {is} from 'electron-util'; -export type StoreType = { +type StoreType = { followSystemAppearance: boolean; darkMode: boolean; privateMode: boolean; diff --git a/source/util.ts b/source/util.ts index 679b08667..b2878d961 100644 --- a/source/util.ts +++ b/source/util.ts @@ -52,8 +52,14 @@ export function stripTrackingFromUrl(url: string): string { } export const toggleTrayIcon = (): void => { - config.set('showTrayIcon', !config.get('showTrayIcon')); - config.get('showTrayIcon') ? tray.create(getWindow()) : tray.destroy(); + const showTrayIconState = config.get('showTrayIcon'); + config.set('showTrayIcon', !showTrayIconState); + + if (showTrayIconState) { + return tray.destroy(); + } + + return tray.create(getWindow()); }; export const toggleLaunchMinimized = (menu: Menu): void => {