feat(menu): add theme list in menu

This commit is contained in:
Su-Yong
2024-05-22 18:06:20 +09:00
parent 4557aff9b6
commit 933b4cc8f0
2 changed files with 91 additions and 65 deletions

View File

@ -162,6 +162,14 @@
"submenu": {
"import-css-file": "Import custom CSS file",
"no-theme": "No theme"
},
"dialog": {
"remove-theme": "Are you sure you want to remove the custom theme?",
"remove-theme-message": "This will remove the custom theme",
"button": {
"cancel": "Cancel",
"remove": "Remove"
}
}
}
}

View File

@ -1,13 +1,5 @@
import is from 'electron-is';
import {
app,
BrowserWindow,
clipboard,
dialog,
Menu,
MenuItem,
shell,
} from 'electron';
import { app, BrowserWindow, clipboard, dialog, Menu, MenuItem, shell, } from 'electron';
import prompt from 'custom-electron-prompt';
import { satisfies } from 'semver';
@ -235,16 +227,41 @@ export const mainMenuTemplate = async (
'main.menu.options.submenu.visual-tweaks.submenu.theme.label',
),
submenu: [
...((config.get('options.themes')?.length ?? 0) === 0
? [
{
label: t(
'main.menu.options.submenu.visual-tweaks.submenu.theme.submenu.no-theme',
),
type: 'radio',
checked: config.get('options.themes')?.length === 0, // Todo rename "themes"
click() {
config.set('options.themes', []);
},
},
}
]
: []),
...config.get('options.themes')?.map((theme: string) => ({
type: 'normal' as const,
label: theme,
async click() {
const { response } = await dialog.showMessageBox(win, {
type: 'question',
defaultId: 1,
title: t(
'main.menu.options.submenu.visual-tweaks.submenu.theme.dialog.remove-theme',
),
message: t(
'main.menu.options.submenu.visual-tweaks.submenu.theme.dialog.remove-theme-message',
{ theme },
),
buttons: [
t('main.menu.options.submenu.visual-tweaks.submenu.theme.dialog.button.cancel'),
t('main.menu.options.submenu.visual-tweaks.submenu.theme.dialog.button.remove'),
],
});
if (response === 1) {
config.set('options.themes', config.get('options.themes')?.filter((t) => t !== theme));
innerRefreshMenu();
}
}
})),
{ type: 'separator' },
{
label: t(
@ -258,6 +275,7 @@ export const mainMenuTemplate = async (
});
if (filePaths) {
config.set('options.themes', filePaths);
innerRefreshMenu();
}
},
},