Log undefined menu models and action groups. Fix null errors for workspaces and update array property accessors for services. (#583)
* Handle null values for actionGroup. * Add logs * more logs * Fix property accessors and workspace null errors.
This commit is contained in:
@@ -10,7 +10,7 @@ const systemtray = AstalTray.get_default();
|
|||||||
const { ignore, customIcons } = options.bar.systray;
|
const { ignore, customIcons } = options.bar.systray;
|
||||||
|
|
||||||
//TODO: Connect to `notify::menu-model` and `notify::action-group` to have up to date menu and action group
|
//TODO: Connect to `notify::menu-model` and `notify::action-group` to have up to date menu and action group
|
||||||
const createMenu = (menuModel: Gio.MenuModel, actionGroup: Gio.ActionGroup): Gtk.Menu => {
|
const createMenu = (menuModel: Gio.MenuModel, actionGroup: Gio.ActionGroup | null): Gtk.Menu => {
|
||||||
const menu = Gtk.Menu.new_from_model(menuModel);
|
const menu = Gtk.Menu.new_from_model(menuModel);
|
||||||
menu.insert_action_group('dbusmenu', actionGroup);
|
menu.insert_action_group('dbusmenu', actionGroup);
|
||||||
|
|
||||||
@@ -38,9 +38,14 @@ const MenuEntry = ({ item, child }: MenuEntryProps): JSX.Element => {
|
|||||||
const entryBinding = Variable.derive(
|
const entryBinding = Variable.derive(
|
||||||
[bind(item, 'menuModel'), bind(item, 'actionGroup')],
|
[bind(item, 'menuModel'), bind(item, 'actionGroup')],
|
||||||
(menuModel, actionGroup) => {
|
(menuModel, actionGroup) => {
|
||||||
if (menuModel && actionGroup) {
|
if (!menuModel) {
|
||||||
menu = createMenu(menuModel, actionGroup);
|
return console.error(`Menu Model not found for ${item.id}`);
|
||||||
}
|
}
|
||||||
|
if (!actionGroup) {
|
||||||
|
return console.error(`Action Group not found for ${item.id}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
menu = createMenu(menuModel, actionGroup);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -33,9 +33,13 @@ export const getWorkspacesForMonitor = (
|
|||||||
|
|
||||||
const monitorMap: MonitorMap = {};
|
const monitorMap: MonitorMap = {};
|
||||||
|
|
||||||
const workspaceMonitorList = workspaceList.map((m) => {
|
const wsList = workspaceList ?? [];
|
||||||
return { id: m.monitor.id, name: m.monitor.name };
|
|
||||||
});
|
const workspaceMonitorList = wsList
|
||||||
|
.filter((m) => m !== null)
|
||||||
|
.map((m) => {
|
||||||
|
return { id: m.monitor?.id, name: m.monitor?.name };
|
||||||
|
});
|
||||||
|
|
||||||
const monitors = [...new Map([...workspaceMonitorList, ...monitorList].map((item) => [item.id, item])).values()];
|
const monitors = [...new Map([...workspaceMonitorList, ...monitorList].map((item) => [item.id, item])).values()];
|
||||||
|
|
||||||
@@ -150,7 +154,7 @@ const navigateWorkspace = (
|
|||||||
|
|
||||||
if (workspacesList.length === 0) return;
|
if (workspacesList.length === 0) return;
|
||||||
|
|
||||||
const currentIndex = workspacesList.indexOf(hyprlandService.focusedWorkspace.id);
|
const currentIndex = workspacesList.indexOf(hyprlandService.focusedWorkspace?.id);
|
||||||
const step = direction === 'next' ? 1 : -1;
|
const step = direction === 'next' ? 1 : -1;
|
||||||
let newIndex = (currentIndex + step + workspacesList.length) % workspacesList.length;
|
let newIndex = (currentIndex + step + workspacesList.length) % workspacesList.length;
|
||||||
let attempts = 0;
|
let attempts = 0;
|
||||||
@@ -283,7 +287,8 @@ export const getWorkspacesToRender = (
|
|||||||
let allWorkspaces = range(totalWorkspaces || 8);
|
let allWorkspaces = range(totalWorkspaces || 8);
|
||||||
const activeWorkspaces = workspaceList.map((ws) => ws.id);
|
const activeWorkspaces = workspaceList.map((ws) => ws.id);
|
||||||
|
|
||||||
const workspaceMonitorList = workspaceList.map((ws) => {
|
const wsList = workspaceList ?? [];
|
||||||
|
const workspaceMonitorList = wsList.map((ws) => {
|
||||||
return {
|
return {
|
||||||
id: ws.monitor?.id || -1,
|
id: ws.monitor?.id || -1,
|
||||||
name: ws.monitor?.name || '',
|
name: ws.monitor?.name || '',
|
||||||
@@ -310,7 +315,7 @@ export const getWorkspacesToRender = (
|
|||||||
|
|
||||||
if (isMonitorSpecific) {
|
if (isMonitorSpecific) {
|
||||||
const workspacesInRange = range(totalWorkspaces).filter((ws) => {
|
const workspacesInRange = range(totalWorkspaces).filter((ws) => {
|
||||||
return getWorkspacesForMonitor(ws, workspaceRules, monitor, workspaceList, monitorList);
|
return getWorkspacesForMonitor(ws, workspaceRules, monitor, wsList, monitorList);
|
||||||
});
|
});
|
||||||
|
|
||||||
allWorkspaces = [...new Set([...activesForMonitor, ...workspacesInRange])];
|
allWorkspaces = [...new Set([...activesForMonitor, ...workspacesInRange])];
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ const { showWsIcons, showAllActive, numbered_active_indicator: wsActiveIndicator
|
|||||||
* @returns True if the workspace is active on the monitor, false otherwise.
|
* @returns True if the workspace is active on the monitor, false otherwise.
|
||||||
*/
|
*/
|
||||||
const isWorkspaceActiveOnMonitor = (monitor: number, i: number): boolean => {
|
const isWorkspaceActiveOnMonitor = (monitor: number, i: number): boolean => {
|
||||||
return showAllActive.get() && hyprlandService.get_monitor(monitor).activeWorkspace.id === i;
|
return showAllActive.get() && hyprlandService.get_monitor(monitor)?.activeWorkspace?.id === i;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,7 +84,7 @@ export const getWsColor = (
|
|||||||
showWsIcons.get() &&
|
showWsIcons.get() &&
|
||||||
smartHighlight &&
|
smartHighlight &&
|
||||||
wsActiveIndicator.get() === 'highlight' &&
|
wsActiveIndicator.get() === 'highlight' &&
|
||||||
(hyprlandService.focusedWorkspace.id === i || isWorkspaceActiveOnMonitor(monitor, i))
|
(hyprlandService.focusedWorkspace?.id === i || isWorkspaceActiveOnMonitor(monitor, i))
|
||||||
) {
|
) {
|
||||||
const iconColor = monochrome.get() ? background.get() : wsBackground.get();
|
const iconColor = monochrome.get() ? background.get() : wsBackground.get();
|
||||||
const iconBackground = hasColor && isValidGjsColor(iconEntry.color) ? iconEntry.color : active.get();
|
const iconBackground = hasColor && isValidGjsColor(iconEntry.color) ? iconEntry.color : active.get();
|
||||||
@@ -122,7 +122,7 @@ export const getAppIcon = (
|
|||||||
|
|
||||||
const clients = hyprlandService
|
const clients = hyprlandService
|
||||||
.get_clients()
|
.get_clients()
|
||||||
.filter((client) => client.workspace.id === workspaceIndex)
|
.filter((client) => client?.workspace?.id === workspaceIndex)
|
||||||
.map((client) => [client.class, client.title]);
|
.map((client) => [client.class, client.title]);
|
||||||
|
|
||||||
if (!clients.length) {
|
if (!clients.length) {
|
||||||
@@ -200,7 +200,7 @@ export const renderClassnames = (
|
|||||||
|
|
||||||
if (showNumbered || showWsIcons) {
|
if (showNumbered || showWsIcons) {
|
||||||
const numActiveInd =
|
const numActiveInd =
|
||||||
hyprlandService.focusedWorkspace.id === i || isWorkspaceActiveOnMonitor(monitor, i)
|
hyprlandService.focusedWorkspace?.id === i || isWorkspaceActiveOnMonitor(monitor, i)
|
||||||
? numberedActiveIndicator
|
? numberedActiveIndicator
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
@@ -255,7 +255,7 @@ export const renderLabel = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (showIcons) {
|
if (showIcons) {
|
||||||
if (hyprlandService.focusedWorkspace.id === i || isWorkspaceActiveOnMonitor(monitor, i)) {
|
if (hyprlandService.focusedWorkspace?.id === i || isWorkspaceActiveOnMonitor(monitor, i)) {
|
||||||
return activeIndicator;
|
return activeIndicator;
|
||||||
}
|
}
|
||||||
if ((hyprlandService.get_workspace(i)?.get_clients().length || 0) > 0) {
|
if ((hyprlandService.get_workspace(i)?.get_clients().length || 0) > 0) {
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ export const WorkspaceModule = ({ monitor }: WorkspaceModuleProps): JSX.Element
|
|||||||
smartHighlightEnabled: boolean,
|
smartHighlightEnabled: boolean,
|
||||||
monitorList: AstalHyprland.Monitor[],
|
monitorList: AstalHyprland.Monitor[],
|
||||||
) => {
|
) => {
|
||||||
const activeWorkspace = hyprlandService.focusedWorkspace.id;
|
const activeWorkspace = hyprlandService.focusedWorkspace?.id || -99999;
|
||||||
|
|
||||||
const workspacesToRender = getWorkspacesToRender(
|
const workspacesToRender = getWorkspacesToRender(
|
||||||
totalWorkspaces,
|
totalWorkspaces,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ const MonitorListDropdown = (): JSX.Element => {
|
|||||||
const monitorList: Variable<AstalHyprland.Monitor[]> = Variable([]);
|
const monitorList: Variable<AstalHyprland.Monitor[]> = Variable([]);
|
||||||
|
|
||||||
const monitorBinding = Variable.derive([bind(hyprlandService, 'monitors')], () =>
|
const monitorBinding = Variable.derive([bind(hyprlandService, 'monitors')], () =>
|
||||||
monitorList.set(hyprlandService.monitors),
|
monitorList.set(hyprlandService.get_monitors()),
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -24,12 +24,12 @@ const focusedClient = (focusedClient: AstalHyprland.Client): void => {
|
|||||||
export const initializeAutoHide = (): void => {
|
export const initializeAutoHide = (): void => {
|
||||||
Variable.derive([bind(autoHide), bind(forceUpdater), bind(hyprlandService, 'workspaces')], (shouldAutohide) => {
|
Variable.derive([bind(autoHide), bind(forceUpdater), bind(hyprlandService, 'workspaces')], (shouldAutohide) => {
|
||||||
if (shouldAutohide === 'never') {
|
if (shouldAutohide === 'never') {
|
||||||
hyprlandService.monitors.forEach((monitor) => {
|
hyprlandService.get_monitors().forEach((monitor) => {
|
||||||
App.get_window(`bar-${monitor.id}`)?.set_visible(true);
|
App.get_window(`bar-${monitor.id}`)?.set_visible(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
hyprlandService.workspaces.map((workspace) => {
|
hyprlandService.get_workspaces().map((workspace) => {
|
||||||
if (autoHide.get() === 'single-window') {
|
if (autoHide.get() === 'single-window') {
|
||||||
App.get_window(`bar-${workspace.monitor.id}`)?.set_visible(workspace.get_clients().length !== 1);
|
App.get_window(`bar-${workspace.monitor.id}`)?.set_visible(workspace.get_clients().length !== 1);
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,7 @@ export const initializeAutoHide = (): void => {
|
|||||||
|
|
||||||
Variable.derive([bind(autoHide)], (shouldAutohide) => {
|
Variable.derive([bind(autoHide)], (shouldAutohide) => {
|
||||||
if (shouldAutohide === 'fullscreen') {
|
if (shouldAutohide === 'fullscreen') {
|
||||||
hyprlandService.workspaces.forEach((workspace) => {
|
hyprlandService.get_workspaces().forEach((workspace) => {
|
||||||
App.get_window(`bar-${workspace.monitor.id}`)?.set_visible(!workspace.hasFullscreen);
|
App.get_window(`bar-${workspace.monitor.id}`)?.set_visible(!workspace.hasFullscreen);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user