Skip to content

Commit f82ac9a

Browse files
committed
support macOs
1 parent e0585fd commit f82ac9a

File tree

9 files changed

+60
-25
lines changed

9 files changed

+60
-25
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ To package apps for the local platform:
3333
npm run package
3434
```
3535

36+
分发mac 安装包
37+
38+
```
39+
npm run package -- --mac
40+
```
41+
3642
## Docs
3743

3844
See our [docs and guides here]()

assets/icon.icns

-86.8 KB
Binary file not shown.

package.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Toolkit",
3-
"version": "0.0.7",
3+
"version": "0.0.8",
44
"description": "A toolkit for scalable desktop apps",
55
"keywords": [
66
"electron",
@@ -86,15 +86,16 @@
8686
}
8787
},
8888
"dependencies": {
89+
"@electron/notarize": "^2.3.2",
8990
"antd": "^5.10.1",
9091
"axios": "^1.6.2",
91-
"electron-store": "^8.1.0",
92-
"express": "^4.19.2",
93-
"portfinder": "^1.0.32",
94-
"@electron/notarize": "^2.3.2",
9592
"electron-debug": "^3.2.0",
9693
"electron-log": "^4.4.8",
94+
"electron-store": "^8.1.0",
9795
"electron-updater": "^6.1.4",
96+
"express": "^4.19.2",
97+
"fix-path": "^4.0.0",
98+
"portfinder": "^1.0.32",
9899
"react": "^18.2.0",
99100
"react-dom": "^18.2.0",
100101
"react-router-dom": "^6.16.0"
@@ -243,4 +244,4 @@
243244
],
244245
"logLevel": "quiet"
245246
}
246-
}
247+
}

release/app/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

release/app/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Toolkit",
3-
"version": "0.0.7",
3+
"version": "0.0.8",
44
"description": "A toolkit for scalable desktop apps",
55
"license": "MIT",
66
"author": {

src/main/main.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@
1010
* `./src/main.js` using webpack. This gives us some performance wins.
1111
*/
1212
import path from 'path';
13-
import { app, BrowserWindow, globalShortcut, shell, ipcMain } from 'electron';
13+
import fixPath from 'fix-path';
14+
import {
15+
app,
16+
BrowserWindow,
17+
globalShortcut,
18+
shell,
19+
ipcMain,
20+
Menu,
21+
} from 'electron';
1422

1523
import log from 'electron-log';
1624
import { resolveHtmlPath, getAssetPath, getAppDir } from './util';
@@ -22,6 +30,8 @@ import InitCheck from './init_check';
2230
app.commandLine.appendSwitch('enable-experimental-web-platform-features');
2331
app.setAppUserModelId('top.trumandu.Toolkit');
2432

33+
fixPath();
34+
2535
let mainWindow: BrowserWindow | null = null;
2636
let dashboardWindow: BrowserWindow | null = null;
2737

@@ -68,6 +78,11 @@ const createDashboardWindow = async () => {
6878
},
6979
});
7080

81+
if (process.platform === 'darwin') {
82+
app.dock.setIcon(getAssetPath('icon.png'));
83+
app.dock.bounce();
84+
}
85+
7186
newDashboardWindow.loadURL(resolveHtmlPath('dashboard.html'));
7287
newDashboardWindow.on('close', (event) => {
7388
newDashboardWindow.hide();
@@ -216,6 +231,13 @@ app
216231
})
217232
.catch(console.log);
218233

234+
// 拦截系统默认的 Quit 行为
235+
app.on('before-quit', (event) => {
236+
event.preventDefault(); // 阻止默认退出
237+
// 强制退出
238+
app.exit();
239+
});
240+
219241
app.on('ready', () => {
220242
const appInstallDir = getAppDir();
221243
// 将应用程序安装目录发送给渲染进程

src/main/tray.ts

+8-14
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ import pkg from '../../package.json';
33
import { getAppDir, getAssetPath } from './util';
44
import API from './api';
55

6-
const isMac = process.platform === 'darwin';
7-
86
function createTray(
97
window: BrowserWindow,
108
dashboard: BrowserWindow,
119
api: API,
1210
): Promise<Tray> {
1311
return new Promise((resolve) => {
14-
const iconPath = getAssetPath('icon.png');
12+
const iconPath = getAssetPath('icons/16x16.png');
13+
1514
const appTray = new Tray(iconPath);
1615

1716
const openInstallDirectory = () => {
@@ -68,17 +67,12 @@ function createTray(
6867
},
6968

7069
{ type: 'separator' },
71-
isMac
72-
? {
73-
role: 'close',
74-
label: ' 退出 ',
75-
}
76-
: {
77-
label: ' 退出 ',
78-
click() {
79-
app.exit();
80-
},
81-
},
70+
{
71+
label: ' 退出 ',
72+
click() {
73+
app.exit();
74+
},
75+
},
8276
{
8377
label: ' 重启 ',
8478
click() {

src/main/util.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ export function getAssetPath(...paths: string[]): string {
2525
}
2626

2727
export function getAppDir(): string {
28-
return app.isPackaged ? path.dirname(app.getPath('exe')) : app.getAppPath();
28+
const homedir = os.homedir();
29+
// 用户配置信息,插件,data目录
30+
const appDataPath = path.join(homedir, 'Toolkit');
31+
return app.isPackaged ? appDataPath : app.getAppPath();
2932
}
3033

3134
export function deleteFolder(filePath: string) {

src/renderer/index.ejs

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@
1212
overflow: hidden;
1313
}
1414
</style>
15+
<script>
16+
var _hmt = _hmt || [];
17+
(function () {
18+
var hm = document.createElement('script');
19+
hm.src = 'https://hm.baidu.com/hm.js?077ebf5af4b96181076eefc3db60ad2c';
20+
var s = document.getElementsByTagName('script')[0];
21+
s.parentNode.insertBefore(hm, s);
22+
})();
23+
</script>
1524
</head>
1625
<body>
1726
<div id="root"></div>

0 commit comments

Comments
 (0)