Added the ability to restart AGS on monitor connect or awake from sleep. (#432)
* Added the ability to restart AGS on monitor connect or awake from sleep. * Made nix check more robust
This commit is contained in:
46
main.ts
46
main.ts
@@ -5,11 +5,13 @@ 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 { forMonitors } from 'lib/utils';
|
||||
import { bash, forMonitors } from 'lib/utils';
|
||||
import options from 'options.js';
|
||||
import OSD from 'modules/osd/index';
|
||||
|
||||
App.config({
|
||||
@@ -21,3 +23,45 @@ App.config({
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -892,7 +892,7 @@ const options = mkOptions(OPTIONS, {
|
||||
occupied: opt(''),
|
||||
},
|
||||
workspaceIconMap: opt<WorkspaceIcons | WorkspaceIconsColored>({}),
|
||||
workspaces: opt(10),
|
||||
workspaces: opt(5),
|
||||
spacing: opt(1),
|
||||
monitorSpecific: opt(true),
|
||||
hideUnoccupied: opt(true),
|
||||
@@ -1216,6 +1216,11 @@ const options = mkOptions(OPTIONS, {
|
||||
clearDelay: opt(100),
|
||||
},
|
||||
|
||||
hyprpanel: {
|
||||
restartAgs: opt(true),
|
||||
restartCommand: opt('ags -q; ags'),
|
||||
},
|
||||
|
||||
dummy: opt(true),
|
||||
});
|
||||
|
||||
|
||||
@@ -34,6 +34,20 @@ export const BarGeneral = (): Scrollable<Child, Attribute> => {
|
||||
themeOnly: false,
|
||||
},
|
||||
}),
|
||||
Option({
|
||||
opt: options.hyprpanel.restartAgs,
|
||||
title: 'Restart Hyprpanel On Wake Or Monitor Connection',
|
||||
subtitle:
|
||||
'WARNING: Disabling this will stop the bar from appearing on monitors after waking \n' +
|
||||
'from sleep or when a new monitor is connected.',
|
||||
type: 'boolean',
|
||||
}),
|
||||
Option({
|
||||
opt: options.hyprpanel.restartCommand,
|
||||
title: 'Restart Command',
|
||||
subtitle: 'Command to execute when a restart is initiated.',
|
||||
type: 'string',
|
||||
}),
|
||||
Option({
|
||||
opt: options.terminal,
|
||||
title: 'Terminal',
|
||||
|
||||
Reference in New Issue
Block a user