-
Notifications
You must be signed in to change notification settings - Fork 285
Expand file tree
/
Copy pathcomms.ts
More file actions
88 lines (71 loc) · 2.38 KB
/
comms.ts
File metadata and controls
88 lines (71 loc) · 2.38 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
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
import { ipcRenderer, shell } from 'electron';
import { namespacedEvent } from '../../shared/events';
import { defaultSettings } from '../context/defaults';
import { type Link, OpenPreference } from '../types';
import { Constants } from './constants';
import { loadState } from './storage';
export function openExternalLink(url: Link): void {
if (url.toLowerCase().startsWith('https://')) {
// Load the state from local storage to avoid having to pass settings as a parameter
const { settings } = loadState();
const openPreference = settings
? settings.openLinks
: defaultSettings.openLinks;
shell.openExternal(url, {
activate: openPreference === OpenPreference.FOREGROUND,
});
}
}
export async function getAppVersion(): Promise<string> {
return await ipcRenderer.invoke(namespacedEvent('version'));
}
export async function encryptValue(value: string): Promise<string> {
return await ipcRenderer.invoke(
namespacedEvent('safe-storage-encrypt'),
value,
);
}
export async function decryptValue(value: string): Promise<string> {
return await ipcRenderer.invoke(
namespacedEvent('safe-storage-decrypt'),
value,
);
}
export function quitApp(): void {
ipcRenderer.send(namespacedEvent('quit'));
}
export function showWindow(): void {
ipcRenderer.send(namespacedEvent('window-show'));
}
export function hideWindow(): void {
ipcRenderer.send(namespacedEvent('window-hide'));
}
export function setAutoLaunch(value: boolean): void {
ipcRenderer.send(namespacedEvent('update-auto-launch'), {
openAtLogin: value,
openAsHidden: value,
});
}
export function setAlternateIdleIcon(value: boolean): void {
ipcRenderer.send(namespacedEvent('use-alternate-idle-icon'), value);
}
export function setKeyboardShortcut(keyboardShortcut: boolean): void {
ipcRenderer.send(namespacedEvent('update-keyboard-shortcut'), {
enabled: keyboardShortcut,
keyboardShortcut: Constants.DEFAULT_KEYBOARD_SHORTCUT,
});
}
export function updateTrayIcon(notificationsLength = 0): void {
if (notificationsLength < 0) {
ipcRenderer.send(namespacedEvent('icon-error'));
return;
}
if (notificationsLength > 0) {
ipcRenderer.send(namespacedEvent('icon-active'));
return;
}
ipcRenderer.send(namespacedEvent('icon-idle'));
}
export function updateTrayTitle(title = ''): void {
ipcRenderer.send(namespacedEvent('update-title'), title);
}