-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: cloudflare warp custom modules
- Loading branch information
1 parent
e4a5e80
commit 3e107a9
Showing
7 changed files
with
138 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { execAsync, Variable } from "astal"; | ||
|
||
export const isWarpConnectCommand = `bash -c "warp-cli status | awk {'print $3'}"` | ||
export const isWarpDisconnectCommand = `bash -c "warp-cli status | head -1 | awk {'print $3'}"` | ||
|
||
export const isWarpConnect = Variable(false); | ||
|
||
export const toggleWarp = async (isWarpConnect: Variable<boolean>): Promise<void> => { | ||
try { | ||
await execAsync(`bash -c "warp-cli ${isWarpConnect.get() ? 'disconnect' : 'connect'}"`); | ||
|
||
const res = await execAsync(isWarpConnect.get() ? isWarpConnectCommand : isWarpDisconnectCommand); | ||
isWarpConnect.set(isWarpConnect.get() ? res === 'Disconnected' : res === 'Connected'); | ||
} catch (err) { | ||
await execAsync(`bash -c "notify-send -a 'hyprpanel' 'Warp service not active!' 'Error: ${err}'"`); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
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 { bind, Variable } from "astal"; | ||
import { Astal } from "astal/gtk3"; | ||
|
||
const { | ||
label, | ||
onIcon, | ||
offIcon, | ||
onLabel, | ||
offLabel, | ||
rightClick, | ||
middleClick, | ||
scrollUp, | ||
scrollDown, | ||
} = options.bar.customModules.warp; | ||
|
||
const thorttledToggleWarp = throttleInput(() => toggleWarp(isWarpConnect), 1000); | ||
|
||
export const Warp = (): BarBoxChild => { | ||
const iconBinding = Variable.derive([bind(isWarpConnect), bind(onIcon), bind(offIcon)], (active, onIcn, offIcn) => { | ||
return active ? onIcn : offIcn; | ||
}) | ||
|
||
const tooltipBinding = Variable.derive([isWarpConnect], (active) => { | ||
return active ? 'Connect' : "Disconnect"; | ||
}); | ||
|
||
const labelBinding = Variable.derive([bind(isWarpConnect), bind(onLabel), bind(offLabel)], (active, onLbl, offLbl) => { | ||
return active ? onLbl : offLbl; | ||
}); | ||
|
||
const warpModule = Module({ | ||
textIcon: iconBinding(), | ||
tooltipText: tooltipBinding(), | ||
boxClass: 'warp', | ||
label: labelBinding(), | ||
showLabelBinding: bind(label), | ||
props: { | ||
setup: (self: Astal.Button) => { | ||
inputHandler(self, { | ||
onPrimaryClick: { | ||
fn: () => { | ||
thorttledToggleWarp(); | ||
}, | ||
}, | ||
onSecondaryClick: { | ||
cmd: rightClick, | ||
}, | ||
onMiddleClick: { | ||
cmd: middleClick, | ||
}, | ||
onScrollUp: { | ||
cmd: scrollUp, | ||
}, | ||
onScrollDown: { | ||
cmd: scrollDown, | ||
}, | ||
}); | ||
}, | ||
onDestroy: () => { | ||
iconBinding.drop(); | ||
tooltipBinding.drop(); | ||
labelBinding.drop(); | ||
}, | ||
}, | ||
}); | ||
|
||
return warpModule; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters