mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-04-11 16:19:27 -07:00
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import electron from 'electron';
|
|
import type { BrowserWindow } from 'electron';
|
|
import { createLogger } from '../../logger';
|
|
|
|
const { globalShortcut } = electron;
|
|
const logger = createLogger('main:shortcut');
|
|
|
|
export interface GlobalShortcutConfig {
|
|
toggleVisibleOverlayGlobal: string | null | undefined;
|
|
openJimaku?: string | null | undefined;
|
|
}
|
|
|
|
export interface RegisterGlobalShortcutsServiceOptions {
|
|
shortcuts: GlobalShortcutConfig;
|
|
onToggleVisibleOverlay: () => void;
|
|
onOpenYomitanSettings: () => void;
|
|
onOpenJimaku?: () => void;
|
|
isDev: boolean;
|
|
getMainWindow: () => BrowserWindow | null;
|
|
}
|
|
|
|
export function registerGlobalShortcuts(options: RegisterGlobalShortcutsServiceOptions): void {
|
|
const settingsRegistered = globalShortcut.register('Alt+Shift+Y', () => {
|
|
options.onOpenYomitanSettings();
|
|
});
|
|
if (!settingsRegistered) {
|
|
logger.warn('Failed to register global shortcut: Alt+Shift+Y');
|
|
}
|
|
|
|
if (options.isDev) {
|
|
const devtoolsRegistered = globalShortcut.register('F12', () => {
|
|
const mainWindow = options.getMainWindow();
|
|
if (mainWindow && !mainWindow.isDestroyed()) {
|
|
mainWindow.webContents.toggleDevTools();
|
|
}
|
|
});
|
|
if (!devtoolsRegistered) {
|
|
logger.warn('Failed to register global shortcut: F12');
|
|
}
|
|
}
|
|
}
|