Skip to content

Commit a3e8c16

Browse files
feat: add deep link for exam-environment (#59)
* feat: add deep link for exam-environment * feat: maybe macos support?
1 parent bbd9f4d commit a3e8c16

File tree

8 files changed

+187
-4
lines changed

8 files changed

+187
-4
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "exam-env",
33
"private": true,
4-
"version": "0.8.0",
4+
"version": "0.9.0",
55
"type": "module",
66
"scripts": {
77
"prisma": "prisma",
@@ -21,6 +21,7 @@
2121
"@tanstack/react-query": "5.87.4",
2222
"@tanstack/react-router": "1.131.41",
2323
"@tauri-apps/api": "2.8.0",
24+
"@tauri-apps/plugin-deep-link": "~2",
2425
"@tauri-apps/plugin-dialog": "2.4.0",
2526
"@tauri-apps/plugin-http": "2.5.2",
2627
"@tauri-apps/plugin-log": "2.7.0",

pnpm-lock.yaml

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

src-tauri/Cargo.lock

Lines changed: 110 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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "exam-env"
3-
version = "0.8.0"
3+
version = "0.9.0"
44
description = "Exam environment for freeCodeCamp"
55
authors = ["freeCodeCamp"]
66
edition = "2021"
@@ -29,6 +29,8 @@ time = "0.3.44"
2929
tauri-plugin-log = "2"
3030
tracing = "0.1.41"
3131
tracing-subscriber = { version = "0.3.20", features = ["env-filter"] }
32+
tauri-plugin-deep-link = "2"
3233

3334
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
35+
tauri-plugin-single-instance = { version = "2", features = ["deep-link"] }
3436
tauri-plugin-updater = "2.9.0"

src-tauri/Info.plist

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,16 @@
66
<string>Request microphone access for WebRTC</string>
77
<key>ITSAppUsesNonExemptEncryption</key>
88
<false/>
9+
<key>CFBundleURLTypes</key>
10+
<array>
11+
<dict>
12+
<key>CFBundleURLName</key>
13+
<string>org.freecodecamp.exam</string>
14+
<key>CFBundleURLSchemes</key>
15+
<array>
16+
<string>exam-environment</string>
17+
</array>
18+
</dict>
19+
</array>
920
</dict>
1021
</plist>

src-tauri/src/main.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
22
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
33

4+
use tauri::Manager;
5+
#[cfg(debug_assertions)]
6+
#[cfg(desktop)]
7+
use tauri_plugin_deep_link::DeepLinkExt;
48
use tracing::info;
59
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
610
use utils::valid_sentry_dsn;
@@ -71,6 +75,22 @@ fn main() {
7175
);
7276

7377
tauri::Builder::default()
78+
.plugin(tauri_plugin_deep_link::init())
79+
// Ensure only one window of the app may be open at a time.
80+
.plugin(tauri_plugin_single_instance::init(|app, _argv, _cwd| {
81+
// NOTE: `argv` is ordinarily double-checked for CSRF for runtime-registered deep links.
82+
// However, deep links are only registered during runtime for development.
83+
// println!("a new app instance was opened with {argv:?} and the deep link event was already triggered");
84+
// If app is already open, focus window when deep link is triggered
85+
let _ = app
86+
.get_webview_window("main")
87+
.expect("no main window")
88+
.set_focus();
89+
// let callback_url = argv.get(1)
90+
// .expect("no callback URL")
91+
// .to_string();
92+
// app.emit("auth0-redirect", callback_url).expect("failed to emit deep link event");
93+
}))
7494
.plugin(tauri_plugin_log::Builder::new().skip_logger().build())
7595
.plugin(tauri_plugin_opener::init())
7696
.plugin(tauri_plugin_http::init())
@@ -86,6 +106,22 @@ fn main() {
86106
commands::check,
87107
])
88108
.manage(sentry_state)
109+
.setup(|app| {
110+
// Deep Link for app is registered during runtime as well as install,
111+
// because this is the only way to use deep links during development.
112+
#[cfg(desktop)]
113+
#[cfg(debug_assertions)]
114+
app.deep_link().register("exam-environment")?;
115+
116+
#[cfg(target_os = "macos")]
117+
{
118+
log::trace!("hiding Dock icon on macOS");
119+
app.set_activation_policy(tauri::ActivationPolicy::Accessory);
120+
log::trace!("Dock icon should be hidden now");
121+
}
122+
123+
Ok(())
124+
})
89125
.run(tauri::generate_context!())
90126
.expect("error while running tauri application");
91127
}

src-tauri/tauri.conf.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"productName": "Exam Environment",
3-
"version": "0.8.0",
3+
"version": "0.9.0",
44
"identifier": "org.freecodecamp.exam",
55
"build": {
66
"beforeDevCommand": "pnpm run dev",
@@ -51,6 +51,13 @@
5151
}
5252
},
5353
"plugins": {
54+
"deep-link": {
55+
"desktop": {
56+
"schemes": [
57+
"exam-environment"
58+
]
59+
}
60+
},
5461
"updater": {
5562
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDQwMkZBRkI4MUY5QzZBQzQKUldURWFwd2Z1Szh2UU81ZmVJenNsTXpSQURMbUFqaDF1Rm1WOG9XUEJxYUxxa1RLalRtVm5DVVkK",
5663
"endpoints": [

src-tauri/tauri.dev.conf.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@
3636
"windows": null
3737
},
3838
"plugins": {
39+
"deep-link": {
40+
"desktop": {
41+
"schemes": [
42+
"exam-environment"
43+
]
44+
}
45+
},
3946
"updater": {
4047
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IERBMEZDMUIzMTc4N0E1NTMKUldSVHBZY1hzOEVQMnEydTAzSFNQOWxjelRMdHJ1SmZwVy9vNnJ0bmVtSU1LTFFFZzhsRlZ0UmEK",
4148
"endpoints": [

0 commit comments

Comments
 (0)