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
2 changes: 2 additions & 0 deletions Cargo.lock

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

21 changes: 17 additions & 4 deletions apps/desktop/src/routes/__root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
import { lazy, useEffect } from "react";

import type { DeepLink } from "@hypr/plugin-deeplink2";
import {
type DeepLink,
events as deeplink2Events,
} from "@hypr/plugin-deeplink2";
import { events as windowsEvents } from "@hypr/plugin-windows";

import { AuthProvider } from "../auth";
Expand Down Expand Up @@ -41,7 +44,8 @@ const useNavigationEvents = () => {
const navigate = useNavigate();

useEffect(() => {
let unlisten: (() => void) | undefined;
let unlistenNavigate: (() => void) | undefined;
let unlistenDeepLink: (() => void) | undefined;

const webview = getCurrentWebviewWindow();

Expand All @@ -51,11 +55,20 @@ const useNavigationEvents = () => {
navigate({ to: payload.path, search: payload.search ?? undefined });
})
.then((fn) => {
unlisten = fn;
unlistenNavigate = fn;
});

deeplink2Events.deepLinkEvent
.listen(({ payload }) => {
navigate({ to: payload.to, search: payload.search });
})
.then((fn) => {
unlistenDeepLink = fn;
});

return () => {
unlisten?.();
unlistenNavigate?.();
unlistenDeepLink?.();
};
}, [navigate]);
};
Expand Down
10 changes: 9 additions & 1 deletion apps/desktop/src/routes/notification.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { createFileRoute, redirect } from "@tanstack/react-router";

import type { NotificationSearch } from "@hypr/plugin-deeplink2";

export const Route = createFileRoute("/notification")({
beforeLoad: async () => {
validateSearch: (search): NotificationSearch => {
return {
key: (search as NotificationSearch).key ?? "",
};
},
beforeLoad: async ({ search }) => {
console.log("notification deeplink received", search);
throw redirect({ to: "/app/main" });
},
});
2 changes: 2 additions & 0 deletions plugins/deeplink2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ serde_yaml = { workspace = true }

[dependencies]
tauri = { workspace = true, features = ["test"] }
tauri-plugin-deep-link = { workspace = true }
tauri-specta = { workspace = true, features = ["derive", "typescript"] }

serde = { workspace = true }
specta = { workspace = true }
strum = { workspace = true, features = ["derive"] }

thiserror = { workspace = true }
tracing = { workspace = true }
url = { workspace = true }
31 changes: 30 additions & 1 deletion plugins/deeplink2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ mod types;
mod docs;

pub use error::{Error, Result};
pub use types::{DeepLink, DeepLinkEvent};

use std::str::FromStr;

use tauri_plugin_deep_link::DeepLinkExt;
use tauri_specta::Event;

const PLUGIN_NAME: &str = "deeplink2";

Expand All @@ -22,7 +28,30 @@ pub fn init<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> {

tauri::plugin::Builder::new(PLUGIN_NAME)
.invoke_handler(specta_builder.invoke_handler())
.setup(|_app, _api| Ok(()))
.setup(|app, _api| {
let app_handle = app.clone();

app.deep_link().on_open_url(move |event| {
for url in event.urls() {
let url_str = url.as_str();
tracing::info!(url = url_str, "deeplink_received");

match DeepLink::from_str(url_str) {
Ok(deep_link) => {
tracing::info!(deep_link = ?deep_link, "deeplink_parsed");
if let Err(e) = DeepLinkEvent(deep_link).emit(&app_handle) {
tracing::error!(error = ?e, "deeplink_event_emit_failed");
}
}
Err(e) => {
tracing::warn!(error = ?e, url = url_str, "deeplink_parse_failed");
}
}
}
});

Ok(())
})
.build()
}

Expand Down
Loading