Skip to content

Commit

Permalink
add(Settings): reset settings
Browse files Browse the repository at this point in the history
add(Settings): app version
  • Loading branch information
feightwywx committed May 14, 2023
1 parent e35eb03 commit fec3958
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 9 deletions.
2 changes: 1 addition & 1 deletion release/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aam",
"version": "0.0.1",
"version": "0.0.2",
"description": "一个Arcaea资产管理工具",
"license": "MIT",
"author": {
Expand Down
14 changes: 13 additions & 1 deletion src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { app, BrowserWindow, shell, ipcMain, dialog } from 'electron';
// import { autoUpdater } from 'electron-updater';
import log, { LevelOption } from 'electron-log';
import installExtension, { REDUX_DEVTOOLS } from 'electron-devtools-installer';
import { Song, Songlist } from 'type';
import { AppInfo, Song, Songlist } from 'type';

import MenuBuilder from './menu';
import { resolveHtmlPath } from './util';
Expand Down Expand Up @@ -229,5 +229,17 @@ app
ipcMain.handle('showLogFile', async () => {
shell.openPath(path.dirname(log.transports.file.getFile().path));
});

ipcMain.handle('reset', async () => {
globalStore.reset('settings');
app.exit();
});

ipcMain.handle('getAppInfo', async () => {
return {
version: app.getVersion(),
isDebug,
} as AppInfo;
});
})
.catch(console.log);
2 changes: 2 additions & 0 deletions src/main/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ contextBridge.exposeInMainWorld('electron', {
},
openDirectory: () => ipcRenderer.invoke('dialog:openDirectory'),
showLogFile: () => ipcRenderer.invoke('showLogFile'),
reset: () => ipcRenderer.invoke('reset'),
getAppInfo: () => ipcRenderer.invoke('getAppInfo'),
},
});

Expand Down
58 changes: 52 additions & 6 deletions src/renderer/pages/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { ExclamationCircleFilled } from '@ant-design/icons';
import {
Button,
Form,
Input,
InputNumber,
Layout,
Modal,
Select,
Space,
Typography,
message,
} from 'antd';
import React from 'react';
import { SettingsType } from 'type';
import React, { useState } from 'react';
import { AppInfo, SettingsType } from 'type';

const Settings: React.FC = () => {
const [form] = Form.useForm();
Expand All @@ -18,11 +21,18 @@ const Settings: React.FC = () => {
| undefined;
console.log(settings);

const [messageApi] = message.useMessage();

const [appInfo, setAppInfo] = useState<AppInfo>();
const appInfoPromise = window.electron.ipcRenderer
.getAppInfo()
.then((resp) => setAppInfo(resp));

return (
<>
<div style={{ height: '100vh', overflow: 'scroll' }}>
<Form
form={form}
style={{padding: '0 24px'}}
style={{ padding: '0 24px' }}
autoComplete="off"
layout="vertical"
initialValues={settings}
Expand All @@ -38,7 +48,7 @@ const Settings: React.FC = () => {
) {
window.electron.ipcRenderer.store.set(
`settings.${i}`,
changedVal[i]
changedVal[i as keyof SettingsType]
);
}
}
Expand Down Expand Up @@ -96,8 +106,44 @@ const Settings: React.FC = () => {
</Typography.Text>
</Space>
</Form.Item>

<Form.Item label="初始化">
<Space direction="vertical" style={{ width: '100%' }}>
<Button
danger
onClick={() => {
Modal.confirm({
title: '你确定吗?',
icon: <ExclamationCircleFilled />,
content: 'AAM将在初始化后退出。此操作不能撤销。',
onOk() {
return new Promise((resolve, reject) => {
window.electron.ipcRenderer.reset();
messageApi.success('已重置');
resolve();
}).catch(() => console.log('Oops errors!'));
},
onCancel() {},
});
}}
>
初始化
</Button>
<Typography.Text type="secondary">
如果您遇到了问题,可以尝试初始化AAM。这将把所有设置恢复到默认状态。
</Typography.Text>
</Space>
</Form.Item>
<Form.Item>
<Typography.Text type="secondary">
aam -{' '}
{appInfo?.isDebug
? `development mode, electron ${appInfo.version}`
: appInfo?.version}
</Typography.Text>
</Form.Item>
</Form>
</>
</div>
);
};

Expand Down
4 changes: 3 additions & 1 deletion src/renderer/preload.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Channels } from 'main/preload';
import { IPCResponse, Song, Songlist } from '../type';
import { AppInfo, IPCResponse, Song, Songlist } from '../type';

declare global {
interface Window {
Expand All @@ -13,6 +13,8 @@ declare global {
once(channel: Channels, func: (...args: unknown[]) => void): void;
openDirectory: () => Promise<string | undefined>;
showLogFile: () => Promise<void>;
reset: () => Promise<void>;
getAppInfo: () => Promise<AppInfo>;

store: {
get: (key: string) => unknown;
Expand Down
5 changes: 5 additions & 0 deletions src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,8 @@ export interface SettingsType {
minimalRating: number;
ignoredSong: string;
}

export interface AppInfo {
version: string;
isDebug: boolean;
}

0 comments on commit fec3958

Please sign in to comment.