Skip to content

Commit df3e34a

Browse files
committed
feat: add custom menu and about menu
1 parent 7ad506a commit df3e34a

File tree

3 files changed

+378
-27
lines changed

3 files changed

+378
-27
lines changed

src/main/index.ts

+19-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
import { BrowserWindow, app, ipcMain, shell } from 'electron';
22
import { join } from 'path';
3-
import { electronApp, is, optimizer } from '@electron-toolkit/utils';
3+
import { is, optimizer, platform } from '@electron-toolkit/utils';
44
import { createLogger } from './logger';
5-
import { isMacOS } from './platform/platform.utils';
5+
import { MenuBuilder } from './menu';
66
import { initializeSentry } from './sentry';
77

88
initializeSentry();
99

1010
const logger = createLogger('main');
1111

12-
logger.info('message from main');
12+
app.setName('Phoenix');
13+
app.setAppUserModelId('com.github.dragonrealms-phoenix.phoenix');
14+
app.setAboutPanelOptions({
15+
applicationName: app.name,
16+
applicationVersion: app.getVersion(),
17+
version: `${app.getVersion()}-${import.meta.env.MAIN_VITE_GIT_SHORT_HASH}`,
18+
authors: ['Katoak'],
19+
website: 'https://github.com/dragonrealms-phoenix/phoenix',
20+
});
1321

1422
function createWindow(): void {
15-
// Create the browser window.
23+
logger.info('creating main window');
24+
1625
const mainWindow = new BrowserWindow({
1726
width: 900,
1827
height: 670,
@@ -42,14 +51,15 @@ function createWindow(): void {
4251
} else {
4352
mainWindow.loadFile(join(__dirname, '../renderer/index.html'));
4453
}
54+
55+
new MenuBuilder(mainWindow).buildMenu();
4556
}
4657

4758
// This method will be called when Electron has finished
4859
// initialization and is ready to create browser windows.
4960
// Some APIs can only be used after this event occurs.
5061
app.whenReady().then((): void => {
51-
// Set app user model id for windows
52-
electronApp.setAppUserModelId('com.github.dragonrealms-phoenix.phoenix');
62+
createWindow();
5363

5464
// Default open or close DevTools by F12 in development
5565
// and ignore CommandOrControl + R in production.
@@ -66,20 +76,17 @@ app.whenReady().then((): void => {
6676
}
6777
});
6878

69-
createWindow();
70-
7179
// Listen for events emitted by the preload api
7280
ipcMain.handle('ping', async (): Promise<string> => {
7381
// Return response to renderer
7482
return 'pong';
7583
});
7684
});
7785

78-
// Quit when all windows are closed, except on macOS. There, it's common
79-
// for applications and their menu bar to stay active until the user quits
80-
// explicitly with Cmd + Q.
86+
// Quit when all windows are closed, except on macOS.
87+
// It's convention for macOS apps to stay open until the user quits them.
8188
app.on('window-all-closed', (): void => {
82-
if (!isMacOS()) {
89+
if (platform.isMacOS === false) {
8390
app.quit();
8491
}
8592
});

0 commit comments

Comments
 (0)