Files
youtube-generator/tests/utils/uuid.test.ts
T
poli0981andClaude Opus 4.8 89c0e76c2c feat(android): Android (.apk) build + packaging, WebView fixes, Android 11+ (v0.29.0)
Build and package the app for Android from the same Tauri 2 codebase, shipping
an installable, sideloadable signed APK alongside the desktop binaries.

Build / packaging
- cfg-gate desktop-only tray / single-instance / hide-to-tray / exit-prevention
  in lib.rs behind #[cfg(desktop)]; move tauri-plugin-single-instance to a
  desktop-only target table so the library compiles for Android.
- `cargo tauri android init` -> committed gen/android Gradle project; release
  signingConfigs read keystore.properties (gitignored, from CI secrets locally).
- .github/workflows/release-android.yml: JDK 17 + Android SDK/NDK + rust targets,
  decode keystore from secrets, build --apk, upload to the same draft release.
- vite.config.ts: es2020 build.target for Tauri builds (older-WebView safety).

Runtime fixes (found via on-device testing)
- External links: a real tap on `<a target="_blank">` makes the Android WebView
  fire onCreateWindow, which Tauri tries to satisfy via the shell plugin's open
  (no such binary on Android -> uncaught error, nothing opens). Strip
  target="_blank" from external anchors and route clicks through the opener
  plugin in the capture phase. (open-external.ts, main.tsx)
- Boot black screen on old WebViews: crypto.randomUUID() (Chrome/WebView 92+)
  ran at module load and threw on WebView 91. Fall back to a manual RFC 4122 v4
  built on getRandomValues. (uuid.ts; +4 regression tests, 509 -> 513)
- File export on Android routes through the in-WebView blob download. (IS_MOBILE)

Compatibility
- minSdk 30 (Android 11+), targetSdk 36 (Android 16): covers the large majority
  of active devices with a modern, patched WebView + Google Play system updates.

Release: bump manifests 0.28.0 -> 0.29.0; docs (README, FEATURES, PACKAGING,
CHANGELOG). Verified on an Android 13 emulator (render, links, export).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-15 18:56:37 +07:00

36 lines
1.2 KiB
TypeScript

import { describe, it, expect, afterEach, vi } from "vitest";
import { generateId } from "@utils/uuid";
// RFC 4122 v4: 8-4-4-4-12 hex, version nibble "4", variant nibble 8/9/a/b.
const V4 = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
describe("generateId", () => {
afterEach(() => {
vi.unstubAllGlobals();
});
it("returns a valid v4 UUID via the native crypto.randomUUID path", () => {
expect(generateId()).toMatch(V4);
});
it("falls back to a valid v4 UUID when crypto.randomUUID is missing (Android WebView < 92)", () => {
// Chromium 91 has getRandomValues but not randomUUID — the exact gap that
// black-screened the app at boot before the fallback existed.
const real = globalThis.crypto;
vi.stubGlobal("crypto", {
getRandomValues: (a: Uint8Array) => real.getRandomValues(a),
});
expect(generateId()).toMatch(V4);
});
it("falls back to a valid v4 UUID when crypto is entirely absent", () => {
vi.stubGlobal("crypto", undefined);
expect(generateId()).toMatch(V4);
});
it("produces unique values across many calls", () => {
const ids = new Set(Array.from({ length: 1000 }, () => generateId()));
expect(ids.size).toBe(1000);
});
});