pragma ComponentBehavior: Bound import ".." import "../components" import QtQuick import Quickshell import 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}`); } } } }