mirror of
https://github.com/Nystik-gh/ignis.git
synced 2026-06-17 04:35:53 +00:00
60 lines
1.5 KiB
JavaScript
60 lines
1.5 KiB
JavaScript
// Shim for remote.Menu and remote.MenuItem
|
|
// Obsidian uses: Menu.buildFromTemplate, Menu.popup, Menu.setApplicationMenu
|
|
|
|
export class menuShim {
|
|
constructor() {
|
|
this.items = [];
|
|
}
|
|
|
|
static buildFromTemplate(template) {
|
|
const menu = new menuShim();
|
|
menu.items = (template || []).map(item => new menuItemShim(item));
|
|
return menu;
|
|
}
|
|
|
|
static setApplicationMenu(menu) {
|
|
// No native menu bar in browser - no-op
|
|
console.log('[shim:Menu] setApplicationMenu (stub)');
|
|
}
|
|
|
|
static getApplicationMenu() {
|
|
return null;
|
|
}
|
|
|
|
popup(options) {
|
|
// TODO: implement custom HTML context menu rendered at mouse position
|
|
console.log('[shim:Menu] popup (stub)', options);
|
|
}
|
|
|
|
append(menuItem) {
|
|
this.items.push(menuItem);
|
|
}
|
|
|
|
insert(pos, menuItem) {
|
|
this.items.splice(pos, 0, menuItem);
|
|
}
|
|
|
|
closePopup() {
|
|
// TODO: hide custom context menu
|
|
}
|
|
}
|
|
|
|
export class menuItemShim {
|
|
constructor(options = {}) {
|
|
this.label = options.label || '';
|
|
this.type = options.type || 'normal';
|
|
this.click = options.click || null;
|
|
this.role = options.role || null;
|
|
this.accelerator = options.accelerator || '';
|
|
this.enabled = options.enabled !== false;
|
|
this.visible = options.visible !== false;
|
|
this.checked = !!options.checked;
|
|
this.submenu = options.submenu
|
|
? menuShim.buildFromTemplate(
|
|
Array.isArray(options.submenu) ? options.submenu : []
|
|
)
|
|
: null;
|
|
this.id = options.id || '';
|
|
}
|
|
}
|