fix mdict import

This commit is contained in:
an-lee
2024-09-14 06:29:40 +08:00
parent 5ea2b6946c
commit 9b8cc54071
5 changed files with 11 additions and 4 deletions

View File

@@ -762,6 +762,7 @@
"dictSettings": "Dictionaries Settings",
"dictSettingsShort": "Dictionaries",
"importDict": "Import Dictionary",
"failedToImportDict": "Failed to import dictionary: {{error}}",
"dictRemoved": "Dictionary removed successfully",
"interrupted": "Interrupted",
"paused": "Paused",

View File

@@ -762,6 +762,7 @@
"dictSettings": "词典设置",
"dictSettingsShort": "词典设置",
"importDict": "导入词典",
"failedToImportDict": "导入词典失败: {{error}}",
"dictRemoved": "成功删除词典",
"interrupted": "已中断",
"paused": "已暂停",

View File

@@ -7,7 +7,7 @@ import { Mdict as MdictReader } from "@divisey/js-mdict";
import { hashFile } from "@/main/utils";
import settings from "./settings";
const logger = log.scope("dict");
const logger = log.scope("mdict");
export class MDictHandler {
private cache = new LRUCache({ max: 20 });
@@ -26,6 +26,7 @@ export class MDictHandler {
}
async import(pathes: string[]) {
logger.info("Importing mdict: ", pathes);
const mdxs = pathes.filter((_path) => _path.match(/\.mdx$/));
const mdds = pathes.filter((_path) => _path.match(/\.mdd$/));

View File

@@ -39,7 +39,7 @@ export const DictImportButton = () => {
await EnjoyApp.dict.import(pathes[0]);
setOpen(false);
} catch (err) {
toast.error(err.message);
toast.error(t("failedToImportDict", { error: err.message }));
}
setLoading(false);
@@ -60,7 +60,7 @@ export const DictImportButton = () => {
await importMDict(mdict);
setOpen(false);
} catch (err) {
toast.error(err.message);
toast.error(t("failedToImportDict", { error: err.message }));
}
setLoading(false);

View File

@@ -112,7 +112,11 @@ export const DictProvider = ({ children }: { children: React.ReactNode }) => {
const fetchSettings = async () => {
return EnjoyApp.userSettings.get(UserSettingKeyEnum.DICTS).then((res) => {
res && setSettings(res);
if (res) {
setSettings({ ...initialState.settings, ...res });
} else {
setSettings(initialState.settings);
}
});
};