1- const { app, BrowserWindow, nativeImage, shell } = require ( 'electron' ) ;
2- const path = require ( 'path' ) ;
1+ const { app, ipcMain, shell } = require ( 'electron' ) ;
2+ const createMenu = require ( './menu' ) ;
3+ const createWindow = require ( './window' ) ;
34
4- let mainWindow ;
5+ app . on ( 'ready' , ( ) => {
6+ const mainWindow = createWindow ( ) ;
7+ createMenu ( mainWindow ) ;
58
6- function createWindow ( ) {
7- const iconPath = path . join ( __dirname , 'assets/icon.png' ) ;
8-
9- mainWindow = new BrowserWindow ( {
10- width : 800 ,
11- height : 600 ,
12- autoHideMenuBar : true , // Hide the toolbar
13- icon : nativeImage . createFromPath ( iconPath ) ,
14- } ) ;
15-
16- mainWindow . loadURL ( 'https://misskey.id' ) ;
17-
18- mainWindow . webContents . on ( 'new-window' , ( event , url , frameName , disposition , options ) => {
19- event . preventDefault ( ) ; // Prevent opening the link in a new window
20-
21- // Check if the clicked link has a class ending with "_link"
22- const regex = / ( \S + _ l i n k ) $ / i;
23- const className = frameName . match ( regex ) ?. [ 0 ] ;
24-
25- if ( className ) {
26- // Open links with the specified class in the default browser
27- shell . openExternal ( url ) ;
28- } else {
29- // Handle other types of links within the Electron app
30- mainWindow . loadURL ( url ) ;
31- }
9+ // Register an IPC listener to receive messages from the renderer process
10+ ipcMain . on ( 'open-external-link' , ( event , url ) => {
11+ shell . openExternal ( url ) ; // Open external links in the default browser
3212 } ) ;
33-
34- mainWindow . on ( 'closed' , ( ) => {
35- mainWindow = null ;
36- } ) ;
37- }
38-
39- app . on ( 'ready' , createWindow ) ;
13+ } ) ;
4014
4115app . on ( 'window-all-closed' , ( ) => {
4216 if ( process . platform !== 'darwin' ) {
@@ -46,6 +20,7 @@ app.on('window-all-closed', () => {
4620
4721app . on ( 'activate' , ( ) => {
4822 if ( mainWindow === null ) {
49- createWindow ( ) ;
23+ const mainWindow = createWindow ( ) ;
24+ createMenu ( mainWindow ) ;
5025 }
5126} ) ;
0 commit comments