Skip to content

Commit 5142779

Browse files
committed
feat:custom clone app
1 parent dddd181 commit 5142779

14 files changed

Lines changed: 2409 additions & 187 deletions

File tree

chat2db-client/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
"electron": "^22.3.0",
6464
"electron-builder": "^23.6.0",
6565
"electron-debug": "^3.2.0",
66-
"electron-reload": "^2.0.0-alpha.1",
6766
"eslint": "^8.49.0",
6867
"eslint-config-airbnb-base": "^15.0.0",
6968
"eslint-config-prettier": "^9.0.0",

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

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,38 @@
55
display: flex;
66
justify-content: space-between;
77
align-items: center;
8-
height: 30px;
9-
padding: 0px 10px;
10-
.appName {
8+
height: 34px;
9+
.appTitleBarGlobal{
1110
flex: 1;
12-
text-align: center;
13-
font-weight: bold;
11+
display: flex;
12+
align-items: center;
13+
justify-content: space-between;
14+
padding: 0px 10px;
15+
.appName {
16+
flex: 1;
17+
text-align: center;
18+
font-weight: bold;
19+
}
20+
}
21+
.spacer {
22+
width: 126px;
23+
flex-shrink: 0;
24+
}
25+
.windowsCloseBar {
26+
display: flex;
27+
height: 100%;
28+
flex-shrink: 0;
29+
width: 126px;
30+
.windowsCloseBarItem {
31+
width: 42px;
32+
height: 100%;
33+
display: flex;
34+
justify-content: center;
35+
align-items: center;
36+
cursor: pointer;
37+
&:hover {
38+
background-color: var(--color-hover-bg);
39+
}
40+
}
1441
}
1542
}
Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import React, { memo } from 'react';
1+
import React, { memo, useMemo } from 'react';
22
import styles from './index.less';
33
import classnames from 'classnames';
44
import { useCommonStore } from '@/store/common';
5-
6-
// import Iconfont from '@/components/Iconfont';
5+
import Iconfont from '@/components/Iconfont';
76

87
interface IProps {
98
className?: string;
@@ -18,26 +17,40 @@ export default memo<IProps>((props) => {
1817
};
1918
});
2019

20+
const isWin = useMemo(() => {
21+
return window.electronApi?.getPlatform().isWin;
22+
}, []);
23+
24+
// const isWin = true;
25+
2126
const handleDoubleClick = () => {
2227
window.electronApi?.setMaximize();
2328
};
2429

30+
const handelMaximize = () => {
31+
window.electronApi?.setMaximize();
32+
}
33+
2534
return (
2635
<div className={classnames(styles.appTitleBar, className)} onDoubleClick={handleDoubleClick}>
27-
<div />
28-
<div className={styles.appName}>Chat2DB Community</div>
29-
<div>{appTitleBarRightComponent}</div>
30-
{/* <div className={styles.windowsCloseBar}>
31-
<div>
32-
<Iconfont code="icon-minimize" />
33-
</div>
34-
<div>
35-
<Iconfont code="icon-minimize" />
36-
</div>
37-
<div>
38-
<Iconfont code="icon-minimize" />
36+
<div className={styles.appTitleBarGlobal}>
37+
<div className={classnames({ [styles.windowsSpacer]: isWin })} />
38+
<div className={styles.appName}>Chat2DB Community</div>
39+
<div>{appTitleBarRightComponent}</div>
40+
</div>
41+
{isWin && (
42+
<div className={styles.windowsCloseBar}>
43+
<div className={styles.windowsCloseBarItem}>
44+
<Iconfont code="&#xeb78;" />
45+
</div>
46+
<div className={styles.windowsCloseBarItem} onClick={handelMaximize}>
47+
<Iconfont code="&#xeb78;" />
48+
</div>
49+
<div className={styles.windowsCloseBarItem}>
50+
<Iconfont code="&#xeb78;" />
51+
</div>
3952
</div>
40-
</div> */}
53+
)}
4154
</div>
4255
);
4356
});

chat2db-client/src/main/index.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function createWindow() {
2626
minHeight: 720,
2727
show: false,
2828
frame: false, // 无边框
29-
titleBarStyle: 'hiddenInset',
29+
titleBarStyle: 'hidden',
3030
webPreferences: {
3131
webSecurity: false,
3232
spellcheck: false, // 禁用拼写检查器
@@ -82,16 +82,7 @@ app.on('activate', () => {
8282
}
8383
});
8484

85-
// app.on('window-all-closed', (event) => {
86-
// event.preventDefault();
87-
// console.log('window-all-closed', process);
88-
// if (process.platform !== 'darwin') {
89-
// app.quit();
90-
// }
91-
// });
92-
9385
app.on('window-all-closed', (e) => {
94-
// 禁止默认行为
9586
if (isMac) return;
9687
app.quit();
9788
});

chat2db-client/src/main/main.js

Lines changed: 2282 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/** @license URI.js v4.4.1 (c) 2011 Gary Court. License: http://github.com/garycourt/uri-js */

chat2db-client/src/main/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
8+
"build:dev": "cross-env NODE_ENV=development webpack",
89
"build": "webpack"
910
},
1011
"author": "",

chat2db-client/src/main/preload.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { contextBridge, ipcRenderer } = require('electron');
22
const { spawn } = require('child_process');
33
const { JAVA_APP_NAME, JAVA_PATH } = require('./constants');
44
const path = require('path');
5-
const { readVersion } = require('./utils');
5+
const { readVersion, isLinux, isWin } = require('./utils');
66

77
contextBridge.exposeInMainWorld('electronApi', {
88
startServerForSpawn: async () => {
@@ -58,4 +58,12 @@ contextBridge.exposeInMainWorld('electronApi', {
5858
setMaximize: () => {
5959
ipcRenderer.send('set-maximize');
6060
},
61+
// 获取环境是mac还是windows还是linux
62+
getPlatform: () => {
63+
return {
64+
isLinux,
65+
isWin,
66+
isLinux,
67+
};
68+
},
6169
});

chat2db-client/src/main/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function loadMainResource(mainWindow) {
1717
mainWindow.loadURL(DEV_WEB_URL);
1818
mainWindow.webContents.openDevTools();
1919
// 监听应用程序根路径下的所有文件,当文件发生修改时,自动刷新应用程序
20-
require('electron-reload')(path.join(__dirname, '..'));
20+
// require('electron-reload')(path.join(__dirname, '..'));
2121
} else {
2222
mainWindow.loadURL(
2323
url.format({

chat2db-client/src/pages/main/index.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import getConnectionEnvList from './functions/getConnection';
1818
import { useMainStore, setMainPageActiveTab } from '@/pages/main/store/main';
1919
import { getConnectionList } from '@/pages/main/store/connection';
2020
import { useUserStore, setCurUser } from '@/store/user';
21+
import { setAppTitleBarRightComponent } from '@/store/common/appTitleBarConfig';
22+
23+
// ----- component -----
24+
import CustomLayout from '@/components/CustomLayout';
2125

2226
// ----- block -----
2327
import Workspace from './workspace';
@@ -77,6 +81,18 @@ function MainPage() {
7781
__ENV__ === 'desktop' ? mainPageActiveTab : window.location.pathname.split('/')[1] || mainPageActiveTab,
7882
);
7983

84+
// 当页面在workspace时,显示自定义布局
85+
useEffect(() => {
86+
if(mainPageActiveTab === 'workspace'){
87+
setAppTitleBarRightComponent(<CustomLayout />);
88+
}else{
89+
setAppTitleBarRightComponent(false);
90+
}
91+
return () => {
92+
setAppTitleBarRightComponent(false);
93+
}
94+
}, [mainPageActiveTab]);
95+
8096
useEffect(() => {
8197
handleInitPage();
8298
getConnectionList();

0 commit comments

Comments
 (0)