forked from darkreader/darkreader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
48 lines (43 loc) · 1.4 KB
/
Copy pathindex.ts
File metadata and controls
48 lines (43 loc) · 1.4 KB
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
import {Extension} from './extension';
import {getHelpURL, UNINSTALL_URL} from '../utils/links';
// Initialize extension
const extension = new Extension();
extension.start();
chrome.runtime.onInstalled.addListener(({reason}) => {
if (reason === 'install') {
chrome.tabs.create({url: getHelpURL()});
}
});
chrome.runtime.setUninstallURL(UNINSTALL_URL);
declare const __WATCH__: boolean;
declare const __PORT__: number;
const WATCH = __WATCH__;
if (WATCH) {
const PORT = __PORT__;
const listen = () => {
const socket = new WebSocket(`ws://localhost:${PORT}`);
const send = (message: any) => socket.send(JSON.stringify(message));
socket.onmessage = (e) => {
const message = JSON.parse(e.data);
if (message.type.startsWith('reload:')) {
send({type: 'reloading'});
}
switch (message.type) {
case 'reload:css': {
chrome.runtime.sendMessage({type: 'css-update'});
break;
}
case 'reload:ui': {
chrome.runtime.sendMessage({type: 'ui-update'});
break;
}
case 'reload:full': {
chrome.runtime.reload();
break;
}
}
};
socket.onclose = () => setTimeout(listen, 1000);
};
listen();
}