Fix astal system tray

This commit is contained in:
Thomas Avé 2025-10-28 18:35:26 +07:00
parent 991882d485
commit c9ebaa4f19
5 changed files with 80 additions and 29 deletions

View File

@ -19,6 +19,7 @@ const wirePlumber = Wp.get_default();
function SysTray(): JSX.Element {
const tray = Tray.get_default();
let items = createBinding(tray, "items");
const init = (btn: Gtk.MenuButton, item: Tray.TrayItem) => {
btn.menuModel = item.menuModel;
btn.insert_action_group("dbusmenu", item.actionGroup);
@ -26,6 +27,7 @@ function SysTray(): JSX.Element {
btn.insert_action_group("dbusmenu", item.actionGroup);
});
};
return (
<box>
<For each={items}>
@ -38,7 +40,10 @@ function SysTray(): JSX.Element {
tooltipMarkup={createBinding(item, "tooltipMarkup")}
menuModel={createBinding(item, "menuModel")}
>
<image gicon={item.gicon} class="systray-item" />
<image
gicon={createBinding(item, "gicon")}
class="systray-item"
/>
</menubutton>
);
}}

View File

@ -1,40 +1,72 @@
import Apps from "gi://AstalApps"
import Apps from "gi://AstalApps";
import AstalHyprland from "gi://AstalHyprland";
const app_icons = new Apps.Apps().list.reduce(
(acc, app) => {
if (app.icon_name) {
acc.classOrNames[app.wm_class ?? app.name] = app.icon_name;
// keys from AstalApps entries are typically wm_class (snake_case) or name
const key = app.wm_class ?? app.name;
if (key) {
acc.classOrNames[key] = app.icon_name;
}
if (app.executable) {
acc.executables[app.executable] = app.icon_name;
}
return acc;
},
{ classOrNames: {}, executables: {} },
{ classOrNames: {} as Record<string, string>, executables: {} as Record<string, string> },
);
export function getIconName(client: AstalHyprland.Client) {
if (!client) {
return "";
}
export function getIconName(client: AstalHyprland.Client | null | undefined) {
if (!client) return "";
let icon = app_icons.classOrNames[client.class];
if (!icon) {
const icon_key = Object.keys(app_icons.classOrNames).find(
(key) =>
key.includes(client.title) ||
key.includes(client.initialTitle) ||
key.includes(client.initialClass) ||
key.includes(client.class),
);
if (icon_key) {
icon = app_icons.classOrNames[icon_key];
app_icons.classOrNames[client.class] = icon;
// try a bunch of fields (snake_case and camelCase variants)
const possibleKeys = [
// common client properties (snake_case)
(client as any).wm_class,
(client as any).initial_class,
(client as any).executable,
// camelCase variants (some bindings expose these)
(client as any).class,
(client as any).initialClass,
(client as any).initialTitle,
(client as any).title,
(client as any).name,
].filter(Boolean) as string[];
// 1) direct exact match
for (const k of possibleKeys) {
const icon = app_icons.classOrNames[k] ?? app_icons.executables[k];
if (icon) {
// cache the mapping for this client's canonical class (prefer wm_class or class)
const cacheKey = (client as any).wm_class ?? (client as any).class ?? (client as any).name ?? k;
app_icons.classOrNames[cacheKey] = icon;
return icon;
}
}
if (!icon) {
app_icons.classOrNames[client.class] = "";
// 2) fuzzy match: see if any stored key includes any of the client strings (title, name, etc.)
const searchStrings = [
(client as any).title,
(client as any).initialTitle,
(client as any).initial_class,
(client as any).initialClass,
(client as any).wm_class,
(client as any).class,
(client as any).name,
].filter(Boolean) as string[];
for (const s of searchStrings) {
const matchKey = Object.keys(app_icons.classOrNames).find((key) => key.includes(s));
if (matchKey) {
const icon = app_icons.classOrNames[matchKey];
const cacheKey = (client as any).wm_class ?? (client as any).class ?? (client as any).name ?? s;
app_icons.classOrNames[cacheKey] = icon;
return icon;
}
}
return icon;
// nothing found — cache empty string so we don't repeat work
const cacheKey = (client as any).wm_class ?? (client as any).class ?? (client as any).name ?? "";
if (cacheKey) app_icons.classOrNames[cacheKey] = "";
return "";
}

View File

@ -12,6 +12,7 @@
tweak = {
sixel = "yes";
};
scrollback.lines = 100000;
colors = {
background = "000010";
foreground = "F8F8F2";

View File

@ -5,8 +5,8 @@
pname = "Helium";
version = "0.4.7.1";
src = pkgs.fetchurl {
url = "https://github.com/imputnet/helium-linux/releases/download/0.4.7.1/helium-0.4.7.1-x86_64.AppImage";
sha256 = "b7a64d9cd96c841119f4729545d7b88ed804fdcac99d3878099f338766dfdd2d";
url = "https://release-assets.githubusercontent.com/github-production-release-asset/1043354934/31a5650e-2719-4734-8aa7-8b45ff506fe7";
sha256 = "275853aae038ee08a6d07ed314c33e25a6d8e5845c2f9b27253a4cfde94dd732";
};
})
];

View File

@ -33,7 +33,7 @@ in {
networking.wireless.iwd.enable = true;
networking.wireless.iwd.settings = {
IPv6 = {
Enabled = true;
Enabled = false;
};
Settings = {
AutoConnect = true;
@ -77,7 +77,7 @@ in {
networking.wg-quick.interfaces = {
Tunnel = {
address = [ "10.0.0.5/24" "2a02:a03f:83ad:2101::5/128" ];
address = [ "10.0.0.5/24" ];
privateKeyFile = "/home/user/.secrets/Wireguard/Aloria.key";
listenPort = 51820;
autostart = false;
@ -91,7 +91,7 @@ in {
}];
};
OPNsense = {
address = [ "10.0.0.5/24" "2a02:a03f:83ad:2101::5/128" ];
address = [ "10.0.0.5/24" ];
privateKeyFile = "/home/user/.secrets/Wireguard/Aloria.key";
listenPort = 51820;
autostart = true;
@ -104,6 +104,19 @@ in {
persistentKeepalive = 25;
}];
};
GCP = {
address = [ "10.5.0.5/24" ];
privateKeyFile = "/home/user/.secrets/Wireguard/GCP.key";
listenPort = 51820;
autostart = false;
postUp = "resolvectl dns GCP 1.1.1.1;resolvectl dns wlan0 1.1.1.1;";
peers = [{
publicKey = "NEBNE4Czf2MkZF2X5aVhmofENH1uXjDpvXjIMJvfMFA=";
allowedIPs = [ "0.0.0.0/0" ];
endpoint = "35.201.231.151:443";
persistentKeepalive = 25;
}];
};
};
systemd.services."wg-quick-OPNsense" = {
serviceConfig = { Restart = "on-failure"; RestartSec = "2s"; };