-
Notifications
You must be signed in to change notification settings - Fork 7
fix: iPhone app links open in external browser #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /** | ||
| * Opens an external URL using the Tauri opener plugin when running on iOS in a Tauri environment, | ||
| * with fallback to window.open for web environments and other platforms. | ||
| * | ||
| * @param url - The external URL to open | ||
| */ | ||
| export const openExternalLink = async (url: string): Promise<void> => { | ||
| try { | ||
| // Check if we're in a Tauri environment first | ||
| const { isTauri } = await import("@tauri-apps/api/core"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: dynamically importing isTauri could be moved outside function to avoid performance overhead on every link click |
||
| const tauriEnv = await isTauri(); | ||
|
|
||
| if (tauriEnv) { | ||
| // Check if we're on iOS | ||
| const { type } = await import("@tauri-apps/plugin-os"); | ||
| const platform = await type(); | ||
|
|
||
| if (platform === "ios") { | ||
| // Use Tauri opener plugin for iOS | ||
| const { invoke } = await import("@tauri-apps/api/core"); | ||
| await invoke("plugin:opener|open_url", { url }); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| // Fallback for non-iOS or non-Tauri environments | ||
| window.open(url, "_blank", "noopener,noreferrer"); | ||
| } catch (error) { | ||
| // Final fallback if everything fails | ||
| console.warn("Failed to open URL with Tauri opener, falling back to window.open:", error); | ||
| try { | ||
| window.open(url, "_blank", "noopener,noreferrer"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: second window.open call unnecessarily repeats code from line 27 - consider extracting to shared function |
||
| } catch (windowError) { | ||
| console.error("Failed to open URL with window.open:", windowError); | ||
| } | ||
| } | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: add role='link' to button for better accessibility since this behaves like a link