This repository has been archived by the owner on Oct 18, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathstate.ts
64 lines (57 loc) · 1.52 KB
/
state.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
import { BrowserWindow } from "electron";
import Store from "electron-store";
import { notifyLaravel } from "./utils";
const settingsStore = new Store();
settingsStore.onDidAnyChange((newValue, oldValue) => {
// Only notify of the changed key/value pair
const changedKey = Object.keys(newValue).find(
(key) => newValue[key] !== oldValue[key]
);
if (changedKey) {
notifyLaravel("events", {
event: "Native\\Laravel\\Events\\Settings\\SettingChanged",
payload: {
key: changedKey,
value: newValue[changedKey] || null,
},
});
}
});
interface State {
electronApiPort: number | null;
activeMenuBar: any;
php: string | null;
phpPort: number | null;
phpIni: any;
caCert: string | null;
icon: string | null;
windows: Record<string, BrowserWindow>;
randomSecret: string;
store: Store;
findWindow: (id: string) => BrowserWindow | null;
}
function generateRandomString(length: number) {
let result = "";
const characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
const charactersLength = characters.length;
for (let i = 0; i < length; i += 1) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
export default {
electronApiPort: null,
activeMenuBar: null,
php: null,
phpPort: null,
phpIni: null,
caCert: null,
icon: null,
store: settingsStore,
randomSecret: generateRandomString(32),
windows: {},
findWindow(id: string) {
return this.windows[id] || null;
},
} as State;