Skip to content

Commit

Permalink
handle uri scheme when app is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyrAhmady committed Aug 17, 2024
1 parent cefcb14 commit bd2646f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
14 changes: 10 additions & 4 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::sync::Mutex;

use gumdrop::Options;
use injector::run_samp;
use log::{error, LevelFilter};
use log::{error, info, LevelFilter};
use tauri::Manager;
use tauri::PhysicalSize;

Expand Down Expand Up @@ -104,7 +104,12 @@ Options:
}
}
Err(e) => {
println!("{}", e);
if raw_args[1].contains("omp://") || raw_args[1].contains("samp://") {
let mut uri_scheme_value = URI_SCHEME_VALUE.lock().unwrap();
*uri_scheme_value = String::from(raw_args[1].as_str());
} else {
info!("Unknown argument has been passed: {}", e);
}
}
};

Expand Down Expand Up @@ -135,15 +140,16 @@ Options:
tauri_plugin_deep_link::register("omp", move |request| {
dbg!(&request);
let mut uri_scheme_value = URI_SCHEME_VALUE.lock().unwrap();
*uri_scheme_value = request.clone();
*uri_scheme_value = String::from(request.as_str());
handle.emit_all("scheme-request-received", request).unwrap();
})
.unwrap();

tauri_plugin_deep_link::register("samp", move |request| {
dbg!(&request);
let mut uri_scheme_value = URI_SCHEME_VALUE.lock().unwrap();
*uri_scheme_value = request.clone();
(*uri_scheme_value).clone_from(&request);
*uri_scheme_value = String::from(request.as_str());
handle2
.emit_all("scheme-request-received", request)
.unwrap();
Expand Down
34 changes: 19 additions & 15 deletions src/containers/ExternalServerHandler/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,25 @@ const ExternalServerHandler = () => {
const { addToFavorites } = usePersistentServers();

useEffect(() => {
(async () => {
const value = await invoke<string>("get_uri_scheme_value");
if (
value.length &&
(value.includes("omp://") || value.includes("samp://"))
) {
const serverAddress = value
.replace("omp://", "")
.replace("samp://", "")
.replace("/", "");

showModal(true);
setServerAddress(serverAddress);
}
})();
try {
(async () => {
const value = await invoke<string>("get_uri_scheme_value");
if (
value.length &&
(value.includes("omp://") || value.includes("samp://"))
) {
const serverAddress = value
.replace("omp://", "")
.replace("samp://", "")
.replace("/", "");

showModal(true);
setServerAddress(serverAddress);
}
})();
} catch (e) {
console.log(e);
}

const unlisten = listen<string>("scheme-request-received", (event) => {
if (typeof event.payload === "string") {
Expand Down

0 comments on commit bd2646f

Please sign in to comment.