forked from Jas-SinghFSU/HyprPanel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
68 lines (59 loc) · 1.96 KB
/
main.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
68
import 'lib/session';
import 'scss/style';
import 'globals/useTheme';
import 'globals/wallpaper';
import 'globals/systray';
import 'globals/dropdown.js';
import 'globals/utilities';
const hyprland = await Service.import('hyprland');
import { Bar } from 'modules/bar/Bar';
import MenuWindows from './modules/menus/main.js';
import SettingsDialog from 'widget/settings/SettingsDialog';
import Notifications from './modules/notifications/index.js';
import { bash, forMonitors, warnOnLowBattery } from 'lib/utils';
import options from 'options.js';
import OSD from 'modules/osd/index';
App.config({
onConfigParsed: () => [Utils.execAsync(`python3 ${App.configDir}/services/bluetooth.py`), warnOnLowBattery()],
windows: [...MenuWindows, Notifications(), SettingsDialog(), ...forMonitors(Bar), OSD()],
closeWindowDelay: {
sideright: 350,
launcher: 350,
bar0: 350,
},
});
/**
* Function to determine if the current OS is NixOS by parsing /etc/os-release.
* @returns True if NixOS, false otherwise.
*/
const isNixOS = (): boolean => {
try {
const osRelease = Utils.exec('cat /etc/os-release').toString();
const idMatch = osRelease.match(/^ID\s*=\s*"?([^"\n]+)"?/m);
if (idMatch && idMatch[1].toLowerCase() === 'nixos') {
return true;
}
return false;
} catch (error) {
console.error('Error detecting OS:', error);
return false;
}
};
/**
* Function to generate the appropriate restart command based on the OS.
* @returns The modified or original restart command.
*/
const getRestartCommand = (): string => {
const isNix = isNixOS();
const command = options.hyprpanel.restartCommand.value;
if (isNix) {
return command.replace(/\bags\b/g, 'hyprpanel');
}
return command;
};
hyprland.connect('monitor-added', () => {
if (options.hyprpanel.restartAgs.value) {
const restartAgsCommand = getRestartCommand();
bash(restartAgsCommand);
}
});