fix reset button (#1045)
This commit is contained in:
@@ -288,6 +288,7 @@
|
||||
"resetAllConfirmation": "It will remove all of your personal data, are you sure?",
|
||||
"resetSettings": "Reset Settings",
|
||||
"resetSettingsConfirmation": "It will reset all of your settings, are you sure? The library will not be affected.",
|
||||
"settingsReseted": "Settings reseted",
|
||||
"proxySettings": "Proxy Settings",
|
||||
"proxyConfigUpdated": "Proxy config updated",
|
||||
"apiSettings": "API Settings",
|
||||
@@ -757,8 +758,8 @@
|
||||
"import": "Import",
|
||||
"default": "Default",
|
||||
"setDefault": "Set Default",
|
||||
"dictSettings": "Dict Settings",
|
||||
"dictSettingsShort": "Dict Settings",
|
||||
"dictSettings": "Dictionaries Settings",
|
||||
"dictSettingsShort": "Dictionaries",
|
||||
"importDict": "Import Dictionary",
|
||||
"dictRemoved": "Dictionary removed successfully",
|
||||
"interrupted": "Interrupted",
|
||||
|
||||
@@ -288,6 +288,7 @@
|
||||
"resetAllConfirmation": "这将删除您的所有个人数据, 您确定要重置吗?",
|
||||
"resetSettings": "重置设置选项",
|
||||
"resetSettingsConfirmation": "您确定要重置个人设置选项吗?资料库不会受影响。",
|
||||
"settingsReseted": "设置选项已重置",
|
||||
"proxySettings": "代理设置",
|
||||
"proxyConfigUpdated": "代理配置已更新",
|
||||
"apiSettings": "API 设置",
|
||||
|
||||
@@ -68,6 +68,10 @@ export class UserSetting extends Model<UserSetting> {
|
||||
}
|
||||
}
|
||||
|
||||
static async clear(): Promise<void> {
|
||||
await UserSetting.destroy({ where: {} });
|
||||
}
|
||||
|
||||
static async migrateFromSettings(): Promise<void> {
|
||||
// hotkeys
|
||||
const hotkeys = await UserSetting.get(UserSettingKeyEnum.HOTKEYS);
|
||||
|
||||
@@ -24,6 +24,7 @@ import echogarden from "./echogarden";
|
||||
import camdict from "./camdict";
|
||||
import dict from "./dict";
|
||||
import decompresser from "./decompresser";
|
||||
import { UserSetting } from "@main/db/models";
|
||||
|
||||
const __filename = url.fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
@@ -292,8 +293,12 @@ main.init = async () => {
|
||||
};
|
||||
});
|
||||
|
||||
ipcMain.handle("app-reset", () => {
|
||||
fs.removeSync(settings.userDataPath());
|
||||
ipcMain.handle("app-reset", async () => {
|
||||
const userDataPath = settings.userDataPath();
|
||||
|
||||
await db.disconnect();
|
||||
|
||||
fs.removeSync(userDataPath);
|
||||
fs.removeSync(settings.file());
|
||||
|
||||
app.relaunch();
|
||||
@@ -301,10 +306,7 @@ main.init = async () => {
|
||||
});
|
||||
|
||||
ipcMain.handle("app-reset-settings", () => {
|
||||
fs.removeSync(settings.file());
|
||||
|
||||
app.relaunch();
|
||||
app.exit();
|
||||
UserSetting.clear();
|
||||
});
|
||||
|
||||
ipcMain.handle("app-relaunch", () => {
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
AlertDialogTrigger,
|
||||
toast,
|
||||
} from "@renderer/components/ui";
|
||||
import { useContext } from "react";
|
||||
import { AppSettingsProviderContext } from "../../context";
|
||||
@@ -48,8 +49,13 @@ export const ResetAllButton = (props: { children: React.ReactNode }) => {
|
||||
export const ResetSettingsButton = (props: { children: React.ReactNode }) => {
|
||||
const { EnjoyApp } = useContext(AppSettingsProviderContext);
|
||||
|
||||
const reset = () => {
|
||||
EnjoyApp.app.resetSettings();
|
||||
const reset = async () => {
|
||||
try {
|
||||
await EnjoyApp.app.resetSettings();
|
||||
toast.success(t("settingsReseted"));
|
||||
} catch (error) {
|
||||
toast.error(error.message);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { t } from "i18next";
|
||||
import { Button } from "@renderer/components/ui";
|
||||
import { ResetAllButton } from "@renderer/components";
|
||||
import { ResetSettingsButton } from "@renderer/components";
|
||||
import { InfoIcon } from "lucide-react";
|
||||
|
||||
export const ResetSettings = () => {
|
||||
@@ -15,11 +15,11 @@ export const ResetSettings = () => {
|
||||
|
||||
<div className="">
|
||||
<div className="mb-2 flex justify-end">
|
||||
<ResetAllButton>
|
||||
<ResetSettingsButton>
|
||||
<Button variant="secondary" className="text-destructive" size="sm">
|
||||
{t("resetSettings")}
|
||||
</Button>
|
||||
</ResetAllButton>
|
||||
</ResetSettingsButton>
|
||||
</div>
|
||||
<div className="text-xs text-muted-foreground">
|
||||
<InfoIcon className="mr-1 w-3 h-3 inline" />
|
||||
|
||||
Reference in New Issue
Block a user