Skip to content

Commit

Permalink
fix: console warning when using system follow settings
Browse files Browse the repository at this point in the history
  • Loading branch information
kirklin committed Jul 19, 2023
1 parent 7e96552 commit bf28364
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion apps/admin/src/setting/themeSetting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const DEFAULT_THEME_SETTING: ThemeSetting = {

// 是否开启跟随系统颜色
// Whether to follow the system theme
shouldFollowSystemTheme: false,
shouldFollowSystemTheme: true,

// 主题颜色
// The theme color
Expand Down
14 changes: 6 additions & 8 deletions apps/admin/src/store/modules/design/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { deepMerge } from "@celeris/utils";
import { defineStore } from "pinia";
import { APP_DESIGN_STORE_ID } from "@celeris/constants";
import type { GlobalTheme, GlobalThemeOverrides } from "naive-ui";
import { darkTheme, useOsTheme } from "naive-ui";
import { darkTheme } from "naive-ui";
import { getNaiveUICustomTheme } from "./themeUtils";
import { DEFAULT_THEME_SETTING } from "~/setting/themeSetting";

Expand All @@ -13,6 +13,7 @@ interface DesignState {
const colorMode = useColorMode({
initialValue: DEFAULT_THEME_SETTING.shouldFollowSystemTheme ? "auto" : (DEFAULT_THEME_SETTING.shouldEnableDarkMode ? "dark" : "light"),
});
const isOsDarkTheme = usePreferredDark();
export const useDesignStore = defineStore({
id: APP_DESIGN_STORE_ID,
persist: {
Expand All @@ -28,10 +29,7 @@ export const useDesignStore = defineStore({
},
// 获取Naive UI 预设主题
getNaiveUIPresetTheme(state): GlobalTheme | null {

Check warning on line 31 in apps/admin/src/store/modules/design/index.ts

View workflow job for this annotation

GitHub Actions / LINT

'state' is defined but never used. Allowed unused args must match /^_/u
if (state.themeSetting.shouldFollowSystemTheme) {
return useOsTheme().value === "dark" ? darkTheme : null;
}
return colorMode.value === "dark" ? darkTheme : null;
return this.getDarkMode ? darkTheme : null;
},
// 获取Naive UI 自定义主题
getNaiveUICustomTheme(state): GlobalThemeOverrides | null {
Expand All @@ -42,8 +40,8 @@ export const useDesignStore = defineStore({
},
// 获取暗黑模式
getDarkMode(state): boolean {
if (state.themeSetting.shouldFollowSystemTheme) {
return useOsTheme().value === "dark";
if (this.getFollowSystemTheme) {
return isOsDarkTheme.value;
}
return state.themeSetting.shouldEnableDarkMode;
},
Expand Down Expand Up @@ -73,7 +71,7 @@ export const useDesignStore = defineStore({
setDarkMode(darkMode: boolean): void {
if (this.themeSetting.shouldFollowSystemTheme) {
colorMode.value = "auto";
this.setThemeSetting({ shouldEnableDarkMode: useOsTheme().value === "dark" });
this.setThemeSetting({ shouldEnableDarkMode: isOsDarkTheme.value });
} else {
colorMode.value = darkMode ? "dark" : "light";
this.setThemeSetting({ shouldEnableDarkMode: darkMode });
Expand Down

2 comments on commit bf28364

@vercel
Copy link

@vercel vercel bot commented on bf28364 Jul 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

celeris-web-api – ./services/admin

celeris-web-api.vercel.app
celeris-web-api-git-master-kirklin.vercel.app
celeris-web-api-kirklin.vercel.app

@vercel
Copy link

@vercel vercel bot commented on bf28364 Jul 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

celeris-web – ./apps/admin

celeris-web-git-master-kirklin.vercel.app
celeris-web-kirklin.vercel.app
celeris-web.vercel.app

Please sign in to comment.