quickshell: ip aliases

This commit is contained in:
2025-10-20 00:45:48 +02:00
parent a443546b2f
commit 26f8a81d8b
4 changed files with 48 additions and 16 deletions

View File

@@ -1,2 +1,3 @@
# some sensitive files # some sensitive files
GeoInfoToken.txt GeoInfoToken.txt
IpAliases.json

View File

@@ -85,7 +85,6 @@ Variants {
symbol: Icons.distro symbol: Icons.distro
buttonColor: Colors.distroColor buttonColor: Colors.distroColor
onClicked: { onClicked: {
// PanelService.getPanel("controlCenterPanel")?.toggle(this)
PanelService.getPanel("controlCenterPanel")?.toggle(this) PanelService.getPanel("controlCenterPanel")?.toggle(this)
} }
onRightClicked: { onRightClicked: {
@@ -95,18 +94,15 @@ Variants {
SymbolButton { SymbolButton {
symbol: SettingsService.wifiEnabled ? Icons.wifiOn : Icons.wifiOff symbol: SettingsService.wifiEnabled ? Icons.wifiOn : Icons.wifiOff
buttonColor: Colors.green buttonColor: Colors.rosewater
onClicked: { onClicked: {
PanelService.getPanel("wifiPanel")?.toggle(this) PanelService.getPanel("wifiPanel")?.toggle(this)
} }
onRightClicked: {
Quickshell.execDetached(["nm-connection-editor"]);
}
} }
SymbolButton { SymbolButton {
symbol: BluetoothService.enabled ? Icons.bluetoothOn : Icons.bluetoothOff symbol: BluetoothService.enabled ? Icons.bluetoothOn : Icons.bluetoothOff
buttonColor: Colors.peach buttonColor: Colors.blue
onClicked: { onClicked: {
PanelService.getPanel("bluetoothPanel")?.toggle(this) PanelService.getPanel("bluetoothPanel")?.toggle(this)
} }

View File

@@ -7,7 +7,9 @@ import qs.Services
Item { Item {
id: root id: root
property bool _showCountryCode: true property int displayIndex: 0
readonly property list<string> displayTexts: [IpService.countryCode, IpService.ip, IpService.alias]
readonly property string displayText: displayTexts[displayIndex]
implicitHeight: parent.height implicitHeight: parent.height
implicitWidth: layout.width + 10 implicitWidth: layout.width + 10
@@ -35,8 +37,8 @@ Item {
Text { Text {
id: ipText id: ipText
text: _showCountryCode ? IpService.countryCode : IpService.ip text: displayText
font.pointSize: _showCountryCode ? Fonts.medium : Fonts.small font.pointSize: displayIndex === 0 ? Fonts.medium : Fonts.small
font.family: Fonts.primary font.family: Fonts.primary
color: Colors.peach color: Colors.peach
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
@@ -65,11 +67,14 @@ Item {
acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
onClicked: (mouse) => { onClicked: (mouse) => {
if (mouse.button === Qt.LeftButton) { if (mouse.button === Qt.LeftButton) {
WriteClipboard.write(_showCountryCode ? IpService.countryCode : IpService.ip); WriteClipboard.write(displayText);
SendNotification.show("Copied to clipboard", _showCountryCode ? IpService.countryCode : IpService.ip); SendNotification.show("Copied to clipboard", displayText);
} else if (mouse.button === Qt.RightButton) } else if (mouse.button === Qt.RightButton){
_showCountryCode = !_showCountryCode; let iter = 0;
else if (mouse.button === Qt.MiddleButton) do {
displayIndex = (displayIndex + 1) % displayTexts.length;
} while (!displayTexts[displayIndex] && iter++ < displayTexts.length);
} else if (mouse.button === Qt.MiddleButton)
IpService.refresh(); IpService.refresh();
} }
} }

View File

@@ -8,7 +8,9 @@ pragma Singleton
Singleton { Singleton {
property alias ip: cacheFileAdapter.ip property alias ip: cacheFileAdapter.ip
readonly property string cacheFilePath: CacheService.ipCacheFile readonly property string cacheFilePath: CacheService.ipCacheFile
readonly property string aliasFilePath: Qt.resolvedUrl("../Assets/Config/IpAliases.json")
property string countryCode: "N/A" property string countryCode: "N/A"
property string alias: ""
property real fetchInterval: 120 // in s property real fetchInterval: 120 // in s
property real fetchTimeout: 10 // in s property real fetchTimeout: 10 // in s
readonly property string ipURL: "https://api.uyanide.com/ip" readonly property string ipURL: "https://api.uyanide.com/ip"
@@ -68,7 +70,7 @@ Singleton {
} else { } else {
Logger.error("IpService", "Failed to fetch geo info"); 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(); cacheFile.writeAdapter();
}); });
} }
@@ -82,6 +84,17 @@ Singleton {
Component.onCompleted: { 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 { NetworkFetch {
id: curl 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: []
}
}
} }