Skip to content

Commit

Permalink
fix: handle error on create tray menu
Browse files Browse the repository at this point in the history
  • Loading branch information
syns2191 committed Nov 27, 2024
1 parent 65147c4 commit 9d07de3
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions apps/server-web/src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,11 @@ const createWindow = async (type: 'SETTING_WINDOW' | 'LOG_WINDOW' | 'SETUP_WINDO
url = resolveHtmlPath('index.html', 'setup');
setupWindow?.loadURL(url);
mainBindings(ipcMain, setupWindow, fs);
setupWindow?.setMenuBarVisibility(false);
Menu.setApplicationMenu(Menu.buildFromTemplate([]));
if (process.platform === 'darwin') {
Menu.setApplicationMenu(Menu.buildFromTemplate([]));
} else {
setupWindow.removeMenu();
}
setupWindow.on('closed', () => {
setupWindow = null;
})
Expand Down Expand Up @@ -429,25 +432,35 @@ const onInitApplication = () => {
}

const initTrayMenu = () => {
try {
LocalStore.setDefaultServerConfig();
createIntervalAutoUpdate()
trayMenuItems = trayMenuItems.length ? trayMenuItems : defaultTrayMenuItem(eventEmitter);
appMenuItems = appMenuItems.length ? appMenuItems : appMenu.defaultMenu();
tray = _initTray(trayMenuItems, getAssetPath('icons/icon.png'));
} catch (error) {
console.error('Failed to initialize application:', error);
dialog.showErrorBox('Initialization Error', 'Failed to initialize application');
}
const MAX_RETRIES = 2;
const retryInit = async (attemps: number = 0) => {

Check warning on line 436 in apps/server-web/src/main/main.ts

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (attemps)
try {
LocalStore.setDefaultServerConfig();
createIntervalAutoUpdate()
trayMenuItems = trayMenuItems.length ? trayMenuItems : defaultTrayMenuItem(eventEmitter);
appMenuItems = appMenuItems.length ? appMenuItems : appMenu.defaultMenu();
tray = _initTray(trayMenuItems, getAssetPath('icons/icon.png'));

eventEmitter.on(EventLists.webServerStart, async () => {
updateTrayMenu('SERVER_START', { enabled: false }, eventEmitter, tray, trayMenuItems, i18nextMainBackend);
isServerRun = true;
await runServer();
})
eventEmitter.on(EventLists.webServerStart, async () => {
updateTrayMenu('SERVER_START', { enabled: false }, eventEmitter, tray, trayMenuItems, i18nextMainBackend);
isServerRun = true;
await runServer();
})

trayMenuItems = trayMenuItems.length ? trayMenuItems : defaultTrayMenuItem(eventEmitter);
updateTrayMenu('none', {}, eventEmitter, tray, trayMenuItems, i18nextMainBackend);
trayMenuItems = trayMenuItems.length ? trayMenuItems : defaultTrayMenuItem(eventEmitter);
updateTrayMenu('none', {}, eventEmitter, tray, trayMenuItems, i18nextMainBackend);
} catch (error) {
if (attemps < MAX_RETRIES) {

Check warning on line 453 in apps/server-web/src/main/main.ts

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (attemps)
await new Promise((resolve) => setTimeout(resolve, 1000))
retryInit(attemps + 1)

Check warning on line 455 in apps/server-web/src/main/main.ts

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (attemps)
}
console.error('Failed to initialize application:', error);
dialog.showErrorBox('Initialization Error', 'Failed to initialize application');
}
}
if (!tray) {
return retryInit(0)
}
}

(async () => {
Expand Down

0 comments on commit 9d07de3

Please sign in to comment.