Skip to content

Commit 1f7b7dd

Browse files
authored
Merge pull request #169 from flystar233/master
style: normalize the settings page
2 parents 5435aa5 + 8590dda commit 1f7b7dd

File tree

22 files changed

+512
-220
lines changed

22 files changed

+512
-220
lines changed

electron/ipc/app.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { app, ipcMain } from "electron";
2+
import isDev from "electron-is-dev";
23

34
import { autoUpdater } from "../updater";
45
import { channel } from "./channel";
@@ -38,4 +39,8 @@ export function registerAppHandlers() {
3839
ipcMain.handle(channel.app.quitAndInstall, async () => {
3940
return autoUpdater.quitAndInstall();
4041
});
42+
43+
ipcMain.handle(channel.app.isDev, async () => {
44+
return isDev;
45+
});
4146
}

electron/ipc/channel.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export const channel = {
6161
quitAndInstall: "app:quit-and-install",
6262
openInstallerDirectory: "app:open-installer-directory",
6363
onBeforeQuit: "app:on-before-quit",
64+
isDev: "app:is-dev",
6465
},
6566
cookie: {
6667
get: "cookie:get",
@@ -77,5 +78,6 @@ export const channel = {
7778
enterFullScreen: "window:enter-full-screen",
7879
leaveFullScreen: "window:leave-full-screen",
7980
isFullScreen: "window:is-full-screen",
81+
toggleDevTools: "window:toggle-dev-tools",
8082
},
8183
};

electron/ipc/window.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,9 @@ export function registerWindowHandlers({ getMainWindow }) {
4545
createMiniPlayer();
4646
}
4747
});
48+
49+
ipcMain.on(channel.window.toggleDevTools, event => {
50+
const win = BrowserWindow.fromWebContents(event.sender);
51+
win?.webContents.toggleDevTools();
52+
});
4853
}

electron/main.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ function createWindow() {
6969

7070
const indexPath = path.resolve(__dirname, "../dist/web/index.html");
7171
mainWindow.loadFile(indexPath);
72-
if (isDev) {
73-
mainWindow.webContents.openDevTools({
74-
mode: "bottom",
75-
});
76-
}
7772

7873
// 初始化 Windows 任务栏缩略按钮,并监听播放状态更新
7974
if (process.platform === "win32") {

electron/preload.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ const api: ElectronAPI = {
139139
},
140140
// 获取应用版本
141141
getAppVersion: () => ipcRenderer.invoke(channel.app.getVersion),
142+
isDev: () => ipcRenderer.invoke(channel.app.isDev),
142143
// 检查应用更新
143144
checkAppUpdate: () => ipcRenderer.invoke(channel.app.checkUpdate),
144145
// 监听应用更新事件
@@ -228,6 +229,8 @@ const api: ElectronAPI = {
228229
},
229230
// 清除文件下载任务列表
230231
clearMediaDownloadTaskList: () => ipcRenderer.invoke(channel.download.clear),
232+
// 切换开发者工具
233+
toggleDevTools: () => ipcRenderer.send(channel.window.toggleDevTools),
231234
};
232235

233236
contextBridge.exposeInMainWorld("electron", api);

shared/settings/app-settings.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,40 @@ export const defaultAppSettings: AppSettings = {
44
fontFamily: "system-ui",
55
borderRadius: 8,
66
downloadPath: "",
7-
backgroundColor: "#18181b",
8-
contentBackgroundColor: "#1f1f1f",
97
primaryColor: "#17c964",
108
audioQuality: "auto",
119
hiddenMenuKeys: [],
1210
displayMode: "card",
1311
ffmpegPath: "",
12+
themeMode: "dark",
13+
pageTransition: "none",
14+
searchMusicOnly: true,
15+
showSearchHistory: true,
16+
};
17+
18+
export const lightThemeColors = {
19+
backgroundColor: "#f5f5f5",
20+
contentBackgroundColor: "#ffffff",
21+
foregroundColor: "#000000",
22+
};
23+
24+
export const darkThemeColors = {
25+
backgroundColor: "#18181b",
26+
contentBackgroundColor: "#1f1f1f",
27+
foregroundColor: "#ffffff",
1428
};
29+
30+
/**
31+
* 根据主题模式获取对应的颜色配置
32+
*/
33+
export function getThemeColors(themeMode: ThemeMode) {
34+
return themeMode === "light" ? lightThemeColors : darkThemeColors;
35+
}
36+
37+
/**
38+
* 主题模式选项
39+
*/
40+
export const THEME_MODE_OPTIONS = [
41+
{ key: "light" as const, label: "浅色" },
42+
{ key: "dark" as const, label: "深色" },
43+
] as const;

shared/types/app-setting.d.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
type AudioQuality = "auto" | "lossless" | "high" | "medium" | "low";
2+
type ThemeMode = "light" | "dark";
3+
type PageTransition = "none" | "fade" | "slide" | "scale" | "slideUp";
24

35
interface AppSettings {
46
fontFamily: string;
5-
backgroundColor: string;
6-
contentBackgroundColor: string;
77
primaryColor: string;
88
borderRadius: number;
99
downloadPath?: string;
@@ -13,4 +13,8 @@ interface AppSettings {
1313
hiddenMenuKeys: string[];
1414
displayMode: "card" | "list";
1515
ffmpegPath?: string;
16+
themeMode: ThemeMode;
17+
pageTransition: PageTransition;
18+
searchMusicOnly: boolean;
19+
showSearchHistory: boolean;
1620
}

shared/types/renderer.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ declare global {
4646
onPlayerCommand: (cb: (cmd: "prev" | "next" | "toggle") => void) => VoidFunction;
4747
/** 获取当前应用版本 */
4848
getAppVersion: () => Promise<string>;
49+
/** 判断是否为开发模式 */
50+
isDev: () => Promise<boolean>;
4951
/** 是否支持自动更新 */
5052
isSupportAutoUpdate: () => boolean;
5153
/** 检查更新 */
@@ -74,6 +76,8 @@ declare global {
7476
isFullScreen: () => Promise<boolean>;
7577
/** 监听窗口全屏状态变化 */
7678
onWindowFullScreenChange: (cb: (isFullScreen: boolean) => void) => VoidFunction;
79+
/** 切换开发者工具 */
80+
toggleDevTools: () => void;
7781
/** 获取下载任务列表 */
7882
getMediaDownloadTaskList: () => Promise<MediaDownloadTask[]>;
7983
/** 同步下载任务列表 */

src/app.css

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,38 @@ html, body, #root {
5151

5252
padding: 0;
5353
}
54+
55+
/*
56+
* 修复暗色主题下 Portal 渲染组件的文本颜色
57+
*/
58+
59+
/* SelectItem 组件文本颜色 */
60+
body.dark [data-slot="base"] :is([data-slot="content"], [data-slot="content"] > span) {
61+
color: var(--heroui-foreground);
62+
}
63+
64+
/* Select 下拉菜单中的项目 */
65+
body.dark [role="listbox"] :is([role="option"], [role="option"] > span) {
66+
color: var(--heroui-foreground);
67+
}
68+
69+
/* 登录弹窗内文本颜色 */
70+
body.dark .login-modal.text-foreground :is(
71+
p,
72+
label,
73+
input,
74+
textarea,
75+
span:not([class*="icon"]),
76+
div:not(button, [role="button"], [class*="button"])) {
77+
color: var(--heroui-foreground);
78+
}
79+
80+
/* Input 错误消息 */
81+
body.dark .login-modal.text-foreground :is([data-slot="errorMessage"], [data-slot="errorMessage"] > span) {
82+
color: var(--heroui-danger);
83+
}
84+
85+
/* placeholder */
86+
body.dark .login-modal.text-foreground :is(input, textarea)::placeholder {
87+
color: var(--heroui-default-400);
88+
}

src/components/confirm-modal/index.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import { RiErrorWarningLine } from "@remixicon/react";
55
import { useShallow } from "zustand/shallow";
66

77
import { useModalStore } from "@/store/modal";
8+
import { useSettings } from "@/store/settings";
89

9-
type ConfirmModalType = "warning" | "danger";
10+
type ConfirmModalType = "warning" | "danger" | "primary";
1011

11-
const colorMap: Record<ConfirmModalType, string> = {
12+
const colorMap: Record<Exclude<ConfirmModalType, "primary">, string> = {
1213
warning: "#F5A524",
1314
danger: "#dc1258",
1415
};
@@ -35,8 +36,17 @@ const ConfirmModal = () => {
3536
cancelText = "取消",
3637
} = confirmModalData || {};
3738

39+
const primaryColor = useSettings(s => s.primaryColor);
3840
const [loading, setLoading] = useState(false);
3941

42+
// 根据类型获取图标颜色
43+
const getIconColor = () => {
44+
if (type === "primary") {
45+
return primaryColor;
46+
}
47+
return colorMap[type as Exclude<ConfirmModalType, "primary">];
48+
};
49+
4050
const handleClose = () => onConfirmModalOpenChange(false);
4151

4252
const handleConfirm = async () => {
@@ -62,8 +72,8 @@ const ConfirmModal = () => {
6272
<ModalContent>
6373
{() => (
6474
<>
65-
<ModalHeader className="flex items-center gap-1">
66-
<RiErrorWarningLine color={colorMap[type]} />
75+
<ModalHeader className="flex items-center gap-1 [&>span]:text-[var(--heroui-foreground)]">
76+
<RiErrorWarningLine color={getIconColor()} />
6777
<span>{title}</span>
6878
</ModalHeader>
6979
{description ? (
@@ -75,7 +85,7 @@ const ConfirmModal = () => {
7585
<Button variant="light" onPress={handleClose} isDisabled={loading}>
7686
{cancelText}
7787
</Button>
78-
<Button color={type} onPress={handleConfirm} isLoading={loading}>
88+
<Button color={type === "primary" ? "primary" : type} onPress={handleConfirm} isLoading={loading}>
7989
{confirmText}
8090
</Button>
8191
</ModalFooter>

0 commit comments

Comments
 (0)