Skip to content

Commit 9ccda26

Browse files
committed
fix:window-all-closed
1 parent 1d2dfd7 commit 9ccda26

2 files changed

Lines changed: 37 additions & 26 deletions

File tree

chat2db-client/src/main/index.js

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const registerAppMenu = require('./menu');
77
const registerAnalysis = require('./analysis');
88
const i18n = require('./i18n');
99
const store = require('./store');
10-
const { loadMainResource } = require('./utils');
10+
const { loadMainResource, isMac } = require('./utils');
1111

1212
let mainWindow = null;
1313

@@ -46,12 +46,6 @@ function createWindow() {
4646
// 加载应用-----
4747
loadMainResource(mainWindow);
4848

49-
// 关闭window时触发下列事件.
50-
mainWindow.on('closed', function (event) {
51-
event.preventDefault();
52-
app.hide();
53-
});
54-
5549
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
5650
shell.openExternal(url);
5751
return { action: 'deny' };
@@ -75,19 +69,37 @@ app.on('ready', () => {
7569
createWindow();
7670
registerAppMenu(mainWindow);
7771
registerAnalysis();
78-
79-
app.on('activate', () => {
80-
app.show();
81-
});
8272
});
8373

84-
app.on('window-all-closed', (event) => {
85-
event.preventDefault();
86-
if (process.platform !== 'darwin') {
87-
app.quit();
74+
app.on('activate', () => {
75+
if (!!mainWindow) {
76+
createWindow();
77+
} else {
78+
if (mainWindow.isMinimized()) {
79+
mainWindow.restore();
80+
}
81+
if (mainWindow.isVisible()) {
82+
mainWindow.focus();
83+
} else {
84+
mainWindow.show();
85+
}
8886
}
8987
});
9088

89+
// app.on('window-all-closed', (event) => {
90+
// event.preventDefault();
91+
// console.log('window-all-closed', process);
92+
// if (process.platform !== 'darwin') {
93+
// app.quit();
94+
// }
95+
// });
96+
97+
app.on('window-all-closed', (e) => {
98+
// 禁止默认行为
99+
if (isMac) return;
100+
app.quit();
101+
});
102+
91103
app.on('before-quit', () => {
92104
if (baseUrl) {
93105
try {

chat2db-client/src/main/menu.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,16 @@ const registerAppMenu = (mainWindow, orgs) => {
6060
// label: i18n('menu.edit'),
6161
label: '视图',
6262
submenu: [
63-
{
64-
label: '刷新',
65-
// accelerator: process.platform === 'darwin' ? 'Cmd+R' : 'Ctrl+R',
66-
accelerator: 'CmdOrCtrl+Shift+R',
67-
click() {
68-
const focusedWindow = BrowserWindow.getFocusedWindow();
69-
if (focusedWindow) {
70-
focusedWindow.reload();
71-
}
72-
},
73-
},
63+
// {
64+
// label: '刷新',
65+
// accelerator: 'CmdOrCtrl+Shift+R',
66+
// click() {
67+
// const focusedWindow = BrowserWindow.getFocusedWindow();
68+
// if (focusedWindow) {
69+
// focusedWindow.reload();
70+
// }
71+
// },
72+
// },
7473
{ type: 'separator' },
7574
{
7675
label: '放大',

0 commit comments

Comments
 (0)