-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.ts
67 lines (55 loc) · 1.58 KB
/
control.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
import { WebPreferences, ipcRenderer } from 'electron';
import { type TabID } from './index.js';
// Used in Renderer process
/**
* Tell browser view to load url
* @param {string} url
*/
const sendEnterURL = (url: string) => ipcRenderer.send('url-enter', url);
/**
* Tell browser view url in address bar changed
* @param {string} url
*/
const sendChangeURL = (url: string) => ipcRenderer.send('url-change', url);
const sendAct = (actName: string) => {
ipcRenderer.send('act', actName);
};
/**
* Tell browser view to goBack
*/
const sendGoBack = () => sendAct('goBack');
/**
* Tell browser view to goForward
*/
const sendGoForward = () => sendAct('goForward');
// Tell browser view to reload
const sendReload = () => sendAct('reload');
// Tell browser view to stop load
const sendStop = () => sendAct('stop');
/**
* Tell browser view to close tab
* @param {TabID} id
*/
const sendCloseTab = (id: TabID) => ipcRenderer.send('close-tab', id);
/**
* Create a new tab
* @param {string} [url]
* @param {object} [references]
*/
const sendNewTab = (url?: string, references?: WebPreferences) => ipcRenderer.send('new-tab', url, references);
/**
* Tell browser view to switch to specified tab
* @param {TabID} id
*/
const sendSwitchTab = (id: TabID) => ipcRenderer.send('switch-tab', id);
export default {
sendEnterURL, // sendEnterURL(url) to load url
sendChangeURL, // sendChangeURL(url) on addressbar input change
sendGoBack,
sendGoForward,
sendReload,
sendStop,
sendNewTab, // sendNewTab([url])
sendSwitchTab, // sendSwitchTab(toID)
sendCloseTab // sendCloseTab(id)
};