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
GeoInfoToken.txt
IpAliases.json

View File

@@ -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)
}

View File

@@ -7,7 +7,9 @@ import qs.Services
Item {
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
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();
}
}

View File

@@ -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: []
}
}
}