fix: menu label is null when i18n failed to load by other bugs

this fixes https://github.com/tiddly-gittly/TiddlyGit-Desktop/issues/75
This commit is contained in:
林一二 2021-08-07 21:28:00 +08:00
parent c116ea40ea
commit fd72bf5a57

View file

@ -60,12 +60,12 @@ export class MenuService implements IMenuService {
* You don't need to call this after calling method like insertMenu, it will be call automatically.
*/
public async buildMenu(): Promise<void> {
const latestTemplate = (await this.getCurrentMenuItemConstructorOptions(this.menuTemplate)) ?? [];
try {
const latestTemplate = (await this.getCurrentMenuItemConstructorOptions(this.menuTemplate)) ?? [];
const menu = Menu.buildFromTemplate(latestTemplate);
Menu.setApplicationMenu(menu);
} catch (error) {
logger.error(`buildMenu() failed ${(error as Error).message} ${(error as Error).stack ?? ''}`);
logger.error(`buildMenu() failed: ${(error as Error).message} ${(error as Error).stack ?? ''}\n${JSON.stringify(latestTemplate)}`);
}
}
@ -81,7 +81,8 @@ export class MenuService implements IMenuService {
return await Promise.all(
submenu.map(async (item) => ({
...item,
label: typeof item.label === 'function' ? item.label() : item.label,
/** label sometimes is null, causing */
label: typeof item.label === 'function' ? item.label() ?? undefined : item.label,
checked: typeof item.checked === 'function' ? await item.checked() : item.checked,
enabled: typeof item.enabled === 'function' ? await item.enabled() : item.enabled,
submenu: