Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.
feat(desktop): battery full-charge target and PC-side phone nicknames (#98)
Armone834e15bceeb0
diff --git a/desktop/app/i18n/nectarlink_de.ts b/desktop/app/i18n/nectarlink_de.tsindex 3cb7a57..cb587e7 100644--- a/desktop/app/i18n/nectarlink_de.ts+++ b/desktop/app/i18n/nectarlink_de.ts@@ -316,6 +316,18 @@<source>Your phone</source><translation>Dein Gerät</translation></message>+ <message>+ <source>%1 has reached %2% charge</source>+ <translation>%1 hat %2% Ladung erreicht</translation>+ </message>+ <message>+ <source>%1's battery is low</source>+ <translation>Akku von %1 ist fast leer</translation>+ </message>+ <message>+ <source>%1% left. Charge it soon.</source>+ <translation>Noch %1% verbleibend. Bitte bald laden.</translation>+ </message></context><context><name>BtHfp</name>@@ -4317,6 +4329,22 @@ Voraussetzungen<source>Open externally</source><translation>Extern öffnen</translation></message>+ <message>+ <source>Set nickname</source>+ <translation>Spitznamen festlegen</translation>+ </message>+ <message>+ <source>Change nickname</source>+ <translation>Spitznamen ändern</translation>+ </message>+ <message>+ <source>Phone nickname</source>+ <translation>Telefon-Spitzname</translation>+ </message>+ <message>+ <source>Set a custom name for this phone on your PC. Leave blank to use "%1".</source>+ <translation>Legen Sie einen benutzerdefinierten Namen für dieses Telefon auf Ihrem PC fest. Leer lassen, um "%1" zu verwenden.</translation>+ </message></context><context><name>Hotspot</name>@@ -7942,6 +7970,22 @@ Voraussetzungen<source>Clear everything</source><translation>Alles löschen</translation></message>+ <message>+ <source>Full charge target</source>+ <translation>Ziel für vollständige Ladung</translation>+ </message>+ <message>+ <source>Alert at 100%, or at 80% if your phone has battery protection enabled.</source>+ <translation>Benachrichtigung bei 100 % oder bei 80 %, wenn der Akkuschutz auf Ihrem Telefon aktiviert ist.</translation>+ </message>+ <message>+ <source>100% (Standard)</source>+ <translation>100 % (Standard)</translation>+ </message>+ <message>+ <source>80% (Protect battery)</source>+ <translation>80 % (Akkuschutz)</translation>+ </message></context><context><name>Setup</name>diff --git a/desktop/app/i18n/nectarlink_tr.ts b/desktop/app/i18n/nectarlink_tr.tsindex 51adce0..8bb43df 100644--- a/desktop/app/i18n/nectarlink_tr.ts+++ b/desktop/app/i18n/nectarlink_tr.ts@@ -316,6 +316,18 @@<source>Your phone</source><translation>Telefonunuz</translation></message>+ <message>+ <source>%1 has reached %2% charge</source>+ <translation>%1 %%%2 şarja ulaştı</translation>+ </message>+ <message>+ <source>%1's battery is low</source>+ <translation>%1 cihazının pili zayıf</translation>+ </message>+ <message>+ <source>%1% left. Charge it soon.</source>+ <translation>%%%1 kaldı. Yakında şarj edin.</translation>+ </message></context><context><name>BtHfp</name>@@ -4315,6 +4327,22 @@ Neler gerekir<source>Open externally</source><translation>Harici olarak aç</translation></message>+ <message>+ <source>Set nickname</source>+ <translation>Takma ad belirle</translation>+ </message>+ <message>+ <source>Change nickname</source>+ <translation>Takma adı değiştir</translation>+ </message>+ <message>+ <source>Phone nickname</source>+ <translation>Telefon takma adı</translation>+ </message>+ <message>+ <source>Set a custom name for this phone on your PC. Leave blank to use "%1".</source>+ <translation>Bu telefon için bilgisayarınızda özel bir ad belirleyin. "%1" kullanmak için boş bırakın.</translation>+ </message></context><context><name>Hotspot</name>@@ -7934,6 +7962,22 @@ Neler gerekir<source>Clear everything</source><translation>Her şeyi temizle</translation></message>+ <message>+ <source>Full charge target</source>+ <translation>Tam şarj hedefi</translation>+ </message>+ <message>+ <source>Alert at 100%, or at 80% if your phone has battery protection enabled.</source>+ <translation>Standart olarak %100'de, veya telefonunuzda pil koruması açıksa %80'de uyarın.</translation>+ </message>+ <message>+ <source>100% (Standard)</source>+ <translation>%100 (Standart)</translation>+ </message>+ <message>+ <source>80% (Protect battery)</source>+ <translation>%80 (Pili koru)</translation>+ </message></context><context><name>Setup</name>diff --git a/desktop/app/i18n/nectarlink_zh_CN.ts b/desktop/app/i18n/nectarlink_zh_CN.tsindex 30eb9f5..2173263 100644--- a/desktop/app/i18n/nectarlink_zh_CN.ts+++ b/desktop/app/i18n/nectarlink_zh_CN.ts@@ -316,6 +316,18 @@<source>Your phone</source><translation>你的手机</translation></message>+ <message>+ <source>%1 has reached %2% charge</source>+ <translation>%1 已充至 %2%</translation>+ </message>+ <message>+ <source>%1's battery is low</source>+ <translation>%1 的电量不足</translation>+ </message>+ <message>+ <source>%1% left. Charge it soon.</source>+ <translation>剩余 %1%,请尽快充电。</translation>+ </message></context><context><name>BtHfp</name>@@ -4315,6 +4327,22 @@ What it needs<source>Open externally</source><translation>用外部程序打开</translation></message>+ <message>+ <source>Set nickname</source>+ <translation>设置昵称</translation>+ </message>+ <message>+ <source>Change nickname</source>+ <translation>更改昵称</translation>+ </message>+ <message>+ <source>Phone nickname</source>+ <translation>手机昵称</translation>+ </message>+ <message>+ <source>Set a custom name for this phone on your PC. Leave blank to use "%1".</source>+ <translation>在您的电脑上为此手机设置自定义名称。留空以使用“%1”。</translation>+ </message></context><context><name>Hotspot</name>@@ -7938,6 +7966,22 @@ What it needs<source>Clear everything</source><translation>清除全部</translation></message>+ <message>+ <source>Full charge target</source>+ <translation>满电提醒目标</translation>+ </message>+ <message>+ <source>Alert at 100%, or at 80% if your phone has battery protection enabled.</source>+ <translation>在 100% 时提醒,如果您的手机开启了电池保护则在 80% 时提醒。</translation>+ </message>+ <message>+ <source>100% (Standard)</source>+ <translation>100%(标准)</translation>+ </message>+ <message>+ <source>80% (Protect battery)</source>+ <translation>80%(电池保护)</translation>+ </message></context><context><name>Setup</name>diff --git a/desktop/app/i18n/rust_strings.h b/desktop/app/i18n/rust_strings.hindex 66f45c6..8ecd11e 100644--- a/desktop/app/i18n/rust_strings.h+++ b/desktop/app/i18n/rust_strings.h@@ -38,7 +38,10 @@ static const char *const nectarlink_rust_strings[] = {QT_TRANSLATE_NOOP("App", "Wi-Fi %1/4"), // desktop/app/src/bridge/app.rsQT_TRANSLATE_NOOP("App", "Your phone"), // desktop/app/src/bridge/app.rsQT_TRANSLATE_NOOP("Automations", "Triggered by %1"), // desktop/app/src/automations.rs+ QT_TRANSLATE_NOOP("Battery", "%1 has reached %2% charge"), // desktop/app/src/battery.rsQT_TRANSLATE_NOOP("Battery", "%1 is fully charged"), // desktop/app/src/battery.rs+ QT_TRANSLATE_NOOP("Battery", "%1% left. Charge it soon."), // desktop/app/src/battery.rs+ QT_TRANSLATE_NOOP("Battery", "%1's battery is low"), // desktop/app/src/battery.rsQT_TRANSLATE_NOOP("Battery", "You can unplug it."), // desktop/app/src/battery.rsQT_TRANSLATE_NOOP("Battery", "Your phone"), // desktop/app/src/battery.rsQT_TRANSLATE_NOOP("Calls", "Calling %1"), // desktop/app/src/calls.rsdiff --git a/desktop/app/i18n/template/nectarlink.ts b/desktop/app/i18n/template/nectarlink.tsindex 24feb14..8ff5aae 100644--- a/desktop/app/i18n/template/nectarlink.ts+++ b/desktop/app/i18n/template/nectarlink.ts@@ -316,6 +316,18 @@<source>Your phone</source><translation type="unfinished"></translation></message>+ <message>+ <source>%1 has reached %2% charge</source>+ <translation type="unfinished"></translation>+ </message>+ <message>+ <source>%1's battery is low</source>+ <translation type="unfinished"></translation>+ </message>+ <message>+ <source>%1% left. Charge it soon.</source>+ <translation type="unfinished"></translation>+ </message></context><context><name>CallCard</name>@@ -4039,6 +4051,22 @@ What it needs<source>Open externally</source><translation type="unfinished"></translation></message>+ <message>+ <source>Set nickname</source>+ <translation type="unfinished"></translation>+ </message>+ <message>+ <source>Change nickname</source>+ <translation type="unfinished"></translation>+ </message>+ <message>+ <source>Phone nickname</source>+ <translation type="unfinished"></translation>+ </message>+ <message>+ <source>Set a custom name for this phone on your PC. Leave blank to use "%1".</source>+ <translation type="unfinished"></translation>+ </message></context><context><name>Hotspot</name>@@ -7658,6 +7686,22 @@ What it needs<source>Clear everything</source><translation type="unfinished"></translation></message>+ <message>+ <source>Full charge target</source>+ <translation type="unfinished"></translation>+ </message>+ <message>+ <source>Alert at 100%, or at 80% if your phone has battery protection enabled.</source>+ <translation type="unfinished"></translation>+ </message>+ <message>+ <source>100% (Standard)</source>+ <translation type="unfinished"></translation>+ </message>+ <message>+ <source>80% (Protect battery)</source>+ <translation type="unfinished"></translation>+ </message></context><context><name>Setup</name>diff --git a/desktop/app/qml/pages/HomePage.qml b/desktop/app/qml/pages/HomePage.qmlindex d26b964..cb51bd6 100644--- a/desktop/app/qml/pages/HomePage.qml+++ b/desktop/app/qml/pages/HomePage.qml@@ -594,6 +594,8 @@ Item {id: homerequired property string deviceIdrequired property string name+ required property string rawName+ required property bool hasNicknamerequired property string kindrequired property string osVersionrequired property string model@@ -1096,15 +1098,28 @@ Item {anchors.right: parent.rightanchors.verticalCenter: parent.verticalCenterspacing: 6- Txt {+ Row {width: parent.width- text: home.name- role: "displaySmall"- size: home.name.length > 14 ? 20 : (home.name.length > 10 ? 22 : 25)- fontSizeMode: Text.HorizontalFit- minimumPixelSize: 16- color: Theme.heroContent- elide: Text.ElideRight+ spacing: 6+ Txt {+ id: nameTxt+ width: Math.min(implicitWidth, parent.width - editNicknameBtn.width - parent.spacing)+ text: home.name+ role: "displaySmall"+ size: home.name.length > 14 ? 20 : (home.name.length > 10 ? 22 : 25)+ fontSizeMode: Text.HorizontalFit+ minimumPixelSize: 16+ color: Theme.heroContent+ elide: Text.ElideRight+ }+ IconButton {+ id: editNicknameBtn+ anchors.verticalCenter: nameTxt.verticalCenter+ iconPath: Icons.edit+ iconSize: 14+ label: home.hasNickname ? qsTr("Change nickname") : qsTr("Set nickname")+ onClicked: nicknameSheet.openFor(home.deviceId, home.name, home.rawName)+ }}Txt {width: parent.width@@ -2629,6 +2644,75 @@ Item {}}+ // Set a custom PC-side nickname for a phone.+ Sheet {+ id: nicknameSheet+ property string targetDeviceId: ""+ property string currentName: ""+ property string rawName: ""+ cardWidth: 420+ function openFor(devId, name, raw) {+ targetDeviceId = devId+ currentName = name+ rawName = raw+ nicknameInput.text = (name !== raw) ? name : ""+ open()+ nicknameInput.forceActiveFocus()+ }+ function saveNickname() {+ Preferences.setNickname(targetDeviceId, nicknameInput.text.trim())+ nicknameSheet.close()+ }+ Column {+ width: parent.width+ spacing: 16+ Txt {+ width: parent.width+ text: qsTr("Phone nickname")+ role: "headline"+ }+ Txt {+ width: parent.width+ wrapMode: Text.WordWrap+ role: "body"+ muted: true+ text: qsTr("Set a custom name for this phone on your PC. Leave blank to use \"%1\".").arg(nicknameSheet.rawName)+ }+ Rectangle {+ width: parent.width+ height: 40+ radius: Theme.radiusMd+ color: Theme.surfaceContainerHighest+ border.width: nicknameInput.activeFocus ? 2 : 1+ border.color: nicknameInput.activeFocus ? Theme.primary : Theme.outlineVariant++ TextInput {+ id: nicknameInput+ anchors.fill: parent+ anchors.margins: 10+ color: Theme.surfaceContent+ font.pixelSize: 14+ selectByMouse: true+ clip: true+ onAccepted: nicknameSheet.saveNickname()+ }+ }+ Row {+ anchors.right: parent.right+ spacing: 8+ Button {+ text: qsTr("Cancel")+ outlined: true+ onClicked: nicknameSheet.close()+ }+ Button {+ text: qsTr("Save")+ onClicked: nicknameSheet.saveNickname()+ }+ }+ }+ }+// Notifications from the last day that are gone from the phone.AppsSheet {id: appsSheetdiff --git a/desktop/app/qml/pages/SettingsPage.qml b/desktop/app/qml/pages/SettingsPage.qmlindex c26b7d4..98be6cf 100644--- a/desktop/app/qml/pages/SettingsPage.qml+++ b/desktop/app/qml/pages/SettingsPage.qml@@ -1149,6 +1149,31 @@ Item {}}+ // Sub-row: Full charge alert target (100% or 80% Protect battery)+ Column {+ id: batteryThresholdBlock+ visible: Preferences.batteryAlerts+ width: parent.width+ spacing: 0++ Divider { width: parent.width }++ ListRow {+ width: parent.width+ iconPath: Icons.bolt+ title: qsTr("Full charge target")+ description: qsTr("Alert at 100%, or at 80% if your phone has battery protection enabled.")+ Segmented {+ options: [+ { value: 100, label: qsTr("100% (Standard)") },+ { value: 80, label: qsTr("80% (Protect battery)") }+ ]+ value: Preferences.batteryFullThreshold <= 80 ? 80 : 100+ onPicked: (val) => Preferences.batteryFullThreshold = val+ }+ }+ }+Divider { width: parent.width }// Row 3: Sync clipboard to phonediff --git a/desktop/app/src/battery.rs b/desktop/app/src/battery.rsindex 9526e3a..8db136a 100644--- a/desktop/app/src/battery.rs+++ b/desktop/app/src/battery.rs@@ -35,7 +35,7 @@ pub fn set_enabled(on: bool) {#[derive(Debug, Clone, Copy, PartialEq, Eq)]enum Alert {Low(u8),- Full,+ Full(u8),}/// What a phone has been told about already.@@ -49,13 +49,14 @@ struct Watch {}impl Watch {- fn update(&mut self, battery: &Battery) -> Option<Alert> {- let low = !battery.charging && battery.level <= LOW;- let full = battery.charging && battery.level >= 100;- if battery.charging || battery.level >= RECOVERED {+ fn update(&mut self, battery: &Battery, full_target: u8) -> Option<Alert> {+ let power = battery.charging || battery.plugged.is_some();+ let low = !power && battery.level <= LOW;+ let full = power && battery.level >= full_target;+ if power || battery.level >= RECOVERED {self.told_low = false;}- if !battery.charging || battery.level < 100 {+ if !power || battery.level < full_target {self.told_full = false;}let first = !self.seen;@@ -66,7 +67,7 @@ impl Watch {Some(Alert::Low(battery.level))} else if full && !self.told_full {self.told_full = true;- (!first).then_some(Alert::Full)+ (!first).then_some(Alert::Full(battery.level))} else {None}@@ -75,9 +76,10 @@ impl Watch {pub fn on_event(event: &NodeEvent) {let NodeEvent::Battery { device, battery } = event else { return };+ let full_target = crate::settings::battery_full_threshold();let alert = {let mut watches = WATCHES.lock().unwrap_or_else(|e| e.into_inner());- watches.get_or_insert_default().entry(*device).or_default().update(battery)+ watches.get_or_insert_default().entry(*device).or_default().update(battery, full_target)};let Some(alert) = alert else { return };if !ENABLED.load(Ordering::Relaxed) {@@ -86,8 +88,19 @@ pub fn on_event(event: &NodeEvent) {let name =core_host::host().hub.read(|s| s.name_of(device)).unwrap_or_else(|| tr!("Battery", "Your phone"));let (title, body) = match alert {- Alert::Low(level) => (format!("{name}'s battery is low"), format!("{level}% left. Charge it soon.")),- Alert::Full => (tr!("Battery", "%1 is fully charged", name), tr!("Battery", "You can unplug it.")),+ Alert::Low(level) => {+ (tr!("Battery", "%1's battery is low", name), tr!("Battery", "%1% left. Charge it soon.", level))+ }+ Alert::Full(level) => {+ if level >= 100 {+ (tr!("Battery", "%1 is fully charged", name), tr!("Battery", "You can unplug it."))+ } else {+ (+ tr!("Battery", "%1 has reached %2% charge", name, level),+ tr!("Battery", "You can unplug it."),+ )+ }+ }};toast::show(Toast {device: TOAST_GROUP.into(),@@ -124,33 +137,57 @@ mod tests {#[test]fn low_is_told_once_until_it_recovers() {let mut w = Watch::default();- assert_eq!(w.update(&at(40, false)), None);- assert_eq!(w.update(&at(15, false)), Some(Alert::Low(15)));- assert_eq!(w.update(&at(12, false)), None);+ assert_eq!(w.update(&at(40, false), 100), None);+ assert_eq!(w.update(&at(15, false), 100), Some(Alert::Low(15)));+ assert_eq!(w.update(&at(12, false), 100), None);// Plugged in, then out again while still low: worth saying again.- assert_eq!(w.update(&at(13, true)), None);- assert_eq!(w.update(&at(13, false)), Some(Alert::Low(13)));+ assert_eq!(w.update(&at(13, true), 100), None);+ assert_eq!(w.update(&at(13, false), 100), Some(Alert::Low(13)));// Bouncing around the line doesn't repeat it.- assert_eq!(w.update(&at(16, false)), None);- assert_eq!(w.update(&at(15, false)), None);- assert_eq!(w.update(&at(30, false)), None);- assert_eq!(w.update(&at(14, false)), Some(Alert::Low(14)));+ assert_eq!(w.update(&at(16, false), 100), None);+ assert_eq!(w.update(&at(15, false), 100), None);+ assert_eq!(w.update(&at(30, false), 100), None);+ assert_eq!(w.update(&at(14, false), 100), Some(Alert::Low(14)));}#[test]fn low_is_told_right_after_connecting() {- assert_eq!(Watch::default().update(&at(9, false)), Some(Alert::Low(9)));+ assert_eq!(Watch::default().update(&at(9, false), 100), Some(Alert::Low(9)));}#[test]fn full_is_told_when_it_gets_there() {let mut w = Watch::default();- assert_eq!(w.update(&at(99, true)), None);- assert_eq!(w.update(&at(100, true)), Some(Alert::Full));- assert_eq!(w.update(&at(100, true)), None);- assert_eq!(w.update(&at(100, false)), None);- assert_eq!(w.update(&at(100, true)), Some(Alert::Full));+ assert_eq!(w.update(&at(99, true), 100), None);+ assert_eq!(w.update(&at(100, true), 100), Some(Alert::Full(100)));+ assert_eq!(w.update(&at(100, true), 100), None);+ assert_eq!(w.update(&at(100, false), 100), None);+ assert_eq!(w.update(&at(100, true), 100), Some(Alert::Full(100)));// Already full when it connected: not news.- assert_eq!(Watch::default().update(&at(100, true)), None);+ assert_eq!(Watch::default().update(&at(100, true), 100), None);+ }++ #[test]+ fn full_respects_protect_battery_threshold() {+ let mut w = Watch::default();+ assert_eq!(w.update(&at(79, true), 80), None);+ assert_eq!(w.update(&at(80, true), 80), Some(Alert::Full(80)));+ assert_eq!(w.update(&at(80, true), 80), None);+ assert_eq!(w.update(&at(80, false), 80), None);+ assert_eq!(w.update(&at(80, true), 80), Some(Alert::Full(80)));+ }++ #[test]+ fn full_alerts_when_holding_at_protect_threshold_while_plugged() {+ let mut w = Watch::default();+ let mut b = at(80, false);+ b.plugged = Some("ac".into());+ // First report after connect doesn't alert if already 80+ assert_eq!(w.update(&b, 80), None);+ // Level dips to 79 and back up to 80 while still plugged+ b.level = 79;+ assert_eq!(w.update(&b, 80), None);+ b.level = 80;+ assert_eq!(w.update(&b, 80), Some(Alert::Full(80)));}}diff --git a/desktop/app/src/bridge/devices.rs b/desktop/app/src/bridge/devices.rsindex 79c552f..c056b60 100644--- a/desktop/app/src/bridge/devices.rs+++ b/desktop/app/src/bridge/devices.rs@@ -132,6 +132,8 @@ pub struct DeviceListRust {const ROLES: &[&str] = &["deviceId","name",+ "rawName",+ "hasNickname","kind","os","osVersion",@@ -159,7 +161,12 @@ fn role_value(device: &Row, role: &str) -> QVariant {let text = |s: &str| QVariant::from(&QString::from(s));match role {"deviceId" => text(&device.id.to_string()),- "name" => text(&device.info.name),+ "name" => text(+ &crate::settings::nickname_for(&device.id.to_string())+ .unwrap_or_else(|| device.info.name.clone()),+ ),+ "rawName" => text(&device.info.name),+ "hasNickname" => QVariant::from(&crate::settings::nickname_for(&device.id.to_string()).is_some()),"kind" => text(match device.info.kind {DeviceKind::Phone => "phone",DeviceKind::Tablet => "tablet",@@ -297,7 +304,11 @@ impl qobject::DeviceList {usize::try_from(row).ok().and_then(|i| self.rows.get(i))- .map(|d| QString::from(&d.info.name))+ .map(|d| {+ let name =+ crate::settings::nickname_for(&d.id.to_string()).unwrap_or_else(|| d.info.name.clone());+ QString::from(&name)+ }).unwrap_or_default()}}diff --git a/desktop/app/src/bridge/prefs.rs b/desktop/app/src/bridge/prefs.rsindex 61dcd37..aaecb4a 100644--- a/desktop/app/src/bridge/prefs.rs+++ b/desktop/app/src/bridge/prefs.rs@@ -75,6 +75,8 @@ pub mod qobject {#[qproperty(bool, install_updates)]/// Tell when a phone's battery is low, or full.#[qproperty(bool, battery_alerts)]+ /// Charge level threshold for full battery alerts (e.g. 100 or 80 for protect battery mode).+ #[qproperty(i32, battery_full_threshold)]/// Folder where voice recordings from phones are saved.#[qproperty(QString, recordings_folder)]/// Whether `recordings_folder` is the default (`Documents\Nectarlink Recordings`).@@ -221,6 +223,12 @@ pub mod qobject {/// Enables or disables an automation rule by ID.#[qinvokable]fn set_automation_rule_enabled(self: Pin<&mut Preferences>, rule_id: &QString, enabled: bool);+ /// Gets custom nickname for a device or empty.+ #[qinvokable]+ fn nickname_of(self: &Preferences, device_id: &QString) -> QString;+ /// Sets or clears a custom nickname for a device.+ #[qinvokable]+ fn set_nickname(self: Pin<&mut Preferences>, device_id: &QString, nickname: &QString);#[qobject]#[qml_element]@@ -302,6 +310,7 @@ pub struct PreferencesRust {auto_update: bool,install_updates: bool,battery_alerts: bool,+ battery_full_threshold: i32,recordings_folder: QString,recordings_folder_is_default: bool,recordings_format: QString,@@ -385,6 +394,7 @@ impl cxx_qt::Initialize for qobject::Preferences {self.as_mut().set_auto_update(settings.auto_update);self.as_mut().set_install_updates(settings.install_updates);self.as_mut().set_battery_alerts(settings.battery_alerts);+ self.as_mut().set_battery_full_threshold(i32::from(settings.battery_full_threshold));let start_effective = crate::startup::effective(settings.start_with_windows);self.as_mut().set_start_with_windows(start_effective);self.as_mut().set_start_at_login(start_effective);@@ -533,6 +543,13 @@ impl cxx_qt::Initialize for qobject::Preferences {p.save();}).release();+ self.as_mut()+ .on_battery_full_threshold_changed(|p| {+ let val = p.battery_full_threshold.clamp(50, 100) as u8;+ crate::settings::set_battery_full_threshold(val);+ p.save();+ })+ .release();self.as_mut().on_start_with_windows_changed(|mut p| {let on = p.start_with_windows;@@ -835,6 +852,18 @@ impl qobject::Preferences {}}+ pub fn nickname_of(&self, device_id: &QString) -> QString {+ QString::from(&crate::settings::nickname_for(&String::from(device_id)).unwrap_or_default())+ }++ pub fn set_nickname(self: Pin<&mut Self>, device_id: &QString, nickname: &QString) {+ let dev = String::from(device_id);+ let nick = String::from(nickname);+ crate::settings::set_nickname(&dev, if nick.trim().is_empty() { None } else { Some(nick) });+ self.save();+ core_host::host().hub.changed(crate::state::Changes::DEVICES);+ }+pub fn choose_recordings_folder(mut self: Pin<&mut Self>, url: &QString) {let raw = QUrl::from(url).to_local_file()@@ -1012,6 +1041,8 @@ impl qobject::Preferences {auto_update: p.auto_update,install_updates: p.install_updates,battery_alerts: p.battery_alerts,+ battery_full_threshold: p.battery_full_threshold.clamp(50, 100) as u8,+ device_nicknames: crate::settings::device_nicknames(),start_with_windows: p.start_choice,recordings_folder: p.custom_recordings_folder.clone(),recordings_format: RecordingFormat::from_str_lossy(&String::from(&p.recordings_format)),diff --git a/desktop/app/src/settings.rs b/desktop/app/src/settings.rsindex 8b08820..072f202 100644--- a/desktop/app/src/settings.rs+++ b/desktop/app/src/settings.rs@@ -225,6 +225,47 @@ pub fn set_away_mode(on: bool) {}}+static BATTERY_FULL_THRESHOLD: std::sync::atomic::AtomicU8 = std::sync::atomic::AtomicU8::new(100);++pub fn battery_full_threshold() -> u8 {+ BATTERY_FULL_THRESHOLD.load(std::sync::atomic::Ordering::Relaxed)+}++pub fn set_battery_full_threshold(threshold: u8) {+ let clamped = threshold.clamp(50, 100);+ BATTERY_FULL_THRESHOLD.store(clamped, std::sync::atomic::Ordering::Relaxed);+}++fn default_battery_full_threshold() -> u8 {+ 100+}++static NICKNAMES: std::sync::Mutex<Option<std::collections::HashMap<String, String>>> =+ std::sync::Mutex::new(None);++pub fn device_nicknames() -> std::collections::HashMap<String, String> {+ NICKNAMES.lock().unwrap_or_else(|e| e.into_inner()).clone().unwrap_or_default()+}++pub fn set_device_nicknames(nicknames: std::collections::HashMap<String, String>) {+ *NICKNAMES.lock().unwrap_or_else(|e| e.into_inner()) = Some(nicknames);+}++pub fn nickname_for(device_id: &str) -> Option<String> {+ let lock = NICKNAMES.lock().unwrap_or_else(|e| e.into_inner());+ lock.as_ref()?.get(device_id).cloned().filter(|s| !s.trim().is_empty())+}++pub fn set_nickname(device_id: &str, nickname: Option<String>) {+ let mut lock = NICKNAMES.lock().unwrap_or_else(|e| e.into_inner());+ let map = lock.get_or_insert_default();+ if let Some(nick) = nickname.filter(|s| !s.trim().is_empty()) {+ map.insert(device_id.to_string(), nick.trim().to_string());+ } else {+ map.remove(device_id);+ }+}+static OBS: std::sync::Mutex<(u16, Option<String>)> = std::sync::Mutex::new((crate::obs::DEFAULT_PORT, None));/// OBS port and encrypted password, as stored.@@ -362,6 +403,16 @@ pub struct Settings {/// Tell when a phone's battery is low, or full.#[serde(alias = "battery_alerts")]pub battery_alerts: bool,+ /// Battery charge level percent to treat as "full" for alerts (default `100`, or `80` for battery protection mode).+ #[serde(default = "default_battery_full_threshold", alias = "battery_full_threshold")]+ pub battery_full_threshold: u8,+ /// User-assigned nicknames for paired phones by their device ID (hex string).+ #[serde(+ default,+ skip_serializing_if = "std::collections::HashMap::is_empty",+ alias = "device_nicknames"+ )]+ pub device_nicknames: std::collections::HashMap<String, String>,/// Start when the user signs in. Unset until the user chooses: then an/// installed copy starts with Windows and a build run from its folder/// doesn't.@@ -514,6 +565,8 @@ impl Default for Settings {auto_update: true,install_updates: true,battery_alerts: true,+ battery_full_threshold: default_battery_full_threshold(),+ device_nicknames: std::collections::HashMap::new(),start_with_windows: None,recordings_folder: None,recordings_format: RecordingFormat::default(),@@ -609,6 +662,8 @@ impl Settings {set_share_pc_storage(self.share_pc_storage);set_forward_pc_notifications_to_phone(self.forward_pc_notifications_to_phone);set_away_mode(self.away_mode);+ set_battery_full_threshold(self.battery_full_threshold);+ set_device_nicknames(self.device_nicknames.clone());set_window_geometry(self.window_screen.clone(),self.window_x,@@ -746,6 +801,8 @@ mod tests {auto_update: false,install_updates: false,battery_alerts: false,+ battery_full_threshold: 80,+ device_nicknames: std::collections::HashMap::from([("abc".to_owned(), "Work phone".to_owned())]),start_with_windows: Some(true),recordings_folder: Some(PathBuf::from(r"C:\Recordings")),recordings_format: RecordingFormat::Flac,diff --git a/desktop/app/src/state.rs b/desktop/app/src/state.rsindex 4a43cf0..6416011 100644--- a/desktop/app/src/state.rs+++ b/desktop/app/src/state.rs@@ -316,9 +316,10 @@ impl AppState {}/// A name for any device we know of (paired, nearby, or LocalSend peer).+ /// If the user set a custom nickname for a paired device on this PC, it takes precedence.pub fn name_of(&self, id: &DeviceId) -> Option<String> {- self.device(id)- .map(|d| d.info.name.clone())+ crate::settings::nickname_for(&id.to_string())+ .or_else(|| self.device(id).map(|d| d.info.name.clone())).or_else(|| self.discovered.iter().find(|d| d.id == *id).and_then(|d| d.name.clone())).or_else(|| self.localsend_peers.iter().find(|p| p.id == *id).map(|p| p.alias.clone()))}