feat(client): protocol v2 wire layer, screen sharing, channel webhooks and secure voice

Verified against the real gateway via tests/gateway_interop.rs.
This commit is contained in:
Loki 2026-10-24 16:51:15 +02:00
parent 8460fb28fd
commit 3d7dd5413b
Signed by: boba
GPG key ID: 253067914055423B
65 changed files with 6048 additions and 1156 deletions

View file

@ -3,10 +3,15 @@ use crate::ui::slint::{MainWindow, ScreenShareWindow};
use slint::ComponentHandle;
/// Register the screen preview window; unsupported builds explain their capability.
pub fn wire(main: &MainWindow) -> Result<(), slint::PlatformError> {
pub fn wire(
main: &MainWindow,
state: &std::rc::Rc<std::cell::RefCell<crate::AppState>>,
) -> Result<(), slint::PlatformError> {
#[cfg(not(all(target_os = "linux", feature = "screen-capture")))]
let _ = state;
let dialog = ScreenShareWindow::new()?;
#[cfg(all(target_os = "linux", feature = "screen-capture"))]
let controller = native::Controller::new(dialog.clone_strong());
let controller = native::Controller::new(dialog.clone_strong(), state)?;
let main_weak = main.as_weak();
main.on_open_screen_share(move || {
if let Some(main) = main_weak.upgrade() {
@ -26,6 +31,11 @@ pub fn wire(main: &MainWindow) -> Result<(), slint::PlatformError> {
fn media_message(error: &str) -> crate::ui::i18n::Message {
use crate::ui::i18n::Message;
match error {
"Broadcast authorization timed out" => {
Message::with("Broadcast authorization timed out", vec![])
}
"Broadcast connection timed out" => Message::with("Broadcast connection timed out", vec![]),
"WebRTC connection timed out" => Message::with("WebRTC connection timed out", vec![]),
"Audio source inventory exceeds the supported size." => {
Message::with("Audio source inventory exceeds the supported size.", vec![])
}
@ -128,22 +138,50 @@ fn media_message(error: &str) -> crate::ui::i18n::Message {
#[cfg(all(target_os = "linux", feature = "screen-capture"))]
mod native {
use super::*;
use crate::ui::{slint::ScreenViewerWindow, state::ConnState};
use std::{
cell::{Cell, RefCell},
rc::Rc,
rc::{Rc, Weak},
sync::mpsc,
time::{Duration, Instant},
};
use vnox_client::media::{
self, AudioChoice, AudioKind, AudioSource, CaptureOptions, CaptureSession,
use vnox_client::{
media::{
self, AudioChoice, AudioKind, AudioSource, CaptureOptions, CaptureSession,
broadcast::{AvailableShare, BroadcastManager},
peer::{AudioTrack, Tracks},
},
net::{NetCommand, wire::MediaEvent},
};
thread_local! { static ACTIVE: RefCell<Weak<Controller>> = const { RefCell::new(Weak::new()) }; }
pub fn route(event: MediaEvent) {
ACTIVE.with(|active| {
if let Some(controller) = active.borrow().upgrade()
&& let Err(error) = controller.manager.borrow_mut().on_event(event)
{
controller.set_error(&error);
}
});
}
pub fn reject(error: &str) {
ACTIVE.with(|active| {
if let Some(controller) = active.borrow().upgrade() {
controller.manager.borrow_mut().stop();
controller.set_error(error);
}
});
}
enum Event {
Sources(Result<Vec<AudioSource>, String>),
Capture(u64, Result<CaptureSession, String>),
}
pub struct Controller {
window: ScreenShareWindow,
viewer: ScreenViewerWindow,
state: Weak<RefCell<crate::AppState>>,
manager: RefCell<BroadcastManager>,
shares: RefCell<Vec<AvailableShare>>,
viewing: RefCell<Option<String>>,
sources: RefCell<Vec<AudioSource>>,
selected: RefCell<Vec<AudioSource>>,
session: RefCell<Option<CaptureSession>>,
@ -156,11 +194,26 @@ mod native {
error: RefCell<Option<crate::ui::i18n::Message>>,
}
impl Controller {
pub fn new(window: ScreenShareWindow) -> Rc<Self> {
pub fn new(
window: ScreenShareWindow,
state: &Rc<RefCell<crate::AppState>>,
) -> Result<Rc<Self>, slint::PlatformError> {
window.set_capable(true);
let (tx, rx) = mpsc::channel();
let mut manager = BroadcastManager::default();
let ice_error = manager
.configure_ice(media::peer::IceServers {
stun: std::env::var("VNOX_STUN_SERVER").ok(),
turn: std::env::var("VNOX_TURN_SERVER").ok(),
})
.err();
let this = Rc::new(Self {
window,
viewer: ScreenViewerWindow::new()?,
state: Rc::downgrade(state),
manager: RefCell::new(manager),
shares: RefCell::new(Vec::new()),
viewing: RefCell::new(None),
sources: RefCell::new(Vec::new()),
selected: RefCell::new(Vec::new()),
session: RefCell::new(None),
@ -170,12 +223,13 @@ mod native {
timer: slint::Timer::default(),
started: RefCell::new(None),
generation: Cell::new(0),
error: RefCell::new(None),
error: RefCell::new(ice_error.as_deref().map(super::media_message)),
});
ACTIVE.with(|active| *active.borrow_mut() = Rc::downgrade(&this));
let weak = Rc::downgrade(&this);
this.timer.start(
slint::TimerMode::Repeated,
Duration::from_millis(50),
Duration::from_millis(33),
move || {
if let Some(this) = weak.upgrade() {
this.tick();
@ -207,13 +261,44 @@ mod native {
}
});
let weak = Rc::downgrade(&this);
this.window.on_toggle_broadcast(move || {
if let Some(this) = weak.upgrade() {
this.toggle_broadcast();
}
});
let weak = Rc::downgrade(&this);
this.window.on_watch_broadcast(move || {
if let Some(this) = weak.upgrade() {
this.watch();
}
});
let weak = Rc::downgrade(&this);
this.viewer.on_stop_viewing(move || {
if let Some(this) = weak.upgrade() {
this.stop_viewing();
}
});
let weak = Rc::downgrade(&this);
this.viewer.on_audio_changed(move || {
if let Some(this) = weak.upgrade() {
this.clear_mixer();
}
});
let weak = Rc::downgrade(&this);
this.viewer.window().on_close_requested(move || {
if let Some(this) = weak.upgrade() {
this.stop_viewing();
}
slint::CloseRequestResponse::HideWindow
});
let weak = Rc::downgrade(&this);
this.window.window().on_close_requested(move || {
if let Some(this) = weak.upgrade() {
this.stop();
}
slint::CloseRequestResponse::HideWindow
});
this
Ok(this)
}
pub fn refresh(&self) {
let tx = self.tx.clone();
@ -221,6 +306,13 @@ mod native {
let _ = tx.send(Event::Sources(media::audio_sources().await));
});
}
fn set_error(&self, error: &str) {
*self.error.borrow_mut() = Some(super::media_message(error));
}
fn clear_error(&self) {
self.error.borrow_mut().take();
self.window.set_error("".into());
}
fn filter_sources(&self) {
let kind = match self.window.get_audio_mode() {
1 => Some(AudioKind::Application),
@ -234,27 +326,24 @@ mod native {
.filter(|source| Some(source.kind) == kind)
.cloned()
.collect();
let labels: Vec<slint::SharedString> =
selected.iter().map(|s| s.name.as_str().into()).collect();
let labels: Vec<slint::SharedString> = selected
.iter()
.map(|source| source.name.as_str().into())
.collect();
self.window
.set_audio_sources(Rc::new(slint::VecModel::from(labels)).into());
self.window.set_source_index(0);
*self.selected.borrow_mut() = selected;
}
fn report_error(&self, error: &str) {
let message = media_message(error);
self.window.set_error(message.to_string().into());
*self.error.borrow_mut() = Some(message);
}
fn start(&self) {
self.stop();
self.window.set_error("".into());
self.clear_error();
let audio = match self.window.get_audio_mode() {
1 | 2 => {
let index = usize::try_from(self.window.get_source_index()).ok();
let selected = self.selected.borrow();
let Some(source) = index.and_then(|index| selected.get(index)) else {
self.report_error("Select an available audio source first.");
self.set_error("Select an available audio source first.");
return;
};
match source.kind {
@ -268,39 +357,112 @@ mod native {
let tx = self.tx.clone();
let generation = self.generation.get();
*self.pending.borrow_mut() = Some(tokio::spawn(async move {
let result = CaptureSession::choose(CaptureOptions {
audio,
..Default::default()
})
.await;
let _ = tx.send(Event::Capture(generation, result));
let _ = tx.send(Event::Capture(
generation,
CaptureSession::choose(CaptureOptions {
audio,
..Default::default()
})
.await,
));
}));
}
fn toggle_broadcast(&self) {
let mut manager = self.manager.borrow_mut();
if manager.publication_pending() {
manager.stop_publishing();
self.window.set_publishing(false);
self.window.set_publication_starting(false);
return;
}
let session = self.session.borrow();
let Some(session) = session.as_ref() else {
return;
};
let tracks = Tracks {
application_audio: self.window.get_audio_mode() > 0,
microphone: false,
};
if let Err(error) = manager.publish(&session.feed, tracks) {
self.set_error(&error);
}
}
fn watch(&self) {
self.stop_viewing();
let index = usize::try_from(self.window.get_broadcast_index()).ok();
let share = index.and_then(|index| self.shares.borrow().get(index).cloned());
if let Some(share) = share {
if let Err(error) = self.manager.borrow_mut().watch(&share.id) {
self.set_error(&error);
return;
}
super::sync_viewer_palette(&self.window, &self.viewer);
self.viewer
.set_publisher(self.publisher_name(&share.publisher_user).into());
self.viewer.set_has_frame(false);
self.viewer.set_frame(slint::Image::default());
self.viewer.set_audio_enabled(true);
*self.viewing.borrow_mut() = Some(share.id);
let _ = self.viewer.show();
}
}
fn publisher_name(&self, user: &str) -> String {
self.state
.upgrade()
.and_then(|state| {
state
.try_borrow()
.ok()
.map(|state| state.ui.nick_for(user).to_owned())
})
.unwrap_or_else(|| user.into())
}
fn clear_mixer(&self) {
if let Some(state) = self.state.upgrade()
&& let Ok(state) = state.try_borrow()
&& let Some(audio) = &state.audio
{
audio.media_mixer().clear();
}
}
fn stop_viewing(&self) {
if let Some(id) = self.viewing.borrow_mut().take() {
self.manager.borrow_mut().unwatch(&id);
}
self.clear_mixer();
self.viewer.set_frame(slint::Image::default());
self.viewer.set_has_frame(false);
let _ = self.viewer.hide();
}
fn stop(&self) {
self.manager.borrow_mut().stop_publishing();
self.generation.set(self.generation.get().wrapping_add(1));
if let Some(task) = self.pending.borrow_mut().take() {
task.abort();
}
self.session.borrow_mut().take();
// Discard late completion before another selection can start.
while self.rx.borrow_mut().try_recv().is_ok() {}
*self.started.borrow_mut() = None;
self.error.borrow_mut().take();
self.window.set_error("".into());
self.window.set_running(false);
self.window.set_busy(false);
self.window.set_publishing(false);
self.window.set_publication_starting(false);
self.window.set_has_frame(false);
self.window.set_preview(slint::Image::default());
self.window.set_audio_level(0.0);
}
fn tick(&self) {
while let Ok(event) = self.rx.borrow_mut().try_recv() {
loop {
let event = self.rx.borrow_mut().try_recv();
let Ok(event) = event else {
break;
};
match event {
Event::Sources(Ok(sources)) => {
*self.sources.borrow_mut() = sources;
self.filter_sources();
}
Event::Sources(Err(error)) => self.report_error(&error),
Event::Sources(Err(error)) => self.set_error(&error),
Event::Capture(generation, result) => {
if generation != self.generation.get() {
continue;
@ -313,25 +475,20 @@ mod native {
*self.started.borrow_mut() = Some(Instant::now());
self.window.set_running(true);
}
Err(error) => self.report_error(&error),
Err(error) => self.set_error(&error),
}
}
}
}
let mut error = None;
let mut failure = None;
if let Some(session) = self.session.borrow().as_ref() {
if let Err(message) = session.check() {
error = Some(message);
if let Err(error) = session.check() {
failure = Some(error);
}
if let Some(frame) = session.feed.take_frame() {
let buffer = slint::SharedPixelBuffer::<slint::Rgba8Pixel>::clone_from_slice(
&frame.rgba,
frame.width,
frame.height,
);
self.window.set_preview(slint::Image::from_rgba8(buffer));
self.window.set_preview(image(&frame));
self.window.set_has_frame(true);
*self.started.borrow_mut() = None;
self.started.borrow_mut().take();
}
self.window.set_audio_level(session.feed.audio_level());
if self
@ -339,25 +496,124 @@ mod native {
.borrow()
.is_some_and(|time| time.elapsed() > Duration::from_secs(10))
{
error = Some(
failure = Some(
"No frames received. Capture stopped; select the source again.".into(),
);
}
}
if let Some(error) = error {
if let Some(error) = failure {
self.stop();
self.report_error(&error);
self.set_error(&error);
}
if let Some(message) = self.error.borrow().as_ref() {
self.window.set_error(message.to_string().into());
if let Some(state) = self.state.upgrade()
&& let Ok(state) = state.try_borrow()
{
let session = match &state.ui.conn {
ConnState::Connected { session_id, .. } => session_id.as_str(),
_ => "",
};
let mut manager = self.manager.borrow_mut();
let channel = if session.is_empty() {
None
} else {
state.voice_channel.as_deref()
};
manager.set_scope(session, channel);
self.window.set_can_broadcast(channel.is_some());
// Existing voice owns microphone authorization. No duplicate mic track
// is requested by this UI; the tap remains disabled by default.
if let Some(audio) = &state.audio {
audio.enable_media_microphone(false);
}
manager.tick();
self.window.set_publishing(manager.publishing());
self.window.set_publication_starting(
manager.publication_pending() && !manager.publishing(),
);
self.window.set_viewers(manager.viewer_count() as i32);
let shares: Vec<_> = manager
.shares()
.into_iter()
.filter(|share| share.publisher_session != session)
.collect();
let labels: Vec<slint::SharedString> = shares
.iter()
.map(|share| state.ui.nick_for(&share.publisher_user).into())
.collect();
self.window
.set_broadcasts(Rc::new(slint::VecModel::from(labels)).into());
*self.shares.borrow_mut() = shares;
let mut commands = Vec::new();
while let Some(control) = manager.take_control() {
commands.push(NetCommand::MediaControl(control));
}
let net = state.net.clone();
if !commands.is_empty() {
tokio::spawn(async move {
for command in commands {
net.send(command).await;
}
});
}
while let Some(error) = manager.take_error() {
self.set_error(&error);
}
let viewing = self.viewing.borrow().clone();
if let Some(id) = viewing {
if manager.is_watching(&id) {
if let Some(feed) = manager.remote_feed(&id) {
if let Some(frame) = feed.take_video() {
self.viewer.set_frame(image(&frame));
self.viewer.set_has_frame(true);
}
for (track, suffix) in [
(AudioTrack::Application, "app"),
(AudioTrack::Microphone, "mic"),
] {
while let Some(frame) = feed.take_audio(track) {
if self.viewer.get_audio_enabled()
&& !state.ui.deafen
&& let Some(audio) = &state.audio
&& let Err(error) = audio
.media_mixer()
.push(&format!("{id}:{suffix}"), frame)
{
self.set_error(&error);
}
}
}
}
} else {
self.viewing.borrow_mut().take();
self.viewer.set_frame(slint::Image::default());
self.viewer.set_has_frame(false);
let _ = self.viewer.hide();
if let Some(audio) = &state.audio {
audio.media_mixer().clear();
}
}
}
}
if let Some(error) = self.error.borrow().as_ref() {
self.window.set_error(error.to_string().into());
}
}
}
impl Drop for Controller {
fn drop(&mut self) {
self.stop();
self.stop_viewing();
}
}
fn image(frame: &media::VideoFrame) -> slint::Image {
slint::Image::from_rgba8(
slint::SharedPixelBuffer::<slint::Rgba8Pixel>::clone_from_slice(
&frame.rgba,
frame.width,
frame.height,
),
)
}
}
fn sync_palette(main: &MainWindow, dialog: &ScreenShareWindow) {
@ -383,6 +639,30 @@ fn sync_palette(main: &MainWindow, dialog: &ScreenShareWindow) {
target.set_on_accent(source.get_on_accent());
}
#[cfg(all(target_os = "linux", feature = "screen-capture"))]
fn sync_viewer_palette(main: &ScreenShareWindow, dialog: &crate::ui::slint::ScreenViewerWindow) {
use crate::ui::slint::Theme;
let source = main.global::<Theme>();
let target = dialog.global::<Theme>();
target.set_bg_base(source.get_bg_base());
target.set_bg_surface(source.get_bg_surface());
target.set_bg_rail(source.get_bg_rail());
target.set_bg_hover(source.get_bg_hover());
target.set_bg_interactive(source.get_bg_interactive());
target.set_bg_elevated(source.get_bg_elevated());
target.set_selected(source.get_selected());
target.set_border(source.get_border());
target.set_accent(source.get_accent());
target.set_text_primary(source.get_text_primary());
target.set_text_secondary(source.get_text_secondary());
target.set_text_muted(source.get_text_muted());
target.set_text_disabled(source.get_text_disabled());
target.set_danger(source.get_danger());
target.set_success(source.get_success());
target.set_font_size(source.get_font_size());
target.set_on_accent(source.get_on_accent());
}
#[cfg(test)]
mod message_tests {
use super::*;
@ -420,3 +700,86 @@ mod message_tests {
);
}
}
/// Forward authenticated media events from the existing network/UI event pump.
pub fn on_event(event: vnox_client::net::wire::MediaEvent) {
#[cfg(all(target_os = "linux", feature = "screen-capture"))]
native::route(event);
#[cfg(not(all(target_os = "linux", feature = "screen-capture")))]
let _ = event;
}
#[cfg(test)]
mod window_tests {
use super::*;
use slint::platform::{
Platform, PlatformError, WindowAdapter,
software_renderer::{MinimalSoftwareWindow, RepaintBufferType},
};
use slint::{PhysicalSize, Rgb8Pixel, SharedPixelBuffer};
use std::{cell::RefCell, rc::Rc};
struct PlatformAdapter(Rc<RefCell<Vec<Rc<MinimalSoftwareWindow>>>>);
impl Platform for PlatformAdapter {
fn create_window_adapter(&self) -> Result<Rc<dyn WindowAdapter>, PlatformError> {
let surface = MinimalSoftwareWindow::new(RepaintBufferType::NewBuffer);
self.0.borrow_mut().push(surface.clone());
Ok(surface)
}
}
fn render(
window: &impl ComponentHandle,
surface: &MinimalSoftwareWindow,
name: &str,
width: u32,
height: u32,
) {
surface.set_size(PhysicalSize::new(width, height));
window.window().request_redraw();
let mut pixels = SharedPixelBuffer::<Rgb8Pixel>::new(width, height);
assert!(surface.draw_if_needed(|renderer| {
renderer.render(pixels.make_mut_slice(), width as usize);
}));
assert!(
pixels.as_bytes().windows(3).any(|pair| pair[0] != pair[1]),
"rendered content"
);
if let Some(path) = std::env::var_os("VNOX_UI_SNAPSHOT_DIR") {
std::fs::create_dir_all(&path).expect("snapshot dir");
image::save_buffer(
std::path::PathBuf::from(path).join(format!("{name}.png")),
pixels.as_bytes(),
width,
height,
image::ColorType::Rgb8,
)
.expect("rendered PNG");
}
}
#[test]
fn broadcast_windows_render_without_opening_capture_or_audio_devices() {
let surfaces = Rc::new(RefCell::new(Vec::new()));
slint::platform::set_platform(Box::new(PlatformAdapter(surfaces.clone())))
.expect("software platform");
let preview = ScreenShareWindow::new().expect("preview window");
preview.set_capable(true);
preview.set_can_broadcast(true);
preview.show().expect("show preview");
assert!(!preview.get_running() && !preview.get_publishing());
render(&preview, &surfaces.borrow()[0], "screen-preview", 820, 810);
preview.hide().expect("hide preview");
let viewer = crate::ui::slint::ScreenViewerWindow::new().expect("viewer window");
viewer.set_publisher("Synthetic test publisher".into());
viewer.show().expect("show viewer");
assert!(!viewer.get_has_frame());
render(&viewer, &surfaces.borrow()[1], "screen-viewer", 1100, 720);
viewer.hide().expect("hide viewer");
}
}
/// Fail pending/active media explicitly when the authenticated gateway rejects control.
pub fn on_error(error: &str) {
#[cfg(all(target_os = "linux", feature = "screen-capture"))]
native::reject(error);
#[cfg(not(all(target_os = "linux", feature = "screen-capture")))]
let _ = error;
}

View file

@ -7,3 +7,5 @@ pub mod preferences;
pub mod slint;
pub mod state;
pub mod update;
pub mod webhooks;

View file

@ -81,6 +81,7 @@ export component ChatPanel inherits Rectangle {
in-out property <bool> members-visible: true;
callback input-edited(string);
callback toggle-members();
callback open-webhooks();
callback send-message(string, string);
callback load-more(string);
callback react(string, string);
@ -99,6 +100,7 @@ export component ChatPanel inherits Rectangle {
Text { text: root.is-dm ? root.dm-partner-name : root.active-channel-name; color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 1.0); font-weight: 600; overflow: elide; vertical-alignment: center; }
if root.e2ee-enabled : Text { text: @tr("End-to-end encrypted"); color: Theme.success; font-size: Math.max(11px, Theme.font-size * 0.6875); }
Rectangle { horizontal-stretch: 1; }
if !root.is-dm : ActionButton { text: @tr("Webhooks"); quiet: true; clicked => { root.open-webhooks(); } }
if !root.is-dm : ActionButton { text: @tr("Members"); active: root.members-visible; clicked => { root.toggle-members(); } }
}
}

View file

@ -1,4 +1,5 @@
export { ScreenShareWindow } from "screen-share.slint";
export { WebhookWindow, WebhookRow } from "webhooks.slint";
export { ScreenShareWindow, ScreenViewerWindow } from "screen-share.slint";
export { UnlockWindow } from "unlock.slint";
export { Theme } from "theme.slint";
import { Theme, ActionButton } from "theme.slint";
@ -128,6 +129,7 @@ export component MainWindow inherits Window {
callback friend-input-edited(string);
callback open-settings();
callback open-screen-share();
callback open-webhooks();
callback show-voice-view();
callback show-friends-view();
callback audio-settings-changed(int, int, float, int, float);
@ -231,6 +233,7 @@ export component MainWindow inherits Window {
members: root.members;
input-text <=> root.input-text;
members-visible: root.members-visible && root.width > 1100px;
open-webhooks => { root.open-webhooks(); }
toggle-members => { root.members-visible = !root.members-visible; }
input-edited(text) => { root.input-edited(text); }
is-dm: root.is-dm;

View file

@ -3,7 +3,7 @@ import { Theme, ActionButton } from "theme.slint";
export component ScreenShareWindow inherits Window {
title: @tr("Screen preview");
preferred-width: 820px; preferred-height: 740px; min-width: 640px; min-height: 650px;
preferred-width: 820px; preferred-height: 810px; min-width: 640px; min-height: 720px;
background: Theme.bg-base;
in-out property <image> preview;
in-out property <bool> has-frame;
@ -15,21 +15,33 @@ export component ScreenShareWindow inherits Window {
in-out property <int> source-index;
in-out property <int> audio-mode;
in-out property <float> audio-level;
in-out property <bool> can-broadcast;
in-out property <bool> publishing;
in-out property <bool> publication-starting;
in-out property <int> viewers;
in-out property <[string]> broadcasts;
in-out property <int> broadcast-index;
callback toggle-broadcast();
callback watch-broadcast();
callback refresh-audio();
callback choose-source();
callback stop-capture();
callback audio-mode-changed();
VerticalLayout {
padding: 28px; spacing: 14px;
spacing: 0;
Flickable {
content-width: self.width;
VerticalLayout {
padding: 24px; spacing: 12px;
Text { text: @tr("Choose what you share"); color: Theme.text-primary; font-size: 24px; font-weight: 600; }
Text { text: @tr("Video, application audio and your microphone stay separate."); color: Theme.text-secondary; wrap: word-wrap; }
Rectangle {
min-height: 270px; vertical-stretch: 1; background: Theme.bg-rail; border-radius: 10px;
min-height: 230px; vertical-stretch: 1; background: Theme.bg-rail; border-radius: 10px;
Image { visible: root.has-frame; source: root.preview; image-fit: contain; }
if !root.has-frame : Text { text: root.busy ? @tr("Choose a screen or window in the system dialog…") : @tr("Your preview appears here after you choose a source."); color: Theme.text-muted; wrap: word-wrap; horizontal-alignment: center; vertical-alignment: center; }
if root.running : Rectangle {
x: 12px; y: 12px; width: 132px; height: 28px; border-radius: 5px; background: Theme.bg-surface;
Text { text: @tr("LOCAL PREVIEW"); color: Theme.accent; font-size: 11px; horizontal-alignment: center; vertical-alignment: center; }
Text { text: root.publishing ? @tr("LIVE") : @tr("LOCAL PREVIEW"); color: Theme.accent; font-size: 11px; horizontal-alignment: center; vertical-alignment: center; }
}
}
Text { text: @tr("Share audio"); color: Theme.text-primary; font-weight: 600; }
@ -47,12 +59,49 @@ export component ScreenShareWindow inherits Window {
Text { text: @tr("Microphone uses your existing voice controls. This preview never enables or mixes it."); color: Theme.text-secondary; wrap: word-wrap; }
Rectangle {
height: note.preferred-height + 24px; background: Theme.bg-surface; border-radius: 8px;
note := Text { x: 12px; y: 12px; width: parent.width - 24px; text: root.capable ? @tr("Local capture is available. Broadcasting to other members is not available until the media transport is connected.") : @tr("Screen capture is not available in this build."); color: Theme.text-muted; wrap: word-wrap; }
note := Text { x: 12px; y: 12px; width: parent.width - 24px; text: root.capable ? @tr("Preview stays local until you start broadcasting. Only members of your voice channel can watch.") : @tr("Screen capture is not available in this build."); color: Theme.text-muted; wrap: word-wrap; }
}
if root.broadcasts.length > 0 : HorizontalLayout {
DeviceSelect { model: root.broadcasts; current-index <=> root.broadcast-index; horizontal-stretch: 1; }
ActionButton { text: @tr("Watch broadcast"); clicked => { root.watch-broadcast(); } }
}
if root.error != "" : Text { text: root.error; color: Theme.danger; wrap: word-wrap; }
}
}
Rectangle {
height: 72px; background: Theme.bg-surface;
HorizontalLayout {
Text { text: root.running && root.has-frame ? @tr("Preview active · not broadcasting") : @tr("Nothing is being broadcast"); color: Theme.text-muted; vertical-alignment: center; horizontal-stretch: 1; }
padding: 20px; spacing: 12px;
Text { text: root.publication-starting ? @tr("Starting broadcast…") : root.publishing ? @tr("Broadcasting · {n} viewer" | "Broadcasting · {n} viewers" % root.viewers) : root.running && root.has-frame ? @tr("Preview active · not broadcasting") : @tr("Nothing is being broadcast"); color: Theme.text-muted; vertical-alignment: center; horizontal-stretch: 1; }
if root.running && root.has-frame && root.can-broadcast : ActionButton { text: root.publication-starting ? @tr("Cancel broadcast") : root.publishing ? @tr("Stop broadcast") : @tr("Start broadcast"); active: root.publishing; clicked => { root.toggle-broadcast(); } }
if root.capable : ActionButton { text: root.running || root.busy ? @tr("Stop") : @tr("Choose screen or window"); clicked => { if root.running || root.busy { root.stop-capture(); } else { root.choose-source(); } } }
}
}
}
}
export component ScreenViewerWindow inherits Window {
title: @tr("Broadcast");
preferred-width: 1100px; preferred-height: 720px; min-width: 640px; min-height: 420px;
background: Theme.bg-rail;
in-out property <image> frame;
in-out property <bool> has-frame;
in-out property <bool> audio-enabled: true;
in-out property <string> publisher;
callback stop-viewing();
callback audio-changed();
VerticalLayout {
padding: 16px; spacing: 12px;
HorizontalLayout {
Text { text: root.publisher; color: Theme.text-primary; font-size: 16px; vertical-alignment: center; horizontal-stretch: 1; }
ActionButton { text: root.audio-enabled ? @tr("Mute broadcast") : @tr("Unmute broadcast"); active: !root.audio-enabled; clicked => { root.audio-enabled = !root.audio-enabled; root.audio-changed(); } }
ActionButton { text: @tr("Stop watching"); clicked => { root.stop-viewing(); } }
}
Rectangle {
background: #000000; vertical-stretch: 1; border-radius: 8px;
Image { source: root.frame; visible: root.has-frame; image-fit: contain; }
if !root.has-frame : Text { text: @tr("Connecting to broadcast…"); color: Theme.text-muted; horizontal-alignment: center; vertical-alignment: center; }
}
}
}

View file

@ -7,8 +7,9 @@ component ThemeChoice inherits Rectangle {
in property <color> preview-background;
in property <color> preview-sidebar;
in property <color> preview-ink;
in property <color> preview-accent: #bba583;
callback clicked();
height: 142px;
height: 160px;
border-radius: 9px;
border-width: keyboard.has-focus || root.selected ? 2px : 1px;
border-color: root.selected || keyboard.has-focus ? Theme.accent : Theme.border;
@ -17,13 +18,52 @@ component ThemeChoice inherits Rectangle {
accessible-label: root.label;
VerticalLayout {
padding: 8px; spacing: 10px;
Rectangle {
height: 86px; background: root.preview-background; border-radius: 5px; clip: true;
Rectangle { width: 23%; height: 100%; background: root.preview-sidebar; }
Rectangle { x: parent.width * 0.29; y: 15px; width: 41%; height: 6px; background: root.preview-ink; opacity: 0.8; border-radius: 2px; }
Rectangle { x: parent.width * 0.29; y: 29px; width: 59%; height: 4px; background: root.preview-ink; opacity: 0.28; border-radius: 2px; }
Rectangle { x: parent.width * 0.29; y: 40px; width: 45%; height: 4px; background: root.preview-ink; opacity: 0.28; border-radius: 2px; }
Rectangle { x: parent.width * 0.29; y: 61px; width: 60%; height: 13px; background: root.preview-sidebar; border-radius: 3px; }
mini := Rectangle {
height: 108px;
background: root.preview-background;
border-radius: 5px;
border-width: 1px;
border-color: root.preview-ink.with-alpha(0.1);
clip: true;
// A miniature client: server rail, channel list, conversation and composer.
rail := Rectangle {
x: 0px; y: 0px;
width: 17px; height: parent.height; background: root.preview-sidebar.darker(8%);
Rectangle { x: 4px; y: 8px; width: 9px; height: 9px; border-radius: 3px; background: root.preview-accent;
Image { source: @image-url("../assets/vnox-mark.svg"); width: 9px; height: 9px; image-fit: contain; }
}
Rectangle { x: 4px; y: 24px; width: 9px; height: 9px; border-radius: 4px; background: root.preview-ink.with-alpha(0.14); }
Rectangle { x: 4px; y: 38px; width: 9px; height: 9px; border-radius: 4px; background: root.preview-ink.with-alpha(0.08); }
Rectangle { x: 4px; y: parent.height - 13px; width: 8px; height: 8px; border-radius: 4px; background: root.preview-ink.with-alpha(0.3); }
}
side := Rectangle {
x: 17px; y: 0px; width: parent.width * 0.27; height: parent.height; background: root.preview-sidebar;
Text { x: 5px; y: 7px; text: "Vnox"; color: root.preview-ink; font-size: 7px; font-weight: 700; }
Rectangle { x: 3px; y: 24px; width: parent.width - 6px; height: 13px; border-radius: 2px; background: root.preview-accent.with-alpha(0.18);
Text { x: 4px; text: "#"; color: root.preview-accent; font-size: 9px; vertical-alignment: center; }
Rectangle { x: 14px; y: 5px; width: Math.max(parent.width - 21px, 3px); height: 3px; border-radius: 1px; background: root.preview-ink.with-alpha(0.65); }
}
Text { x: 7px; y: 42px; text: "#"; color: root.preview-ink.with-alpha(0.4); font-size: 8px; }
Text { x: 7px; y: 59px; text: "♪"; color: root.preview-ink.with-alpha(0.4); font-size: 8px; }
Rectangle { x: 7px; y: 80px; width: 4px; height: 4px; border-radius: 2px; background: root.preview-accent; }
Rectangle { x: 15px; y: 81px; width: Math.max(parent.width - 24px, 3px); height: 2px; background: root.preview-ink.with-alpha(0.3); }
}
thread := Rectangle {
x: side.x + side.width; y: 0px; width: parent.width - self.x; height: parent.height; background: transparent;
Text { x: 7px; y: 5px; text: "#"; color: root.preview-ink.with-alpha(0.65); font-size: 10px; }
Rectangle { x: 21px; y: 10px; width: parent.width * 0.29; height: 3px; border-radius: 1px; background: root.preview-ink.with-alpha(0.65); }
Rectangle { y: 23px; width: parent.width; height: 1px; background: root.preview-ink.with-alpha(0.08); }
Rectangle { x: 7px; y: 33px; width: 10px; height: 10px; border-radius: 4px; background: root.preview-accent; }
Rectangle { x: 23px; y: 34px; width: parent.width * 0.35; height: 3px; border-radius: 1px; background: root.preview-ink.with-alpha(0.75); }
Rectangle { x: 23px; y: 42px; width: parent.width - 32px; height: 3px; border-radius: 1px; background: root.preview-ink.with-alpha(0.25); }
Rectangle { x: 7px; y: 56px; width: 10px; height: 10px; border-radius: 4px; background: root.preview-ink.with-alpha(0.22); }
Rectangle { x: 23px; y: 57px; width: parent.width * 0.25; height: 3px; border-radius: 1px; background: root.preview-ink.with-alpha(0.65); }
Rectangle { x: 23px; y: 65px; width: parent.width * 0.4; height: 3px; border-radius: 1px; background: root.preview-ink.with-alpha(0.25); }
Rectangle { x: 6px; y: parent.height - 23px; width: parent.width - 12px; height: 16px; border-radius: 4px; background: root.preview-sidebar;
Text { x: 4px; text: "+"; color: root.preview-ink.with-alpha(0.45); font-size: 10px; vertical-alignment: center; }
Rectangle { x: parent.width - 12px; y: 5px; width: 6px; height: 6px; border-radius: 2px; background: root.preview-accent; }
}
}
}
HorizontalLayout {
Text { text: root.label; color: Theme.text-primary; font-size: Math.max(Theme.font-size - 3px, 11px); font-weight: 500; overflow: elide; horizontal-stretch: 1; }
@ -72,7 +112,7 @@ export component AppearanceSettings inherits Rectangle {
ThemeChoice { label: @tr("Light"); selected: root.theme-mode == "light"; preview-background: #f5f4f2; preview-sidebar: #e6e4e0; preview-ink: #353330; clicked => { root.theme-selected("light"); } }
ThemeChoice { label: @tr("Dark"); selected: root.theme-mode == "dark"; preview-background: #272729; preview-sidebar: #202022; preview-ink: #e9e7e4; clicked => { root.theme-selected("dark"); } }
ThemeChoice { label: @tr("Extra dark"); selected: root.theme-mode == "black"; preview-background: #080808; preview-sidebar: #131313; preview-ink: #dedbd5; clicked => { root.theme-selected("black"); } }
ThemeChoice { label: @tr("Custom"); selected: root.theme-mode == "custom"; preview-background: Theme.bg-base; preview-sidebar: Theme.bg-surface; preview-ink: Theme.accent; clicked => { root.theme-selected("custom"); } }
ThemeChoice { label: @tr("Custom"); selected: root.theme-mode == "custom"; preview-background: Theme.bg-base; preview-sidebar: Theme.bg-surface; preview-ink: Theme.text-primary; preview-accent: Theme.accent; clicked => { root.theme-selected("custom"); } }
}
Rectangle { height: 29px; }
Rectangle { height: 1px; background: Theme.border; }

126
src/ui/slint/webhooks.slint Normal file
View file

@ -0,0 +1,126 @@
import { Theme, ActionButton } from "theme.slint";
import { ThemeInput, DeviceSelect } from "controls.slint";
export struct WebhookRow { id: string, name: string, detail: string, paused: bool }
export component WebhookWindow inherits Window {
title: @tr("Channel webhooks");
preferred-width: 820px; preferred-height: 700px; min-width: 680px; min-height: 620px;
background: Theme.bg-base;
in property <string> channel-name;
in property <[WebhookRow]> hooks;
in property <bool> allowed;
in property <bool> busy;
in property <string> error;
in property <string> secret;
in property <string> secret-name;
in property <string> secret-path;
in property <bool> secret-outgoing;
in property <string> confirmation-name;
in property <bool> confirming;
in property <bool> confirming-revoke;
in-out property <string> new-name;
in-out property <string> new-endpoint;
in-out property <int> new-kind;
callback refresh();
callback create();
callback rotate(string);
callback revoke(string);
callback confirm();
callback cancel-confirmation();
callback hide-secret();
callback dismiss();
VerticalLayout {
padding: 28px; spacing: 12px;
HorizontalLayout {
VerticalLayout {
spacing: 4px;
Text { text: @tr("Channel webhooks"); color: Theme.text-primary; font-size: Theme.font-size + 8px; font-weight: 600; }
Text { text: root.channel-name; color: Theme.text-muted; font-size: Theme.font-size; overflow: elide; }
}
if !root.busy && root.secret == "" && !root.confirming : ActionButton { text: @tr("Refresh"); clicked => { root.refresh(); } }
}
Text { text: @tr("Receive updates here, or send signed channel events to your own service."); color: Theme.text-secondary; wrap: word-wrap; }
Rectangle { height: 1px; background: Theme.border; }
if root.error != "" : Text { text: root.error; color: Theme.danger; wrap: word-wrap; }
if root.busy : Text { text: @tr("Waiting for the server…"); color: Theme.text-muted; }
if root.secret != "" : Rectangle {
height: secret-content.preferred-height + 28px;
background: Theme.bg-surface; border-radius: Theme.radius;
border-width: 1px; border-color: Theme.accent;
secret-content := VerticalLayout {
padding: 14px; spacing: 10px;
Text { text: @tr("Save this secret now"); color: Theme.text-primary; font-weight: 600; }
Text { text: root.secret-name; color: Theme.text-secondary; overflow: elide; }
Text { text: @tr("It is shown once. Closing this window or hiding it removes it from the client."); color: Theme.text-muted; wrap: word-wrap; }
credential := TextInput {
text: root.secret; read-only: true; wrap: word-wrap; height: 44px;
color: Theme.text-primary; font-family: "monospace"; font-size: Theme.font-size - 2px;
selection-background-color: Theme.selected;
accessible-label: @tr("Webhook secret");
}
if !root.secret-outgoing : Text { text: root.secret-path; color: Theme.text-secondary; wrap: word-wrap; }
Text { text: root.secret-outgoing ? @tr("Use this key to verify X-Vnox-Signature over the timestamp and raw request body.") : @tr("Use your server's HTTPS webhook endpoint. Generic integrations send this secret in Authorization: Bearer; GitHub uses it as the webhook secret."); color: Theme.text-muted; wrap: word-wrap; }
HorizontalLayout {
ActionButton { text: @tr("Copy and hide"); active: true; clicked => { credential.select-all(); credential.copy(); root.hide-secret(); } }
ActionButton { text: @tr("Hide secret"); quiet: true; clicked => { root.hide-secret(); } }
Rectangle { horizontal-stretch: 1; }
}
}
}
if root.confirming : Rectangle {
height: confirm-content.preferred-height + 28px; background: Theme.bg-surface; border-radius: Theme.radius;
confirm-content := VerticalLayout {
padding: 14px; spacing: 10px;
Text { text: root.confirming-revoke ? @tr("Revoke this webhook?") : @tr("Rotate this secret?"); color: Theme.text-primary; font-weight: 600; }
Text { text: root.confirmation-name; color: Theme.text-secondary; overflow: elide; }
Text { text: root.confirming-revoke ? @tr("New deliveries stop. Existing messages stay in the channel.") : @tr("The old secret stops working. Update the external integration with the new secret."); color: Theme.text-muted; wrap: word-wrap; }
HorizontalLayout {
ActionButton { text: root.confirming-revoke ? @tr("Revoke webhook") : @tr("Rotate secret"); danger: root.confirming-revoke; clicked => { root.confirm(); } }
ActionButton { text: @tr("Cancel"); quiet: true; clicked => { root.cancel-confirmation(); } }
Rectangle { horizontal-stretch: 1; }
}
}
}
list := Flickable {
min-height: 80px; vertical-stretch: 1; content-width: self.width;
VerticalLayout {
spacing: 0; alignment: start;
if root.allowed && !root.busy && root.hooks.length == 0 : Text { text: @tr("No webhooks yet. Add an integration below."); color: Theme.text-muted; wrap: word-wrap; }
for hook in root.hooks : Rectangle {
height: 76px; background: transparent;
HorizontalLayout {
padding-top: 10px; padding-bottom: 10px; spacing: 10px;
VerticalLayout {
spacing: 5px; horizontal-stretch: 1;
Text { text: hook.name; color: Theme.text-primary; font-weight: 600; overflow: elide; }
Text { text: hook.detail; color: hook.paused ? Theme.danger : Theme.text-muted; font-size: Theme.font-size - 3px; overflow: elide; }
}
if root.allowed && !root.busy && root.secret == "" && !root.confirming : ActionButton { text: @tr("Rotate"); clicked => { root.rotate(hook.id); } }
if root.allowed && !root.busy && root.secret == "" && !root.confirming : ActionButton { text: @tr("Revoke"); quiet: true; danger: true; clicked => { root.revoke(hook.id); } }
}
Rectangle { y: parent.height - 1px; height: 1px; background: Theme.border; }
}
}
}
if root.allowed && !root.busy && root.secret == "" && !root.confirming : VerticalLayout {
spacing: 10px;
Text { text: @tr("Add an integration"); color: Theme.text-primary; font-weight: 600; }
HorizontalLayout {
spacing: 10px;
ThemeInput { text <=> root.new-name; placeholder-text: @tr("Integration name"); horizontal-stretch: 1; }
DeviceSelect { width: 210px; model: [@tr("Incoming message"), @tr("GitHub updates"), @tr("Outgoing events")]; current-index <=> root.new-kind; }
}
if root.new-kind == 2 : ThemeInput { text <=> root.new-endpoint; placeholder-text: "https://example.org/vnox-events"; }
HorizontalLayout {
Text { text: root.new-kind == 2 ? @tr("Only public HTTPS destinations. Events: message.created.") : @tr("An integration can post only in this channel, using its own identity."); color: Theme.text-muted; wrap: word-wrap; horizontal-stretch: 1; }
ActionButton { text: @tr("Create webhook"); active: true; clicked => { root.create(); } }
}
}
if !root.allowed && !root.busy : Text { text: @tr("Only the server owner or members with Manage Webhooks can change integrations."); color: Theme.text-muted; wrap: word-wrap; }
HorizontalLayout {
Rectangle { horizontal-stretch: 1; }
ActionButton { text: @tr("Close"); quiet: true; clicked => { root.dismiss(); } }
}
}
}

View file

@ -10,12 +10,42 @@ use crate::AppState;
pub fn process_net_events(state: &mut AppState) {
while let Some(event) = state.net.try_recv() {
match event {
NetEvent::VoiceRevoked { channel_id } => {
if state.voice_channel.as_deref() == Some(channel_id.as_str())
|| state.ui.voice_target.as_deref() == Some(channel_id.as_str())
{
state.ui.voice = VoiceUiState::Off;
state.ui.voice_target = None;
state.voice_channel = None;
state.audio = None;
state.last_pipeline_config = None;
}
}
NetEvent::MediaEvent(event) => crate::ui::media::on_event(event),
NetEvent::WebhookResult(result) => {
if let Some(ui) = &state.webhooks {
ui.receive_result(&result.request_id, result.hook, result.secret);
}
}
NetEvent::WebhookList(result) => {
if let Some(ui) = &state.webhooks {
ui.receive_list(&result.request_id, result.hooks);
}
}
NetEvent::WebhookError(result) => {
if let Some(ui) = &state.webhooks {
ui.receive_error(&result.request_id, result.code);
}
}
NetEvent::Connected {
session_id,
node_name,
restored,
private_mode,
} => {
state.connection_generation = state.connection_generation.wrapping_add(1);
state.ui.conn = ConnState::Connected {
session_id,
node_name: node_name.clone(),
@ -46,6 +76,9 @@ pub fn process_net_events(state: &mut AppState) {
}
}
NetEvent::Disconnected { reason, will_retry } => {
if let Some(ui) = &state.webhooks {
ui.disconnected();
}
state.ui.voice = VoiceUiState::Off;
state.audio = None;
state.voice_channel = None;
@ -308,6 +341,11 @@ fn process_net_event(ui: &mut UiState, net: &NetHandle, event: NetEvent) {
| NetEvent::PresenceSync { .. }
| NetEvent::PresenceUpdated { .. } => status_handle(ui, net, event),
NetEvent::VoiceRevoked { .. }
| NetEvent::MediaEvent(_)
| NetEvent::WebhookResult(_)
| NetEvent::WebhookList(_)
| NetEvent::WebhookError(_) => unreachable!("handled before generic UI dispatch"),
NetEvent::Connected { .. }
| NetEvent::Disconnected { .. }
| NetEvent::Reconnecting { .. }
@ -532,6 +570,9 @@ fn chat_handle(ui: &mut UiState, net: &NetHandle, event: NetEvent) {
ui.scroll_bottom = true;
}
NetEvent::Error { message, .. } => {
if message.starts_with("media:") {
crate::ui::media::on_error(&message);
}
ui.status_msg = Some(crate::ui::i18n::Message::with(
"Server error: {message}",
vec![("message", message.to_string())],

287
src/ui/webhooks.rs Normal file
View file

@ -0,0 +1,287 @@
//! Native, authenticated channel integration management. Credentials are never persisted.
use crate::ui::{
i18n,
slint::{MainWindow, Theme, WebhookRow, WebhookWindow},
};
use slint::{ComponentHandle, ModelRc, VecModel};
use std::{
cell::RefCell,
rc::Rc,
time::{Duration, Instant},
};
use vnox_client::{
net::{NetCommand, wire::WebhookInfo},
webhooks::{Controller, Error, Form, Kind, Scope},
};
type Send = Rc<dyn Fn(NetCommand)>;
/// Keep this bridge alive for the lifetime of the application. The caller feeds correlated network responses.
pub struct WebhookUi {
window: WebhookWindow,
controller: Rc<RefCell<Controller>>,
send: Send,
_timer: slint::Timer,
}
impl WebhookUi {
pub fn new(send: Send) -> Result<Self, slint::PlatformError> {
let window = WebhookWindow::new()?;
let controller = Rc::new(RefCell::new(Controller::default()));
for action in [0, 1, 2] {
let weak = window.as_weak();
let model = controller.clone();
let send = send.clone();
let callback = move || {
if let Some(window) = weak.upgrade() {
let result = match action {
0 => model.borrow_mut().refresh(),
1 => {
let kind = Kind::from_index(window.get_new_kind());
if let Some(kind) = kind {
model.borrow_mut().create(Form {
name: window.get_new_name().to_string(),
kind,
endpoint: window.get_new_endpoint().to_string(),
})
} else {
model.borrow_mut().show_error(Error::RequestFailed);
Err(Error::RequestFailed)
}
}
_ => model.borrow_mut().confirm(),
};
if let Ok(command) = result {
send(command)
}
render(&window, &model.borrow());
}
};
match action {
0 => window.on_refresh(callback),
1 => window.on_create(callback),
_ => window.on_confirm(callback),
}
}
for revoke in [false, true] {
let weak = window.as_weak();
let model = controller.clone();
let callback = move |id: slint::SharedString| {
if let Some(window) = weak.upgrade() {
let _ = if revoke {
model.borrow_mut().ask_revoke(&id)
} else {
model.borrow_mut().ask_rotate(&id)
};
render(&window, &model.borrow());
}
};
if revoke {
window.on_revoke(callback)
} else {
window.on_rotate(callback)
}
}
{
let weak = window.as_weak();
let model = controller.clone();
window.on_hide_secret(move || {
model.borrow_mut().hide_secret();
if let Some(window) = weak.upgrade() {
render(&window, &model.borrow())
}
});
}
{
let weak = window.as_weak();
let model = controller.clone();
window.on_cancel_confirmation(move || {
model.borrow_mut().cancel_confirmation();
if let Some(window) = weak.upgrade() {
render(&window, &model.borrow())
}
});
}
{
let weak = window.as_weak();
let model = controller.clone();
window.on_dismiss(move || {
model.borrow_mut().close();
if let Some(window) = weak.upgrade() {
render(&window, &model.borrow());
let _ = window.hide();
}
});
}
{
let weak = window.as_weak();
let model = controller.clone();
window.window().on_close_requested(move || {
model.borrow_mut().close();
if let Some(window) = weak.upgrade() {
render(&window, &model.borrow())
}
slint::CloseRequestResponse::HideWindow
});
}
let timer = slint::Timer::default();
{
let weak = window.as_weak();
let model = controller.clone();
timer.start(
slint::TimerMode::Repeated,
Duration::from_millis(250),
move || {
if model.borrow_mut().expire(Instant::now())
&& let Some(window) = weak.upgrade()
{
render(&window, &model.borrow());
}
},
);
}
Ok(Self {
window,
controller,
send,
_timer: timer,
})
}
pub fn open(
&self,
main: &MainWindow,
scope: Scope,
connected: bool,
) -> Result<(), slint::PlatformError> {
sync_palette(main, &self.window);
self.window.set_new_name("".into());
self.window.set_new_endpoint("".into());
self.window.set_new_kind(0);
if let Ok(command) = self.controller.borrow_mut().open(scope, connected) {
(self.send)(command)
}
render(&self.window, &self.controller.borrow());
self.window.show()
}
pub fn receive_list(&self, request_id: &str, hooks: Vec<WebhookInfo>) {
if self.controller.borrow_mut().receive_list(request_id, hooks) {
render(&self.window, &self.controller.borrow())
}
}
pub fn receive_result(&self, request_id: &str, hook: Option<WebhookInfo>, secret: String) {
if self
.controller
.borrow_mut()
.receive_result(request_id, hook, secret)
{
self.window.set_new_name("".into());
self.window.set_new_endpoint("".into());
render(&self.window, &self.controller.borrow())
}
}
pub fn receive_error(&self, request_id: &str, code: u32) {
if self.controller.borrow_mut().receive_error(request_id, code) {
render(&self.window, &self.controller.borrow())
}
}
pub fn disconnected(&self) {
self.controller.borrow_mut().disconnected();
render(&self.window, &self.controller.borrow())
}
}
fn render(window: &WebhookWindow, controller: &Controller) {
window.set_channel_name(
controller
.scope()
.map(|s| format!("# {}", s.channel_name))
.unwrap_or_default()
.into(),
);
window.set_allowed(controller.allowed());
window.set_busy(controller.busy());
window.set_error(
controller
.error()
.map(|e| i18n::text(e.message()))
.unwrap_or_default()
.into(),
);
window.set_secret(controller.secret().into());
window.set_secret_name(
controller
.secret_hook()
.map(|h| h.name.as_str())
.unwrap_or_default()
.into(),
);
window.set_secret_outgoing(
controller
.secret_hook()
.is_some_and(|h| h.direction == "outgoing"),
);
window.set_secret_path(
controller
.secret_hook()
.filter(|h| h.direction == "incoming")
.map(|h| format!("POST /v1/webhooks/{}", h.id))
.unwrap_or_default()
.into(),
);
let confirmation = controller.confirmation();
window.set_confirming(confirmation.is_some());
window.set_confirming_revoke(confirmation.is_some_and(|(revoke, _)| revoke));
window.set_confirmation_name(
confirmation
.and_then(|(_, id)| controller.hooks().iter().find(|h| h.id == id))
.map(|h| h.name.as_str())
.unwrap_or_default()
.into(),
);
let rows = controller
.hooks()
.iter()
.map(|h| {
let mode = i18n::text(if h.direction == "outgoing" {
"Outgoing events"
} else if h.provider == "github" {
"GitHub updates"
} else {
"Incoming message"
});
let paused = !h.suspended_reason.is_empty();
let detail = if paused {
i18n::text("Paused: delivery queue full. Rotate the secret to resume.")
} else if h.direction == "outgoing" {
format!("{mode} · {}", h.endpoint)
} else {
mode
};
WebhookRow {
id: h.id.as_str().into(),
name: h.name.as_str().into(),
detail: detail.into(),
paused,
}
})
.collect::<Vec<_>>();
window.set_hooks(ModelRc::from(Rc::new(VecModel::from(rows))));
}
fn sync_palette(main: &MainWindow, dialog: &WebhookWindow) {
let source = main.global::<Theme>();
let target = dialog.global::<Theme>();
target.set_bg_base(source.get_bg_base());
target.set_bg_surface(source.get_bg_surface());
target.set_bg_rail(source.get_bg_rail());
target.set_bg_hover(source.get_bg_hover());
target.set_bg_interactive(source.get_bg_interactive());
target.set_bg_elevated(source.get_bg_elevated());
target.set_selected(source.get_selected());
target.set_border(source.get_border());
target.set_accent(source.get_accent());
target.set_text_primary(source.get_text_primary());
target.set_text_secondary(source.get_text_secondary());
target.set_text_muted(source.get_text_muted());
target.set_text_disabled(source.get_text_disabled());
target.set_danger(source.get_danger());
target.set_success(source.get_success());
target.set_font_size(source.get_font_size());
target.set_on_accent(source.get_on_accent());
}