fix(android): show legal gate on first launch + clean file-load toast (#98)
The Android sideload APK never showed the consent gate and the file-load toast surfaced opaque content-URI document ids: 1. Legal gate: `consentStore` skipped the gate for ALL Tauri builds, justified by the desktop installer's license page — which the sideload APK doesn't have, so Android users never saw or accepted the terms. Add a build-time `__IS_ANDROID_BUILD__` define (`TAURI_ENV_PLATFORM === 'android'`) and gate only on desktop Tauri (`__IS_TAURI_BUILD__ && !__IS_ANDROID_BUILD__`); Android now shows the gate like the web build. Acceptance persists in the Android WebView's localStorage, so it asks only once. 2. Legal links: add an `openExternal()` helper that routes through `@tauri-apps/plugin-shell` inside Tauri (web keeps `window.open`), and wire the gate's License/Terms/Privacy/Disclaimer links to it — plain `target="_blank"` is swallowed by the Android WebView. 3. File-load toast: when the picked name has no usable extension (opaque Android content URIs like `msf:1000000123`), fall back to a count-based "N file(s) loaded" via new `toast.files_loaded` keys; keep the clean "Loaded <name>" when a real filename is available. Desktop/web are unchanged. Also reword `consent.intro` "in your browser" -> "on your device" (accurate on the native app). typecheck / lint / 215 tests / web build all green; verified on the Android emulator (gate shows once, links open the system browser, toast). Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
db11ce0f6e
commit
27e704fe4f
9 files changed
+52
-10
No files matched your search
@@ -9,6 +9,7 @@ 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';
|
||||
|
||||
@@ -20,10 +21,11 @@ const LEGAL_LINKS = [
|
||||
] as const;
|
||||
|
||||
/**
|
||||
* First-launch legal gate (web only). Blocks the app behind a non-dismissible
|
||||
* modal until the user accepts. On desktop the store seeds `accepted = true`
|
||||
* (the installer's license page already gated acceptance), so this renders its
|
||||
* children straight through.
|
||||
* First-launch legal gate (web + Android). Blocks the app behind a
|
||||
* non-dismissible modal until the user accepts. On desktop the store seeds
|
||||
* `accepted = true` (the installer's license page already gated acceptance), so
|
||||
* this renders its children straight through; the Android sideload APK has no
|
||||
* such installer step, so it shows the gate like the web build.
|
||||
*/
|
||||
export function ConsentGate({ children }: { children: ReactNode }) {
|
||||
const accepted = useConsentStore((s) => s.accepted);
|
||||
@@ -55,6 +57,14 @@ 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}`)}
|
||||
|
||||
@@ -116,7 +116,14 @@ export function InputPanel({
|
||||
}
|
||||
const text = await file.text();
|
||||
onChange(text);
|
||||
toast.success(t('toast.file_loaded', { name: file.name }));
|
||||
// Android content URIs sometimes yield an opaque document id with no
|
||||
// real filename (e.g. `msf:1000000123`). When there's no usable
|
||||
// extension to show a clean name, fall back to a count-based message.
|
||||
toast.success(
|
||||
pickedExt
|
||||
? t('toast.file_loaded', { name: file.name })
|
||||
: t('toast.files_loaded', { count: 1 }),
|
||||
);
|
||||
} catch (err) {
|
||||
toast.error(t('toast.file_failed', { message: (err as Error).message }));
|
||||
}
|
||||
|
||||
@@ -174,6 +174,8 @@
|
||||
"copy_failed": "Couldn't copy to clipboard",
|
||||
"downloaded": "Downloaded {{filename}}",
|
||||
"file_loaded": "Loaded {{name}}",
|
||||
"files_loaded": "{{count}} file loaded",
|
||||
"files_loaded_other": "{{count}} files loaded",
|
||||
"file_failed": "Failed to load file: {{message}}",
|
||||
"options_reset": "Options reset to defaults"
|
||||
},
|
||||
@@ -331,7 +333,7 @@
|
||||
},
|
||||
"consent": {
|
||||
"title": "Before you start",
|
||||
"intro": "JSONPrism runs entirely in your browser — your data never leaves your device. Please review and accept the terms:",
|
||||
"intro": "JSONPrism runs entirely on your device — your data never leaves it. Please review and accept the terms:",
|
||||
"agree": "I have read and agree to the License, Terms (EULA), Privacy Policy, and Disclaimer.",
|
||||
"continue": "Continue",
|
||||
"links": {
|
||||
|
||||
@@ -174,6 +174,8 @@
|
||||
"copy_failed": "Không thể chép vào clipboard",
|
||||
"downloaded": "Đã tải {{filename}}",
|
||||
"file_loaded": "Đã nạp {{name}}",
|
||||
"files_loaded": "Đã nạp {{count}} file",
|
||||
"files_loaded_other": "Đã nạp {{count}} file",
|
||||
"file_failed": "Không nạp được file: {{message}}",
|
||||
"options_reset": "Đã khôi phục tuỳ chọn mặc định"
|
||||
},
|
||||
@@ -331,7 +333,7 @@
|
||||
},
|
||||
"consent": {
|
||||
"title": "Trước khi bắt đầu",
|
||||
"intro": "JSONPrism chạy hoàn toàn trong trình duyệt của bạn — dữ liệu không bao giờ rời khỏi thiết bị. Vui lòng đọc và chấp nhận các điều khoản:",
|
||||
"intro": "JSONPrism chạy hoàn toàn trên thiết bị của bạn — dữ liệu không bao giờ rời khỏi máy. Vui lòng đọc và chấp nhận các điều khoản:",
|
||||
"agree": "Tôi đã đọc và đồng ý với Giấy phép, Điều khoản (EULA), Chính sách bảo mật và Tuyên bố miễn trừ trách nhiệm.",
|
||||
"continue": "Tiếp tục",
|
||||
"links": {
|
||||
|
||||
@@ -152,6 +152,20 @@ export async function fileFromNativePath(path: string): Promise<File> {
|
||||
return new File([text], name, { type, lastModified });
|
||||
}
|
||||
|
||||
/**
|
||||
* Open an external URL. In Tauri the webview won't honour `target="_blank"`
|
||||
* (Android in particular swallows it), so route through the shell plugin to
|
||||
* hand the URL to the system browser. On the web, open a new tab as usual.
|
||||
*/
|
||||
export async function openExternal(url: string): Promise<void> {
|
||||
if (!isTauri()) {
|
||||
window.open(url, '_blank', 'noopener,noreferrer');
|
||||
return;
|
||||
}
|
||||
const { open } = await import('@tauri-apps/plugin-shell');
|
||||
await open(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Diagnostic info from the Rust side (OS, arch, app version).
|
||||
* Not currently shown in the UI but useful for bug reports.
|
||||
|
||||
@@ -7,9 +7,10 @@ interface ConsentState {
|
||||
}
|
||||
|
||||
function initialAccepted(): boolean {
|
||||
// Desktop builds gate acceptance through the installer's license page, so the
|
||||
// in-app web gate is a no-op there.
|
||||
if (__IS_TAURI_BUILD__) return true;
|
||||
// Desktop installers gate acceptance through their license page, so the in-app
|
||||
// gate is a no-op there. The Android sideload APK has no installer license
|
||||
// step, so it must show the gate just like the web build.
|
||||
if (__IS_TAURI_BUILD__ && !__IS_ANDROID_BUILD__) return true;
|
||||
return isConsentValid(loadConsent());
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
@@ -2,5 +2,6 @@
|
||||
|
||||
declare const __APP_VERSION__: string;
|
||||
declare const __IS_TAURI_BUILD__: boolean;
|
||||
declare const __IS_ANDROID_BUILD__: boolean;
|
||||
declare const __APP_COMMIT__: string;
|
||||
declare const __APP_BUILD_DATE__: string;
|
||||
@@ -7,6 +7,9 @@ import pkg from './package.json';
|
||||
|
||||
// Tauri exposes env vars during dev/build; presence indicates a Tauri context.
|
||||
const isTauriContext = !!process.env.TAURI_ENV_PLATFORM;
|
||||
// `android` during `tauri android build`. The Android sideload APK has no
|
||||
// installer license page, so it must show the in-app consent gate (web does).
|
||||
const isAndroidBuild = process.env.TAURI_ENV_PLATFORM === 'android';
|
||||
const tauriHost = process.env.TAURI_DEV_HOST;
|
||||
|
||||
// Resolve commit SHA + build date once per Vite config load. The About page
|
||||
@@ -32,6 +35,7 @@ export default defineConfig(({ mode }) => ({
|
||||
define: {
|
||||
__APP_VERSION__: JSON.stringify(pkg.version),
|
||||
__IS_TAURI_BUILD__: JSON.stringify(isTauriContext),
|
||||
__IS_ANDROID_BUILD__: JSON.stringify(isAndroidBuild),
|
||||
__APP_COMMIT__: JSON.stringify(appCommit),
|
||||
__APP_BUILD_DATE__: JSON.stringify(appBuildDate),
|
||||
},
|
||||
|
||||
@@ -8,6 +8,7 @@ export default defineConfig({
|
||||
define: {
|
||||
__APP_VERSION__: JSON.stringify(pkg.version),
|
||||
__IS_TAURI_BUILD__: 'false',
|
||||
__IS_ANDROID_BUILD__: 'false',
|
||||
__APP_COMMIT__: '"test"',
|
||||
__APP_BUILD_DATE__: '"1970-01-01"',
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user