Skip to content
Snippets Groups Projects
Commit ab95709e authored by Loïc Correnson's avatar Loïc Correnson
Browse files

[dome] more types in dome/main/menubar

parent cc97d551
No related branches found
No related tags found
No related merge requests found
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
/* */ /* */
/* ************************************************************************ */ /* ************************************************************************ */
/* eslint-disable @typescript-eslint/explicit-function-return-type */
/* eslint-disable no-console */ /* eslint-disable no-console */
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
...@@ -42,7 +41,7 @@ import * as System from 'dome/system'; ...@@ -42,7 +41,7 @@ import * as System from 'dome/system';
// --- Special Callbacks // --- Special Callbacks
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
function reloadWindow() { function reloadWindow(): void {
reset(); // declared below reset(); // declared below
BrowserWindow.getAllWindows().forEach((win) => { BrowserWindow.getAllWindows().forEach((win) => {
if (win) { if (win) {
...@@ -60,7 +59,7 @@ function toggleFullScreen( ...@@ -60,7 +59,7 @@ function toggleFullScreen(
_item: MenuItem, _item: MenuItem,
focusedWindow: BrowserWindow | undefined, focusedWindow: BrowserWindow | undefined,
_evt: KeyboardEvent, _evt: KeyboardEvent,
) { ): void {
if (focusedWindow) if (focusedWindow)
focusedWindow.setFullScreen(!focusedWindow.isFullScreen()); focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
} }
...@@ -69,7 +68,7 @@ function toggleDevTools( ...@@ -69,7 +68,7 @@ function toggleDevTools(
_item: MenuItem, _item: MenuItem,
focusedWindow: BrowserWindow | undefined, focusedWindow: BrowserWindow | undefined,
_evt: KeyboardEvent, _evt: KeyboardEvent,
) { ): void {
if (focusedWindow) if (focusedWindow)
focusedWindow.webContents.toggleDevTools(); focusedWindow.webContents.toggleDevTools();
} }
...@@ -78,7 +77,7 @@ function userFindInfo( ...@@ -78,7 +77,7 @@ function userFindInfo(
_item: MenuItem, _item: MenuItem,
focusedWindow: BrowserWindow | undefined, focusedWindow: BrowserWindow | undefined,
_evt: KeyboardEvent, _evt: KeyboardEvent,
) { ): void {
if (focusedWindow) if (focusedWindow)
focusedWindow.webContents.send('dome.ipc.find'); focusedWindow.webContents.send('dome.ipc.find');
} }
...@@ -292,7 +291,7 @@ const helpMenuItems: MenuSpec = [ ...@@ -292,7 +291,7 @@ const helpMenuItems: MenuSpec = [
let updateRequired = false; let updateRequired = false;
let updateTriggered = false; let updateTriggered = false;
function requestUpdate() { function requestUpdate(): void {
if (updateRequired && !updateTriggered) { if (updateRequired && !updateTriggered) {
updateTriggered = true; updateTriggered = true;
setImmediate(install); setImmediate(install);
...@@ -326,7 +325,7 @@ function findMenu(label: string): MenuSpec | undefined { ...@@ -326,7 +325,7 @@ function findMenu(label: string): MenuSpec | undefined {
} }
} }
export function addMenu(label: string) { export function addMenu(label: string): void {
if (findMenu(label)) { if (findMenu(label)) {
console.warn(`Already defined menu '${label}'`); console.warn(`Already defined menu '${label}'`);
} else { } else {
...@@ -348,7 +347,7 @@ export interface SeparatorItem { ...@@ -348,7 +347,7 @@ export interface SeparatorItem {
export type CustomMenuItemSpec = SeparatorItem | CustomMenuItem; export type CustomMenuItemSpec = SeparatorItem | CustomMenuItem;
export function addMenuItem(custom: CustomMenuItemSpec) { export function addMenuItem(custom: CustomMenuItemSpec): void {
const menuSpec = findMenu(custom.menu); const menuSpec = findMenu(custom.menu);
if (!menuSpec) { if (!menuSpec) {
console.error('[Dome] Unknown menu', custom); console.error('[Dome] Unknown menu', custom);
...@@ -402,12 +401,12 @@ export function addMenuItem(custom: CustomMenuItemSpec) { ...@@ -402,12 +401,12 @@ export function addMenuItem(custom: CustomMenuItemSpec) {
requestUpdate(); requestUpdate();
} }
export function setMenuItem({ id, ...options }: CustomMenuItem) { export function setMenuItem({ id, ...options }: CustomMenuItem): void {
const entry = customItems.get(id); const entry = customItems.get(id);
if (entry) { if (entry) {
if (entry.spec) Object.assign(entry.spec, options); if (entry.spec) Object.assign(entry.spec, options);
if (entry.item) Object.assign(entry.item, options); if (entry.item) Object.assign(entry.item, options);
requestUpdate (); requestUpdate();
} else } else
console.warn(`[Dome] unknown menu item #${id}`); console.warn(`[Dome] unknown menu item #${id}`);
} }
...@@ -482,7 +481,7 @@ function template(): CustomMenu[] { ...@@ -482,7 +481,7 @@ function template(): CustomMenu[] {
let menubar: Menu; let menubar: Menu;
function registerCustomItems(menu: Menu) { function registerCustomItems(menu: Menu): void {
menu.items.forEach((item: MenuItem) => { menu.items.forEach((item: MenuItem) => {
const entry = customItems.get(item.id); const entry = customItems.get(item.id);
if (entry) entry.item = item; if (entry) entry.item = item;
...@@ -491,7 +490,7 @@ function registerCustomItems(menu: Menu) { ...@@ -491,7 +490,7 @@ function registerCustomItems(menu: Menu) {
} }
// Initialize the menubar machinery // Initialize the menubar machinery
export function install() { export function install(): void {
updateRequired = true; updateRequired = true;
updateTriggered = false; updateTriggered = false;
menubar = Menu.buildFromTemplate(template()); menubar = Menu.buildFromTemplate(template());
...@@ -500,7 +499,7 @@ export function install() { ...@@ -500,7 +499,7 @@ export function install() {
} }
// Called by reload above // Called by reload above
function reset() { function reset(): void {
fileMenuItemsCustom.length = 0; fileMenuItemsCustom.length = 0;
editMenuItemsCustom.length = 0; editMenuItemsCustom.length = 0;
viewMenuItemsCustom.length = 0; viewMenuItemsCustom.length = 0;
...@@ -540,7 +539,7 @@ function handlePopupMenu(_: Event, items: PopupMenuItem[]): Promise<number> { ...@@ -540,7 +539,7 @@ function handlePopupMenu(_: Event, items: PopupMenuItem[]): Promise<number> {
const { display = true, enabled, checked } = item; const { display = true, enabled, checked } = item;
if (display) { if (display) {
const label = item.label || `#${++kid}`; const label = item.label || `#${++kid}`;
const click = () => { selected = index; }; const click = (): void => { selected = index; };
const type = checked !== undefined ? 'checkbox' : 'normal'; const type = checked !== undefined ? 'checkbox' : 'normal';
menu.append(new MenuItem({ label, enabled, type, checked, click })); menu.append(new MenuItem({ label, enabled, type, checked, click }));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment