build(android): cfg-gate desktop-only Tauri surfaces for android target

Phase 1 of the Android same-repo target plan: make the workspace
compilable for `aarch64-linux-android` (and the other NDK ABIs) by
removing the desktop-only crate dependencies and command bodies from the
Android build. After this commit, `tauri android init` followed by
`cargo tauri android build` is structurally unblocked — the remaining
work is the SDK/NDK toolchain (off-sandbox), the Svelte single-window
refactor, and the Phase 3 MVP feature surface.

What's gated under `cfg(not(target_os = "android"))`:

- src-tauri/Cargo.toml: `tauri = { features = ["tray-icon"] }` is now
  declared in the desktop-only target block. The `global-shortcut`,
  `window-state`, and `autostart` plugins join it — none of the three
  support Android natively. The base `tauri = "2"` plus `dialog`,
  `opener`, and `notification` plugins remain unconditional because they
  do support Android.
- src-tauri/src/lib.rs: `mod tray` declaration, the matching
  `tray::setup(app)` call, the close-to-tray `WindowEvent::CloseRequested`
  handler, and the `.plugin(tauri_plugin_global_shortcut::*)` /
  `_autostart` / `_window_state` chain are all desktop-only. The
  builder is split with a single `#[cfg(not(target_os = "android"))]`
  branch that adds the desktop plugins on top of the universal base.
- src-tauri/src/commands/tts.rs: `tts_speak` previously had three
  `#[cfg(target_os = ...)]` branches but no fallback, so on Android the
  `spawned` binding was unbound and the function failed to compile.
  Mirrored the existing `paste.rs` not-implemented fallback. Same fix
  for `list_voices_impl`. Frontend will hide the Read Page Aloud button
  on Android via `isAndroid()`.
- src-tauri/src/commands/windows.rs: all four multi-window commands
  (`open_task_window`, `open_preview_window`, `close_preview_window`,
  `open_viewer_window`) get an Android stub that returns a clear
  "Multi-window is not supported on Android" error. Tauri on Android
  is single-Activity; the previously-secondary content (preview overlay,
  transcript viewer, task float) will live as routes inside the main
  window, gated by `isAndroid()` on the frontend.

What's *not* changed:
- Top-level `identifier` in tauri.conf.json stays `uk.co.corbel.kon`.
  The Phase 10b Kon → Corbie rename sweep will land
  `corbel.technology.corbie` as part of a coherent rebrand commit
  rather than fragmenting the rename across this branch.
- `bundle.android.minSdkVersion: 24` added so a future
  `tauri android init` knows to target Android 7.0+ (Vulkan available,
  scoped storage starts at 29 — we'll surface scoped-storage paths
  via Tauri's dialog plugin on Phase 3).
- `kon-hotkey` already exports a non-Linux stub; no changes needed.
- `commands/meeting.rs` still calls `process_watch::list_running_process_names()`
  which compiles on Android but returns an empty list (SELinux blocks
  /proc walk on API 24+). Frontend will hide the toggle on Android.

Verification: 91/91 tests still pass on the buildable-in-sandbox crates
(kon-storage 60, kon-core 16, kon-mcp 9, kon-hotkey 4, kon-cloud-providers
2). svelte-check 0/0 across 3957 files. The src-tauri crate itself can't
be compiled in this sandbox (no webkit2gtk); CI's desktop builders will
exercise the desktop branch, and Jake's Android-equipped dev box will
exercise the Android branch via `tauri android init`.

https://claude.ai/code/session_0189xUb6ie6t9qHkzatGZ9Rb
This commit is contained in:
Claude
2026-04-25 12:50:33 +00:00
parent bd16c118cc
commit 4abc2356c2
4 changed files with 130 additions and 30 deletions

View File

@@ -1,4 +1,7 @@
mod commands;
// System tray uses Tauri's `tray-icon` feature which is desktop-only.
// Android has no tray surface — drop the module entirely on that target.
#[cfg(not(target_os = "android"))]
mod tray;
use std::sync::Arc;
@@ -132,9 +135,23 @@ pub fn run() {
// Settings → About can attach them. Local only; nothing transmitted.
commands::diagnostics::install_panic_hook();
tauri::Builder::default()
let builder = tauri::Builder::default()
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_dialog::init())
// Phase 6 nudges: OS-native notifications. The plugin exposes
// isPermissionGranted / requestPermission / sendNotification on
// the JS side; our deliver_nudge wrapper guards those calls
// against the nudge-bus suppression rules and restricts
// invocation to the main window via ensure_main_window.
.plugin(tauri_plugin_notification::init());
// Desktop-only plugins. Each is either unsupported on Android
// (global-shortcut, autostart) or structurally meaningless on a
// single-window mobile app (window-state). Gating here matches the
// Cargo.toml `cfg(not(target_os = "android"))` block that drops the
// crates entirely on Android targets.
#[cfg(not(target_os = "android"))]
let builder = builder
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
// Phase 5 rituals: autostart. The plugin registers JS-facing
// commands (isEnabled / enable / disable) that the Settings
@@ -145,18 +162,14 @@ pub fn run() {
tauri_plugin_autostart::MacosLauncher::LaunchAgent,
None,
))
// Phase 6 nudges: OS-native notifications. The plugin exposes
// isPermissionGranted / requestPermission / sendNotification on
// the JS side; our deliver_nudge wrapper guards those calls
// against the nudge-bus suppression rules and restricts
// invocation to the main window via ensure_main_window.
.plugin(tauri_plugin_notification::init())
// Remember size + position of every window across app restarts.
// Without this, secondary windows (preview overlay, task float,
// transcript viewer) open at whatever spot the compositor picks,
// which feels random. State is persisted per-window-label to
// app-data/window-state.json.
.plugin(tauri_plugin_window_state::Builder::default().build())
.plugin(tauri_plugin_window_state::Builder::default().build());
builder
.setup(|app| {
// Initialise database (blocking in setup — runs once at startup)
let db_path = database_path();
@@ -256,14 +269,20 @@ pub fn run() {
});
}
// Close-to-tray: hide window instead of exiting
let win = main_window.clone();
main_window.on_window_event(move |event| {
if let tauri::WindowEvent::CloseRequested { api, .. } = event {
api.prevent_close();
let _ = win.hide();
}
});
// Close-to-tray: hide the window instead of exiting so the
// tray icon stays as the canonical entry point. Desktop-only;
// mobile has no tray and "hide on close" maps to the
// platform's own background-app behaviour.
#[cfg(not(target_os = "android"))]
{
let win = main_window.clone();
main_window.on_window_event(move |event| {
if let tauri::WindowEvent::CloseRequested { api, .. } = event {
api.prevent_close();
let _ = win.hide();
}
});
}
}
// Store init script for secondary windows (float, viewer)
@@ -287,6 +306,7 @@ pub fn run() {
// hint. No-ops on a fully-supported box.
crate::commands::models::emit_runtime_warnings(app.handle());
#[cfg(not(target_os = "android"))]
if let Err(e) = tray::setup(app) {
eprintln!("Failed to setup tray: {e}");
}