diff --git a/FIX_PROPOSAL.md b/FIX_PROPOSAL.md new file mode 100644 index 0000000..4eabee7 --- /dev/null +++ b/FIX_PROPOSAL.md @@ -0,0 +1,41 @@ +To address the issue of `TerminalLinkProvider` falling back to `window.open` when `shell_open` fails, we need to implement a more reliable fallback mechanism that works within the Tauri framework. + +Given the constraints and the goal of opening a URL externally in a way that's compatible with Tauri, we can utilize the `tauri::Window` API to launch the URL. This approach ensures that the URL is opened in the default system browser, providing a consistent user experience across different platforms. + +Here's a concise code snippet that demonstrates how to achieve this: + +```rust +use tauri::{Window, WindowBuilder}; + +// Assuming `link` is the URL you want to open +let link = "https://example.com"; + +// Attempt to open the link using shell_open +if let Err(_) = invoke("shell_open", link) { + // Fallback: Open the link using tauri::Window + WindowBuilder::new(tauri::generate_handler![]) + .title("External Link") + .url(link) + .build(tauri::generate_context!()) + .expect("Failed to create window"); +} +``` + +However, since creating a new window just to open a link might not be the most efficient or user-friendly approach, we can also consider using the `webview` API provided by Tauri to open the link in the default browser. Unfortunately, Tauri's API does not directly support launching external URLs without creating a new window or using `shell_open`. + +An alternative and more straightforward approach, considering the limitations, is to use the `open` command provided by Tauri, which allows you to open a URL in the system's default browser: + +```rust +use tauri::Window; + +// Assuming `link` is the URL you want to open +let link = "https://example.com"; + +// Attempt to open the link using shell_open +if let Err(_) = invoke("shell_open", link) { + // Fallback: Open the link using the open command + tauri::shell::open(link).expect("Failed to open link"); +} +``` + +This approach is more in line with the expected behavior and provides a reliable fallback when `shell_open` fails, ensuring that the URL is opened in the default system browser. \ No newline at end of file