Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 116 additions & 1 deletion packages/desktop/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ tauri-build = { version = "2", features = [] }
tauri = { version = "2", features = [] }
tauri-plugin-http = "2"
tauri-plugin-shell = "2"
tauri-plugin-deep-link = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
35 changes: 18 additions & 17 deletions packages/desktop/src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Default capabilities for the OpenConcho desktop window",
"windows": ["main"],
"permissions": [
"core:default",
{
"identifier": "http:default",
"allow": [
{ "url": "http://*" },
{ "url": "http://*:*" },
{ "url": "https://*" },
{ "url": "https://*:*" }
]
},
"shell:allow-open"
]
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Default capabilities for the OpenConcho desktop window",
"windows": ["main"],
"permissions": [
"core:default",
{
"identifier": "http:default",
"allow": [
{ "url": "http://*" },
{ "url": "http://*:*" },
{ "url": "https://*" },
{ "url": "https://*:*" }
]
},
"shell:allow-open",
"deep-link:default"
]
}
1 change: 1 addition & 0 deletions packages/desktop/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_http::init())
.plugin(tauri_plugin_shell::init())
.plugin(tauri_plugin_deep_link::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
8 changes: 8 additions & 0 deletions packages/desktop/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,13 @@
"security": {
"csp": null
}
},
"plugins": {
"deep-link": {
"mobile": [],
"desktop": {
"schemes": ["openconcho"]
}
}
}
}
1 change: 1 addition & 0 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@tanstack/react-query": "^5.74.4",
"@tanstack/react-router": "^1.120.3",
"@tauri-apps/api": "^2",
"@tauri-apps/plugin-deep-link": "^2.4.9",
"@tauri-apps/plugin-http": "^2",
"@tauri-apps/plugin-shell": "^2",
"class-variance-authority": "^0.7.1",
Expand Down
40 changes: 40 additions & 0 deletions packages/web/src/lib/deep-link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import type { Router } from "@tanstack/react-router";

const SCHEME = "openconcho:";

function isTauri(): boolean {
return typeof window !== "undefined" && "__TAURI_INTERNALS__" in window;
}

function navigateFromUrl(router: Router<never, never>, raw: string): void {
let parsed: URL;
try {
parsed = new URL(raw);
} catch {
return;
}
if (parsed.protocol !== SCHEME) return;

const host = parsed.hostname || parsed.pathname.replace(/^\/+/, "").split("/")[0];
const search = parsed.search;

if (host === "explore") {
router.navigate({ to: `/explore${search}` as never });
return;
}

const path = parsed.pathname.startsWith("/") ? parsed.pathname : `/${parsed.pathname}`;
router.navigate({ to: `${path}${search}` as never });
}

export async function initDeepLinks(router: Router<never, never>): Promise<void> {
if (!isTauri()) return;
const { onOpenUrl, getCurrent } = await import("@tauri-apps/plugin-deep-link");

const initial = await getCurrent();
if (initial?.length) navigateFromUrl(router, initial[0]);

await onOpenUrl((urls) => {
if (urls[0]) navigateFromUrl(router, urls[0]);
});
}
3 changes: 3 additions & 0 deletions packages/web/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createRouter, RouterProvider } from "@tanstack/react-router";
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import { DemoProvider } from "./context/DemoContext";
import { initDeepLinks } from "./lib/deep-link";
import { routeTree } from "./routeTree.gen";
import "./index.css";

Expand All @@ -27,6 +28,8 @@ declare module "@tanstack/react-router" {
}
}

void initDeepLinks(router as never);

const root = document.getElementById("root");
if (!root) throw new Error("Missing #root element");

Expand Down
Loading
Loading