quickshell: ip monitor addr route
This commit is contained in:
@@ -8,7 +8,7 @@ pragma Singleton
|
|||||||
Singleton {
|
Singleton {
|
||||||
property alias ip: cacheFileAdapter.ip
|
property alias ip: cacheFileAdapter.ip
|
||||||
property string countryCode: "N/A"
|
property string countryCode: "N/A"
|
||||||
property real fetchInterval: 30 // in s
|
property real fetchInterval: 120 // in s
|
||||||
property real fetchTimeout: 10 // in s
|
property real fetchTimeout: 10 // in s
|
||||||
property string ipURL: "https://api.uyanide.com/ip"
|
property string ipURL: "https://api.uyanide.com/ip"
|
||||||
property string geoURL: "https://api.ipinfo.io/lite/"
|
property string geoURL: "https://api.ipinfo.io/lite/"
|
||||||
@@ -24,9 +24,7 @@ Singleton {
|
|||||||
Logger.log("IpService", "Fetched IP: " + newIP);
|
Logger.log("IpService", "Fetched IP: " + newIP);
|
||||||
if (newIP !== ip) {
|
if (newIP !== ip) {
|
||||||
ip = newIP;
|
ip = newIP;
|
||||||
fetchGeoInfo(); // Fetch geo info only if IP has changed
|
fetchGeoInfo(true); // Fetch geo info only if IP has changed
|
||||||
SendNotification.show("New IP", `IP: ${ip}\nCountry: ${countryCode}`);
|
|
||||||
cacheFile.writeAdapter();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ip = "N/A";
|
ip = "N/A";
|
||||||
@@ -46,7 +44,7 @@ Singleton {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchGeoInfo() {
|
function fetchGeoInfo(notify) {
|
||||||
if (!ip || ip === "N/A") {
|
if (!ip || ip === "N/A") {
|
||||||
countryCode = "N/A";
|
countryCode = "N/A";
|
||||||
return ;
|
return ;
|
||||||
@@ -62,9 +60,7 @@ Singleton {
|
|||||||
if (response && response.country_code) {
|
if (response && response.country_code) {
|
||||||
let newCountryCode = response.country_code;
|
let newCountryCode = response.country_code;
|
||||||
Logger.log("IpService", "Fetched country code: " + newCountryCode);
|
Logger.log("IpService", "Fetched country code: " + newCountryCode);
|
||||||
if (newCountryCode !== countryCode)
|
countryCode = newCountryCode;
|
||||||
countryCode = newCountryCode;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
countryCode = "N/A";
|
countryCode = "N/A";
|
||||||
Logger.error("IpService", "Geo response does not contain 'country_code' field");
|
Logger.error("IpService", "Geo response does not contain 'country_code' field");
|
||||||
@@ -79,6 +75,8 @@ Singleton {
|
|||||||
countryCode = "N/A";
|
countryCode = "N/A";
|
||||||
Logger.error("IpService", "Failed to fetch geo info");
|
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
|
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 {
|
FileView {
|
||||||
id: tokenFile
|
id: tokenFile
|
||||||
|
|
||||||
@@ -132,15 +167,4 @@ Singleton {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer {
|
|
||||||
id: fetchTimer
|
|
||||||
|
|
||||||
interval: fetchInterval * 1000
|
|
||||||
repeat: true
|
|
||||||
running: false
|
|
||||||
onTriggered: {
|
|
||||||
fetchIP();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ Item {
|
|||||||
|
|
||||||
function fetch(url, callback) {
|
function fetch(url, callback) {
|
||||||
if (curlProcess.running) {
|
if (curlProcess.running) {
|
||||||
Logger.log("NetworkFetch", "A fetch operation is already in progress.");
|
Logger.warn("NetworkFetch", "A fetch operation is already in progress.");
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
fetchedData = "";
|
fetchedData = "";
|
||||||
@@ -23,7 +23,7 @@ Item {
|
|||||||
|
|
||||||
function fakeFetch(resp, callback) {
|
function fakeFetch(resp, callback) {
|
||||||
if (curlProcess.running) {
|
if (curlProcess.running) {
|
||||||
Logger.log("NetworkFetch", "A fetch operation is already in progress.");
|
Logger.warn("NetworkFetch", "A fetch operation is already in progress.");
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
fetchedData = "";
|
fetchedData = "";
|
||||||
@@ -45,7 +45,6 @@ Item {
|
|||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
if (exitCode === 0) {
|
if (exitCode === 0) {
|
||||||
Logger.log("NetworkFetch", "Fetch completed successfully.");
|
|
||||||
Logger.log("NetworkFetch", "Fetched data: " + fetchedData);
|
Logger.log("NetworkFetch", "Fetched data: " + fetchedData);
|
||||||
fetchingCallback(true, fetchedData);
|
fetchingCallback(true, fetchedData);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user