Merge branch 'claude/gifted-lovelace-1crlx2' into worktree-agent-a5ecbed1e5dd55ddc

This commit is contained in:
selikhov committed 2026-10-04 09:28:11 +03:00
commit 608bd2fbf2
22 files changed
+614 -84

No files matched your search

+8 -8
View File
@@ -534,24 +534,24 @@ pub fn run(options: RunOptions) -> Result<()> {
let prefs = open_settings(&dir, &options.setting_overrides);
let switches = crate::dev::Switches::from_env();
// New identities of the official TeamSpeak clients, on every start (not
// with the sample data of VOELIN_DEMO_UI); with none of our own yet, the
// client's default identity becomes ours.
let had_identity = !store.identities()?.is_empty();
// with the sample data of VOELIN_DEMO_UI); the client's default
// identity becomes ours while we have none the user chose.
let imported = if prefs.get(&IDENTITY_IMPORT) && !switches.demo_ui {
voelin_core::identity::import_new(&store, &voelin_core::identity::discover())
.unwrap_or_else(|e| {
warn!(%e, "could not import TeamSpeak identities");
Vec::new()
Default::default()
})
} else {
Vec::new()
Default::default()
};
let identity = match store.identities()?.first() {
let identity = match store.default_identity()? {
Some(entry) => store.identity(entry.id)?,
None => {
// Creating an identity takes a moment (security level 8).
let identity = tsclientlib::Identity::create();
store.add_identity(crate::servers::CREATED_IDENTITY, &identity)?;
let origin = voelin_store::IdentityOrigin::Created;
store.add_identity(crate::servers::CREATED_IDENTITY, &identity, origin)?;
identity
}
};
@@ -636,7 +636,7 @@ pub fn run(options: RunOptions) -> Result<()> {
if app.demo {
app.start_demo();
}
if let Some(text) = crate::servers::imported_status(&imported, had_identity) {
if let Some(text) = crate::servers::imported_status(&imported) {
app.set_status(text);
}
});
+6
View File
@@ -52,4 +52,10 @@ pub(super) fn wire(ui: &MainWindow) {
bridge.on_open_about(|| {
with_app(|app| app.load_notices());
});
bridge.on_use_identity(|id| {
with_app(|app| app.use_identity(id as i64));
});
bridge.on_set_identity_import(|on| {
with_app(|app| app.set_identity_import(on));
});
}
+2 -1
View File
@@ -12,7 +12,7 @@
//! - `VOELIN_DEMO_STREAM=1`: a local test stream in the viewer.
//! - `VOELIN_OPEN=<what>[,<what>...]`: open screens on start: `home`,
//! `server`, `settings[:<section>]` (voice, keybinds, streaming, privacy,
//! appearance, or 0-4), `about`, `share`, `bookmark` (add a server;
//! appearance, identities, or 0-5), `about`, `share`, `bookmark` (add a server;
//! `bookmark:edit` the current one, Advanced open),
//! `emoji` (the picker), `client` (the volume dialog of the first other
//! client once connected), `panel` / `no-panel` (the members panel),
@@ -108,6 +108,7 @@ fn section(name: &str) -> SettingsSection {
"2" | "streaming" => SettingsSection::Streaming,
"3" | "privacy" => SettingsSection::Privacy,
"4" | "appearance" => SettingsSection::Appearance,
"5" | "identities" => SettingsSection::Identities,
_ => SettingsSection::Voice,
}
}
+101
View File
@@ -0,0 +1,101 @@
//! Settings → Identities: the stored identities, which one servers see us
//! as (the default), and the import of the official clients' identities on
//! start (`voelin_core::identity::import_new`, app.rs).
use slint::ComponentHandle;
use tracing::warn;
use voelin_core::settings::IDENTITY_IMPORT;
use voelin_store::{IdentityEntry, IdentityOrigin};
use crate::app::{App, Bridge, IdentityItem, model};
use crate::vm::avatar;
/// A row of the identities card.
fn item(entry: &IdentityEntry) -> IdentityItem {
let origin = match entry.origin {
IdentityOrigin::Imported => "From TeamSpeak",
IdentityOrigin::Created | IdentityOrigin::User => "Made in Voelin",
};
IdentityItem {
id: entry.id as i32,
name: entry.name.clone().into(),
detail: format!("{origin} · level {}", entry.level).into(),
uid: entry.uid.clone().into(),
initials: avatar::initials(&entry.name).into(),
tint: avatar::tint(&entry.name),
is_default: entry.is_default,
}
}
impl App {
pub(crate) fn refresh_identities(&self) {
let Some(ui) = self.ui.upgrade() else { return };
let bridge = ui.global::<Bridge>();
let mut entries = self.store.identities().unwrap_or_default();
// A store from before defaults were marked: the first one.
let default = self.store.default_identity().ok().flatten().map(|e| e.id);
for entry in &mut entries {
entry.is_default = Some(entry.id) == default;
}
bridge.set_identities(model(entries.iter().map(item).collect()));
bridge.set_identity_import(self.prefs.get(&IDENTITY_IMPORT));
}
/// The user's choice of the identity servers see us as, from the next
/// connection on; no import replaces it.
pub(crate) fn use_identity(&mut self, id: i64) {
let result =
self.store.set_default_identity(id, true).and_then(|()| self.store.identity(id));
match result {
Ok(identity) => {
self.identity = identity;
let name = self
.store
.identities()
.ok()
.and_then(|all| all.into_iter().find(|e| e.id == id))
.map(|e| e.name)
.unwrap_or_default();
self.set_status(format!(
"Servers see you as \u{201c}{name}\u{201d} from your next connection"
));
}
Err(e) => self.set_status(format!("Could not change the identity: {e}")),
}
self.refresh_identities();
}
pub(crate) fn set_identity_import(&mut self, on: bool) {
if let Err(e) = self.prefs.set(&IDENTITY_IMPORT, on) {
warn!(%e, "could not store the setting");
}
self.refresh_identities();
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn rows_say_where_an_identity_came_from() {
let entry = |origin, is_default| IdentityEntry {
id: 3,
name: "Main Nick".into(),
uid: "uid=".into(),
level: 8,
origin,
is_default,
};
let row = item(&entry(IdentityOrigin::Imported, true));
assert_eq!((row.id, row.name.as_str(), row.uid.as_str()), (3, "Main Nick", "uid="));
assert_eq!(row.detail, "From TeamSpeak · level 8");
assert!(row.is_default);
assert_eq!(row.initials, avatar::initials("Main Nick"));
for origin in [IdentityOrigin::Created, IdentityOrigin::User] {
let row = item(&entry(origin, false));
assert_eq!(row.detail, "Made in Voelin · level 8");
assert!(!row.is_default);
}
}
}
+1
View File
@@ -7,6 +7,7 @@ mod chat;
mod dev;
mod emoji;
mod hotkey;
mod identities;
mod images;
mod inbox;
mod members;
+31 -19
View File
@@ -3,7 +3,7 @@
use slint::{ComponentHandle, SharedString};
use tracing::warn;
use voelin_core::identity::Found;
use voelin_core::identity::LaunchImport;
use voelin_core::{Command, ObserveState, Source, VoiceOptions, VoiceState};
use voelin_store::{Bookmark, QueryConfig, QueryTransport};
@@ -14,20 +14,20 @@ use crate::vm;
pub(crate) const CREATED_IDENTITY: &str = "Default";
/// What to tell the user about the identities imported from the official
/// clients at start ([`voelin_core::identity::import_new`]), if any.
/// `had_identity`: we had one before, so it stays the default.
pub(crate) fn imported_status(imported: &[Found], had_identity: bool) -> Option<String> {
let first = imported.first()?;
let n = imported.len();
let names = imported.iter().map(|f| f.nickname.as_str()).collect::<Vec<_>>().join(", ");
Some(match (had_identity, n) {
(true, 1) => format!("Imported the identity \u{201c}{names}\u{201d} from TeamSpeak"),
(true, _) => format!("Imported {n} identities from TeamSpeak: {names}"),
(false, 1) => format!("Using your TeamSpeak identity \u{201c}{names}\u{201d}"),
(false, _) => format!(
"Using your TeamSpeak identity \u{201c}{}\u{201d} ({n} imported: {names})",
first.nickname
/// clients at start ([`voelin_core::identity::import_new`]), if anything.
pub(crate) fn imported_status(report: &LaunchImport) -> Option<String> {
let n = report.added.len();
let names = report.added.iter().map(|f| f.nickname.as_str()).collect::<Vec<_>>().join(", ");
let more = if n > 1 { format!(" ({n} imported: {names})") } else { String::new() };
Some(match &report.default {
Some(f) if report.replaced => format!(
"You now use your TeamSpeak identity \u{201c}{}\u{201d}; your previous one is kept{more}",
f.nickname
),
Some(f) => format!("Using your TeamSpeak identity \u{201c}{}\u{201d}{more}", f.nickname),
None if n == 1 => format!("Imported the identity \u{201c}{names}\u{201d} from TeamSpeak"),
None if n > 1 => format!("Imported {n} identities from TeamSpeak: {names}"),
None => return None,
})
}
@@ -104,9 +104,9 @@ impl App {
/// from TeamSpeak keeps the nickname used there), else the system user's.
pub(crate) fn default_nickname(&self) -> String {
self.store
.identities()
.default_identity()
.ok()
.and_then(|identities| identities.into_iter().next())
.flatten()
.map(|identity| identity.name)
.filter(|name| {
![CREATED_IDENTITY, voelin_core::identity::DEFAULT_NICKNAME]
@@ -470,6 +470,8 @@ impl App {
#[cfg(test)]
mod tests {
use voelin_core::identity::Found;
use super::*;
#[test]
@@ -536,14 +538,24 @@ mod tests {
source: "settings.db".into(),
selected: false,
};
assert_eq!(imported_status(&[], false), None);
let report = |added: &[&str], default: Option<&str>, replaced| LaunchImport {
added: added.iter().map(|n| found(n)).collect(),
default: default.map(found),
replaced,
};
assert_eq!(imported_status(&report(&[], None, false)), None);
assert_eq!(
imported_status(&[found("Main")], false).unwrap(),
imported_status(&report(&["Main"], Some("Main"), false)).unwrap(),
"Using your TeamSpeak identity \u{201c}Main\u{201d}"
);
assert_eq!(
imported_status(&[found("Main"), found("Alt")], true).unwrap(),
imported_status(&report(&["Main", "Alt"], None, false)).unwrap(),
"Imported 2 identities from TeamSpeak: Main, Alt"
);
// Imported earlier, now ours instead of the one the app made.
assert_eq!(
imported_status(&report(&[], Some("Main"), true)).unwrap(),
"You now use your TeamSpeak identity \u{201c}Main\u{201d}; your previous one is kept"
);
}
}
+1
View File
@@ -41,6 +41,7 @@ impl App {
bridge.set_h264_enabled(self.settings.openh264);
bridge.set_image_cache_usage(crate::images::usage_text().into());
self.refresh_h264();
self.refresh_identities();
}
pub(crate) fn close_settings(&mut self) {