From 26f8a81d8bbeb09f79ac36f1a8cc9a2c5123c4f9 Mon Sep 17 00:00:00 2001 From: Uyanide Date: Mon, 20 Oct 2025 00:45:48 +0200 Subject: [PATCH] quickshell: ip aliases --- config/quickshell/Assets/Config/.gitignore | 3 +- config/quickshell/Modules/Bar/Bar.qml | 8 ++--- .../quickshell/Modules/Bar/Components/Ip.qml | 21 +++++++----- config/quickshell/Services/IpService.qml | 32 ++++++++++++++++++- 4 files changed, 48 insertions(+), 16 deletions(-) diff --git a/config/quickshell/Assets/Config/.gitignore b/config/quickshell/Assets/Config/.gitignore index 5f1b178..f287df1 100644 --- a/config/quickshell/Assets/Config/.gitignore +++ b/config/quickshell/Assets/Config/.gitignore @@ -1,2 +1,3 @@ # some sensitive files -GeoInfoToken.txt \ No newline at end of file +GeoInfoToken.txt +IpAliases.json \ No newline at end of file diff --git a/config/quickshell/Modules/Bar/Bar.qml b/config/quickshell/Modules/Bar/Bar.qml index afa666c..4a46ad6 100644 --- a/config/quickshell/Modules/Bar/Bar.qml +++ b/config/quickshell/Modules/Bar/Bar.qml @@ -85,7 +85,6 @@ Variants { symbol: Icons.distro buttonColor: Colors.distroColor onClicked: { - // PanelService.getPanel("controlCenterPanel")?.toggle(this) PanelService.getPanel("controlCenterPanel")?.toggle(this) } onRightClicked: { @@ -95,18 +94,15 @@ Variants { SymbolButton { symbol: SettingsService.wifiEnabled ? Icons.wifiOn : Icons.wifiOff - buttonColor: Colors.green + buttonColor: Colors.rosewater onClicked: { PanelService.getPanel("wifiPanel")?.toggle(this) } - onRightClicked: { - Quickshell.execDetached(["nm-connection-editor"]); - } } SymbolButton { symbol: BluetoothService.enabled ? Icons.bluetoothOn : Icons.bluetoothOff - buttonColor: Colors.peach + buttonColor: Colors.blue onClicked: { PanelService.getPanel("bluetoothPanel")?.toggle(this) } diff --git a/config/quickshell/Modules/Bar/Components/Ip.qml b/config/quickshell/Modules/Bar/Components/Ip.qml index e975d4c..19d8ef6 100644 --- a/config/quickshell/Modules/Bar/Components/Ip.qml +++ b/config/quickshell/Modules/Bar/Components/Ip.qml @@ -7,7 +7,9 @@ import qs.Services Item { id: root - property bool _showCountryCode: true + property int displayIndex: 0 + readonly property list displayTexts: [IpService.countryCode, IpService.ip, IpService.alias] + readonly property string displayText: displayTexts[displayIndex] implicitHeight: parent.height implicitWidth: layout.width + 10 @@ -35,8 +37,8 @@ Item { Text { id: ipText - text: _showCountryCode ? IpService.countryCode : IpService.ip - font.pointSize: _showCountryCode ? Fonts.medium : Fonts.small + text: displayText + font.pointSize: displayIndex === 0 ? Fonts.medium : Fonts.small font.family: Fonts.primary color: Colors.peach anchors.verticalCenter: parent.verticalCenter @@ -65,11 +67,14 @@ Item { acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton onClicked: (mouse) => { if (mouse.button === Qt.LeftButton) { - WriteClipboard.write(_showCountryCode ? IpService.countryCode : IpService.ip); - SendNotification.show("Copied to clipboard", _showCountryCode ? IpService.countryCode : IpService.ip); - } else if (mouse.button === Qt.RightButton) - _showCountryCode = !_showCountryCode; - else if (mouse.button === Qt.MiddleButton) + WriteClipboard.write(displayText); + SendNotification.show("Copied to clipboard", displayText); + } else if (mouse.button === Qt.RightButton){ + let iter = 0; + do { + displayIndex = (displayIndex + 1) % displayTexts.length; + } while (!displayTexts[displayIndex] && iter++ < displayTexts.length); + } else if (mouse.button === Qt.MiddleButton) IpService.refresh(); } } diff --git a/config/quickshell/Services/IpService.qml b/config/quickshell/Services/IpService.qml index 7cfa8a4..52cf565 100644 --- a/config/quickshell/Services/IpService.qml +++ b/config/quickshell/Services/IpService.qml @@ -8,7 +8,9 @@ pragma Singleton Singleton { property alias ip: cacheFileAdapter.ip readonly property string cacheFilePath: CacheService.ipCacheFile + readonly property string aliasFilePath: Qt.resolvedUrl("../Assets/Config/IpAliases.json") property string countryCode: "N/A" + property string alias: "" property real fetchInterval: 120 // in s property real fetchTimeout: 10 // in s readonly property string ipURL: "https://api.uyanide.com/ip" @@ -68,7 +70,7 @@ Singleton { } else { Logger.error("IpService", "Failed to fetch geo info"); } - SendNotification.show("New IP", `IP: ${ip}\nCountry: ${countryCode}`); + SendNotification.show("New IP", `IP: ${ip}\nCountry: ${countryCode}${alias ? `\nAlias: ${alias}` : ""}`); cacheFile.writeAdapter(); }); } @@ -82,6 +84,17 @@ Singleton { Component.onCompleted: { } + onIpChanged: { + alias = ""; + for (let i = 0; i < aliasFileAdapter.aliases.length; i++) { + let entry = aliasFileAdapter.aliases[i]; + if (entry.ip === ip) { + alias = entry.alias; + Logger.log("IpService", "Found alias for IP " + ip + ": " + alias); + break; + } + } + } NetworkFetch { id: curl @@ -162,4 +175,21 @@ Singleton { } + FileView { + id: aliasFile + + path: aliasFilePath + watchChanges: true + onLoaded: { + Logger.log("IpService", "Loaded IP aliases from file, total aliases: " + aliasFileAdapter.aliases.length); + } + + JsonAdapter { + id: aliasFileAdapter + + property var aliases: [] + } + + } + }