From 5e447ccb447a19c5b2696a9ce0d3e373271f096d Mon Sep 17 00:00:00 2001 From: Erwan Leboucher Date: Mon, 27 Jul 2026 15:32:39 +0200 Subject: [PATCH 1/2] fix(android): keep calls active in background --- .../android/app/src/main/AndroidManifest.xml | 11 ++++ .../moe/sable/client/CallForegroundService.kt | 52 +++++++++++++++++++ .../java/moe/sable/client/MainActivity.kt | 20 +++++++ src-tauri/src/lib.rs | 4 ++ src-tauri/src/mobile.rs | 23 ++++++++ src/app/plugins/call/CallEmbed.ts | 12 ++++- 6 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 src-tauri/gen/android/app/src/main/java/moe/sable/client/CallForegroundService.kt diff --git a/src-tauri/gen/android/app/src/main/AndroidManifest.xml b/src-tauri/gen/android/app/src/main/AndroidManifest.xml index 8e061c935..37c8515e5 100644 --- a/src-tauri/gen/android/app/src/main/AndroidManifest.xml +++ b/src-tauri/gen/android/app/src/main/AndroidManifest.xml @@ -11,6 +11,12 @@ + + + + + + @@ -111,6 +117,11 @@ + + Result<(), String> { call_bar_color("setNavigationBarColorNative", color) } +#[tauri::command] +pub fn start_call_foreground_service() -> Result<(), String> { + call_static_method("startCallForegroundServiceNative") +} + +#[tauri::command] +pub fn stop_call_foreground_service() -> Result<(), String> { + call_static_method("stopCallForegroundServiceNative") +} + /// `kind` is "notification" or "invite"; mapped to an int to avoid JNI string /// marshalling (mirrors set_*_bar_color). pub(crate) fn play_notification_sound(kind: String) -> Result<(), String> { @@ -75,3 +85,16 @@ fn call_bar_color(method: &str, color: u32) -> Result<(), String> { Ok(()) } + +fn call_static_method(method: &str) -> Result<(), String> { + let vm = JAVA_VM.get().ok_or("java vm not initialized")?; + let mut env = vm.attach_current_thread().map_err(|e| e.to_string())?; + + let result = env.call_static_method("moe/sable/client/MainActivity", method, "()V", &[]); + if result.is_err() { + let _ = env.exception_clear(); + } + result.map_err(|e| e.to_string())?; + + Ok(()) +} diff --git a/src/app/plugins/call/CallEmbed.ts b/src/app/plugins/call/CallEmbed.ts index f80f75ab2..fe86a76d0 100644 --- a/src/app/plugins/call/CallEmbed.ts +++ b/src/app/plugins/call/CallEmbed.ts @@ -1,5 +1,6 @@ import type { MatrixClient, MatrixEvent, Room } from '$types/matrix-sdk'; import { ClientEvent, KnownMembership, MatrixEventEvent, RoomStateEvent } from '$types/matrix-sdk'; +import { invoke } from '@tauri-apps/api/core'; import type { IRoomEvent, IWidget, WidgetDriver } from 'matrix-widget-api'; import { ClientWidgetApi, @@ -10,7 +11,7 @@ import { } from 'matrix-widget-api'; import { CallWidgetDriver } from './CallWidgetDriver'; import { trimTrailingSlash } from '../../utils/common'; -import { getWindowOrigin } from '../../utils/platform'; +import { getWindowOrigin, isAndroidTauri } from '../../utils/platform'; import type { ElementCallThemeKind, ElementMediaStateDetail } from './types'; import { color, config } from 'folds'; import { ElementCallIntent, ElementWidgetActions } from './types'; @@ -355,6 +356,7 @@ export class CallEmbed { */ public dispose(): void { debugLog.info('call', 'Disposing call widget', { roomId: this.roomId }); + this.invokeForegroundService('stop_call_foreground_service'); this.disposables.forEach((disposable) => { disposable(); }); @@ -373,10 +375,18 @@ export class CallEmbed { this.call.transport.reply(evt.detail as IWidgetApiRequest, {}); debugLog.info('call', 'Call joined', { roomId: this.roomId }); this.joined = true; + this.invokeForegroundService('start_call_foreground_service'); this.applyStyles(); this.control.startObserving(); } + private invokeForegroundService( + command: 'start_call_foreground_service' | 'stop_call_foreground_service' + ): void { + if (!isAndroidTauri()) return; + void invoke(command).catch(() => {}); + } + private applyStyles(): void { const doc = this.document; if (!doc) return; From 511892625478892f6aeb5683c8c28c60730dd980 Mon Sep 17 00:00:00 2001 From: Erwan Leboucher Date: Mon, 27 Jul 2026 16:47:34 +0200 Subject: [PATCH 2/2] fix(ios): keep calls active in background --- src-tauri/ios-project.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/src-tauri/ios-project.yml b/src-tauri/ios-project.yml index e81c8681c..6ca678e09 100644 --- a/src-tauri/ios-project.yml +++ b/src-tauri/ios-project.yml @@ -102,6 +102,7 @@ targets: - UIInterfaceOrientationLandscapeRight CFBundleShortVersionString: {{apple.bundle-version-short}} CFBundleVersion: "{{apple.bundle-version}}" + UIBackgroundModes: [audio] # Mirrors plugins.deep-link in tauri.conf.json: the plugin only patches # these in when cargo reruns its build script, so a fresh `tauri ios # init` silently loses them unless they live here.