Android: notifications that read like the app's voice bar

The voice service's notification said "In voice on <server>" with Mute
and Disconnect, and the screen-sharing one only "Sharing your screen".
The voice notification now shows what the app's voice card shows: the
channel as its title, the server and how many are there ("Home · 3 in
voice", "just you"), the time in voice as a chronometer, and Mute,
Deafen and Leave, which act on every voice session as the old Mute did.
Several servers at once read "In voice on 2 servers" with their names.
Tapping it opens the voice channel screen (the activity forwards the
action to Rust, which queues it until the window runs). While our
stream is live the screen-sharing notification says where it goes and
how many watch ("Live in Chill Zone", "Home · 2 watching"). Both use
the app's accent colour.

The window takes such platform requests through a small inbox in
voelin-ui (`voelin_ui::request`), handled on the window's thread and
outside the app's borrow, since navigating calls back into Rust.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
selikhovandClaude Opus 5.5 committed 2026-10-03 17:17:38 +03:00
1 parent 5f51eb15a2
commit d4b6baaa42
15 files changed
+529 -98

No files matched your search

+67 -7
View File
@@ -15,7 +15,7 @@ use jni::refs::{Global, Reference as _};
use jni::sys::{jboolean, jint, jlong};
use jni::{Env, JavaVM, jni_sig, jni_str, native_method};
use crate::foreground::VoiceNotice;
use crate::foreground::{ScreenNotice, VoiceNotice};
static BRIDGE: OnceLock<Global<JClass<'static>>> = OnceLock::new();
@@ -58,18 +58,56 @@ pub fn request_permissions() -> Result<()> {
})
}
/// A Java string, or `null` for `None`.
fn string_or_null<'local>(env: &mut Env<'local>, text: Option<&str>) -> Result<JObject<'local>> {
Ok(match text {
Some(text) => JObject::from(env.new_string(text)?),
None => JObject::null(),
})
}
/// Show or update the voice service's notification; `None` stops the service.
pub fn set_voice_notification(notice: Option<&VoiceNotice>) -> Result<()> {
with_bridge(|env, class| {
let (text, muted) = match notice {
Some(n) => (JObject::from(env.new_string(&n.text)?), n.muted),
None => (JObject::null(), false),
};
let title = string_or_null(env, notice.map(|n| n.title.as_str()))?;
let text = string_or_null(env, notice.map(|n| n.text.as_str()))?;
let (muted, deafened, since) =
notice.map_or((false, false, 0), |n| (n.muted, n.deafened, n.since_ms));
env.call_static_method(
class,
jni_str!("setVoiceNotification"),
jni_sig!((text: java.lang.String, muted: jboolean) -> void),
&[JValue::Object(&text), JValue::Bool(muted)],
jni_sig!(
(
title: java.lang.String,
text: java.lang.String,
muted: jboolean,
deafened: jboolean,
since_ms: jlong,
) -> void
),
&[
JValue::Object(&title),
JValue::Object(&text),
JValue::Bool(muted),
JValue::Bool(deafened),
JValue::Long(since as jlong),
],
)?;
Ok(())
})
}
/// What the screen-sharing notification says while our stream is live;
/// `None` puts back the plain "sharing your screen".
pub fn set_screen_notification(notice: Option<&ScreenNotice>) -> Result<()> {
with_bridge(|env, class| {
let title = string_or_null(env, notice.map(|n| n.title.as_str()))?;
let text = string_or_null(env, notice.map(|n| n.text.as_str()))?;
env.call_static_method(
class,
jni_str!("setScreenNotification"),
jni_sig!((title: java.lang.String, text: java.lang.String) -> void),
&[JValue::Object(&title), JValue::Object(&text)],
)?;
Ok(())
})
@@ -368,3 +406,25 @@ fn on_toggle_mute<'local>(_env: &mut Env<'local>, _class: JClass<'local>) -> Res
crate::app::toggle_mute();
Ok(())
}
const _: jni::NativeMethod = native_method! {
java_type = "io.github.faumaray.voelin.Native",
static extern fn on_toggle_deafen(),
};
/// "Deafen" / "Undeafen" in the voice notification.
fn on_toggle_deafen<'local>(_env: &mut Env<'local>, _class: JClass<'local>) -> Result<()> {
crate::app::toggle_deafen();
Ok(())
}
const _: jni::NativeMethod = native_method! {
java_type = "io.github.faumaray.voelin.Native",
static extern fn on_open_voice(),
};
/// The voice notification was tapped: show the voice channel.
fn on_open_voice<'local>(_env: &mut Env<'local>, _class: JClass<'local>) -> Result<()> {
voelin_ui::request(voelin_ui::Request::ShowVoice);
Ok(())
}