fix mdict import
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -762,6 +762,7 @@
|
||||
"dictSettings": "词典设置",
|
||||
"dictSettingsShort": "词典设置",
|
||||
"importDict": "导入词典",
|
||||
"failedToImportDict": "导入词典失败: {{error}}",
|
||||
"dictRemoved": "成功删除词典",
|
||||
"interrupted": "已中断",
|
||||
"paused": "已暂停",
|
||||
|
||||
@@ -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$/));
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user