Skip to content

Commit 127a440

Browse files
committed
feat:holdingService
1 parent fe1b362 commit 127a440

9 files changed

Lines changed: 60 additions & 4 deletions

File tree

chat2db-client/src/blocks/Setting/About/index.less

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
}
4848
}
4949
}
50+
.holdingService{
51+
margin-top: 20px;
52+
}
5053
.brief {
5154
display: flex;
5255
flex-direction: column;

chat2db-client/src/blocks/Setting/About/index.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import React, { useEffect, useMemo } from 'react';
22
import styles from './index.less';
33
import i18n from '@/i18n';
4+
import classnames from 'classnames';
45
import BrandLogo from '@/components/BrandLogo';
56
import { APP_NAME, WEBSITE_DOC } from '@/constants/appConfig';
6-
import { Button, Radio, Space } from 'antd';
7+
import { Button, Radio, Space, Checkbox } from 'antd';
78
import configService from '@/service/config';
89
import { DownloadOutlined } from '@ant-design/icons';
910
import { IUpdateDetectionData } from '../index';
1011
import { IUpdateDetectionRef, UpdatedStatusEnum } from '../UpdateDetection';
1112
import Iconfont from '@/components/Iconfont';
13+
import {useSettingStore,setHoldingService} from '@/store/setting';
14+
1215
interface IProps {
1316
updateDetectionData: IUpdateDetectionData | null;
1417
updateDetectionRef: React.MutableRefObject<IUpdateDetectionRef> | null;
@@ -19,6 +22,14 @@ export default function AboutUs(props: IProps) {
1922
const { updateDetectionData, updateDetectionRef } = props;
2023
const [updateRule, setUpdateRule] = React.useState<'manual' | 'auto'>(updateDetectionData?.type || 'manual');
2124

25+
const {holdingService} = useSettingStore((state)=>{
26+
return {
27+
holdingService:state.holdingService
28+
}
29+
});
30+
31+
console.log('holdingService',holdingService)
32+
2233
const onChangeUpdateRul = (e) => {
2334
configService.setAppUpdateType(e.target.value).then(() => {
2435
setUpdateRule(e.target.value);
@@ -89,6 +100,11 @@ export default function AboutUs(props: IProps) {
89100
}
90101
}, [updateDetectionData]);
91102

103+
const changeHoldingService = (e) => {
104+
setHoldingService(e.target.checked);
105+
window.electronApi?.setForceQuitCode?.(e.target.checked);
106+
}
107+
92108
return (
93109
<div className={styles.aboutUs}>
94110
<div className={styles.versionsInfo}>
@@ -129,6 +145,10 @@ export default function AboutUs(props: IProps) {
129145
</Space>
130146
</Radio.Group>
131147
</div>
148+
<div className={classnames(styles.updateRule, styles.holdingService) }>
149+
<div className={styles.updateRuleTitle}>{i18n('setting.title.holdingService')}</div>
150+
<Checkbox checked={holdingService} onChange={changeHoldingService}>{i18n('setting.text.holdingService')}</Checkbox>
151+
</div>
132152
{/* <div className={styles.brief}>
133153
<div className={styles.appName}>{APP_NAME}</div>
134154
<div className={styles.env}>

chat2db-client/src/i18n/en-us/setting.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,6 @@ export default {
5454
'setting.text.newEditionIsReady': 'New version to download completed, restart the software will install the new version',
5555
'setting.button.goToUpdate': 'Go to update',
5656
'setting.text.UpdatedLatestVersion': 'Updated to the latest version {1}',
57+
'setting.title.holdingService': 'Holding Service',
58+
'setting.text.holdingService': 'Keep the service when exiting the application to speed up startup',
5759
};

chat2db-client/src/i18n/zh-cn/setting.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,7 @@ export default {
5454
'setting.text.newEditionIsReady': '新版本已下载完成, 重启软件将会安装新版本',
5555
'setting.button.goToUpdate': '前往更新',
5656
'setting.text.UpdatedLatestVersion': '已更新到最新版本 {1}',
57+
'setting.title.holdingService': '保持服务',
58+
'setting.text.holdingService': '退出应用时保持服务,加快启动速度',
5759

5860
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// 注册Electron关闭时,关闭服务
2+
import { useSettingStore } from '@/store/setting'
23
const registerElectronApi = () => {
34
window.electronApi?.registerAppMenu({
45
version: __APP_VERSION__,
56
});
67
window.electronApi?.setBaseURL?.(window._BaseURL);
8+
window.electronApi?.setForceQuitCode?.(useSettingStore.getState().holdingService);
79
};
810

911
export default registerElectronApi;

chat2db-client/src/main/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const { loadMainResource } = require('./utils');
1111
let mainWindow = null;
1212

1313
let baseUrl = null;
14+
let _forceQuitCode = false;
1415

1516
function createWindow() {
1617
mainWindow = new BrowserWindow({
@@ -78,7 +79,7 @@ app.on('before-quit', () => {
7879
'Content-Type': 'application/json',
7980
},
8081
method: 'POST',
81-
url: `${baseUrl}/api/system/stop`,
82+
url: `${baseUrl}/api/system/stop?forceQuit=${_forceQuitCode}`,
8283
});
8384
request.end();
8485
} catch (error) {}
@@ -105,4 +106,8 @@ ipcMain.on('set-base-url',(event,_baseUrl)=>{
105106
baseUrl = _baseUrl;
106107
})
107108

109+
ipcMain.on('set-force-quit-code',(event,_forceQuitCode)=>{
110+
forceQuitCode = _forceQuitCode;
111+
})
112+
108113

chat2db-client/src/main/preload.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ contextBridge.exposeInMainWorld('electronApi', {
4848
setBaseURL: (baseUrl) => {
4949
ipcRenderer.send('set-base-url', baseUrl);
5050
},
51+
setForceQuitCode: (code) => {
52+
ipcRenderer.send('set-force-quit-code', code);
53+
},
5154
registerAppMenu: (menuProps) => {
5255
ipcRenderer.send('register-app-menu', menuProps);
5356
},

chat2db-client/src/store/setting/index.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { UseBoundStoreWithEqualityFn, createWithEqualityFn } from 'zustand/traditional';
2-
import { devtools } from 'zustand/middleware';
2+
import { devtools, persist } from 'zustand/middleware';
33
import { shallow } from 'zustand/shallow';
44
import { StoreApi } from 'zustand';
55

@@ -15,6 +15,7 @@ export interface ISettingState {
1515
aiConfig: IAiConfig;
1616
remainingUse?: IRemainingUse;
1717
hasWhite: boolean;
18+
holdingService: boolean;
1819
}
1920

2021
const initSetting = {
@@ -23,10 +24,23 @@ const initSetting = {
2324
aiSqlSource: AIType.CHAT2DBAI,
2425
},
2526
hasWhite: false,
27+
holdingService: true,
2628
}
2729

2830
export const useSettingStore: UseBoundStoreWithEqualityFn<StoreApi<ISettingState>> = createWithEqualityFn(
29-
devtools(() => (initSetting)),
31+
devtools(
32+
persist(
33+
() => (initSetting),
34+
{
35+
name: 'global-setting',
36+
getStorage: () => localStorage,
37+
// 工作区的状态只保存 layout布局信息
38+
partialize: (state: ISettingState) => ({
39+
holdingService: state.holdingService,
40+
}),
41+
},
42+
),
43+
),
3044
shallow
3145
);
3246

@@ -80,6 +94,10 @@ export const fetchRemainingUse = (apiKey)=>{
8094
})
8195
}
8296

97+
export const setHoldingService = (holdingService: boolean) => {
98+
useSettingStore.setState({ holdingService });
99+
}
100+
83101

84102

85103

chat2db-client/typings.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ declare global {
2727
quitApp: () => void;
2828
setBaseURL: (baseUrl: string) => void;
2929
registerAppMenu: (data: any) => void;
30+
setForceQuitCode: (code: boolean) => void;
3031
};
3132
}
3233
const __APP_VERSION__: string;

0 commit comments

Comments
 (0)