feat(client): updates settings panel and updater wiring

This commit is contained in:
Loki 2026-11-01 16:20:51 +01:00
parent cd22254027
commit 2790aadeba
Signed by: boba
GPG key ID: 253067914055423B
10 changed files with 412 additions and 5 deletions

View file

@ -83,6 +83,7 @@ fn main() -> Result<()> {
))?));
wire_signals(&window, &state);
ui::media::wire(&window, &state)?;
let _update_timer = ui::updater::wire(&window, &state);
let timer = slint::Timer::default();
{

View file

@ -10,5 +10,6 @@ pub mod slint;
pub mod sounds;
pub mod state;
pub mod update;
pub mod updater;
pub mod webhooks;

View file

@ -2,6 +2,7 @@ export { WebhookWindow, WebhookRow } from "webhooks.slint";
export { ScreenShareWindow, ScreenViewerWindow } from "screen-share.slint";
export { UnlockWindow } from "unlock.slint";
export { Theme } from "theme.slint";
export { UpdateUi } from "settings/updates.slint";
export { EmojiCatalog, EmojiItem } from "emoji-picker.slint";
import { Theme, ActionButton } from "theme.slint";
import { Sidebar, ChannelItem, GuildItem, DmItem } from "sidebar.slint";

View file

@ -3,6 +3,7 @@ import { AudioSettings } from "settings/audio.slint";
import { SoundSettings } from "settings/sounds.slint";
import { AppearanceSettings } from "settings/appearance.slint";
import { IdentitySettings } from "settings/identity.slint";
import { UpdateSettings } from "settings/updates.slint";
component SettingsNav inherits Rectangle {
in property <string> label;
@ -102,6 +103,7 @@ export component SettingsWindow inherits Rectangle {
SettingsNav { label: @tr("Audio & microphone"); detail: @tr("Devices and voice input"); mark: "mic"; active: root.active-tab == "audio"; clicked => { root.active-tab = "audio"; } }
SettingsNav { label: @tr("Appearance"); detail: @tr("Themes, colours and text"); mark: "palette"; active: root.active-tab == "appearance"; clicked => { root.active-tab = "appearance"; } }
SettingsNav { label: @tr("Profile and keys"); detail: @tr("Security and backup"); mark: "user"; active: root.active-tab == "identity"; clicked => { root.active-tab = "identity"; } }
SettingsNav { label: @tr("Updates"); detail: @tr("Version and updates"); mark: "shield-check"; active: root.active-tab == "updates"; clicked => { root.active-tab = "updates"; } }
Rectangle { vertical-stretch: 1; }
Rectangle { height: 1px; background: Theme.border; }
Text { text: "VNOX"; color: Theme.text-secondary; font-size: Math.max(Theme.font-size - 3px, 11px); font-weight: 700; height: 30px; vertical-alignment: bottom; }
@ -118,8 +120,8 @@ export component SettingsWindow inherits Rectangle {
padding-left: 34px; padding-right: 28px; padding-top: 29px; padding-bottom: 20px; spacing: 18px;
VerticalLayout {
spacing: 6px;
Text { text: root.active-tab == "appearance" ? @tr("Appearance") : root.active-tab == "identity" ? @tr("Profile and keys") : @tr("Audio & microphone"); color: Theme.text-primary; font-size: Theme.font-size + 12px; font-weight: 700; }
Text { text: root.active-tab == "appearance" ? @tr("Make Vnox yours.") : root.active-tab == "identity" ? @tr("Your profile, kept safe.") : @tr("Make yourself heard, your way."); color: Theme.text-muted; font-size: Math.max(Theme.font-size - 3px, 11px); }
Text { text: root.active-tab == "appearance" ? @tr("Appearance") : root.active-tab == "identity" ? @tr("Profile and keys") : root.active-tab == "updates" ? @tr("Updates") : @tr("Audio & microphone"); color: Theme.text-primary; font-size: Theme.font-size + 12px; font-weight: 700; }
Text { text: root.active-tab == "appearance" ? @tr("Make Vnox yours.") : root.active-tab == "identity" ? @tr("Your profile, kept safe.") : root.active-tab == "updates" ? @tr("Stay current, safely.") : @tr("Make yourself heard, your way."); color: Theme.text-muted; font-size: Math.max(Theme.font-size - 3px, 11px); }
}
Rectangle { horizontal-stretch: 1; }
VerticalLayout { alignment: start; ActionButton { text: @tr("Close settings"); icon: "x"; width: 34px; height: 34px; quiet: true; clicked => { root.close(); } } }
@ -130,7 +132,7 @@ export component SettingsWindow inherits Rectangle {
content-width: self.width;
VerticalLayout {
padding-left: 34px; padding-right: 34px; padding-top: 28px; padding-bottom: 16px; spacing: 0;
if root.active-tab == "audio" || (root.active-tab != "appearance" && root.active-tab != "identity") : AudioSettings {
if root.active-tab == "audio" || (root.active-tab != "appearance" && root.active-tab != "identity" && root.active-tab != "updates") : AudioSettings {
input-devices: root.input-devices;
output-devices: root.output-devices;
input-device-index <=> root.input-device-index;
@ -140,7 +142,7 @@ export component SettingsWindow inherits Rectangle {
volume <=> root.volume;
audio-changed => { root.audio-changed(); }
}
if root.active-tab == "audio" || (root.active-tab != "appearance" && root.active-tab != "identity") : SoundSettings {
if root.active-tab == "audio" || (root.active-tab != "appearance" && root.active-tab != "identity" && root.active-tab != "updates") : SoundSettings {
sounds-enabled <=> root.sounds-enabled;
sounds-volume <=> root.sounds-volume;
sounds-voice-room <=> root.sounds-voice-room;
@ -167,6 +169,7 @@ export component SettingsWindow inherits Rectangle {
import-theme(path) => { root.import-theme(path); }
export-theme(path) => { root.export-theme(path); }
}
if root.active-tab == "updates" : UpdateSettings { }
if root.active-tab == "identity" : IdentitySettings {
own-avatar: root.own-avatar;
has-avatar: root.has-avatar;

View file

@ -0,0 +1,79 @@
import { Theme, ActionButton } from "../theme.slint";
// State and actions of the updater. Rust fills the properties and handles the callbacks
// (src/ui/updater.rs); the panel below only shows them.
export global UpdateUi {
in-out property <string> installed-version;
in-out property <string> lnex-version;
in-out property <string> state-text;
in-out property <string> central-text;
in-out property <bool> auto-update: true;
in-out property <bool> busy;
in-out property <bool> can-download;
in-out property <bool> can-install;
in-out property <bool> can-rollback;
callback check();
callback download();
callback install();
callback rollback();
callback auto-update-changed(bool);
}
component InfoRow inherits Rectangle {
in property <string> label;
in property <string> value;
height: 30px;
HorizontalLayout {
spacing: 12px;
Text { text: root.label; color: Theme.text-muted; font-size: Math.max(Theme.font-size - 2px, 11px); width: 170px; vertical-alignment: center; }
Text { text: root.value; color: Theme.text-primary; font-size: Math.max(Theme.font-size - 2px, 11px); vertical-alignment: center; overflow: elide; }
}
}
export component UpdateSettings inherits Rectangle {
VerticalLayout {
spacing: 0;
alignment: start;
Text { text: @tr("Version and updates"); color: Theme.text-primary; font-size: Theme.font-size + 2px; font-weight: 600; }
Text { text: @tr("Updates are signed and checked before they are installed. Your profile and data are not touched."); color: Theme.text-muted; font-size: Math.max(Theme.font-size - 3px, 11px); wrap: word-wrap; }
Rectangle { height: 18px; }
InfoRow { label: @tr("Installed version"); value: UpdateUi.installed-version; }
InfoRow { label: @tr("Protocol version"); value: UpdateUi.lnex-version; }
if UpdateUi.central-text != "" : InfoRow { label: @tr("Latest on the server"); value: UpdateUi.central-text; }
Rectangle { height: 10px; }
Text { text: UpdateUi.state-text; color: Theme.text-primary; font-size: Math.max(Theme.font-size - 1px, 12px); wrap: word-wrap; accessible-role: text; accessible-label: UpdateUi.state-text; }
Rectangle { height: 14px; }
HorizontalLayout {
spacing: 10px; alignment: start;
ActionButton { text: @tr("Check for updates"); width: 170px; opacity: UpdateUi.busy ? 0.5 : 1.0; clicked => { UpdateUi.check(); } }
if UpdateUi.can-download : ActionButton { text: @tr("Download"); width: 120px; opacity: UpdateUi.busy ? 0.5 : 1.0; clicked => { UpdateUi.download(); } }
if UpdateUi.can-install : ActionButton { text: @tr("Install"); primary: true; width: 120px; opacity: UpdateUi.busy ? 0.5 : 1.0; clicked => { UpdateUi.install(); } }
}
Rectangle { height: 16px; }
Rectangle {
height: 46px;
accessible-role: checkbox;
accessible-label: @tr("Update automatically");
accessible-checked: UpdateUi.auto-update;
HorizontalLayout {
spacing: 12px;
VerticalLayout {
alignment: center; spacing: 2px; horizontal-stretch: 1;
Text { text: @tr("Update automatically"); color: Theme.text-primary; font-size: Math.max(Theme.font-size - 2px, 11px); }
Text { text: @tr("Check and download in the background, install on the next start. Never during a voice call."); color: Theme.text-muted; font-size: Math.max(Theme.font-size - 4px, 11px); wrap: word-wrap; }
}
ActionButton {
text: UpdateUi.auto-update ? "✓" : "○"; width: 34px; height: 30px; quiet: true;
clicked => { UpdateUi.auto-update = !UpdateUi.auto-update; UpdateUi.auto-update-changed(UpdateUi.auto-update); }
}
}
}
if UpdateUi.can-rollback : Rectangle {
height: 52px;
HorizontalLayout {
alignment: start;
ActionButton { text: @tr("Roll back to the previous version"); width: 280px; quiet: true; opacity: UpdateUi.busy ? 0.5 : 1.0; clicked => { UpdateUi.rollback(); } }
}
}
}
}

214
src/ui/updater.rs Normal file
View file

@ -0,0 +1,214 @@
//! Glue between the updater (`vnox_client::update`) and the settings panel.
//!
//! Slint owns no logic here: [`wire`] creates the manager, connects the panel callbacks and
//! refreshes the panel from the manager once a second. Installs are deferred while a voice
//! session is active.
use std::cell::RefCell;
use std::rc::Rc;
use std::sync::Arc;
use std::time::Duration;
use slint::ComponentHandle;
use vnox_client::update::settings::default_path;
use vnox_client::update::{Layout, UpdateConfig, UpdateManager, UpdatePhase};
use crate::AppState;
use crate::ui::i18n;
use crate::ui::slint::{MainWindow, UpdateUi};
use crate::ui::state::VoiceUiState;
/// How often the background check runs, in panel refresh ticks (one per second).
const AUTO_CHECK_TICKS: u64 = 6 * 60 * 60;
/// Text shown for an updater phase.
pub fn phase_text(phase: &UpdatePhase) -> String {
let with =
|source: &str, version: &String| i18n::format(source, &[("version", version.clone())]);
match phase {
UpdatePhase::Idle => i18n::text("Not checked yet"),
UpdatePhase::Checking => i18n::text("Checking for updates..."),
UpdatePhase::UpToDate => i18n::text("You are up to date"),
UpdatePhase::Available { version } => i18n::format(
"Version {version} is available",
&[("version", version.clone())],
),
UpdatePhase::Downloading { version } => with_downloading(version),
UpdatePhase::Ready { version } => i18n::format(
"Version {version} is downloaded and ready to install",
&[("version", version.clone())],
),
UpdatePhase::InstallDeferred { version } => i18n::format(
"Version {version} will install when the voice session ends",
&[("version", version.clone())],
),
UpdatePhase::Installing { version } => i18n::format(
"Installing version {version}",
&[("version", version.clone())],
),
UpdatePhase::Installed { version } => i18n::format(
"Version {version} is installed. Restart Vnox to use it.",
&[("version", version.clone())],
),
UpdatePhase::ManualInstallRequired { version } => {
with("Version {version} needs a manual reinstall", version)
}
UpdatePhase::Error(error) => {
i18n::format("Update failed: {error}", &[("error", error.clone())])
}
}
}
fn with_downloading(version: &str) -> String {
i18n::format(
"Downloading version {version}",
&[("version", version.to_string())],
)
}
/// Connects the updater to the settings panel. Keep the returned timer alive for as long as the
/// window lives.
pub fn wire(window: &MainWindow, state: &Rc<RefCell<AppState>>) -> slint::Timer {
let ui = window.global::<UpdateUi>();
ui.set_installed_version(vnox_client::update::CLIENT_VERSION.into());
ui.set_lnex_version(vnox_client::update::LNEX_PROTOCOL.into());
let layout = Layout::user_default();
let manager: Option<Arc<UpdateManager>> = layout
.clone()
.map(|layout| UpdateManager::new(UpdateConfig::production(layout), None, default_path()));
let timer = slint::Timer::default();
let Some(manager) = manager else {
ui.set_state_text(i18n::text("Not checked yet").into());
return timer;
};
// A staged Windows binary is swapped in before the window opens; restart into it.
if let Some(layout) = &layout
&& layout.apply_pending().unwrap_or(false)
&& let Ok(exe) = std::env::current_exe()
&& std::process::Command::new(exe)
.args(std::env::args_os().skip(1))
.spawn()
.is_ok()
{
std::process::exit(0);
}
ui.set_auto_update(manager.auto_update());
let note: Rc<RefCell<String>> = Rc::default();
{
let manager = manager.clone();
tokio::spawn(async move {
manager.startup().await;
manager.auto_pass().await;
});
}
{
let (manager, note) = (manager.clone(), note.clone());
ui.on_check(move || {
note.borrow_mut().clear();
let manager = manager.clone();
tokio::spawn(async move {
let _ = manager.check().await;
});
});
}
{
let (manager, note) = (manager.clone(), note.clone());
ui.on_download(move || {
note.borrow_mut().clear();
let manager = manager.clone();
tokio::spawn(async move {
let _ = manager.download().await;
});
});
}
{
let (manager, note) = (manager.clone(), note.clone());
ui.on_install(move || {
note.borrow_mut().clear();
let manager = manager.clone();
tokio::spawn(async move {
let _ = manager.install().await;
});
});
}
{
let (manager, note) = (manager.clone(), note.clone());
ui.on_rollback(move || {
*note.borrow_mut() = match manager.rollback() {
Ok(()) => i18n::text("Rolled back. Restart Vnox to use the previous version."),
Err(error) => {
i18n::format("Update failed: {error}", &[("error", error.to_string())])
}
};
});
}
{
let (manager, note) = (manager.clone(), note.clone());
ui.on_auto_update_changed(move |enabled| {
if let Err(error) = manager.set_auto_update(enabled) {
*note.borrow_mut() = i18n::format(
"Cannot save the update setting: {error}",
&[("error", error.to_string())],
);
}
});
}
let weak = window.as_weak();
let state = state.clone();
let mut ticks: u64 = 0;
timer.start(
slint::TimerMode::Repeated,
Duration::from_secs(1),
move || {
ticks += 1;
let Some(window) = weak.upgrade() else {
return;
};
let in_voice = {
let s = state.borrow();
s.voice_channel.is_some() || matches!(s.ui.voice, VoiceUiState::Active { .. })
};
manager.set_voice_active(in_voice);
if !in_voice && manager.install_waiting() {
let manager = manager.clone();
tokio::spawn(async move {
let _ = manager.run_deferred().await;
});
}
if ticks.is_multiple_of(AUTO_CHECK_TICKS) {
let manager = manager.clone();
tokio::spawn(async move { manager.auto_pass().await });
}
let status = manager.status();
let ui = window.global::<UpdateUi>();
let note = note.borrow();
ui.set_state_text(if note.is_empty() {
phase_text(&status.phase).into()
} else {
note.as_str().into()
});
ui.set_central_text(status.central_latest.unwrap_or_default().into());
ui.set_busy(matches!(
status.phase,
UpdatePhase::Checking
| UpdatePhase::Downloading { .. }
| UpdatePhase::Installing { .. }
));
ui.set_can_download(matches!(status.phase, UpdatePhase::Available { .. }));
ui.set_can_install(matches!(
status.phase,
UpdatePhase::Ready { .. } | UpdatePhase::InstallDeferred { .. }
));
ui.set_can_rollback(
layout
.as_ref()
.is_some_and(|layout| layout.state().previous.is_some()),
);
},
);
timer
}