Skip to content

Commit

Permalink
Merge pull request #1065 from chat2db/refactor-electron
Browse files Browse the repository at this point in the history
Refactor electron
  • Loading branch information
shanhexi committed Jan 7, 2024
2 parents c7f8802 + 9ccda26 commit d931d8c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 27 deletions.
3 changes: 2 additions & 1 deletion chat2db-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@
"!node_modules/**/*",
"node_modules/uuid",
"node_modules/electron-log",
"node_modules/node-machine-id"
"node_modules/node-machine-id",
"node_modules/electron-store"
],
"nsis": {
"oneClick": false,
Expand Down
42 changes: 27 additions & 15 deletions chat2db-client/src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const registerAppMenu = require('./menu');
const registerAnalysis = require('./analysis');
const i18n = require('./i18n');
const store = require('./store');
const { loadMainResource } = require('./utils');
const { loadMainResource, isMac } = require('./utils');

let mainWindow = null;

Expand Down Expand Up @@ -46,12 +46,6 @@ function createWindow() {
// 加载应用-----
loadMainResource(mainWindow);

// 关闭window时触发下列事件.
mainWindow.on('closed', function (event) {
event.preventDefault();
app.hide();
});

mainWindow.webContents.setWindowOpenHandler(({ url }) => {
shell.openExternal(url);
return { action: 'deny' };
Expand All @@ -75,19 +69,37 @@ app.on('ready', () => {
createWindow();
registerAppMenu(mainWindow);
registerAnalysis();

app.on('activate', () => {
app.show();
});
});

app.on('window-all-closed', (event) => {
event.preventDefault();
if (process.platform !== 'darwin') {
app.quit();
app.on('activate', () => {
if (!!mainWindow) {
createWindow();
} else {
if (mainWindow.isMinimized()) {
mainWindow.restore();
}
if (mainWindow.isVisible()) {
mainWindow.focus();
} else {
mainWindow.show();
}
}
});

// app.on('window-all-closed', (event) => {
// event.preventDefault();
// console.log('window-all-closed', process);
// if (process.platform !== 'darwin') {
// app.quit();
// }
// });

app.on('window-all-closed', (e) => {
// 禁止默认行为
if (isMac) return;
app.quit();
});

app.on('before-quit', () => {
if (baseUrl) {
try {
Expand Down
21 changes: 10 additions & 11 deletions chat2db-client/src/main/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,16 @@ const registerAppMenu = (mainWindow, orgs) => {
// label: i18n('menu.edit'),
label: '视图',
submenu: [
{
label: '刷新',
// accelerator: process.platform === 'darwin' ? 'Cmd+R' : 'Ctrl+R',
accelerator: 'CmdOrCtrl+Shift+R',
click() {
const focusedWindow = BrowserWindow.getFocusedWindow();
if (focusedWindow) {
focusedWindow.reload();
}
},
},
// {
// label: '刷新',
// accelerator: 'CmdOrCtrl+Shift+R',
// click() {
// const focusedWindow = BrowserWindow.getFocusedWindow();
// if (focusedWindow) {
// focusedWindow.reload();
// }
// },
// },
{ type: 'separator' },
{
label: '放大',
Expand Down

0 comments on commit d931d8c

Please sign in to comment.