Skip to content

Commit

Permalink
add polling for icon
Browse files Browse the repository at this point in the history
  • Loading branch information
myamusashi committed Dec 25, 2024
1 parent 3e107a9 commit a91ad7c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/components/bar/modules/warp/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ export const toggleWarp = async (isWarpConnect: Variable<boolean>): Promise<void
await execAsync(`bash -c "notify-send -a 'hyprpanel' 'Warp service not active!' 'Error: ${err}'"`);
}
};

export const checkWarpStatus = (): undefined => {
execAsync(isWarpConnectCommand).then((res) => {
isWarpConnect.set(res === 'Connected');
});
};
12 changes: 11 additions & 1 deletion src/components/bar/modules/warp/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import options from "src/options";
import { Module } from "../../shared/Module";
import { inputHandler, throttleInput } from "../../utils/helpers";
import { BarBoxChild } from "src/lib/types/bar";
import { isWarpConnect, toggleWarp } from "./helpers";
import { checkWarpStatus, isWarpConnect, toggleWarp } from "./helpers";
import { bind, Variable } from "astal";
import { Astal } from "astal/gtk3";
import { FunctionPoller } from "src/lib/poller/FunctionPoller";

const {
label,
pollingInterval,
onIcon,
offIcon,
onLabel,
Expand All @@ -18,6 +20,14 @@ const {
scrollDown,
} = options.bar.customModules.warp;

const dummyVar = Variable(undefined);

checkWarpStatus();

const warpPoller = new FunctionPoller<undefined, []>(dummyVar, [], bind(pollingInterval), checkWarpStatus);

warpPoller.initialize('warp');

const thorttledToggleWarp = throttleInput(() => toggleWarp(isWarpConnect), 1000);

export const Warp = (): BarBoxChild => {
Expand Down
1 change: 1 addition & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,7 @@ const options = mkOptions(CONFIG, {
offIcon: opt('󰇖'),
onLabel: opt('On'),
offLabel: opt('Off'),
pollingInterval: opt(1000 * 2),
rightClick: opt(''),
middleClick: opt(''),
scrollUp: opt(''),
Expand Down

0 comments on commit a91ad7c

Please sign in to comment.