diff options
| author | Rubén Beltrán del Río <jj@r.bdr.sh> | 2026-09-24 21:01:06 +0200 |
|---|---|---|
| committer | Rubén Beltrán del Río <jj@r.bdr.sh> | 2026-09-25 20:16:02 +0200 |
| commit | 628406f0a50e040d4661629446c620a3a495441f (patch) | |
| tree | e1a2b783296b1779a4040b5a7ea55d72547a37e8 /sourcehut-builds/bar.luau | |
Diffstat (limited to 'sourcehut-builds/bar.luau')
| -rw-r--r-- | sourcehut-builds/bar.luau | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/sourcehut-builds/bar.luau b/sourcehut-builds/bar.luau new file mode 100644 index 0000000..862287d --- /dev/null +++ b/sourcehut-builds/bar.luau @@ -0,0 +1,98 @@ +--!nonstrict +-- Sourcehut Builds - Bar widget that toggles the build status panel and shows the status of recent tasks. +-- +-- You can configure the glyphs shown for the different statuses, as well as +-- when there are no recent builds. + +local K = require("./constants.luau") + +-------------------------------------------------------------------------------- +-- Constants +-------------------------------------------------------------------------------- +local GLYPHS = { + default = "glyph", + ok = "ok_glyph", + failed = "failed_glyph", + inProgress = "in_progress_glyph", +} +local STYLE = { + color = { + closed = "on_surface", + open = "primary" + } +} + +-------------------------------------------------------------------------------- +-- State +-------------------------------------------------------------------------------- +local isPanelOpen: boolean = false +local buildState: SourcehutBuildsState = require("./empty_state.luau") + +-------------------------------------------------------------------------------- +-- Internal Functions +-------------------------------------------------------------------------------- + +------------------------------------------------------------------ Logic Helpers + +local function hasRecentBuilds(): boolean + return buildState.successful > 0 or buildState.failed > 0 or buildState.inProgress > 0 +end + +----------------------------------------------------------------------------- UI + +-- Renders the bar +local function render() + barWidget.setGlyphColor(isPanelOpen and STYLE.color.open or STYLE.color.closed) + + barWidget.setTooltip(noctalia.tr("bar.tooltip")) + + local container = barWidget.isVertical() and ui.column or ui.row + barWidget.render(container({ gap = 6, align = "center" }, { + not hasRecentBuilds() and ui.glyph({ name = noctalia.getConfig(GLYPHS.default), size = 14, color = isPanelOpen and STYLE.color.open or STYLE.color.closed }) or nil, + buildState.successful > 0 and ui.glyph({ name = noctalia.getConfig(GLYPHS.ok), size = 14, color = isPanelOpen and STYLE.color.open or STYLE.color.closed }) or nil, + buildState.failed > 0 and ui.glyph({ name = noctalia.getConfig(GLYPHS.failed), size = 14, color = isPanelOpen and STYLE.color.open or STYLE.color.closed }) or nil, + buildState.inProgress > 0 and ui.glyph({ name = noctalia.getConfig(GLYPHS.inProgress), size = 14, color = isPanelOpen and STYLE.color.open or STYLE.color.closed }) or nil, + })) +end + + +---------------------------------------------------------------- Event Listeners + +local function onPanelStateChanged(value: boolean) + isPanelOpen = value + render() +end + +local function onBuildsStateChanged(value: SourcehutBuildsState) + buildState = value + render() +end + +---------------------------------------------------------------------- Lifecycle + +local function run() + noctalia.setUpdateInterval(K.bar.update_interval) +end + +-------------------------------------------------------------------------------- +-- Listeners +-------------------------------------------------------------------------------- + +noctalia.state.watch(K.events.panel_state_updated, onPanelStateChanged) +noctalia.state.watch(K.events.builds_state_updated, onBuildsStateChanged) + +-------------------------------------------------------------------------------- +-- Public API +-------------------------------------------------------------------------------- +function update() + render() +end + +function onClick() + noctalia.togglePanel(K.panel.id) +end + +function onConfigChanged() +end + +run() |