Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(mobile): fix url link sharing + deep linking (#1123)

teod2d12ea51951
diff --git a/js/app/packages/core/util/url.ts b/js/app/packages/core/util/url.ts
index 7f9702a6b6..64be958b71 100644
--- a/js/app/packages/core/util/url.ts
+++ b/js/app/packages/core/util/url.ts
@@ -1,4 +1,5 @@
import { fileTypeToBlockName } from '@core/constant/allBlocks';
+import { isTauri } from './platform';
import shortuuid from 'short-uuid';
const short = shortuuid(shortuuid.constants.flickrBase58, {
@@ -17,6 +18,15 @@ export function openExternalUrl(url: string) {
window.open(url, '_blank', 'noopener,noreferrer')?.focus();
}
+function getWebOrigin(): string {
+ if (isTauri()) {
+ return import.meta.env.MODE === 'development'
+ ? 'https://dev.macro.com'
+ : 'https://macro.com';
+ }
+ return window.location.origin;
+}
+
export function transformShortIdInUrlPathname(pathname: string) {
const parts = pathname.split('/');
const newParts = [];
@@ -37,7 +47,7 @@ export function buildSimpleEntityUrl(
entity: { type: string; id: string },
params: Record<string, any>
): string {
- const urlString = `${window.location.origin}/app/${entity.type}/${entity.id}`;
+ const urlString = `${getWebOrigin()}/app/${entity.type}/${entity.id}`;
const url = new URL(urlString);
for (const [key, value] of Object.entries(params)) {
url.searchParams.set(key, value);
diff --git a/js/app/tauri/navigation_plugin/src/scheme.rs b/js/app/tauri/navigation_plugin/src/scheme.rs
index 60d26aafdb..a2e4779c50 100644
--- a/js/app/tauri/navigation_plugin/src/scheme.rs
+++ b/js/app/tauri/navigation_plugin/src/scheme.rs
@@ -21,7 +21,7 @@ impl MacroScheme {
}
/// turn a http(s) url into a macro scheme url
#[tracing::instrument(err, ret)]
- pub(crate) fn from_url(url: &Url) -> Result<Self, SchemeError> {
+ pub fn from_url(url: &Url) -> Result<Self, SchemeError> {
let ("http" | "https" | "tauri") = url.scheme() else {
return Err(SchemeError::InvalidScheme {
expected: "http(s) or tauri".to_string(),
@@ -29,11 +29,15 @@ impl MacroScheme {
});
};
- let rest = url.fragment().unwrap_or(url.path()).trim_start_matches('/');
+ let mut rest = url.fragment().unwrap_or(url.path()).trim_start_matches('/');
+ // Mobile router uses '/' as base, so strip the 'app/' prefix from universal links
+ if rest.starts_with("app/") {
+ rest = &rest[4..];
+ }
let query = url.query();
let inner = match query {
- Some(q) => format!("macro://{rest}?{q}"),
- None => format!("macro://{rest}"),
+ Some(q) => format!("macro:///{rest}?{q}"),
+ None => format!("macro:///{rest}"),
}
.parse::<Url>()?;
Ok(MacroScheme(inner))
diff --git a/js/app/tauri/navigation_plugin/src/tests.rs b/js/app/tauri/navigation_plugin/src/tests.rs
index d68c2c1a45..b93e6efb3a 100644
--- a/js/app/tauri/navigation_plugin/src/tests.rs
+++ b/js/app/tauri/navigation_plugin/src/tests.rs
@@ -1,4 +1,28 @@
use super::*;
+use crate::scheme::MacroScheme;
+
+#[test]
+fn from_url_extracts_correct_path_from_universal_link() {
+ let url = Url::parse("https://macro.com/app/component/doc123").unwrap();
+ let result = MacroScheme::from_url(&url).unwrap();
+ assert_eq!(result.path(), "/component/doc123");
+ assert_eq!(result.query(), None);
+}
+
+#[test]
+fn from_url_extracts_path_and_query_from_universal_link() {
+ let url = Url::parse("https://macro.com/app/component/doc123?foo=bar").unwrap();
+ let result = MacroScheme::from_url(&url).unwrap();
+ assert_eq!(result.path(), "/component/doc123");
+ assert_eq!(result.query(), Some("foo=bar"));
+}
+
+#[test]
+fn from_url_handles_nested_path() {
+ let url = Url::parse("https://macro.com/app/component/nested/path/here").unwrap();
+ let result = MacroScheme::from_url(&url).unwrap();
+ assert_eq!(result.path(), "/component/nested/path/here");
+}
#[test]
fn transform_external_url_adds_is_mobile_when_query_exists() {
diff --git a/js/app/tauri/src-tauri/src/lib.rs b/js/app/tauri/src-tauri/src/lib.rs
index 4931029c88..ad256eea4d 100644
--- a/js/app/tauri/src-tauri/src/lib.rs
+++ b/js/app/tauri/src-tauri/src/lib.rs
@@ -178,7 +178,14 @@ fn attach_deep_link_handler(app: &mut tauri::App) {
.next()
.ok_or_else(|| report!("expected at least 1 url"))?;
- let macro_scheme = MacroScheme::new(url)?;
+ // Universal/App links come in as https:// URLs, custom scheme links come in as macro://
+ let macro_scheme = match url.scheme() {
+ "macro" => MacroScheme::new(url)?,
+ "http" | "https" => MacroScheme::from_url(&url)?,
+ scheme => {
+ return Err(report!("unexpected deep link scheme: {}", scheme));
+ }
+ };
#[derive(Clone, Serialize, Debug)]
struct NavigatePayload<'a> {