Skip to content

Commit 2077a0d

Browse files
committed
style:electron bar
1 parent 5142779 commit 2077a0d

9 files changed

Lines changed: 65 additions & 2297 deletions

File tree

chat2db-client/.umirc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export default defineConfig({
8383
localStorage.clear();
8484
localStorage.setItem('app-local-storage-versions', 'v4');
8585
}`,
86-
`if (window.electronApi) { window.electronApi.startServerForSpawn() }`,
86+
// `if (window.electronApi) { window.electronApi.startServerForSpawn() }`,
8787
// `if ("serviceWorker" in navigator) {
8888
// window.addEventListener("load", function () {
8989
// navigator.serviceWorker

chat2db-client/src/blocks/AppTitleBar/index.tsx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { memo, useMemo } from 'react';
1+
import React, { memo, useState } from 'react';
22
import styles from './index.less';
33
import classnames from 'classnames';
44
import { useCommonStore } from '@/store/common';
@@ -10,6 +10,7 @@ interface IProps {
1010

1111
export default memo<IProps>((props) => {
1212
const { className } = props;
13+
const [isMaximized, setIsMaximize] = useState(window.electronApi?.isMaximized());
1314

1415
const { appTitleBarRightComponent } = useCommonStore((state) => {
1516
return {
@@ -27,9 +28,21 @@ export default memo<IProps>((props) => {
2728
window.electronApi?.setMaximize();
2829
};
2930

30-
const handelMaximize = () => {
31+
const handelMinimizeWindow = (e) => {
32+
e.stopPropagation();
33+
window.electronApi?.minimizeWindow();
34+
};
35+
36+
const handelMaximize = (e) => {
37+
e.stopPropagation();
3138
window.electronApi?.setMaximize();
32-
}
39+
setIsMaximize(!isMaximized);
40+
};
41+
42+
const handelCloseWindow = (e) => {
43+
e.stopPropagation();
44+
window.electronApi?.closeWindow();
45+
};
3346

3447
return (
3548
<div className={classnames(styles.appTitleBar, className)} onDoubleClick={handleDoubleClick}>
@@ -40,14 +53,14 @@ export default memo<IProps>((props) => {
4053
</div>
4154
{isWin && (
4255
<div className={styles.windowsCloseBar}>
43-
<div className={styles.windowsCloseBarItem}>
44-
<Iconfont code="&#xeb78;" />
56+
<div className={styles.windowsCloseBarItem} onClick={handelMinimizeWindow}>
57+
<Iconfont code="&#xe644;" />
4558
</div>
4659
<div className={styles.windowsCloseBarItem} onClick={handelMaximize}>
47-
<Iconfont code="&#xeb78;" />
60+
{isMaximized ? <Iconfont code="&#xe66e;" /> : <Iconfont code="&#xe66b;" />}
4861
</div>
49-
<div className={styles.windowsCloseBarItem}>
50-
<Iconfont code="&#xeb78;" />
62+
<div className={styles.windowsCloseBarItem} onClick={handelCloseWindow}>
63+
<Iconfont code="&#xe66f;" />
5164
</div>
5265
</div>
5366
)}

chat2db-client/src/components/Iconfont/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ if (__ENV__ === 'local') {
99
/* 在线链接服务仅供平台体验和调试使用,平台不承诺服务的稳定性,企业客户需下载字体包自行发布使用并做好备份。 */
1010
@font-face {
1111
font-family: 'iconfont'; /* Project id 3633546 */
12-
src: url('//at.alicdn.com/t/c/font_3633546_yr9ay65j0fs.woff2?t=1703837870848') format('woff2'),
13-
url('//at.alicdn.com/t/c/font_3633546_yr9ay65j0fs.woff?t=1703837870848') format('woff'),
14-
url('//at.alicdn.com/t/c/font_3633546_yr9ay65j0fs.ttf?t=1703837870848') format('truetype');
12+
src: url('//at.alicdn.com/t/c/font_3633546_vmsq4yq8hw9.woff2?t=1704769259060') format('woff2'),
13+
url('//at.alicdn.com/t/c/font_3633546_vmsq4yq8hw9.woff?t=1704769259060') format('woff'),
14+
url('//at.alicdn.com/t/c/font_3633546_vmsq4yq8hw9.ttf?t=1704769259060') format('truetype');
1515
}
1616
`;
1717
const style = document.createElement('style');

chat2db-client/src/hooks/usePollRequestService.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ const usePollRequestService = ({ maxAttempts = 200, interval = 200, loopService
4545
serviceFn();
4646

4747
if (serviceStatus !== ServiceStatus.SUCCESS) {
48+
// 第一次请求失败,启动服务
49+
if (attempts === 1) {
50+
window.electronApi?.startServerForSpawn();
51+
}
4852
intervalId = setInterval(serviceFn, interval);
4953
}
5054

chat2db-client/src/main/index.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { app, BrowserWindow, shell, net, ipcMain } = require('electron');
1+
const { app, BrowserWindow, shell, net, ipcMain, globalShortcut } = require('electron');
22
const path = require('path');
33
const registerAppMenu = require('./menu');
44
const registerAnalysis = require('./analysis');
@@ -54,6 +54,11 @@ function createWindow() {
5454
mainWindow.on('move', () => {
5555
store.set('windowBounds', mainWindow.getBounds());
5656
});
57+
58+
// 注册快捷键Ctrl+Shift+I打开开发者工具
59+
globalShortcut.register('CommandOrControl+Shift+I', () => {
60+
mainWindow.webContents.openDevTools()
61+
})
5762
}
5863

5964
// const menu = Menu.buildFromTemplate(menuBar);
@@ -68,7 +73,7 @@ app.on('ready', () => {
6873
});
6974

7075
app.on('activate', () => {
71-
if (!!mainWindow) {
76+
if (!mainWindow) {
7277
createWindow();
7378
} else {
7479
if (mainWindow.isMinimized()) {
@@ -83,6 +88,7 @@ app.on('activate', () => {
8388
});
8489

8590
app.on('window-all-closed', (e) => {
91+
mainWindow = null
8692
if (isMac) return;
8793
app.quit();
8894
});
@@ -134,3 +140,17 @@ ipcMain.on('set-base-url', (event, _baseUrl) => {
134140
ipcMain.on('set-force-quit-code', (event, _forceQuitCode) => {
135141
forceQuitCode = _forceQuitCode;
136142
});
143+
144+
ipcMain.on('close-window', () => {
145+
mainWindow.close();
146+
});
147+
148+
// 最小化窗口
149+
ipcMain.on('minimize-window', () => {
150+
mainWindow.minimize();
151+
});
152+
153+
// 获取当前窗口是否是最大化
154+
ipcMain.on('is-maximized', () => {
155+
return mainWindow.isMaximized();
156+
});

chat2db-client/src/main/main.js

Lines changed: 0 additions & 2282 deletions
This file was deleted.

chat2db-client/src/main/main.js.LICENSE.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

chat2db-client/src/main/preload.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ contextBridge.exposeInMainWorld('electronApi', {
5858
setMaximize: () => {
5959
ipcRenderer.send('set-maximize');
6060
},
61+
// 获取当前窗口是否是最大化
62+
isMaximized: () => {
63+
ipcRenderer.send('is-maximized');
64+
},
65+
closeWindow: () => {
66+
ipcRenderer.send('close-window');
67+
},
68+
// 最小化窗口
69+
minimizeWindow: () => {
70+
ipcRenderer.send('minimize-window');
71+
},
6172
// 获取环境是mac还是windows还是linux
6273
getPlatform: () => {
6374
return {

chat2db-client/typings.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ declare global {
3434
isWin: boolean,
3535
isLinux: boolean,
3636
};
37+
minimizeWindow: () => void;
38+
closeWindow: () => void;
39+
isMaximized: () => boolean;
3740
};
3841
}
3942
const __APP_VERSION__: string;

0 commit comments

Comments
 (0)