Skip to content

Commit 61cea6b

Browse files
authored
feat: distinguish normal instances and local scene development instances for deep links (#141)
* ignore lsd instances * recognize local-scene in deeplink; * apply clippy * use cmd_args to determine if local_scene
1 parent b00118f commit 61cea6b

File tree

6 files changed

+66
-123
lines changed

6 files changed

+66
-123
lines changed

core/Cargo.lock

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

core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ serde = { version = "1", features = ["derive"] }
3232
serde_json = "1"
3333
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls", "stream"] }
3434
regex = "1.11.1"
35+
url = "2.5.4"
3536
anyhow = "1.0.97"
3637

3738
futures-util = "0.3.14"

core/src/environment.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const ARG_OPEN_DEEPLINK_IN_NEW_INSTANCE: &str = "open-deeplink-in-new-instance";
1313
const ARG_ALWAYS_TRIGGER_UPDATER: &str = "always-trigger-updater";
1414
const ARG_NEVER_TRIGGER_UPDATER: &str = "never-trigger-updater";
1515
const ARG_USE_UPDATER_URL: &str = "use-updater-url";
16+
const ARG_LOCAL_SCENE: &str = "local-scene";
1617

1718
#[derive(Debug)]
1819
pub enum LauncherEnvironment {
@@ -32,6 +33,9 @@ pub struct Args {
3233
pub always_trigger_updater: bool,
3334
pub never_trigger_updater: bool,
3435
pub use_updater_url: Option<String>,
36+
37+
// used by the client
38+
pub local_scene: bool,
3539
}
3640

3741
impl Args {
@@ -47,6 +51,7 @@ impl Args {
4751
.use_updater_url
4852
.clone()
4953
.or_else(|| other.use_updater_url.clone()),
54+
local_scene: self.local_scene || other.local_scene,
5055
}
5156
}
5257

@@ -62,6 +67,7 @@ impl Args {
6267
always_trigger_updater: Self::has_flag(ARG_ALWAYS_TRIGGER_UPDATER, &vector),
6368
never_trigger_updater: Self::has_flag(ARG_NEVER_TRIGGER_UPDATER, &vector),
6469
use_updater_url: Self::value_by_flag(ARG_USE_UPDATER_URL, &vector),
70+
local_scene: Self::has_flag(ARG_LOCAL_SCENE, &vector),
6571
}
6672
}
6773

@@ -206,6 +212,7 @@ mod tests {
206212
always_trigger_updater: true,
207213
never_trigger_updater: false,
208214
use_updater_url: Some("https://one.com".into()),
215+
local_scene: false,
209216
};
210217

211218
let b = Args {
@@ -214,6 +221,7 @@ mod tests {
214221
always_trigger_updater: false,
215222
never_trigger_updater: true,
216223
use_updater_url: Some("https://two.com".into()),
224+
local_scene: false,
217225
};
218226

219227
let merged = a.merge_with(&b);
@@ -222,6 +230,7 @@ mod tests {
222230
assert!(merged.open_deeplink_in_new_instance);
223231
assert!(merged.always_trigger_updater);
224232
assert!(merged.never_trigger_updater);
233+
assert!(!merged.local_scene);
225234
// Should keep first if present
226235
assert_eq!(merged.use_updater_url.as_deref(), Some("https://one.com"));
227236
}

core/src/flow.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,13 @@ impl WorkflowStep<LaunchFlowState, ()> for AppLaunchStep {
425425

426426
match self.protocol.value() {
427427
Some(deeplink) => {
428-
let open_new_instance = AppEnvironment::cmd_args().open_deeplink_in_new_instance;
428+
let args = AppEnvironment::cmd_args();
429+
430+
let open_new_instance = args.open_deeplink_in_new_instance;
429431
let any_is_running = self.is_any_instance_running().await?;
430-
if !open_new_instance && any_is_running {
432+
let is_local_scene = deeplink.has_true_value("local-scene") || args.local_scene;
433+
434+
if !open_new_instance && any_is_running && !is_local_scene {
431435
channel.send(Status::State {
432436
step: Step::DeeplinkOpening,
433437
})?;

core/src/protocols.rs

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
use std::collections::HashMap;
12
use std::result::Result;
23
use std::sync::Mutex;
4+
use url::form_urlencoded;
35

46
use log::{error, warn};
57

@@ -14,23 +16,63 @@ pub enum DeepLinkCreateError {
1416
}
1517

1618
#[derive(Clone)]
17-
pub struct DeepLink(String);
19+
pub struct DeepLink {
20+
original: String,
21+
args: HashMap<String, String>,
22+
}
1823

1924
impl DeepLink {
2025
fn new(value: String) -> Result<Self, DeepLinkCreateError> {
2126
if value.starts_with(PROTOCOL_PREFIX) {
22-
Ok(Self(value))
27+
let args = Self::parsed_args(value.as_str());
28+
let result = Self {
29+
original: value,
30+
args,
31+
};
32+
Ok(result)
2333
} else {
2434
Err(DeepLinkCreateError::WrongPrefix {
2535
original_content: value,
2636
})
2737
}
2838
}
39+
40+
fn parsed_args(value: &str) -> HashMap<String, String> {
41+
let parts: Vec<&str> = value.splitn(2, "://").collect();
42+
43+
match parts.get(1) {
44+
Some(query) => {
45+
let scheme = parts.first().unwrap_or(&"unknown");
46+
log::info!("Deeplink scheme: {}", scheme);
47+
48+
let parsed = form_urlencoded::parse(query.as_bytes());
49+
let mut map: HashMap<String, String> = HashMap::new();
50+
51+
for (key, value) in parsed {
52+
map.insert(key.into_owned(), value.into_owned());
53+
}
54+
55+
map
56+
}
57+
None => {
58+
log::info!("Cannot get query from: {}", value);
59+
HashMap::new()
60+
}
61+
}
62+
}
63+
64+
pub fn has_true_value(&self, key: &str) -> bool {
65+
if let Some(value) = self.args.get(key) {
66+
value == "true"
67+
} else {
68+
false
69+
}
70+
}
2971
}
3072

3173
impl From<DeepLink> for String {
3274
fn from(deeplink: DeepLink) -> Self {
33-
deeplink.0
75+
deeplink.original
3476
}
3577
}
3678

src-tauri/Cargo.lock

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

0 commit comments

Comments
 (0)