Skip to content

Commit 59cd569

Browse files
committed
deep links + make everything persist
1 parent baaff6b commit 59cd569

15 files changed

Lines changed: 341 additions & 46 deletions

File tree

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@fortawesome/free-solid-svg-icons": "^7.1.0",
1616
"@fortawesome/react-fontawesome": "^3.1.1",
1717
"@tauri-apps/api": "^2.10.1",
18+
"@tauri-apps/plugin-deep-link": "^2.4.8",
1819
"@tauri-apps/plugin-opener": "^2",
1920
"@tauri-apps/plugin-process": "^2.3.1",
2021
"@tauri-apps/plugin-updater": "^2.10.0",

src-tauri/Cargo.lock

Lines changed: 120 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ tauri-plugin-opener = "2"
3030
tauri-plugin-notification = "2"
3131
tauri-plugin-updater = "2"
3232
tauri-plugin-process = "2"
33+
tauri-plugin-deep-link = "2"
34+
tauri-plugin-single-instance = "2"
3335
serde = { version = "1", features = ["derive"] }
3436
serde_json = "1"
3537
reqwest = { version = "0.12", features = ["blocking", "json"] }

src-tauri/capabilities/default.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"core:window:allow-start-dragging",
1313
"core:path:default",
1414
"updater:default",
15-
"process:allow-restart"
15+
"process:allow-restart",
16+
"deep-link:default"
1617
]
1718
}

src-tauri/src/lib.rs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub const DEFAULT_STEAM_NAME: &str = "production";
2626

2727
mod webview2;
2828

29-
use tauri::Manager;
29+
use tauri::{Emitter, Manager};
3030

3131
use auth::{
3232
background_refresh_task, get_access_token, get_auth_state, get_hub_oauth_providers, hub_login,
@@ -46,7 +46,7 @@ use relays::{get_relays, get_selected_relay, set_selected_relay};
4646
use servers::get_servers;
4747
use settings::{
4848
get_settings, save_filter_settings, set_age_verified, set_auth_mode, set_last_played_server,
49-
set_locale, set_rendering_pipeline, set_theme, toggle_favorite_server,
49+
set_last_view_mode, set_locale, set_rendering_pipeline, set_theme, toggle_favorite_server,
5050
toggle_server_notifications,
5151
};
5252

@@ -191,6 +191,7 @@ pub fn build_specta() -> tauri_specta::Builder<tauri::Wry> {
191191
toggle_server_notifications,
192192
set_rendering_pipeline,
193193
set_last_played_server,
194+
set_last_view_mode,
194195
toggle_favorite_server,
195196
save_filter_settings,
196197
get_control_server_port,
@@ -252,6 +253,7 @@ pub fn build_specta() -> tauri_specta::Builder<tauri::Wry> {
252253
toggle_server_notifications,
253254
set_rendering_pipeline,
254255
set_last_played_server,
256+
set_last_view_mode,
255257
toggle_favorite_server,
256258
save_filter_settings,
257259
get_control_server_port,
@@ -287,6 +289,26 @@ pub fn build_specta() -> tauri_specta::Builder<tauri::Wry> {
287289
])
288290
}
289291

292+
#[cfg(target_os = "windows")]
293+
fn register_deep_link_protocol() -> Result<(), Box<dyn std::error::Error>> {
294+
use winreg::enums::HKEY_CURRENT_USER;
295+
use winreg::RegKey;
296+
297+
let exe_path = std::env::current_exe()?;
298+
let exe_str = exe_path.to_string_lossy();
299+
300+
let hkcu = RegKey::predef(HKEY_CURRENT_USER);
301+
let (key, _) = hkcu.create_subkey(r"Software\Classes\ss13")?;
302+
key.set_value("", &"SS13 Launcher")?;
303+
key.set_value("URL Protocol", &"")?;
304+
305+
let (command_key, _) = hkcu.create_subkey(r"Software\Classes\ss13\shell\open\command")?;
306+
command_key.set_value("", &format!("\"{exe_str}\" \"%1\""))?;
307+
308+
tracing::info!("Registered ss13:// protocol handler");
309+
Ok(())
310+
}
311+
290312
#[cfg_attr(mobile, tauri::mobile_entry_point)]
291313
pub fn run() {
292314
let _guard = logging::init_logging();
@@ -302,6 +324,10 @@ pub fn run() {
302324
let _ = open::that("https://go.microsoft.com/fwlink/p/?LinkId=2124703");
303325
std::process::exit(1);
304326
}
327+
328+
if let Err(e) = register_deep_link_protocol() {
329+
tracing::error!("Failed to register ss13:// protocol: {}", e);
330+
}
305331
}
306332

307333
let specta_builder = build_specta();
@@ -322,6 +348,22 @@ pub fn run() {
322348
.plugin(tauri_plugin_opener::init())
323349
.plugin(tauri_plugin_notification::init())
324350
.plugin(tauri_plugin_process::init())
351+
.plugin(tauri_plugin_deep_link::init())
352+
.plugin(tauri_plugin_single_instance::init(|app, argv, _cwd| {
353+
let deep_link_urls: Vec<String> = argv
354+
.iter()
355+
.filter(|arg| arg.starts_with("ss13://"))
356+
.cloned()
357+
.collect();
358+
359+
if !deep_link_urls.is_empty() {
360+
let _ = app.emit("deep-link://new-url", deep_link_urls);
361+
}
362+
363+
if let Some(window) = app.get_webview_window("main") {
364+
let _ = window.set_focus();
365+
}
366+
}))
325367
.invoke_handler(specta_builder.invoke_handler());
326368

327369
// Only include updater for non-CM builds (CM uses Steam for updates)

0 commit comments

Comments
 (0)