diff --git a/src-tauri/gen/android/app/src/main/AndroidManifest.xml b/src-tauri/gen/android/app/src/main/AndroidManifest.xml
index e6e97879e..ce9f7cdf2 100644
--- a/src-tauri/gen/android/app/src/main/AndroidManifest.xml
+++ b/src-tauri/gen/android/app/src/main/AndroidManifest.xml
@@ -12,6 +12,12 @@
+
+
+
+
+
+
@@ -112,6 +118,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;