fix: ts exceptions

This commit is contained in:
Fabio Di Stasio 2022-08-24 10:23:03 +02:00
parent ffc645ba5e
commit df681147aa
2 changed files with 13 additions and 12 deletions

View File

@ -1,4 +1,4 @@
import { app, ipcMain, dialog, BrowserWindow } from 'electron';
import { app, ipcMain, dialog } from 'electron';
import { ShortcutRegister } from '../libs/ShortcutRegister';
export default () => {
@ -15,26 +15,22 @@ export default () => {
});
ipcMain.handle('resotre-default-shortcuts', () => {
const mainWindow = BrowserWindow.getAllWindows()[0];
const shortCutRegister = ShortcutRegister.getInstance({ mainWindow });
const shortCutRegister = ShortcutRegister.getInstance();
shortCutRegister.restoreDefaults();
});
ipcMain.handle('reload-shortcuts', () => {
const mainWindow = BrowserWindow.getAllWindows()[0];
const shortCutRegister = ShortcutRegister.getInstance({ mainWindow });
const shortCutRegister = ShortcutRegister.getInstance();
shortCutRegister.reload();
});
ipcMain.handle('update-shortcuts', (event, shortcuts) => {
const mainWindow = BrowserWindow.getAllWindows()[0];
const shortCutRegister = ShortcutRegister.getInstance({ mainWindow });
const shortCutRegister = ShortcutRegister.getInstance();
shortCutRegister.updateShortcuts(shortcuts);
});
ipcMain.handle('unregister-shortcuts', () => {
const mainWindow = BrowserWindow.getAllWindows()[0];
const shortCutRegister = ShortcutRegister.getInstance({ mainWindow });
const shortCutRegister = ShortcutRegister.getInstance();
shortCutRegister.unregister();
});
};

View File

@ -26,9 +26,14 @@ export class ShortcutRegister {
this.shortcuts = shortcutsStore.get('shortcuts', defaultShortcuts) as ShortcutRecord[];
}
public static getInstance (args: { mainWindow: BrowserWindow; menuTemplate: OsMenu; mode: ShortcutMode }) {
if (!ShortcutRegister._instance)
ShortcutRegister._instance = new ShortcutRegister(args);
public static getInstance (args?: { mainWindow?: BrowserWindow; menuTemplate?: OsMenu; mode?: ShortcutMode }) {
if (!ShortcutRegister._instance && args.menuTemplate !== undefined && args.mode !== undefined) {
ShortcutRegister._instance = new ShortcutRegister({
mainWindow: args.mainWindow,
menuTemplate: args.menuTemplate,
mode: args.mode
});
}
return ShortcutRegister._instance;
}