created at 2023/08/05 02:52:02
updated at 2023/08/05 02:55:41
TypeScript
import path from 'path';
import { protocol } from 'electron';
export async function registerProtocol(): Promise<void> {
protocol.registerFileProtocol('images', (request, callback) => {
const url = request.url.substring(7);
callback(decodeURI(path.normalize(url)));
});
}
// use: images:///...
TypeScript
import { Notification } from 'electron';
import type { NotificationConstructorOptions } from 'electron';
const showNotification = (title: string, body: string): void => {
const notice = {
title,
body,
} as NotificationConstructorOptions;
new Notification(notice).show();
};
export default showNotification;
TypeScript
import { BrowserWindow, globalShortcut, shell } from 'electron';
export function registerShortcut(_mainWindow: BrowserWindow): void {
globalShortcut.register('Control+Shift+I', async () => {
await shell.openPath(/* */);
});
globalShortcut.register('Control+Shift+D', async () => {
_mainWindow.webContents.openDevTools();
});
}