Skip to content

Commit

Permalink
fix: checked is not updated
Browse files Browse the repository at this point in the history
  • Loading branch information
linonetwo committed Jun 23, 2021
1 parent c3b2e62 commit caf26cd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/services/menu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export class MenuService implements IMenuService {
submenu.map(async (item) => ({
...item,
label: typeof item.label === 'function' ? item.label() : item.label,
checked: typeof item.checked === 'function' ? await item.checked() : item.checked,
enabled: typeof item.enabled === 'function' ? await item.enabled() : item.enabled,
submenu:
item.submenu instanceof Menu || item.submenu === undefined ? item.submenu : await this.getCurrentMenuItemConstructorOptions(compact(item.submenu)),
Expand Down
3 changes: 2 additions & 1 deletion src/services/menu/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import type { IpcSafeMenuItem } from './rendererMenuItemProxy';
* MenuItemConstructorOptions that allows properties like "label", "enabled", "submenu" to be () => xxx
* So these value can be determined at every build time (menu will be rebuilt every time the preferences change)
*/
export interface DeferredMenuItemConstructorOptions extends Omit<MenuItemConstructorOptions, 'label' | 'enabled' | 'submenu'> {
export interface DeferredMenuItemConstructorOptions extends Omit<MenuItemConstructorOptions, 'label' | 'enabled' | 'checked' | 'submenu'> {
label?: (() => string) | string;
enabled?: (() => boolean) | (() => Promise<boolean>) | boolean;
checked?: (() => boolean) | (() => Promise<boolean>) | boolean;
submenu?: Array<MenuItemConstructorOptions | DeferredMenuItemConstructorOptions>;
}

Expand Down
4 changes: 2 additions & 2 deletions src/services/workspaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ export class Workspace implements IWorkspaceService {
const newMenuItems = (await this.getWorkspacesAsList()).flatMap((workspace, index) => [
{
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
label: () => workspace.name || `Workspace ${index + 1}`,
label: (): string => workspace.name || `Workspace ${index + 1}`,
id: workspace.id,
type: 'checkbox' as const,
checked: workspace.active,
checked: () => workspace.active,
click: async () => {
await this.workspaceViewService.setActiveWorkspaceView(workspace.id);
// manually update menu since we have alter the active workspace
Expand Down

0 comments on commit caf26cd

Please sign in to comment.