Skip to content

Commit

Permalink
feat: 新增参与测试版体验的配置项 (#499)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayangweb authored Sep 8, 2024
1 parent 7b4a4db commit 90f7513
Show file tree
Hide file tree
Showing 17 changed files with 139 additions and 40 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"arcdash": "^0.0.51",
"clsx": "^2.1.1",
"dayjs": "^1.11.11",
"filesize": "^10.1.4",
"i18next": "^23.12.1",
"lodash-es": "^4.17.21",
"mac-scrollbar": "^0.13.6",
Expand Down
26 changes: 26 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { RouterProvider } from "react-router-dom";
import { useSnapshot } from "valtio";
const { defaultAlgorithm, darkAlgorithm } = theme;
import { listen } from "@tauri-apps/api/event";
import { isString } from "arcdash";
import { isString } from "lodash-es";
import { error } from "tauri-plugin-log-api";

const App = () => {
Expand Down
11 changes: 9 additions & 2 deletions src/components/ProShortcut/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { Flex } from "antd";
import { isEmpty, isEqual } from "arcdash";
import clsx from "clsx";
import { find, intersectionWith, map, remove, some } from "lodash-es";
import {
find,
intersectionWith,
isEmpty,
isEqual,
map,
remove,
some,
} from "lodash-es";
import type { FC, KeyboardEvent, MouseEvent } from "react";
import Icon from "../Icon";
import ProListItem from "../ProListItem";
Expand Down
28 changes: 18 additions & 10 deletions src/components/Update/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { listen } from "@tauri-apps/api/event";
import { relaunch } from "@tauri-apps/api/process";
import {
type UpdateManifest,
checkUpdate,
installUpdate,
onUpdaterEvent,
checkUpdate as tauriCheckUpdate,
} from "@tauri-apps/api/updater";
import type { Timeout } from "ahooks/lib/useRequest/src/types";
import { Flex, Modal, message } from "antd";
Expand Down Expand Up @@ -32,25 +32,27 @@ const Update = () => {
const [messageApi, contextHolder] = message.useMessage();

useMount(() => {
listen(LISTEN_KEY.UPDATE, async () => {
listen<boolean>(LISTEN_KEY.UPDATE, async ({ payload }) => {
check(payload);

if (!payload) return;

messageApi.open({
key: MESSAGE_KEY,
type: "loading",
content: t("component.app_update.hints.checking_update"),
duration: 0,
});

checkUpdate(true);
});

watchKey(globalStore.app, "autoUpdate", (value) => {
watchKey(globalStore.update, "auto", (value) => {
clearInterval(timer);

if (!value) return;

checkUpdate();
check();

timer = setInterval(checkUpdate, 1000 * 60 * 60 * 24);
timer = setInterval(check, 1000 * 60 * 60 * 24);
});
});

Expand All @@ -60,16 +62,22 @@ const Update = () => {
return dayjs.utc(date).local().format("YYYY-MM-DD HH:mm:ss");
}, [state.manifest?.date]);

const checkUpdate = async (showMessage = false) => {
const check = async (showMessage = false) => {
try {
const { shouldUpdate, manifest } = await tauriCheckUpdate();
const { shouldUpdate, manifest } = await checkUpdate();

if (shouldUpdate && manifest) {
const { version, body } = manifest;

const isBeta = /[a-z]/.test(version);

if (isBeta && !globalStore.update.beta) return;

showWindow();

messageApi.destroy(MESSAGE_KEY);

manifest.body = replaceManifestBody(manifest.body);
manifest.body = replaceManifestBody(body);

Object.assign(state, { manifest, open: true });
} else if (showMessage) {
Expand Down
13 changes: 11 additions & 2 deletions src/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,31 @@
"title": "App Settings",
"label": {
"auto_start": "Start at Login",
"auto_update": "Auto Check for Updates",
"hide_tray": "Hide Tray Icon"
}
},
"appearance_settings": {
"title": "Appearance Settings",
"label": {
"language": "Language",
"theme": "Theme Mode",
"theme": "Theme",
"theme_auto": "System",
"theme_light": "Light",
"theme_dark": "Dark"
},
"hints": {
"theme": "Note: The app will restart automatically when switching themes"
}
},
"app_update": {
"title": "App Update",
"label": {
"auto_update": "Auto check for updates",
"update_beta": "Participate in the beta experience"
},
"hints": {
"update_beta": "Will receive beta updates, even if they may be unstable"
}
}
},
"shortcut": {
Expand Down
11 changes: 10 additions & 1 deletion src/locales/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@
"title": "ソフト設定",
"label": {
"auto_start": "ログイン時に起動",
"auto_update": "自動更新チェック",
"hide_tray": "トレイアイコンを隠す"
}
},
Expand All @@ -121,6 +120,16 @@
"hints": {
"theme": "注意: テーマを切り替えると、アプリは自動的に再起動します。"
}
},
"app_update": {
"title": "アプリケーションの更新",
"label": {
"auto_update": "自動更新チェック",
"update_beta": "ベータ体験に参加する"
},
"hints": {
"update_beta": "不安定でもベータ版アップデートを受け取れる"
}
}
},
"shortcut": {
Expand Down
11 changes: 10 additions & 1 deletion src/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@
"title": "应用设置",
"label": {
"auto_start": "登录时启动",
"auto_update": "自动检查更新",
"hide_tray": "隐藏托盘图标"
}
},
Expand All @@ -121,6 +120,16 @@
"hints": {
"theme": "注意:切换主题时,应用将会自动重启"
}
},
"app_update": {
"title": "应用更新",
"label": {
"auto_update": "自动检查更新",
"update_beta": "参与测试版体验"
},
"hints": {
"update_beta": "将会接收测试版更新,即使它们可能不稳定"
}
}
},
"shortcut": {
Expand Down
11 changes: 10 additions & 1 deletion src/locales/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@
"title": "應用設定",
"label": {
"auto_start": "登入時啟動",
"auto_update": "自動檢查更新",
"hide_tray": "隱藏託盤圖標"
}
},
Expand All @@ -121,6 +120,16 @@
"hints": {
"theme": "注意:切換主題時,應用將會自動重啟"
}
},
"app_update": {
"title": "應用更新",
"label": {
"auto_update": "自動檢查更新",
"update_beta": "參與測試版體驗"
},
"hints": {
"update_beta": "將會接收測試版更新,即使它們可能不穩定"
}
}
},
"shortcut": {
Expand Down
8 changes: 3 additions & 5 deletions src/pages/About/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ const About = () => {
const { env } = useSnapshot(globalStore);
const { t } = useTranslation();

const update = () => {
emit(LISTEN_KEY.UPDATE);
};

const copyInfo = async () => {
const { appName, appVersion, platform } = env;

Expand Down Expand Up @@ -55,7 +51,9 @@ const About = () => {
hoverable
name="i-iconamoon:restart"
size={16}
onMouseDown={update}
onMouseDown={() => {
emit(LISTEN_KEY.UPDATE, true);
}}
/>
</Tooltip>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import Icon from "@/components/Icon";
import Scrollbar from "@/components/Scrollbar";
import type { ClipboardItem } from "@/types/database";
import { Flex, Popconfirm } from "antd";
import { autoConvertBytes } from "arcdash";
import clsx from "clsx";
import { filesize } from "filesize";
import type { FC } from "react";

interface HeaderProps extends ClipboardItem {
Expand Down Expand Up @@ -65,7 +65,7 @@ const Header: FC<HeaderProps> = (props) => {

const renderSize = () => {
if (type === "files" || type === "image") {
return autoConvertBytes(size);
return filesize(size, { standard: "jedec" });
}

return t("clipboard.label.n_chars", {
Expand Down
Loading

0 comments on commit 90f7513

Please sign in to comment.