The product is Voelin (app id io.github.faumaray.Voelin), everywhere: - crates tsc-* -> voelin-* (and voelin-fuzz), the desktop binary tsc-desktop -> voelin, the development CLI tsctl -> voelinctl; - the Android app: applicationId, Kotlin package io.github.faumaray.voelin, VoelinApp, libvoelin_android.so (JNI class names follow); - TSC_* environment variables -> VOELIN_*, Gradle properties tsc.* -> voelin.*, signing secrets VOELIN_SIGNING_*; - the data/config/cache/state folder tsc -> voelin, the keyring service, thread names, the dev compose project; - desktop file, metainfo, icon, Flatpak manifest, NSIS installer, docs. The gateway keeps its name: bin tsgw (crate voelin-gateway), TSGW_* env vars, the tsgw.v1+json protocol, the tsgw image. The window title and the About page show "Voelin <version>" from voelin_platform::APP_NAME. Packages (scripts/package.sh): the app only (voelin, voelin.exe, APKs, Flatpak). voelinctl is a development tool and in no package. tsgw is for servers and now its own Linux package, tsgw_<v>_amd64.deb and tsgw-<v>-linux-x86_64.tar.gz, with a sandboxed systemd unit (packaging/linux/tsgw.service; /etc/tsgw config, /var/lib/tsgw state) and dependencies of its own (no GUI libraries). docs/gateway-admin.md has an Install section. Fixes: - package-windows: makensis on Windows found no file through "D:/a/..." paths; pass Windows paths (cygpath -w). - StartupWMClass is the app id, which the app sets as its X11 WM_CLASS (it was the binary name, so desktops could not match the window). - Gradle wrapper download timeout 10 s -> 60 s (slow proxies). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
149 lines
4.6 KiB
Rust
149 lines
4.6 KiB
Rust
//! `android_main`: the activity's native thread.
|
|
//!
|
|
//! android-activity calls it on a new thread for every activity instance
|
|
//! (the process can outlive activities while voice runs in the service).
|
|
//! Process-wide setup happens once; the window is built per activity.
|
|
|
|
use std::path::Path;
|
|
use std::sync::{Mutex, Once, OnceLock, PoisonError};
|
|
|
|
use anyhow::Context as _;
|
|
use slint::android::AndroidApp;
|
|
use tracing::{error, info, warn};
|
|
use voelin_core::Command;
|
|
|
|
use crate::foreground::Foreground;
|
|
use crate::host::EngineHost;
|
|
use crate::{bridge, capture, secrets};
|
|
|
|
/// Store setting (`bool`): the user's opt-in to local crash reports.
|
|
pub const CRASH_REPORTS_SETTING: &str = "crash_reports";
|
|
|
|
static HOST: OnceLock<EngineHost> = OnceLock::new();
|
|
static FOREGROUND: Mutex<Option<Foreground>> = Mutex::new(None);
|
|
|
|
fn host() -> anyhow::Result<&'static EngineHost> {
|
|
if let Some(host) = HOST.get() {
|
|
return Ok(host);
|
|
}
|
|
let host = EngineHost::start().context("starting the engine runtime")?;
|
|
Ok(HOST.get_or_init(|| host))
|
|
}
|
|
|
|
fn with_foreground<R>(f: impl FnOnce(&mut Foreground) -> R) -> R {
|
|
let mut guard = FOREGROUND.lock().unwrap_or_else(PoisonError::into_inner);
|
|
f(guard.get_or_insert_with(Foreground::default))
|
|
}
|
|
|
|
/// The entry point android-activity looks up in this library.
|
|
#[allow(unsafe_code)] // an exported symbol
|
|
#[unsafe(no_mangle)]
|
|
fn android_main(app: AndroidApp) {
|
|
init_logging();
|
|
info!("android_main");
|
|
if let Err(e) = run(app) {
|
|
error!("{e:#}");
|
|
}
|
|
info!("android_main done");
|
|
}
|
|
|
|
fn init_logging() {
|
|
// android-activity forwards stderr to logcat (tag RustStdoutStderr).
|
|
let filter = tracing_subscriber::EnvFilter::try_from_default_env()
|
|
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info"));
|
|
let _ = tracing_subscriber::fmt()
|
|
.with_env_filter(filter)
|
|
.with_ansi(false)
|
|
.without_time()
|
|
.with_writer(std::io::stderr)
|
|
.try_init();
|
|
}
|
|
|
|
fn run(app: AndroidApp) -> anyhow::Result<()> {
|
|
let data_dir = app.internal_data_path().context("the app has no internal storage path")?;
|
|
install_crash_reports(&data_dir);
|
|
jni::JavaVM::singleton()?.attach_current_thread(|env| -> jni::errors::Result<()> {
|
|
bridge::init(env)?;
|
|
// reqwest (HTTPS queries, tsclientlib) verifies certificates with
|
|
// the system's trust store through rustls-platform-verifier.
|
|
let context = bridge::context(env)?;
|
|
rustls_platform_verifier::android::init_with_env(env, context)?;
|
|
Ok(())
|
|
})?;
|
|
let host = host()?;
|
|
static PROCESS: Once = Once::new();
|
|
PROCESS.call_once(|| {
|
|
capture::register();
|
|
watch_voice(host);
|
|
});
|
|
if let Err(e) = bridge::request_permissions() {
|
|
warn!("requesting permissions: {e}");
|
|
}
|
|
|
|
slint::android::init(app).context("Slint Android backend")?;
|
|
let attached = host.attach();
|
|
voelin_ui::run(voelin_ui::RunOptions {
|
|
data_dir: Some(data_dir),
|
|
secrets: Some(Box::new(secrets::KeystoreSecrets)),
|
|
engine: Some(voelin_ui::HostedEngine {
|
|
engine: attached.engine,
|
|
runtime: attached.runtime,
|
|
events: attached.events,
|
|
}),
|
|
})
|
|
}
|
|
|
|
/// Local crash reports in `<files dir>/crash-reports`, recorded only if the
|
|
/// user opted in (off by default).
|
|
fn install_crash_reports(data_dir: &Path) {
|
|
voelin_platform::crash::set_app_version(env!("CARGO_PKG_VERSION"));
|
|
let enabled = voelin_store::Store::open(&data_dir.join("client.db"))
|
|
.ok()
|
|
.and_then(|store| store.setting::<bool>(CRASH_REPORTS_SETTING).ok().flatten())
|
|
.unwrap_or(false);
|
|
voelin_platform::crash::install(data_dir.join(voelin_platform::crash::DIR_NAME), enabled);
|
|
}
|
|
|
|
/// Keep the voice foreground service in step with the voice connections.
|
|
fn watch_voice(host: &'static EngineHost) {
|
|
let mut events = host.engine().subscribe();
|
|
host.runtime().spawn(async move {
|
|
loop {
|
|
match events.recv().await {
|
|
Ok(event) => {
|
|
if let Some(notice) = with_foreground(|f| f.update(&event))
|
|
&& let Err(e) = bridge::set_voice_notification(notice.as_ref())
|
|
{
|
|
warn!("voice service: {e}");
|
|
}
|
|
}
|
|
Err(tokio::sync::broadcast::error::RecvError::Lagged(_)) => continue,
|
|
Err(tokio::sync::broadcast::error::RecvError::Closed) => break,
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
/// "Disconnect" in the voice notification.
|
|
pub fn disconnect_voice() {
|
|
let Some(host) = HOST.get() else {
|
|
return;
|
|
};
|
|
for session in with_foreground(|f| f.voice_sessions()) {
|
|
host.engine().send(Command::DisconnectVoice { session });
|
|
}
|
|
}
|
|
|
|
/// "Mute" / "Unmute" in the voice notification: mute every voice session,
|
|
/// or unmute them all when all are muted.
|
|
pub fn toggle_mute() {
|
|
let Some(host) = HOST.get() else {
|
|
return;
|
|
};
|
|
let (sessions, muted) =
|
|
with_foreground(|f| (f.voice_sessions(), f.notice().is_some_and(|n| n.muted)));
|
|
for session in sessions {
|
|
host.engine().send(Command::SetInputMuted { session, muted: !muted });
|
|
}
|
|
}
|