-
-
Notifications
You must be signed in to change notification settings - Fork 548
/
util.ts
51 lines (41 loc) · 1.15 KB
/
util.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
import {app, BrowserWindow, dialog} from 'electron';
import {is} from 'electron-util';
import config from './config';
export function getWindow(): BrowserWindow {
const [win] = BrowserWindow.getAllWindows();
return win;
}
export function sendAction(action: string, ...args: unknown[]): void {
const win = getWindow();
if (is.macos) {
win.restore();
}
win.webContents.send(action, ...args);
}
export function sendBackgroundAction(action: string, ...args: unknown[]): void {
getWindow().webContents.send(action, ...args);
}
export function showRestartDialog(message: string): void {
const buttonIndex = dialog.showMessageBoxSync({
message,
detail: 'Do you want to restart the app now?',
buttons: [
'Restart',
'Ignore'
],
defaultId: 0,
cancelId: 1
});
if (buttonIndex === 0) {
app.relaunch();
app.quit();
}
}
export const messengerDomain = config.get('useWorkChat') ? 'facebook.com' : 'messenger.com';
export function stripTrackingFromUrl(url: string): string {
const trackingUrlPrefix = `https://l.${messengerDomain}/l.php`;
if (url.startsWith(trackingUrlPrefix)) {
url = new URL(url).searchParams.get('u')!;
}
return url;
}