From c4eeff7e503614227a21e4994325c7f707db54ac Mon Sep 17 00:00:00 2001 From: Uyanide Date: Mon, 13 Oct 2025 03:55:12 +0200 Subject: [PATCH] quickshell: ip monitor addr route --- quickshell/Services/IpService.qml | 62 +++++++++++++++++++--------- quickshell/Services/NetworkFetch.qml | 5 +-- 2 files changed, 45 insertions(+), 22 deletions(-) diff --git a/quickshell/Services/IpService.qml b/quickshell/Services/IpService.qml index 9a92395..a48f0ee 100644 --- a/quickshell/Services/IpService.qml +++ b/quickshell/Services/IpService.qml @@ -8,7 +8,7 @@ pragma Singleton Singleton { property alias ip: cacheFileAdapter.ip property string countryCode: "N/A" - property real fetchInterval: 30 // in s + property real fetchInterval: 120 // in s property real fetchTimeout: 10 // in s property string ipURL: "https://api.uyanide.com/ip" property string geoURL: "https://api.ipinfo.io/lite/" @@ -24,9 +24,7 @@ Singleton { Logger.log("IpService", "Fetched IP: " + newIP); if (newIP !== ip) { ip = newIP; - fetchGeoInfo(); // Fetch geo info only if IP has changed - SendNotification.show("New IP", `IP: ${ip}\nCountry: ${countryCode}`); - cacheFile.writeAdapter(); + fetchGeoInfo(true); // Fetch geo info only if IP has changed } } else { ip = "N/A"; @@ -46,7 +44,7 @@ Singleton { }); } - function fetchGeoInfo() { + function fetchGeoInfo(notify) { if (!ip || ip === "N/A") { countryCode = "N/A"; return ; @@ -62,9 +60,7 @@ Singleton { if (response && response.country_code) { let newCountryCode = response.country_code; Logger.log("IpService", "Fetched country code: " + newCountryCode); - if (newCountryCode !== countryCode) - countryCode = newCountryCode; - + countryCode = newCountryCode; } else { countryCode = "N/A"; Logger.error("IpService", "Geo response does not contain 'country_code' field"); @@ -79,6 +75,8 @@ Singleton { countryCode = "N/A"; Logger.error("IpService", "Failed to fetch geo info"); } + SendNotification.show("New IP", `IP: ${ip}\nCountry: ${countryCode}`); + cacheFile.writeAdapter(); }); } @@ -96,6 +94,43 @@ Singleton { id: curl } + Process { + id: ipMonitor + + command: ["ip", "monitor", "address", "route"] + running: true + + stdout: SplitParser { + splitMarker: "\n" + onRead: { + ipMonitorDebounce.restart(); + } + } + + } + + Timer { + id: ipMonitorDebounce + + interval: 1000 + repeat: false + running: false + onTriggered: { + refresh(); + } + } + + Timer { + id: fetchTimer + + interval: fetchInterval * 1000 + repeat: true + running: true + onTriggered: { + fetchIP(); + } + } + FileView { id: tokenFile @@ -132,15 +167,4 @@ Singleton { } - Timer { - id: fetchTimer - - interval: fetchInterval * 1000 - repeat: true - running: false - onTriggered: { - fetchIP(); - } - } - } diff --git a/quickshell/Services/NetworkFetch.qml b/quickshell/Services/NetworkFetch.qml index e2e20e0..f9fbed1 100644 --- a/quickshell/Services/NetworkFetch.qml +++ b/quickshell/Services/NetworkFetch.qml @@ -12,7 +12,7 @@ Item { function fetch(url, callback) { if (curlProcess.running) { - Logger.log("NetworkFetch", "A fetch operation is already in progress."); + Logger.warn("NetworkFetch", "A fetch operation is already in progress."); return ; } fetchedData = ""; @@ -23,7 +23,7 @@ Item { function fakeFetch(resp, callback) { if (curlProcess.running) { - Logger.log("NetworkFetch", "A fetch operation is already in progress."); + Logger.warn("NetworkFetch", "A fetch operation is already in progress."); return ; } fetchedData = ""; @@ -45,7 +45,6 @@ Item { return ; } if (exitCode === 0) { - Logger.log("NetworkFetch", "Fetch completed successfully."); Logger.log("NetworkFetch", "Fetched data: " + fetchedData); fetchingCallback(true, fetchedData); } else {