Skip to content

Commit

Permalink
feat: add bw switch for Windows and Linux
Browse files Browse the repository at this point in the history
Windows default: true black and white
Linux default: false black and white
  • Loading branch information
hacdias committed Aug 30, 2022
1 parent bc8fb0c commit 786e92a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
Binary file added assets/icons/tray/others/off-large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/tray/others/on-large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion assets/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@
"automaticGC": "Automatic Garbage Collection",
"takeScreenshotShortcut": "Global Screenshot Shortcut",
"experiments": "Experiments",
"npmOnIpfs": "Enable npm on IPFS"
"npmOnIpfs": "Enable npm on IPFS",
"monochromeTrayIcon": "Use Monochrome Tray Icon"
},
"setCustomIpfsBinaryConfirmation": {
"title": "Custom IPFS binary",
Expand Down
1 change: 1 addition & 0 deletions src/common/config-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const CONFIG_KEYS = {
AUTO_GARBAGE_COLLECTOR: 'automaticGC',
SCREENSHOT_SHORTCUT: 'screenshotShortcut',
OPEN_WEBUI_LAUNCH: 'openWebUIAtLaunch',
MONOCHROME_TRAY_ICON: 'monochromeTrayIcon',
EXPERIMENT_PUBSUB: 'experiments.pubsub',
EXPERIMENT_PUBSUB_NAMESYS: 'experiments.pubsubNamesys'
}
Expand Down
25 changes: 22 additions & 3 deletions src/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const CONFIG_KEYS = require('./common/config-keys')

const { SHORTCUT: SCREENSHOT_SHORTCUT, takeScreenshot } = require('./take-screenshot')
const { isSupported: supportsLaunchAtLogin } = require('./auto-launch')
const createToggler = require('./utils/create-toggler')

function buildCheckbox (key, label) {
return {
Expand Down Expand Up @@ -108,6 +109,7 @@ function buildMenu (ctx) {
buildCheckbox(CONFIG_KEYS.OPEN_WEBUI_LAUNCH, 'settings.openWebUIAtLaunch'),
buildCheckbox(CONFIG_KEYS.AUTO_GARBAGE_COLLECTOR, 'settings.automaticGC'),
buildCheckbox(CONFIG_KEYS.SCREENSHOT_SHORTCUT, 'settings.takeScreenshotShortcut'),
...(IS_MAC ? [] : [buildCheckbox(CONFIG_KEYS.MONOCHROME_TRAY_ICON, 'settings.monochromeTrayIcon')]),
{ type: 'separator' },
{
label: i18n.t('settings.experiments'),
Expand Down Expand Up @@ -216,8 +218,16 @@ function icon (status) {
return path.join(dir, 'macos', `${status}-22Template.png`)
}

const theme = nativeTheme.shouldUseDarkColors ? 'dark' : 'light'
return path.join(dir, 'others', `${status}-32-${theme}.png`)
// Get the config value for 'should we use monochrome tray icon?'
// On Windows, the default is true. On Linux, the default is false.
const bw = store.get(CONFIG_KEYS.MONOCHROME_TRAY_ICON, IS_WIN)

if (bw) {
const theme = nativeTheme.shouldUseDarkColors ? 'dark' : 'light'
return path.join(dir, 'others', `${status}-32-${theme}.png`)
} else {
return path.join(dir, 'others', `${status}-large.png`)
}
}

// Ok this one is pretty ridiculous:
Expand Down Expand Up @@ -316,7 +326,11 @@ module.exports = function (ctx) {
// Update configuration checkboxes.
for (const key of Object.values(CONFIG_KEYS)) {
const enabled = store.get(key, false)
menu.getMenuItemById(key).checked = enabled
const item = menu.getMenuItemById(key)
if (item) {
// Not all items are present in all platforms.
item.checked = enabled
}
}

if (!IS_MAC && !IS_WIN) {
Expand Down Expand Up @@ -360,6 +374,11 @@ module.exports = function (ctx) {

setupMenu()

createToggler(CONFIG_KEYS.MONOCHROME_TRAY_ICON, async ({ newValue }) => {
store.set(CONFIG_KEYS.MONOCHROME_TRAY_ICON, newValue)
return true
})

ctx.tray = tray
logger.info('[tray] started')
}

0 comments on commit 786e92a

Please sign in to comment.