fix: add safety checks for updateAppIcon IPC calls to prevent early startup race conditions
This commit is contained in:
@@ -99,7 +99,14 @@ const createTray = () => {
|
||||
mainWindow.show();
|
||||
mainWindow.focus();
|
||||
} });
|
||||
updateTrayMenu();
|
||||
// Load initial themed icon
|
||||
const config = store.get('serverConfig');
|
||||
if (config?.theme) {
|
||||
setAppIcon(config.theme);
|
||||
}
|
||||
else {
|
||||
updateTrayMenu(); // Fallback to refresh menu
|
||||
}
|
||||
}
|
||||
catch (e) { }
|
||||
};
|
||||
@@ -127,6 +134,21 @@ const updateTrayMenu = () => {
|
||||
]);
|
||||
tray.setContextMenu(contextMenu);
|
||||
};
|
||||
const setAppIcon = (themeName = 'steam') => {
|
||||
const assetsDir = path_1.default.join(__dirname, '..', 'assets-build', 'icons');
|
||||
const iconPath = path_1.default.join(assetsDir, `${themeName}.svg`);
|
||||
if (!fs_1.default.existsSync(iconPath))
|
||||
return;
|
||||
const icon = electron_1.nativeImage.createFromPath(iconPath);
|
||||
// Update Tray
|
||||
if (tray) {
|
||||
tray.setImage(icon.resize({ width: 16, height: 16 }));
|
||||
}
|
||||
// Update Main Window
|
||||
if (mainWindow) {
|
||||
mainWindow.setIcon(icon);
|
||||
}
|
||||
};
|
||||
// --- Steam Logic ---
|
||||
const killSteam = async () => {
|
||||
return new Promise((resolve) => {
|
||||
@@ -588,6 +610,11 @@ electron_1.ipcMain.handle('admin-delete-user', async (event, userId) => { initBa
|
||||
electron_1.ipcMain.handle('admin-get-accounts', async () => { initBackend(); return backend ? await backend.getAdminAccounts() : []; });
|
||||
electron_1.ipcMain.handle('admin-remove-account', async (event, steamId) => { initBackend(); if (backend)
|
||||
await backend.forceRemoveAccount(steamId); return true; });
|
||||
electron_1.ipcMain.handle('force-sync', async () => { await syncAccounts(true); return true; });
|
||||
electron_1.ipcMain.handle('update-app-icon', (event, themeName) => {
|
||||
setAppIcon(themeName);
|
||||
return true;
|
||||
});
|
||||
electron_1.ipcMain.handle('switch-account', async (event, loginName) => {
|
||||
if (!loginName)
|
||||
return false;
|
||||
|
||||
@@ -11,6 +11,7 @@ electron_1.contextBridge.exposeInMainWorld('electronAPI', {
|
||||
revokeAccountAccess: (steamId, targetSteamId) => electron_1.ipcRenderer.invoke('revoke-account-access', steamId, targetSteamId),
|
||||
revokeAllAccountAccess: (steamId) => electron_1.ipcRenderer.invoke('revoke-all-account-access', steamId),
|
||||
openExternal: (url) => electron_1.ipcRenderer.invoke('open-external', url),
|
||||
updateAppIcon: (theme) => electron_1.ipcRenderer.invoke('update-app-icon', theme),
|
||||
openSteamAppLogin: () => electron_1.ipcRenderer.invoke('open-steam-app-login'),
|
||||
openSteamLogin: (steamId) => electron_1.ipcRenderer.invoke('open-steam-login', steamId),
|
||||
// Server Config & Auth
|
||||
|
||||
@@ -32,15 +32,24 @@ export const AppThemeProvider: React.FC<{ children: React.ReactNode }> = ({ chil
|
||||
await api.updateServerConfig({ theme });
|
||||
}
|
||||
if (api?.updateAppIcon) {
|
||||
await api.updateAppIcon(theme);
|
||||
try {
|
||||
await api.updateAppIcon(theme);
|
||||
} catch (e) { }
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const api = (window as any).electronAPI;
|
||||
if (api?.updateAppIcon && currentTheme) {
|
||||
api.updateAppIcon(currentTheme);
|
||||
}
|
||||
const updateIcon = async () => {
|
||||
const api = (window as any).electronAPI;
|
||||
if (api?.updateAppIcon && currentTheme) {
|
||||
try {
|
||||
await api.updateAppIcon(currentTheme);
|
||||
} catch (e) {
|
||||
console.warn("[ThemeContext] updateAppIcon failed (likely not registered yet)");
|
||||
}
|
||||
}
|
||||
};
|
||||
updateIcon();
|
||||
}, [currentTheme]);
|
||||
|
||||
const theme = useMemo(() => getTheme(currentTheme), [currentTheme]);
|
||||
|
||||
Reference in New Issue
Block a user