Skip to content

Commit caa5cd6

Browse files
committed
init: UpdateDetection
1 parent 7d42830 commit caa5cd6

12 files changed

Lines changed: 447 additions & 44 deletions

File tree

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"bgcolor",
1212
"blockmap",
1313
"cascader",
14+
"charsets",
1415
"chmod",
1516
"CLOB",
1617
"datasource",

chat2db-client/.umirc.prod.desktop.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const chainWebpack = (config: any, { webpack }: any) => {
1010
languages: ['mysql', 'pgsql', 'sql'],
1111
},
1212
]);
13-
config.output.filename(`[name].${yarn_config.app_version || new Date().getTime()}.js`);
1413
};
1514

1615
export default defineConfig({

chat2db-client/.umirc.prod.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const chainWebpack = (config: any, { webpack }: any) => {
1010
languages: ['mysql', 'pgsql', 'sql'],
1111
},
1212
]);
13-
config.output.filename(`[name].${yarn_config.app_version || new Date().getTime()}.js`);
1413
};
1514

1615
export default defineConfig({

chat2db-client/.umirc.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ const chainWebpack = (config: any, { webpack }: any) => {
1212
languages: ['mysql', 'pgsql', 'sql'],
1313
},
1414
]);
15-
config.output.filename(`[name].${yarn_config.app_version || new Date().getTime()}.js`);
1615
};
1716

1817
export default defineConfig({
1918
title: 'Chat2DB',
2019
base: '/',
2120
publicPath: '/',
22-
hash: false,
21+
hash: true,
2322
routes: [
2423
{ path: '/demo', component: '@/pages/demo' },
2524
{ path: '/connections', component: 'main' },
@@ -98,7 +97,7 @@ export default defineConfig({
9897
define: {
9998
__ENV__: process.env.UMI_ENV,
10099
__BUILD_TIME__: transitionTimezoneTimestamp(new Date().getTime()),
101-
__APP_VERSION__: yarn_config.app_version || '9.9.9',
100+
__APP_VERSION__: yarn_config.app_version || '0.0.0',
102101
__APP_PORT__: yarn_config.app_port,
103102
},
104103
esbuildMinifyIIFE: true

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

Lines changed: 87 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,87 @@
1-
import BrandLogo from '@/components/BrandLogo';
2-
import { APP_NAME, GITHUB_URL, WEBSITE_DOC } from '@/constants/appConfig';
3-
import i18n from '@/i18n';
4-
import React from 'react';
1+
import React, { useEffect, useMemo } from 'react';
52
import styles from './index.less';
3+
// import i18n from '@/i18n';
4+
import BrandLogo from '@/components/BrandLogo';
5+
import { APP_NAME, WEBSITE_DOC } from '@/constants/appConfig';
66
// import { formatDate, getUserTimezoneTimestamp } from '@/utils/date';
77
import { Button, Radio, Space } from 'antd';
8+
import configService from '@/service/config';
9+
import { DownloadOutlined } from '@ant-design/icons';
10+
import { IUpdateDetectionData } from '../index';
11+
import { IUpdateDetectionRef, UpdatedStatusEnum } from '../UpdateDetection';
12+
13+
interface IProps {
14+
updateDetectionData: IUpdateDetectionData | null;
15+
updateDetectionRef: React.MutableRefObject<IUpdateDetectionRef> | null;
16+
}
817

918
// 关于我们
10-
export default function AboutUs() {
11-
const [updateRule, setUpdateRule] = React.useState(1); // 1:自动下载并安装更新 2:仅在新版本发布时提醒我
12-
const onChangeUpdateRul = () => {
13-
setUpdateRule(updateRule === 1 ? 2 : 1);
19+
export default function AboutUs(props: IProps) {
20+
const { updateDetectionData, updateDetectionRef } = props;
21+
const [updateRule, setUpdateRule] = React.useState<'manual' | 'auto'>(updateDetectionData?.type || 'manual');
22+
23+
const onChangeUpdateRul = (e) => {
24+
configService.setAppUpdateType(e.target.value).then(() => {
25+
setUpdateRule(e.target.value);
26+
});
1427
};
1528

29+
useEffect(()=>{
30+
setUpdateRule(updateDetectionData?.type || 'manual');
31+
},[updateDetectionData?.type])
32+
1633
const jumpDoc = () => {
1734
window.open(WEBSITE_DOC, '_blank');
1835
};
1936

37+
const updateButton = useMemo(() => {
38+
if (!updateDetectionData?.needUpdate) {
39+
return false;
40+
}
41+
switch (updateDetectionData?.updatedStatusEnum) {
42+
case UpdatedStatusEnum.NOT_UPDATED:
43+
return (
44+
<Button
45+
onClick={() => {
46+
updateDetectionRef?.current?.openDownload();
47+
}}
48+
icon={<DownloadOutlined />}
49+
type="primary"
50+
>
51+
开始下载
52+
</Button>
53+
);
54+
case UpdatedStatusEnum.UPDATING:
55+
return (
56+
<Button type="primary" loading>
57+
下载中
58+
</Button>
59+
);
60+
// 超时后端如何处理 TODO:
61+
case UpdatedStatusEnum.TIMEOUT:
62+
return (
63+
<Button
64+
onClick={() => {
65+
updateDetectionRef?.current?.openDownload();
66+
}}
67+
icon={<DownloadOutlined />}
68+
type="primary"
69+
loading
70+
>
71+
超时重新下载
72+
</Button>
73+
);
74+
case UpdatedStatusEnum.UPDATED:
75+
return (
76+
<Button icon={<DownloadOutlined />} type="primary">
77+
立即重启
78+
</Button>
79+
);
80+
default:
81+
return false;
82+
}
83+
}, [updateDetectionData]);
84+
2085
return (
2186
<div className={styles.aboutUs}>
2287
<div className={styles.versionsInfo}>
@@ -26,21 +91,29 @@ export default function AboutUs() {
2691
<span className={styles.appName}>{APP_NAME}</span>
2792
<span>{__APP_VERSION__}</span>
2893
</div>
29-
<div className={styles.newVersion}>发现新版本10.0.0</div>
30-
<div className={styles.updateButton}>
31-
<Button type="primary">立即更新</Button>
32-
<Button onClick={jumpDoc}>查看更新日志</Button>
94+
<div className={styles.newVersion}>
95+
{updateDetectionData?.needUpdate ? (
96+
<span>发现新版本{updateDetectionData?.version}</span>
97+
) : (
98+
<span>已是最新版本</span>
99+
)}
33100
</div>
101+
{updateDetectionData?.desktop && (
102+
<div className={styles.updateButton}>
103+
{updateButton}
104+
<Button onClick={jumpDoc}>查看更新日志</Button>
105+
</div>
106+
)}
34107
</div>
35108
</div>
36109
<div className={styles.updateRule}>
37110
<div className={styles.updateRuleTitle}>软件更新</div>
38111
<Radio.Group className={styles.updateRuleGroup} onChange={onChangeUpdateRul} value={updateRule}>
39112
<Space direction="vertical">
40-
<Radio className={styles.updateRuleRadio} value={1}>
113+
<Radio className={styles.updateRuleRadio} value="auto">
41114
新版自动下载并安装更新
42115
</Radio>
43-
<Radio className={styles.updateRuleRadio} value={2}>
116+
<Radio className={styles.updateRuleRadio} value="manual">
44117
仅在新版本发布时提醒我
45118
</Radio>
46119
</Space>

0 commit comments

Comments
 (0)