mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
support-page extension -- menu-registry / part 1
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
ef66f67b39
commit
b853d1d54b
@ -1,4 +1,5 @@
|
|||||||
import { LensMainExtension, Registry } from "@lens/extensions";
|
import { LensMainExtension, Registry } from "@lens/extensions";
|
||||||
|
import { supportPageURL } from "./src/support.route";
|
||||||
|
|
||||||
export default class SupportPageMainExtension extends LensMainExtension {
|
export default class SupportPageMainExtension extends LensMainExtension {
|
||||||
async onActivate() {
|
async onActivate() {
|
||||||
@ -6,6 +7,15 @@ export default class SupportPageMainExtension extends LensMainExtension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async registerAppMenus(registry: Registry.MenuRegistry) {
|
async registerAppMenus(registry: Registry.MenuRegistry) {
|
||||||
// TODO: allow to modify global menu item "Help -> Support"
|
this.disposers.push(
|
||||||
|
registry.add({
|
||||||
|
parentId: "help",
|
||||||
|
label: "Support",
|
||||||
|
async click() {
|
||||||
|
// fixme: require runtime windowManager (ensureMainWindow + navigate for main)
|
||||||
|
console.log(`navigate: ${supportPageURL()}`);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,15 +1,23 @@
|
|||||||
// Extensions API -> Global menu customize
|
// Extensions API -> Global menu customize
|
||||||
|
|
||||||
import { observable } from "mobx";
|
import { observable } from "mobx";
|
||||||
|
import { MenuItemConstructorOptions } from "electron";
|
||||||
|
import type { MenuTopId } from "../main/menu";
|
||||||
|
|
||||||
export interface MenuRegistration {
|
export interface MenuRegistration extends MenuItemConstructorOptions {
|
||||||
data?: any;
|
parentId?: MenuTopId;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class MenuRegistry {
|
export class MenuRegistry {
|
||||||
items = observable<MenuRegistration>([], { deep: false });
|
protected items = observable.array([], { deep: false });
|
||||||
|
|
||||||
|
getItems(): MenuRegistration[] {
|
||||||
|
return this.items.toJS();
|
||||||
|
}
|
||||||
|
|
||||||
add(item: MenuRegistration) {
|
add(item: MenuRegistration) {
|
||||||
|
this.items.push(item);
|
||||||
|
return () => this.items.remove(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -38,12 +38,10 @@ export class PageRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fixme: validate route paths to avoid collisions
|
// fixme: validate route paths to avoid collisions
|
||||||
add(params: PageRegistration) {
|
add(pageInit: PageRegistration) {
|
||||||
this.pages.push(params);
|
this.pages.push(pageInit);
|
||||||
return () => {
|
return () => {
|
||||||
this.pages.replace(
|
this.pages.remove(pageInit); // works because of {deep: false}
|
||||||
this.pages.filter(page => page.components !== params.components)
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,8 +6,11 @@ import { addClusterURL } from "../renderer/components/+add-cluster/add-cluster.r
|
|||||||
import { preferencesURL } from "../renderer/components/+preferences/preferences.route";
|
import { preferencesURL } from "../renderer/components/+preferences/preferences.route";
|
||||||
import { whatsNewURL } from "../renderer/components/+whats-new/whats-new.route";
|
import { whatsNewURL } from "../renderer/components/+whats-new/whats-new.route";
|
||||||
import { clusterSettingsURL } from "../renderer/components/+cluster-settings/cluster-settings.route";
|
import { clusterSettingsURL } from "../renderer/components/+cluster-settings/cluster-settings.route";
|
||||||
|
import { menuRegistry } from "../extensions/menu-registry";
|
||||||
import logger from "./logger";
|
import logger from "./logger";
|
||||||
|
|
||||||
|
export type MenuTopId = "mac" | "file" | "edit" | "view" | "help"
|
||||||
|
|
||||||
export function initMenu(windowManager: WindowManager) {
|
export function initMenu(windowManager: WindowManager) {
|
||||||
autorun(() => buildMenu(windowManager), {
|
autorun(() => buildMenu(windowManager), {
|
||||||
delay: 100
|
delay: 100
|
||||||
@ -53,8 +56,6 @@ export function buildMenu(windowManager: WindowManager) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const mt: MenuItemConstructorOptions[] = [];
|
|
||||||
|
|
||||||
const macAppMenu: MenuItemConstructorOptions = {
|
const macAppMenu: MenuItemConstructorOptions = {
|
||||||
label: app.getName(),
|
label: app.getName(),
|
||||||
submenu: [
|
submenu: [
|
||||||
@ -83,10 +84,6 @@ export function buildMenu(windowManager: WindowManager) {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isMac) {
|
|
||||||
mt.push(macAppMenu);
|
|
||||||
}
|
|
||||||
|
|
||||||
const fileMenu: MenuItemConstructorOptions = {
|
const fileMenu: MenuItemConstructorOptions = {
|
||||||
label: "File",
|
label: "File",
|
||||||
submenu: [
|
submenu: [
|
||||||
@ -124,7 +121,6 @@ export function buildMenu(windowManager: WindowManager) {
|
|||||||
])
|
])
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
mt.push(fileMenu)
|
|
||||||
|
|
||||||
const editMenu: MenuItemConstructorOptions = {
|
const editMenu: MenuItemConstructorOptions = {
|
||||||
label: 'Edit',
|
label: 'Edit',
|
||||||
@ -140,7 +136,7 @@ export function buildMenu(windowManager: WindowManager) {
|
|||||||
{ role: 'selectAll' },
|
{ role: 'selectAll' },
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
mt.push(editMenu)
|
|
||||||
const viewMenu: MenuItemConstructorOptions = {
|
const viewMenu: MenuItemConstructorOptions = {
|
||||||
label: 'View',
|
label: 'View',
|
||||||
submenu: [
|
submenu: [
|
||||||
@ -174,7 +170,6 @@ export function buildMenu(windowManager: WindowManager) {
|
|||||||
{ role: 'togglefullscreen' }
|
{ role: 'togglefullscreen' }
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
mt.push(viewMenu)
|
|
||||||
|
|
||||||
const helpMenu: MenuItemConstructorOptions = {
|
const helpMenu: MenuItemConstructorOptions = {
|
||||||
role: 'help',
|
role: 'help',
|
||||||
@ -214,7 +209,29 @@ export function buildMenu(windowManager: WindowManager) {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
mt.push(helpMenu)
|
// Prepare menu items order
|
||||||
|
const appMenu: Record<MenuTopId, MenuItemConstructorOptions> = {
|
||||||
Menu.setApplicationMenu(Menu.buildFromTemplate(mt));
|
mac: macAppMenu,
|
||||||
|
file: fileMenu,
|
||||||
|
edit: editMenu,
|
||||||
|
view: viewMenu,
|
||||||
|
help: helpMenu,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Modify menu from extensions-api
|
||||||
|
menuRegistry.getItems().forEach(({ parentId, ...menuItem }) => {
|
||||||
|
try {
|
||||||
|
const topMenu = appMenu[parentId].submenu as MenuItemConstructorOptions[];
|
||||||
|
topMenu.push(menuItem);
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(`[MENU]: can't register menu item, parentId=${parentId}`, { menuItem })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!isMac) {
|
||||||
|
delete appMenu.mac
|
||||||
|
}
|
||||||
|
|
||||||
|
const menu = Menu.buildFromTemplate(Object.values(appMenu));
|
||||||
|
Menu.setApplicationMenu(menu);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,7 @@ export interface ILanguage {
|
|||||||
|
|
||||||
export const _i18n = setupI18n({
|
export const _i18n = setupI18n({
|
||||||
missing: (message, id) => {
|
missing: (message, id) => {
|
||||||
console.warn('Missing localization:', message, id);
|
// console.warn('Missing localization:', message, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user