Skip to content

Commit a91ad7c

Browse files
committed
add polling for icon
1 parent 3e107a9 commit a91ad7c

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/components/bar/modules/warp/helpers/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@ export const toggleWarp = async (isWarpConnect: Variable<boolean>): Promise<void
1515
await execAsync(`bash -c "notify-send -a 'hyprpanel' 'Warp service not active!' 'Error: ${err}'"`);
1616
}
1717
};
18+
19+
export const checkWarpStatus = (): undefined => {
20+
execAsync(isWarpConnectCommand).then((res) => {
21+
isWarpConnect.set(res === 'Connected');
22+
});
23+
};

src/components/bar/modules/warp/index.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import options from "src/options";
22
import { Module } from "../../shared/Module";
33
import { inputHandler, throttleInput } from "../../utils/helpers";
44
import { BarBoxChild } from "src/lib/types/bar";
5-
import { isWarpConnect, toggleWarp } from "./helpers";
5+
import { checkWarpStatus, isWarpConnect, toggleWarp } from "./helpers";
66
import { bind, Variable } from "astal";
77
import { Astal } from "astal/gtk3";
8+
import { FunctionPoller } from "src/lib/poller/FunctionPoller";
89

910
const {
1011
label,
12+
pollingInterval,
1113
onIcon,
1214
offIcon,
1315
onLabel,
@@ -18,6 +20,14 @@ const {
1820
scrollDown,
1921
} = options.bar.customModules.warp;
2022

23+
const dummyVar = Variable(undefined);
24+
25+
checkWarpStatus();
26+
27+
const warpPoller = new FunctionPoller<undefined, []>(dummyVar, [], bind(pollingInterval), checkWarpStatus);
28+
29+
warpPoller.initialize('warp');
30+
2131
const thorttledToggleWarp = throttleInput(() => toggleWarp(isWarpConnect), 1000);
2232

2333
export const Warp = (): BarBoxChild => {

src/options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,7 @@ const options = mkOptions(CONFIG, {
11571157
offIcon: opt('󰇖'),
11581158
onLabel: opt('On'),
11591159
offLabel: opt('Off'),
1160+
pollingInterval: opt(1000 * 2),
11601161
rightClick: opt(''),
11611162
middleClick: opt(''),
11621163
scrollUp: opt(''),

0 commit comments

Comments
 (0)