Something went wrong. Try again.
Something went wrong. Try again.
7.3 kB · 215 lines
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216pragma ComponentBehavior: Bound
import ".."import "../components"import QtQuickimport Quickshellimport Quickshell.Io
ModulePill { id: root
property bool moduleVisible: true property var windows: [] property string lastError: "" readonly property double now: clock.date.getTime()
visible: moduleVisible && (lastError.length > 0 || windows.length > 0) moduleClass: lastError ? "warning" : "" text: lastError ? " Fish" : windows.length ? ` ${windows[0].name} ${timing(windows[0])}` : "" onClicked: root.refresh()
Theme { id: theme }
BarPopup { id: popup
readonly property bool pointerInside: root.hovered || popupHover.hovered barWindow: root.barWindow anchorItem: root shown: pointerInside || hoverGrace.running implicitWidth: 360 implicitHeight: root.lastError ? errorLabel.implicitHeight + 24 : Math.min(360, fishList.contentHeight + 16) onPointerInsideChanged: { if (pointerInside) hoverGrace.stop(); else hoverGrace.restart(); }
Timer { id: hoverGrace interval: 250 }
PopupSurface { anchors.fill: parent HoverHandler { id: popupHover }
Text { id: errorLabel
anchors.left: parent.left anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter anchors.margins: 12 visible: root.lastError.length > 0 color: theme.text font.family: theme.fontFamily font.pixelSize: theme.tooltipFontPixelSize textFormat: Text.PlainText wrapMode: Text.Wrap text: root.lastError }
ListView { id: fishList
anchors.fill: parent anchors.margins: 8 clip: true visible: !root.lastError model: root.windows
delegate: Rectangle { id: fishRow
required property var modelData required property int index readonly property bool active: modelData.start <= root.now width: fishList.width height: 28 radius: 6 color: active ? theme.alpha(theme.green, 0.18) : index % 2 ? theme.alpha(theme.crust, 0.28) : "transparent"
Text { anchors.left: parent.left anchors.leftMargin: 8 anchors.right: countdown.left anchors.rightMargin: 12 anchors.verticalCenter: parent.verticalCenter color: theme.text font.family: theme.fontFamily font.pixelSize: theme.tooltipFontPixelSize textFormat: Text.PlainText elide: Text.ElideRight text: fishRow.modelData.name }
Text { id: countdown
anchors.right: parent.right anchors.rightMargin: 8 anchors.verticalCenter: parent.verticalCenter color: fishRow.active ? theme.text : theme.yellow font.family: theme.fontFamily font.pixelSize: theme.tooltipFontPixelSize text: root.timing(fishRow.modelData) } } } } }
function refresh() { if (moduleVisible && !report.running) report.running = true; }
function fail(message) { windows = []; if (message !== lastError) console.warn(`GatherBuddy: ${message}`); lastError = message; }
function duration(ms) { // Match GatherBuddy's long countdown format and round to the nearest second. const seconds = Math.max(0, Math.round(ms / 1000)); const minutes = Math.floor(seconds / 60); const pad = value => String(value).padStart(2, "0"); if (seconds > 86400) return `${(seconds / 86400).toFixed(2)} Days`; if (seconds > 3600) return `${pad(Math.floor(minutes / 60))}:${pad(minutes % 60)} Hours`; return `${pad(minutes)}:${pad(seconds % 60)} Minutes`; }
function timing(window) { const target = window.start <= now ? window.end : window.start; return duration(target - now); }
function applyReport(output) { const data = JSON.parse(output); if (!Array.isArray(data?.items)) throw new Error("Missing fish list"); const now = Date.now(); const upcoming = []; for (const fish of data.items) { const window = fish.condition_windows?.[0]; if (!fish.is_fish || !fish.name || !window || window.end_unix_ms <= now || (window.start_truncated && window.end_truncated)) continue;
upcoming.push({ name: fish.name, start: window.start_unix_ms, end: window.end_unix_ms }); } upcoming.sort((a, b) => a.start - b.start); windows = upcoming; lastError = ""; }
SystemClock { id: clock
enabled: root.moduleVisible precision: SystemClock.Seconds onDateChanged: { const now = date.getTime(); if (root.windows.some(window => window.end <= now)) { root.windows = root.windows.filter(window => window.end > now); root.refresh(); } } }
Timer { interval: 30000 repeat: true triggeredOnStart: true running: root.moduleVisible onTriggered: root.refresh() }
Process { id: report // The shell returns an exit status even if it can't launch the binary. command: ["/bin/sh", "-c", 'exec "$@"', "gatherbuddy", "external-gatherbuddy", "report", "--active-only", "--needed-only", "--windows", "1"] stdout: StdioCollector { id: output } stderr: StdioCollector { id: errors } onExited: code => { if (code !== 0) { if (code === 126 || code === 127) { root.fail("Cannot run external-gatherbuddy. Make sure it is installed and available on Quickshell’s PATH."); } else { let message = errors.text.trim(); try { message = JSON.parse(message).error || message; } catch (error) { // Keep non-JSON stderr as plain text. } root.fail(`GatherBuddy report failed: ${message || `exit status ${code}`}`); } return; } try { root.applyReport(output.text); } catch (error) { root.fail(`invalid report: ${error}`); } } }}