Added error handling in Geolocate API

This commit is contained in:
brotoskyj
2025-02-24 19:45:26 +00:00
parent 768ad21449
commit 6cc8e9bfe3
7 changed files with 231 additions and 27 deletions
Generated
+186 -8
View File
@@ -34,7 +34,7 @@ dependencies = [
"accesskit_consumer", "accesskit_consumer",
"atspi-common", "atspi-common",
"serde", "serde",
"thiserror", "thiserror 1.0.69",
"zvariant", "zvariant",
] ]
@@ -171,7 +171,7 @@ dependencies = [
"ndk-context", "ndk-context",
"ndk-sys", "ndk-sys",
"num_enum", "num_enum",
"thiserror", "thiserror 1.0.69",
] ]
[[package]] [[package]]
@@ -629,7 +629,7 @@ dependencies = [
"polling", "polling",
"rustix", "rustix",
"slab", "slab",
"thiserror", "thiserror 1.0.69",
] ]
[[package]] [[package]]
@@ -710,8 +710,10 @@ version = "0.1.0"
dependencies = [ dependencies = [
"reqwest", "reqwest",
"serde_json", "serde_json",
"simple-ldap",
"slint", "slint",
"slint-build", "slint-build",
"tokio",
] ]
[[package]] [[package]]
@@ -1065,6 +1067,24 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c297a1c74b71ae29df00c3e22dd9534821d60eb9af5a0192823fa2acea70c2a" checksum = "5c297a1c74b71ae29df00c3e22dd9534821d60eb9af5a0192823fa2acea70c2a"
[[package]]
name = "deadpool"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb84100978c1c7b37f09ed3ce3e5f843af02c2a2c431bae5b19230dad2c1b490"
dependencies = [
"async-trait",
"deadpool-runtime",
"num_cpus",
"tokio",
]
[[package]]
name = "deadpool-runtime"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "092966b41edc516079bdf31ec78a2e0588d1d0c08f78b91d8307215928642b2b"
[[package]] [[package]]
name = "derive_more" name = "derive_more"
version = "1.0.0" version = "1.0.0"
@@ -2510,7 +2530,7 @@ dependencies = [
"combine", "combine",
"jni-sys", "jni-sys",
"log", "log",
"thiserror", "thiserror 1.0.69",
"walkdir", "walkdir",
"windows-sys 0.45.0", "windows-sys 0.45.0",
] ]
@@ -2583,6 +2603,40 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "lber"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2df7f9fd9f64cf8f59e1a4a0753fe7d575a5b38d3d7ac5758dcee9357d83ef0a"
dependencies = [
"bytes",
"nom",
]
[[package]]
name = "ldap3"
version = "0.11.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "166199a8207874a275144c8a94ff6eed5fcbf5c52303e4d9b4d53a0c7ac76554"
dependencies = [
"async-trait",
"bytes",
"futures",
"futures-util",
"lazy_static",
"lber",
"log",
"native-tls",
"nom",
"percent-encoding",
"thiserror 1.0.69",
"tokio",
"tokio-native-tls",
"tokio-stream",
"tokio-util",
"url",
]
[[package]] [[package]]
name = "lebe" name = "lebe"
version = "0.5.2" version = "0.5.2"
@@ -2674,6 +2728,16 @@ version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104" checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104"
[[package]]
name = "lock_api"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17"
dependencies = [
"autocfg",
"scopeguard",
]
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.25" version = "0.4.25"
@@ -2703,7 +2767,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ca94c7bf1e2557c2798989c43416822c12fc5dcc5e17cc3307ef0e71894a955" checksum = "1ca94c7bf1e2557c2798989c43416822c12fc5dcc5e17cc3307ef0e71894a955"
dependencies = [ dependencies = [
"lyon_path", "lyon_path",
"thiserror", "thiserror 1.0.69",
] ]
[[package]] [[package]]
@@ -2822,7 +2886,7 @@ dependencies = [
"ndk-sys", "ndk-sys",
"num_enum", "num_enum",
"raw-window-handle", "raw-window-handle",
"thiserror", "thiserror 1.0.69",
] ]
[[package]] [[package]]
@@ -2873,6 +2937,16 @@ dependencies = [
"libm", "libm",
] ]
[[package]]
name = "num_cpus"
version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43"
dependencies = [
"hermit-abi 0.3.9",
"libc",
]
[[package]] [[package]]
name = "num_enum" name = "num_enum"
version = "0.7.3" version = "0.7.3"
@@ -3198,6 +3272,15 @@ dependencies = [
"libredox", "libredox",
] ]
[[package]]
name = "ordered-float"
version = "2.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68f19d67e5a2795c94e73e0bb1cc1a7edeb2e28efd39e2e1c9b7a40c1108b11c"
dependencies = [
"num-traits",
]
[[package]] [[package]]
name = "ordered-stream" name = "ordered-stream"
version = "0.2.0" version = "0.2.0"
@@ -3223,6 +3306,29 @@ version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba"
[[package]]
name = "parking_lot"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
dependencies = [
"cfg-if",
"libc",
"redox_syscall 0.5.8",
"smallvec",
"windows-targets 0.52.6",
]
[[package]] [[package]]
name = "paste" name = "paste"
version = "1.0.15" version = "1.0.15"
@@ -3850,6 +3956,16 @@ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]]
name = "serde-value"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3a1a3341211875ef120e117ea7fd5228530ae7e7036a779fdc9117be6b3282c"
dependencies = [
"ordered-float",
"serde",
]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.217" version = "1.0.217"
@@ -3937,6 +4053,23 @@ version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe"
[[package]]
name = "simple-ldap"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a44f48965194c331276aef5f7328bf4d30d64113289c1211fddade9968166d56"
dependencies = [
"async-trait",
"deadpool",
"futures",
"ldap3",
"log",
"serde",
"serde-value",
"serde_json",
"thiserror 2.0.11",
]
[[package]] [[package]]
name = "simplecss" name = "simplecss"
version = "0.2.2" version = "0.2.2"
@@ -4063,7 +4196,7 @@ dependencies = [
"log", "log",
"memmap2", "memmap2",
"rustix", "rustix",
"thiserror", "thiserror 1.0.69",
"wayland-backend", "wayland-backend",
"wayland-client", "wayland-client",
"wayland-csd-frame", "wayland-csd-frame",
@@ -4326,7 +4459,16 @@ version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
dependencies = [ dependencies = [
"thiserror-impl", "thiserror-impl 1.0.69",
]
[[package]]
name = "thiserror"
version = "2.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc"
dependencies = [
"thiserror-impl 2.0.11",
] ]
[[package]] [[package]]
@@ -4340,6 +4482,17 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "thiserror-impl"
version = "2.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "tiff" name = "tiff"
version = "0.9.1" version = "0.9.1"
@@ -4425,11 +4578,25 @@ dependencies = [
"bytes", "bytes",
"libc", "libc",
"mio", "mio",
"parking_lot",
"pin-project-lite", "pin-project-lite",
"signal-hook-registry",
"socket2", "socket2",
"tokio-macros",
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
[[package]]
name = "tokio-macros"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "tokio-native-tls" name = "tokio-native-tls"
version = "0.3.1" version = "0.3.1"
@@ -4450,6 +4617,17 @@ dependencies = [
"tokio", "tokio",
] ]
[[package]]
name = "tokio-stream"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eca58d7bba4a75707817a2c44174253f9236b2d5fbd055602e9d5c07c139a047"
dependencies = [
"futures-core",
"pin-project-lite",
"tokio",
]
[[package]] [[package]]
name = "tokio-util" name = "tokio-util"
version = "0.7.13" version = "0.7.13"
+2
View File
@@ -6,7 +6,9 @@ edition = "2021"
[dependencies] [dependencies]
reqwest = { version = "0.12.12", features = ["blocking"] } reqwest = { version = "0.12.12", features = ["blocking"] }
serde_json = "1.0.137" serde_json = "1.0.137"
simple-ldap = "2.1.1"
slint = "1.9.2" slint = "1.9.2"
tokio = { version = "1.43.0", features = ["full"] }
[build-dependencies] [build-dependencies]
slint-build = "1.9.2" slint-build = "1.9.2"
+29 -19
View File
@@ -10,23 +10,33 @@ pub fn kill_cherwell() {
pub fn ip_gelocate_api(app: MainWindow) { pub fn ip_gelocate_api(app: MainWindow) {
let mut url: String = String::from("http://ip-api.com/json/"); let mut url: String = String::from("http://ip-api.com/json/");
url.push_str(&app.global::<OtherToolCallbacks>().get_ipaddressbar()); url.push_str(&app.global::<OtherToolCallbacks>().get_ipaddressbar());
let resp: String = reqwest::blocking::get(url) let resp: Result<reqwest::blocking::Response, reqwest::Error> = reqwest::blocking::get(url);
.unwrap() match &resp {
.text() Err(_e) => {
.ok() app.global::<OtherToolCallbacks>()
.unwrap() .set_isp(slint::SharedString::from("Failed to resolve IP/URL"));
.into(); app.global::<OtherToolCallbacks>()
let parsed: Value = serde_json::from_str(&resp).unwrap(); .set_country(slint::SharedString::from("Failed to resolve IP/URL"));
let isp: slint::SharedString = parsed["isp"].to_shared_string(); app.global::<OtherToolCallbacks>()
let country: slint::SharedString = parsed["country"].to_shared_string(); .set_state(slint::SharedString::from("Failed to resolve IP/URL"));
let region: slint::SharedString = parsed["regionName"].to_shared_string(); app.global::<OtherToolCallbacks>()
let city: slint::SharedString = parsed["city"].to_shared_string(); .set_city(slint::SharedString::from("Failed to resolve IP/URL"));
app.global::<OtherToolCallbacks>() }
.set_isp(slint::SharedString::from(isp)); Ok(_t) => {
app.global::<OtherToolCallbacks>() let result: String = resp.unwrap().text().unwrap().into();
.set_country(slint::SharedString::from(country)); let parsed: Value = serde_json::from_str(&result).unwrap();
app.global::<OtherToolCallbacks>() let isp: slint::SharedString = parsed["isp"].to_shared_string();
.set_state(slint::SharedString::from(region)); let country: slint::SharedString = parsed["country"].to_shared_string();
app.global::<OtherToolCallbacks>() let region: slint::SharedString = parsed["regionName"].to_shared_string();
.set_city(slint::SharedString::from(city)); let city: slint::SharedString = parsed["city"].to_shared_string();
app.global::<OtherToolCallbacks>()
.set_isp(slint::SharedString::from(isp));
app.global::<OtherToolCallbacks>()
.set_country(slint::SharedString::from(country));
app.global::<OtherToolCallbacks>()
.set_state(slint::SharedString::from(region));
app.global::<OtherToolCallbacks>()
.set_city(slint::SharedString::from(city));
}
}
} }
+4
View File
@@ -1,5 +1,9 @@
import { AboutSlint, VerticalBox, GridBox, Button, LineEdit, HorizontalBox, TextEdit, SpinBox } from "std-widgets.slint"; import { AboutSlint, VerticalBox, GridBox, Button, LineEdit, HorizontalBox, TextEdit, SpinBox } from "std-widgets.slint";
export global ComputerModuleCallbacks {
pure callback killCherwell();
}
export component ComputerModules inherits Window { export component ComputerModules inherits Window {
VerticalLayout { VerticalLayout {
spacing: 5px; spacing: 5px;
+7
View File
@@ -1,5 +1,9 @@
import { AboutSlint, VerticalBox, GridBox, Button, LineEdit, HorizontalBox, TextEdit, SpinBox, StandardListView } from "std-widgets.slint"; import { AboutSlint, VerticalBox, GridBox, Button, LineEdit, HorizontalBox, TextEdit, SpinBox, StandardListView } from "std-widgets.slint";
export global UserModuleCallbacks {
pure callback searchUser();
}
export component UserModules inherits Window { export component UserModules inherits Window {
VerticalLayout { VerticalLayout {
spacing: 5px; spacing: 5px;
@@ -29,6 +33,9 @@ export component UserModules inherits Window {
Button { Button {
text: "Search"; text: "Search";
primary: true; primary: true;
clicked => {
UserModuleCallbacks.searchUser();
}
} }
} }
+2
View File
@@ -4,6 +4,8 @@ import { ComputerModules } from "pages/computermodules.slint";
import { OtherTools } from "pages/othertools.slint"; import { OtherTools } from "pages/othertools.slint";
import { SettingsModules } from "pages/settings.slint"; import { SettingsModules } from "pages/settings.slint";
import { SideBar } from "sidebar.slint"; import { SideBar } from "sidebar.slint";
export { UserModuleCallbacks } from "pages/usermodules.slint";
export { ComputerModuleCallbacks } from "pages/computermodules.slint";
export { OtherToolCallbacks } from "pages/othertools.slint"; export { OtherToolCallbacks } from "pages/othertools.slint";
export component MainWindow inherits Window { export component MainWindow inherits Window {
+1
View File
@@ -0,0 +1 @@
pub mod other