From 455a59f69318b8cdd9b59d4aa43e133d3da5ede3 Mon Sep 17 00:00:00 2001 From: Shantur Rathore Date: Thu, 2 Apr 2026 17:10:10 +0100 Subject: [PATCH] fix tauri dev server resolution --- .../src-tauri/gen/schemas/capabilities.json | 2 +- .../src-tauri/gen/schemas/macOS-schema.json | 66 +++++++++++++++++++ .../tauri-app/src-tauri/src/cli_manager.rs | 47 +++++++++---- packages/tauri-app/src-tauri/src/main.rs | 15 +++-- 4 files changed, 110 insertions(+), 20 deletions(-) diff --git a/packages/tauri-app/src-tauri/gen/schemas/capabilities.json b/packages/tauri-app/src-tauri/gen/schemas/capabilities.json index 1e595706..3ab025a9 100644 --- a/packages/tauri-app/src-tauri/gen/schemas/capabilities.json +++ b/packages/tauri-app/src-tauri/gen/schemas/capabilities.json @@ -1 +1 @@ -{"main-window-native-dialogs":{"identifier":"main-window-native-dialogs","description":"Grant the main window access to required core features and native dialog commands.","remote":{"urls":["http://127.0.0.1:*","http://localhost:*","http://tauri.localhost/*","https://tauri.localhost/*"]},"local":true,"windows":["main"],"permissions":["core:default","core:menu:default","dialog:allow-open","opener:allow-default-urls","opener:allow-open-url","notification:allow-is-permission-granted","notification:allow-request-permission","notification:allow-notify","notification:allow-show","core:webview:allow-set-webview-zoom"]}} +{"main-window-native-dialogs":{"identifier":"main-window-native-dialogs","description":"Grant the main window access to required core features and native dialog commands.","remote":{"urls":["http://127.0.0.1:*","http://localhost:*","http://tauri.localhost/*","https://tauri.localhost/*"]},"local":true,"windows":["main"],"permissions":["core:default","core:menu:default","dialog:allow-open","opener:allow-default-urls","opener:allow-open-url","notification:allow-is-permission-granted","notification:allow-request-permission","notification:allow-notify","notification:allow-show","core:webview:allow-set-webview-zoom"]}} \ No newline at end of file diff --git a/packages/tauri-app/src-tauri/gen/schemas/macOS-schema.json b/packages/tauri-app/src-tauri/gen/schemas/macOS-schema.json index 3b65da09..f7ab8174 100644 --- a/packages/tauri-app/src-tauri/gen/schemas/macOS-schema.json +++ b/packages/tauri-app/src-tauri/gen/schemas/macOS-schema.json @@ -2378,6 +2378,72 @@ "const": "dialog:deny-save", "markdownDescription": "Denies the save command without any pre-configured scope." }, + { + "description": "No features are enabled by default, as we believe\nthe shortcuts can be inherently dangerous and it is\napplication specific if specific shortcuts should be\nregistered or unregistered.\n", + "type": "string", + "const": "global-shortcut:default", + "markdownDescription": "No features are enabled by default, as we believe\nthe shortcuts can be inherently dangerous and it is\napplication specific if specific shortcuts should be\nregistered or unregistered.\n" + }, + { + "description": "Enables the is_registered command without any pre-configured scope.", + "type": "string", + "const": "global-shortcut:allow-is-registered", + "markdownDescription": "Enables the is_registered command without any pre-configured scope." + }, + { + "description": "Enables the register command without any pre-configured scope.", + "type": "string", + "const": "global-shortcut:allow-register", + "markdownDescription": "Enables the register command without any pre-configured scope." + }, + { + "description": "Enables the register_all command without any pre-configured scope.", + "type": "string", + "const": "global-shortcut:allow-register-all", + "markdownDescription": "Enables the register_all command without any pre-configured scope." + }, + { + "description": "Enables the unregister command without any pre-configured scope.", + "type": "string", + "const": "global-shortcut:allow-unregister", + "markdownDescription": "Enables the unregister command without any pre-configured scope." + }, + { + "description": "Enables the unregister_all command without any pre-configured scope.", + "type": "string", + "const": "global-shortcut:allow-unregister-all", + "markdownDescription": "Enables the unregister_all command without any pre-configured scope." + }, + { + "description": "Denies the is_registered command without any pre-configured scope.", + "type": "string", + "const": "global-shortcut:deny-is-registered", + "markdownDescription": "Denies the is_registered command without any pre-configured scope." + }, + { + "description": "Denies the register command without any pre-configured scope.", + "type": "string", + "const": "global-shortcut:deny-register", + "markdownDescription": "Denies the register command without any pre-configured scope." + }, + { + "description": "Denies the register_all command without any pre-configured scope.", + "type": "string", + "const": "global-shortcut:deny-register-all", + "markdownDescription": "Denies the register_all command without any pre-configured scope." + }, + { + "description": "Denies the unregister command without any pre-configured scope.", + "type": "string", + "const": "global-shortcut:deny-unregister", + "markdownDescription": "Denies the unregister command without any pre-configured scope." + }, + { + "description": "Denies the unregister_all command without any pre-configured scope.", + "type": "string", + "const": "global-shortcut:deny-unregister-all", + "markdownDescription": "Denies the unregister_all command without any pre-configured scope." + }, { "description": "This permission set configures which\nnotification features are by default exposed.\n\n#### Granted Permissions\n\nIt allows all notification related features.\n\n\n#### This default permission set includes:\n\n- `allow-is-permission-granted`\n- `allow-request-permission`\n- `allow-notify`\n- `allow-register-action-types`\n- `allow-register-listener`\n- `allow-cancel`\n- `allow-get-pending`\n- `allow-remove-active`\n- `allow-get-active`\n- `allow-check-permissions`\n- `allow-show`\n- `allow-batch`\n- `allow-list-channels`\n- `allow-delete-channel`\n- `allow-create-channel`\n- `allow-permission-state`", "type": "string", diff --git a/packages/tauri-app/src-tauri/src/cli_manager.rs b/packages/tauri-app/src-tauri/src/cli_manager.rs index f240db3d..f44dffd9 100644 --- a/packages/tauri-app/src-tauri/src/cli_manager.rs +++ b/packages/tauri-app/src-tauri/src/cli_manager.rs @@ -1018,27 +1018,50 @@ impl CliEntry { } fn resolve_tsx(_app: &AppHandle) -> Option { - let candidates = vec![ - std::env::current_dir() - .ok() + let cwd = std::env::current_dir().ok(); + let workspace = workspace_root(); + let mut candidates = vec![ + cwd.as_ref().map(|p| p.join("node_modules/tsx/dist/cli.mjs")), + cwd.as_ref().map(|p| p.join("node_modules/tsx/dist/cli.cjs")), + cwd.as_ref().map(|p| p.join("node_modules/tsx/dist/cli.js")), + cwd.as_ref().map(|p| p.join("../node_modules/tsx/dist/cli.mjs")), + cwd.as_ref().map(|p| p.join("../node_modules/tsx/dist/cli.cjs")), + cwd.as_ref().map(|p| p.join("../node_modules/tsx/dist/cli.js")), + cwd.as_ref().map(|p| p.join("../../node_modules/tsx/dist/cli.mjs")), + cwd.as_ref().map(|p| p.join("../../node_modules/tsx/dist/cli.cjs")), + cwd.as_ref().map(|p| p.join("../../node_modules/tsx/dist/cli.js")), + workspace + .as_ref() + .map(|p| p.join("node_modules/tsx/dist/cli.mjs")), + workspace + .as_ref() + .map(|p| p.join("node_modules/tsx/dist/cli.cjs")), + workspace + .as_ref() .map(|p| p.join("node_modules/tsx/dist/cli.js")), - std::env::current_exe().ok().and_then(|ex| { - ex.parent() - .map(|p| p.join("../node_modules/tsx/dist/cli.js")) - }), ]; + if let Ok(exe) = std::env::current_exe() { + if let Some(dir) = exe.parent() { + candidates.push(Some(dir.join("../node_modules/tsx/dist/cli.mjs"))); + candidates.push(Some(dir.join("../node_modules/tsx/dist/cli.cjs"))); + candidates.push(Some(dir.join("../node_modules/tsx/dist/cli.js"))); + } + } + first_existing(candidates) } fn resolve_dev_entry(_app: &AppHandle) -> Option { + let cwd = std::env::current_dir().ok(); + let workspace = workspace_root(); let candidates = vec![ - std::env::current_dir() - .ok() + workspace + .as_ref() .map(|p| p.join("packages/server/src/index.ts")), - std::env::current_dir() - .ok() - .map(|p| p.join("../server/src/index.ts")), + cwd.as_ref().map(|p| p.join("packages/server/src/index.ts")), + cwd.as_ref().map(|p| p.join("../server/src/index.ts")), + cwd.as_ref().map(|p| p.join("../../server/src/index.ts")), ]; first_existing(candidates) diff --git a/packages/tauri-app/src-tauri/src/main.rs b/packages/tauri-app/src-tauri/src/main.rs index e4d68aad..f15481a5 100644 --- a/packages/tauri-app/src-tauri/src/main.rs +++ b/packages/tauri-app/src-tauri/src/main.rs @@ -129,13 +129,15 @@ fn should_allow_internal(url: &Url) -> bool { } } -fn should_allow_window_origin(app_handle: &AppHandle, window_label: &str, url: &Url) -> bool { +fn should_allow_window_origin(app_handle: &AppHandle, window_label: &str, url: &Url) -> bool { if should_allow_internal(url) { return true; } let state = app_handle.state::(); - let allowed = state.remote_origins.lock(); + let Ok(allowed) = state.remote_origins.lock() else { + return false; + }; if let Some(origin) = allowed.get(window_label) { return origin == &url.origin().ascii_serialization(); } @@ -175,6 +177,7 @@ fn open_remote_window(app: AppHandle, payload: RemoteWindowPayload) -> Result<() app.state::() .remote_origins .lock() + .map_err(|err| err.to_string())? .insert(label.clone(), parsed.origin().ascii_serialization()); let window = WebviewWindowBuilder::new(&app, label.clone(), WebviewUrl::External(parsed.clone())) @@ -187,11 +190,9 @@ fn open_remote_window(app: AppHandle, payload: RemoteWindowPayload) -> Result<() let app_handle = app.clone(); window.on_window_event(move |event| { if let WindowEvent::Destroyed = event { - app_handle - .state::() - .remote_origins - .lock() - .remove(&label); + if let Ok(mut origins) = app_handle.state::().remote_origins.lock() { + origins.remove(&label); + } } });