Skip to content

Commit

Permalink
feat: 将 Windows 主题切换时的弹框提示改为描述提示 (#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayangweb authored Aug 27, 2024
1 parent 565b3f2 commit c418e52
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 37 deletions.
23 changes: 0 additions & 23 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { appWindow } from "@tauri-apps/api/window";
import { ConfigProvider, theme } from "antd";
import { RouterProvider } from "react-router-dom";
import { useSnapshot } from "valtio";
import { subscribeKey } from "valtio/utils";
const { defaultAlgorithm, darkAlgorithm } = theme;
import { isString } from "arcdash";
import { error } from "tauri-plugin-log-api";
Expand All @@ -27,28 +26,6 @@ const App = () => {
setLocale(value);
});

subscribeKey(globalStore.appearance, "theme", async (value) => {
let nextTheme = value;

if (isWin()) {
const yes = await ask("切换主题需要重启 app 才能生效!", {
okLabel: "重启",
cancelLabel: "取消",
type: "warning",
});

if (!yes) return;
}

if (nextTheme === "auto") {
nextTheme = (await appWindow.theme()) ?? "light";
}

globalStore.appearance.isDark = nextTheme === "dark";

setTheme(value);
});

watchKey(globalStore.appearance, "isDark", (value) => {
if (value) {
document.documentElement.classList.add("dark");
Expand Down
2 changes: 1 addition & 1 deletion src/components/ProList/index.module.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.normal {
.root {
--uno: "not-last-of-type:mb-16";

.title {
Expand Down
2 changes: 1 addition & 1 deletion src/components/ProList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const ProList: FC<ListProps<unknown>> = (props) => {
const { header, children, ...rest } = props;

return (
<Flex vertical gap="small" className={styles.normal}>
<Flex vertical gap="small" className={styles.root}>
{header && (
<div data-tauri-drag-region className={styles.title}>
<span>{header}</span>
Expand Down
13 changes: 13 additions & 0 deletions src/layouts/Preference/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Flex } from "antd";
import clsx from "clsx";
import { disable, enable, isEnabled } from "tauri-plugin-autostart-api";
import { subscribe, useSnapshot } from "valtio";
import { subscribeKey } from "valtio/utils";

const Preference = () => {
const { pathname } = useLocation();
Expand Down Expand Up @@ -64,6 +65,18 @@ const Preference = () => {
appWindow.setTitle(t("preference.title"));
});
});

subscribeKey(globalStore.appearance, "theme", async (value) => {
let nextTheme = value;

if (nextTheme === "auto") {
nextTheme = (await appWindow.theme()) ?? "light";
}

globalStore.appearance.isDark = nextTheme === "dark";

setTheme(value);
});
});

useRegister(toggleWindowVisible, [shortcut.preference]);
Expand Down
5 changes: 4 additions & 1 deletion src/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
},
"hints": {
"auto_paste": "Quickly paste content to the input field when using the left mouse button",
"image_ocr": "Helps prevent crashes due to insufficient system OCR support; Linux users may need to download separately",
"image_ocr": "Note: Please be sure to download the",
"copy_as_plain": "Only retains plain text content when copying rich text or HTML formats"
}
}
Expand Down Expand Up @@ -116,6 +116,9 @@
"theme_auto": "System",
"theme_light": "Light",
"theme_dark": "Dark"
},
"hints": {
"theme": "Note: The app will restart automatically when switching themes"
}
}
},
Expand Down
5 changes: 4 additions & 1 deletion src/locales/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
},
"hints": {
"auto_paste": "左クリック時に、内容を素早く入力フィールドに貼り付けます",
"image_ocr": "システムOCRのサポートが不十分な場合のアプリケーションクラッシュを回避するために役立ちます。Linuxユーザーは別途ダウンロードが必要な場合があります",
"image_ocr": "注意:ご使用前に必ずダウンロードしてください",
"copy_as_plain": "リッチテキストやHTML形式をコピーする際に、プレーンテキストのみを保持します"
}
}
Expand Down Expand Up @@ -116,6 +116,9 @@
"theme_auto": "システムに従う",
"theme_light": "ライト",
"theme_dark": "ダーク"
},
"hints": {
"theme": "注意: テーマを切り替えると、アプリは自動的に再起動します。"
}
}
},
Expand Down
5 changes: 4 additions & 1 deletion src/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
},
"hints": {
"auto_paste": "鼠标左键操作时,快速粘贴内容至输入位置",
"image_ocr": "可以暂时避免由于系统 OCR 支持不足导致应用崩溃的问题,如果是 linux 用户请自行下载",
"image_ocr": "注意:使用前请务必先下载",
"copy_as_plain": "富文本和 HTML 格式在复制时仅保留纯文本内容"
}
}
Expand Down Expand Up @@ -116,6 +116,9 @@
"theme_auto": "跟随系统",
"theme_light": "亮色模式",
"theme_dark": "暗色模式"
},
"hints": {
"theme": "注意:切换主题时,应用将会自动重启"
}
}
},
Expand Down
5 changes: 4 additions & 1 deletion src/locales/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
},
"hints": {
"auto_paste": "當使用滑鼠左鍵時,快速將內容貼上到輸入位置",
"image_ocr": "可暫時避免因系統 OCR 支援不足導致應用程式崩潰的問題,若為 Linux 用戶請自行下載",
"image_ocr": "注意:使用前請務必先下載",
"copy_as_plain": "富文本和 HTML 格式在複製時僅保留純文字內容"
}
}
Expand Down Expand Up @@ -116,6 +116,9 @@
"theme_auto": "跟隨系統",
"theme_light": "亮色模式",
"theme_dark": "暗色模式"
},
"hints": {
"theme": "注意:切換主題時,應用將會自動重啟"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.normal {
.root {
display: -webkit-box;
overflow: hidden;
-webkit-line-clamp: 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Text: FC<HistoryItem> = (props) => {
return value;
};

return <div className={styles.normal}>{renderContent()}</div>;
return <div className={styles.root}>{renderContent()}</div>;
};

export default memo(Text);
14 changes: 8 additions & 6 deletions src/pages/Clipboard/Settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ const Clipboard = () => {
<ProSwitch
title={t("preference.clipboard.content_settings.label.image_ocr")}
description={
<>
{t("preference.clipboard.content_settings.hints.image_ocr")}{" "}
<Typography.Link href="https://github.com/tesseract-ocr/tesseract">
tesseract
</Typography.Link>
</>
isLinux() && (
<>
{t("preference.clipboard.content_settings.hints.image_ocr")}{" "}
<Typography.Link href="https://github.com/tesseract-ocr/tesseract">
tesseract
</Typography.Link>
</>
)
}
value={content.ocr}
onChange={(value) => {
Expand Down
3 changes: 3 additions & 0 deletions src/pages/General/components/ThemeMode/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ const ThemeMode = () => {
return (
<ProSelect
title={t("preference.settings.appearance_settings.label.theme")}
description={
isWin() && t("preference.settings.appearance_settings.hints.theme")
}
value={appearance.theme}
options={options}
onChange={(value) => {
Expand Down

0 comments on commit c418e52

Please sign in to comment.