fix(android): open external links via system browser + release v1.7.2 (#103)
Tapping any external link did nothing on the Android build: Tauri's WebView (Android especially) silently ignores `target="_blank"`, so the plain anchors in Header, Footer and About never opened. Only ConsentGate had a per-link workaround (PR #98). Replace that with one app-wide delegated click interceptor (`useExternalLinkInterceptor`, mounted at the App root): when `isTauri()` it catches clicks on any `a[href^=http]` and hands the URL to the system browser via `openExternal()` / plugin-shell. The web build is untouched — the listener is gated behind `isTauri()` so it is never installed there, and in-app router links keep relative hrefs so they aren't intercepted (reads `getAttribute('href')`, not the absolutising `.href` property). Removes the now-redundant onClick handler from ConsentGate. No Tauri/Rust/manifest/CSP changes were needed — shell:allow-open and plugin-shell were already correct (ConsentGate proved it on Android). Bumps version to 1.7.2 (Android versionCode 10702). Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
839bffd000
commit
4370e36628
7 files changed
+40
-14
No files matched your search
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jsonprism",
|
||||
"private": true,
|
||||
"version": "1.7.1",
|
||||
"version": "1.7.2",
|
||||
"type": "module",
|
||||
"description": "Disperse JSON into many formats — JSONL, CSV, YAML, XML, TOML, RESX, Markdown, SQL — fully client-side.",
|
||||
"author": "poli0981 <https://github.com/poli0981>",
|
||||
|
||||
Generated
+1
-1
@@ -1867,7 +1867,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "jsonprism"
|
||||
version = "1.7.1"
|
||||
version = "1.7.2"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "jsonprism"
|
||||
version = "1.7.1"
|
||||
version = "1.7.2"
|
||||
description = "Disperse JSON into many formats."
|
||||
authors = ["poli0981 <https://github.com/poli0981>"]
|
||||
license = "Apache-2.0"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "JSONPrism",
|
||||
"version": "1.7.1",
|
||||
"version": "1.7.2",
|
||||
"identifier": "com.poli0981.jsonprism",
|
||||
"build": {
|
||||
"beforeDevCommand": "npm run dev",
|
||||
@@ -78,7 +78,7 @@
|
||||
},
|
||||
"android": {
|
||||
"minSdkVersion": 31,
|
||||
"versionCode": 10701
|
||||
"versionCode": 10702
|
||||
}
|
||||
},
|
||||
"plugins": {
|
||||
|
||||
@@ -5,6 +5,7 @@ import { ErrorBoundary } from '@/components/common/ErrorBoundary';
|
||||
import { ConsentGate } from '@/components/common/ConsentGate';
|
||||
import { Layout } from '@/components/layout/Layout';
|
||||
import { Toaster } from '@/components/ui/sonner';
|
||||
import { useExternalLinkInterceptor } from '@/hooks/useExternalLinkInterceptor';
|
||||
|
||||
// Routes are code-split so the entry chunk stays small and the consent gate +
|
||||
// app shell paint before any page's heavy graph (editor, parsers) loads.
|
||||
@@ -14,6 +15,8 @@ const NotFound = lazy(() => import('@/pages/errors/NotFound'));
|
||||
const ErrorRoute = lazy(() => import('@/pages/errors/ErrorRoute'));
|
||||
|
||||
export function App() {
|
||||
useExternalLinkInterceptor();
|
||||
|
||||
return (
|
||||
<ThemeProvider defaultTheme="system">
|
||||
<ErrorBoundary>
|
||||
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { useConsentStore } from '@/stores/consentStore';
|
||||
import { isTauri, openExternal } from '@/lib/tauri';
|
||||
|
||||
const REPO_URL = 'https://github.com/poli0981/jsonPrism';
|
||||
|
||||
@@ -57,14 +56,6 @@ export function ConsentGate({ children }: { children: ReactNode }) {
|
||||
href={l.href}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
onClick={(e) => {
|
||||
// Tauri webviews (notably Android) ignore target="_blank";
|
||||
// hand the URL to the system browser instead.
|
||||
if (isTauri()) {
|
||||
e.preventDefault();
|
||||
void openExternal(l.href);
|
||||
}
|
||||
}}
|
||||
className="text-primary inline-flex items-center gap-1 underline-offset-4 hover:underline"
|
||||
>
|
||||
{t(`consent.links.${l.key}`)}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { useEffect } from 'react';
|
||||
import { isTauri, openExternal } from '@/lib/tauri';
|
||||
|
||||
/**
|
||||
* Route external-link clicks to the system browser inside Tauri.
|
||||
*
|
||||
* Tauri webviews (notably Android) silently ignore `target="_blank"`, so a
|
||||
* tapped `<a href="https://…">` does nothing. A single delegated listener
|
||||
* catches every external anchor app-wide and hands the URL to the OS browser
|
||||
* via the shell plugin. No-op on the web build (browsers open new tabs
|
||||
* natively) and for in-app router links (relative hrefs don't match).
|
||||
*/
|
||||
export function useExternalLinkInterceptor(): void {
|
||||
useEffect(() => {
|
||||
if (!isTauri()) return;
|
||||
|
||||
const handler = (e: MouseEvent) => {
|
||||
if (e.button !== 0 || e.defaultPrevented) return;
|
||||
const anchor = (e.target as Element | null)?.closest('a');
|
||||
if (!anchor) return;
|
||||
// Raw attribute, NOT `anchor.href`: the property absolutises relative
|
||||
// router links ("/about" → "http://…/about") and would match.
|
||||
const href = anchor.getAttribute('href');
|
||||
if (!href || !/^https?:\/\//i.test(href)) return;
|
||||
e.preventDefault();
|
||||
void openExternal(href);
|
||||
};
|
||||
|
||||
document.addEventListener('click', handler);
|
||||
return () => document.removeEventListener('click', handler);
|
||||
}, []);
|
||||
}
|
||||
Reference in new issue
Block a user