-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtitlebarIPC.ts
95 lines (75 loc) · 2.23 KB
/
titlebarIPC.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* Copyright (c) 2021, Guasam
*
* This software is provided "as-is", without any express or implied warranty. In no event
* will the authors be held liable for any damages arising from the use of this software.
* Read the LICENSE file for more details.
*
* @author : guasam
* @project : Electron Window
* @package : Titlebar IPC (Main Process)
*/
import { BrowserWindow, ipcMain, shell } from 'electron';
export const registerTitlebarIpc = (mainWindow: BrowserWindow) => {
ipcMain.handle('window-minimize', () => {
mainWindow.minimize();
});
ipcMain.handle('window-maximize', () => {
mainWindow.maximize();
});
ipcMain.handle('window-toggle-maximize', () => {
if (mainWindow.isMaximized()) {
mainWindow.unmaximize();
} else {
mainWindow.maximize();
}
});
ipcMain.handle('window-close', () => {
mainWindow.close();
});
ipcMain.handle('web-undo', () => {
mainWindow.webContents.undo();
});
ipcMain.handle('web-redo', () => {
mainWindow.webContents.redo();
});
ipcMain.handle('web-cut', () => {
mainWindow.webContents.cut();
});
ipcMain.handle('web-copy', () => {
mainWindow.webContents.copy();
});
ipcMain.handle('web-paste', () => {
mainWindow.webContents.paste();
});
ipcMain.handle('web-delete', () => {
mainWindow.webContents.delete();
});
ipcMain.handle('web-select-all', () => {
mainWindow.webContents.selectAll();
});
ipcMain.handle('web-reload', () => {
mainWindow.webContents.reload();
});
ipcMain.handle('web-force-reload', () => {
mainWindow.webContents.reloadIgnoringCache();
});
ipcMain.handle('web-toggle-devtools', () => {
mainWindow.webContents.toggleDevTools();
});
ipcMain.handle('web-actual-size', () => {
mainWindow.webContents.setZoomLevel(0);
});
ipcMain.handle('web-zoom-in', () => {
mainWindow.webContents.setZoomLevel(mainWindow.webContents.zoomLevel + 0.5);
});
ipcMain.handle('web-zoom-out', () => {
mainWindow.webContents.setZoomLevel(mainWindow.webContents.zoomLevel - 0.5);
});
ipcMain.handle('web-toggle-fullscreen', () => {
mainWindow.setFullScreen(!mainWindow.fullScreen);
});
ipcMain.handle('open-url', (e, url) => {
shell.openExternal(url);
});
};