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 ec91c80a3..5e826a213 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} from './util'; +import {sendAction, showRestartDialog, disableMenuItem} from './util'; import {generateSubmenu as generateEmojiSubmenu} from './emoji'; import {toggleMenuBarMode} from './menu-bar-mode'; import {caprineIconPath} from './constants'; @@ -329,9 +329,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() { config.set('showTrayIcon', !config.get('showTrayIcon')); @@ -345,7 +346,23 @@ Press Command/Ctrl+R in Caprine to see your changes. checked: config.get('launchMinimized'), click() { config.set('launchMinimized', !config.get('launchMinimized')); - sendAction('toggle-tray-icon'); + const showTrayIconItem = menu.getMenuItemById('showTrayIcon'); + + if(config.get('launchMinimized')) { + disableMenuItem({ + menuItem: showTrayIconItem, + configKey: 'showTrayIcon', + value: 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; + } } }, { diff --git a/source/util.ts b/source/util.ts index 13cc31eba..a29289cfe 100644 --- a/source/util.ts +++ b/source/util.ts @@ -1,6 +1,6 @@ import {app, BrowserWindow, dialog} from 'electron'; import {is} from 'electron-util'; -import config from './config'; +import config, {StoreType} from './config'; export function getWindow(): BrowserWindow { const [win] = BrowserWindow.getAllWindows(); @@ -49,3 +49,12 @@ export function stripTrackingFromUrl(url: string): string { return url; } + +export function disableMenuItem( + {menuItem, configKey, value}: + {menuItem: Electron.MenuItem, configKey: keyof StoreType, value: boolean}): void { + config.set(configKey, value); + + menuItem.enabled = false; + menuItem.checked = value; +}