|
| 1 | +import QtQuick |
| 2 | +import Quickshell |
| 3 | +import qs.Commons |
| 4 | +import qs.Widgets |
| 5 | +import qs.Services.UI |
| 6 | + |
| 7 | +NIconButtonHot { |
| 8 | + id: root |
| 9 | + |
| 10 | + property ShellScreen screen |
| 11 | + property var pluginApi: null |
| 12 | + property var main: pluginApi?.mainInstance ?? null |
| 13 | + |
| 14 | + readonly property string status: { |
| 15 | + if (!main || main.haToken === "") |
| 16 | + return "Unconfigured"; |
| 17 | + if (main.authFailed) |
| 18 | + return "AuthFailed"; |
| 19 | + if (main.authenticated) |
| 20 | + return "Connected"; |
| 21 | + if (main.isReconnecting) |
| 22 | + return "Disconnected"; |
| 23 | + return "Connecting"; |
| 24 | + } |
| 25 | + |
| 26 | + icon: "smart-home" |
| 27 | + colorFg: { |
| 28 | + switch (status) { |
| 29 | + case "Connected": return Color.mPrimary; |
| 30 | + case "Connecting": return Color.mOnError; |
| 31 | + case "Disconnected": return Color.mError; |
| 32 | + case "AuthFailed": return Color.mError; |
| 33 | + default: return Color.mOnSurfaceVariant; |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + tooltipText: { |
| 38 | + switch (status) { |
| 39 | + case "Connected": return pluginApi?.tr("widget.status_connected"); |
| 40 | + case "Connecting": return pluginApi?.tr("widget.status_connecting"); |
| 41 | + case "Disconnected": return pluginApi?.tr("widget.status_disconnected"); |
| 42 | + case "AuthFailed": return pluginApi?.tr("widget.status_auth_failed"); |
| 43 | + default: return pluginApi?.tr("widget.status_unconfigured"); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + onClicked: { |
| 48 | + if (pluginApi) |
| 49 | + pluginApi.togglePanel(screen); |
| 50 | + } |
| 51 | + |
| 52 | + onRightClicked: { |
| 53 | + if (pluginApi && pluginApi.manifest) |
| 54 | + BarService.openPluginSettings(screen, pluginApi.manifest); |
| 55 | + } |
| 56 | + |
| 57 | + SequentialAnimation on opacity { |
| 58 | + running: status === "Connecting" |
| 59 | + loops: Animation.Infinite |
| 60 | + |
| 61 | + NumberAnimation { to: 0.4; duration: 600; easing.type: Easing.InOutSine } |
| 62 | + NumberAnimation { to: 1.0; duration: 600; easing.type: Easing.InOutSine } |
| 63 | + } |
| 64 | +} |
0 commit comments