Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.
Timeline: translate sessions by what they were, not their English title
Bee054bafba9231
diff --git a/core/nectarlink-core/src/lib.rs b/core/nectarlink-core/src/lib.rsindex 15ef9c4..944ed08 100644--- a/core/nectarlink-core/src/lib.rs+++ b/core/nectarlink-core/src/lib.rs@@ -156,8 +156,8 @@ pub use store::{};pub use timeline::{DEFAULT_TIMELINE_MAX_DAYS, DEFAULT_TIMELINE_MAX_ENTRIES, DEFAULT_TIMELINE_PAGE_LIMIT,- MAX_TIMELINE_PAGE_LIMIT, TimelineEntry, TimelineKind, TimelinePage, TimelineQuery, TimelineRetention,- format_clip_display,+ MAX_TIMELINE_PAGE_LIMIT, SessionKind, TimelineEntry, TimelineKind, TimelinePage, TimelineQuery,+ TimelineRetention, format_clip_display,};pub use transfer::{Direction, FileSource, OutgoingFile, RECORDER, RecordingMarker, Transfer, TransferFailure, TransferState,diff --git a/core/nectarlink-core/src/timeline.rs b/core/nectarlink-core/src/timeline.rsindex 0e95842..8023169 100644--- a/core/nectarlink-core/src/timeline.rs+++ b/core/nectarlink-core/src/timeline.rs@@ -270,8 +270,83 @@ pub fn format_clip_display(raw_text: &str) -> (String, Option<String>) {(collapsed, None)}+/// What a [`TimelineKind::Session`] entry was. Its `title` is English for+/// whoever reads the store directly; an app shows its own words for these.+#[derive(Debug, Clone, Copy, PartialEq, Eq)]+pub enum SessionKind {+ /// A phone's screen, mirrored on this device.+ PhoneScreen,+ /// One of a phone's apps in a window of its own (its mirroring session).+ AppWindow(u32),+ /// This device's screen, shared with a phone.+ PcScreen,+ /// A phone's camera used as a webcam.+ Webcam,+ /// A phone's microphone used on this device.+ Microphone,+}++/// The title the core gives an app window's session entry.+const APP_WINDOW_TITLE: &str = "App window #";++impl TimelineEntry {+ /// What this entry was, if it is a session; from what the core recorded+ /// (`target` and the direction), so it holds for entries made before+ /// this existed too.+ #[must_use]+ pub fn session_kind(&self) -> Option<SessionKind> {+ if self.kind != TimelineKind::Session {+ return None;+ }+ match self.target.as_str() {+ "webcam" => Some(SessionKind::Webcam),+ "mic" => Some(SessionKind::Microphone),+ "mirror" if !self.incoming => Some(SessionKind::PcScreen),+ "mirror" => Some(+ self.title+ .strip_prefix(APP_WINDOW_TITLE)+ .and_then(|n| n.parse().ok())+ .map_or(SessionKind::PhoneScreen, SessionKind::AppWindow),+ ),+ _ => None,+ }+ }+}+#[cfg(test)]mod tests {+ #[test]+ fn sessions_say_what_they_were_whatever_their_title() {+ use super::{SessionKind, TimelineEntry, TimelineKind};+ let entry = |kind, incoming, title: &str, target: &str| TimelineEntry {+ id: 1,+ kind,+ device_id: nectarlink_protocol::DeviceId([1; 32]),+ device_name: "Pixel".into(),+ incoming,+ timestamp: 0,+ title: title.into(),+ detail: String::new(),+ target: target.into(),+ size_bytes: 0,+ duration_secs: 0,+ ref_id: None,+ clip_available: false,+ image_data_url: None,+ };+ let session =+ |incoming, title, target| entry(TimelineKind::Session, incoming, title, target).session_kind();+ assert_eq!(session(true, "Phone webcam", "webcam"), Some(SessionKind::Webcam));+ assert_eq!(session(false, "Phone microphone", "mic"), Some(SessionKind::Microphone));+ assert_eq!(session(true, "Screen mirroring", "mirror"), Some(SessionKind::PhoneScreen));+ assert_eq!(session(false, "Screen mirroring", "mirror"), Some(SessionKind::PcScreen));+ assert_eq!(session(true, "App window #3", "mirror"), Some(SessionKind::AppWindow(3)));+ // The title isn't what decides.+ assert_eq!(session(true, "Bildschirm", "webcam"), Some(SessionKind::Webcam));+ assert_eq!(session(true, "Something", "other"), None);+ assert_eq!(entry(TimelineKind::File, true, "Phone webcam", "webcam").session_kind(), None);+ }+use super::*;#[test]diff --git a/desktop/app/i18n/nectarlink_zh_CN.ts b/desktop/app/i18n/nectarlink_zh_CN.tsindex efffa92..412c7ec 100644--- a/desktop/app/i18n/nectarlink_zh_CN.ts+++ b/desktop/app/i18n/nectarlink_zh_CN.ts@@ -6899,136 +6899,146 @@<name>Timeline</name><message><location filename="rust_strings.h" line="322"/>+ <source>App window #%1</source>+ <translation>应用窗口 #%1</translation>+ </message>+ <message>+ <location filename="rust_strings.h" line="323"/><source>Clip (removed from clipboard history)</source><translation>剪贴内容(已从剪贴板历史中删除)</translation></message><message>- <location filename="rust_strings.h" line="323"/>+ <location filename="rust_strings.h" line="324"/><source>Copied image</source><translation>已复制的图片</translation></message><message>- <location filename="rust_strings.h" line="324"/>+ <location filename="rust_strings.h" line="325"/><source>Copied link to clipboard.</source><translation>已将链接复制到剪贴板。</translation></message><message>- <location filename="rust_strings.h" line="325"/>+ <location filename="rust_strings.h" line="326"/><source>Copied to clipboard.</source><translation>已复制到剪贴板。</translation></message><message>- <location filename="rust_strings.h" line="326"/>+ <location filename="rust_strings.h" line="327"/><source>From %1</source><translation>来自 %1</translation></message><message>- <location filename="rust_strings.h" line="327"/>+ <location filename="rust_strings.h" line="328"/><source>In progress</source><translation>进行中</translation></message><message>- <location filename="rust_strings.h" line="328"/>+ <location filename="rust_strings.h" line="329"/><source>No phone is paired yet.</source><translation>尚未配对手机。</translation></message><message>- <location filename="rust_strings.h" line="329"/>+ <location filename="rust_strings.h" line="330"/><source>Opened from %1</source><translation>从 %1 打开</translation></message><message>- <location filename="rust_strings.h" line="330"/>+ <location filename="rust_strings.h" line="331"/><source>Opened on %1</source><translation>在 %1 上打开</translation></message><message>- <location filename="rust_strings.h" line="331"/>+ <location filename="rust_strings.h" line="332"/><source>Phone microphone</source><translation>手机麦克风</translation></message><message>- <location filename="rust_strings.h" line="332"/>+ <location filename="rust_strings.h" line="333"/><source>Phone webcam</source><translation>手机摄像头</translation></message><message>- <location filename="rust_strings.h" line="333"/>+ <location filename="rust_strings.h" line="334"/><source>Recorded on %1</source><translation>在 %1 上录制</translation></message><message>- <location filename="rust_strings.h" line="334"/>+ <location filename="rust_strings.h" line="335"/><source>Saved from %1</source><translation>从 %1 保存</translation></message><message>- <location filename="rust_strings.h" line="335"/>+ <location filename="rust_strings.h" line="336"/><source>Screen mirroring</source><translation>屏幕镜像</translation></message><message>- <location filename="rust_strings.h" line="336"/>+ <location filename="rust_strings.h" line="337"/><source>Sending to %1…</source><translation>正在发送到 %1…</translation></message><message>- <location filename="rust_strings.h" line="337"/>+ <location filename="rust_strings.h" line="338"/><source>Sent clip to %1.</source><translation>已将剪贴内容发送到 %1。</translation></message><message>- <location filename="rust_strings.h" line="338"/>+ <location filename="rust_strings.h" line="339"/><source>Sent to %1</source><translation>已发送到 %1</translation></message><message>- <location filename="rust_strings.h" line="339"/>+ <location filename="rust_strings.h" line="340"/>+ <source>Session</source>+ <translation>会话</translation>+ </message>+ <message>+ <location filename="rust_strings.h" line="341"/><source>That clip is no longer in clipboard history.</source><translation>该剪贴内容已不在剪贴板历史中。</translation></message><message>- <location filename="rust_strings.h" line="340"/>+ <location filename="rust_strings.h" line="342"/><source>That entry couldn't be removed. Try again.</source><translation>无法删除该条目,请重试。</translation></message><message>- <location filename="rust_strings.h" line="341"/>+ <location filename="rust_strings.h" line="343"/><source>That file was moved or deleted.</source><translation>该文件已被移动或删除。</translation></message><message>- <location filename="rust_strings.h" line="342"/>+ <location filename="rust_strings.h" line="344"/><source>That isn't a web link.</source><translation>这不是网页链接。</translation></message><message>- <location filename="rust_strings.h" line="343"/>+ <location filename="rust_strings.h" line="345"/><source>That photo was moved or deleted.</source><translation>该照片已被移动或删除。</translation></message><message>- <location filename="rust_strings.h" line="344"/>+ <location filename="rust_strings.h" line="346"/><source>The Timeline couldn't be cleared. Try again.</source><translation>无法清除时间线,请重试。</translation></message><message>- <location filename="rust_strings.h" line="345"/>+ <location filename="rust_strings.h" line="347"/><source>The photo couldn't be copied to the clipboard.</source><translation>无法将照片复制到剪贴板。</translation></message><message>- <location filename="rust_strings.h" line="346"/>+ <location filename="rust_strings.h" line="348"/><source>Voice recording</source><translation>录音</translation></message><message>- <location filename="rust_strings.h" line="347"/>+ <location filename="rust_strings.h" line="349"/><source>With %1</source><translation>与 %1</translation></message><message>- <location filename="rust_strings.h" line="348"/>+ <location filename="rust_strings.h" line="350"/><source>device</source><translation>设备</translation></message>@@ -7320,37 +7330,37 @@<context><name>Transfers</name><message>- <location filename="rust_strings.h" line="349"/>+ <location filename="rust_strings.h" line="351"/><source>Accept in NectarLink to save to Downloads\Nectarlink</source><translation>在 NectarLink 中接受即可保存到 Downloads\Nectarlink</translation></message><message>- <location filename="rust_strings.h" line="350"/>+ <location filename="rust_strings.h" line="352"/><source>Files are turned off for that device.</source><translation>已为该设备关闭文件。</translation></message><message>- <location filename="rust_strings.h" line="351"/>+ <location filename="rust_strings.h" line="353"/><source>From %1, opened from Downloads\Nectarlink</source><translation>来自 %1,已从 Downloads\Nectarlink 打开</translation></message><message>- <location filename="rust_strings.h" line="352"/>+ <location filename="rust_strings.h" line="354"/><source>From %1, saved in Downloads\Nectarlink</source><translation>来自 %1,已保存到 Downloads\Nectarlink</translation></message><message>- <location filename="rust_strings.h" line="353"/>+ <location filename="rust_strings.h" line="355"/><source>Nearby device</source><translation>附近的设备</translation></message><message>- <location filename="rust_strings.h" line="354"/>+ <location filename="rust_strings.h" line="356"/><source>That's too many files to send at once.</source><translation>文件太多,无法一次发送。</translation></message><message>- <location filename="rust_strings.h" line="355"/>+ <location filename="rust_strings.h" line="357"/><source>There's nothing to send in there.</source><translation>那里没有可发送的内容。</translation></message>@@ -7358,67 +7368,67 @@<context><name>Updater</name><message>- <location filename="rust_strings.h" line="356"/>+ <location filename="rust_strings.h" line="358"/><source>Couldn't check for updates. Check your internet connection.</source><translation>无法检查更新。请检查网络连接。</translation></message><message>- <location filename="rust_strings.h" line="357"/>+ <location filename="rust_strings.h" line="359"/><source>NectarLink %1 is available</source><translation>NectarLink %1 已发布</translation></message><message>- <location filename="rust_strings.h" line="358"/>+ <location filename="rust_strings.h" line="360"/><source>NectarLink %1 is available.</source><translation>NectarLink %1 已发布。</translation></message><message>- <location filename="rust_strings.h" line="359"/>+ <location filename="rust_strings.h" line="361"/><source>NectarLink is still on the version you had. Try again from Settings.</source><translation>NectarLink 仍是原来的版本。请在设置中重试。</translation></message><message>- <location filename="rust_strings.h" line="360"/>+ <location filename="rust_strings.h" line="362"/><source>NectarLink is up to date.</source><translation>NectarLink 已是最新版本。</translation></message><message>- <location filename="rust_strings.h" line="361"/>+ <location filename="rust_strings.h" line="363"/><source>NectarLink is updated to %1</source><translation>NectarLink 已更新到 %1</translation></message><message>- <location filename="rust_strings.h" line="362"/>+ <location filename="rust_strings.h" line="364"/><source>The download was damaged, so it wasn't installed. Try again.</source><translation>下载的文件已损坏,因此未安装。请重试。</translation></message><message>- <location filename="rust_strings.h" line="363"/>+ <location filename="rust_strings.h" line="365"/><source>The update couldn't be downloaded. Check your internet connection and try again.</source><translation>无法下载更新。请检查网络连接后重试。</translation></message><message>- <location filename="rust_strings.h" line="364"/>+ <location filename="rust_strings.h" line="366"/><source>The update couldn't be saved. Check that there's free space and try again.</source><translation>无法保存更新。请确认有足够的空间后重试。</translation></message><message>- <location filename="rust_strings.h" line="365"/>+ <location filename="rust_strings.h" line="367"/><source>The update couldn't be started. Try again.</source><translation>无法启动更新。请重试。</translation></message><message>- <location filename="rust_strings.h" line="366"/>+ <location filename="rust_strings.h" line="368"/><source>The update didn't install</source><translation>更新未安装</translation></message><message>- <location filename="rust_strings.h" line="367"/>+ <location filename="rust_strings.h" line="369"/><source>Update now, or later from Settings.</source><translation>立即更新,或稍后在设置中更新。</translation></message><message>- <location filename="rust_strings.h" line="368"/>+ <location filename="rust_strings.h" line="370"/><source>Your phone reconnects on its own.</source><translation>手机会自动重新连接。</translation></message>@@ -7618,12 +7628,12 @@<context><name>Webcam</name><message>- <location filename="rust_strings.h" line="369"/>+ <location filename="rust_strings.h" line="371"/><source>Starting camera on %1…</source><translation>正在启动 %1 上的相机…</translation></message><message>- <location filename="rust_strings.h" line="370"/>+ <location filename="rust_strings.h" line="372"/><source>Streaming %1 × %2 · %3 fps from %4</source><translation>正在从 %4 传输 %1 × %2 · %3 fps</translation></message>@@ -7654,17 +7664,17 @@<context><name>Widget</name><message>- <location filename="rust_strings.h" line="371"/>+ <location filename="rust_strings.h" line="373"/><source>No phone connected</source><translation>未连接手机</translation></message><message>- <location filename="rust_strings.h" line="372"/>+ <location filename="rust_strings.h" line="374"/><source>No recent clipboard items</source><translation>没有最近的剪贴板内容</translation></message><message>- <location filename="rust_strings.h" line="373"/>+ <location filename="rust_strings.h" line="375"/><source>Not available</source><translation>不可用</translation></message>diff --git a/desktop/app/i18n/rust_strings.h b/desktop/app/i18n/rust_strings.hindex c643f4c..5ecb5e4 100644--- a/desktop/app/i18n/rust_strings.h+++ b/desktop/app/i18n/rust_strings.h@@ -319,6 +319,7 @@ static const char *const nectarlink_rust_strings[] = {QT_TRANSLATE_NOOP("Setup", "Setup is taking too long. Try again after restarting the PC."), // desktop/app/src/setup.rsQT_TRANSLATE_NOOP("Setup", "Setup stopped with code %1."), // desktop/app/src/setup.rsQT_TRANSLATE_NOOP("Setup", "The uninstaller is missing. Reinstall NectarLink, then uninstall it."), // desktop/app/src/setup.rs+ QT_TRANSLATE_NOOP("Timeline", "App window #%1"), // desktop/app/src/i18n.rsQT_TRANSLATE_NOOP("Timeline", "Clip (removed from clipboard history)"), // desktop/app/src/bridge/timeline.rsQT_TRANSLATE_NOOP("Timeline", "Copied image"), // desktop/app/src/bridge/timeline.rsQT_TRANSLATE_NOOP("Timeline", "Copied link to clipboard."), // desktop/app/src/bridge/timeline.rs@@ -336,6 +337,7 @@ static const char *const nectarlink_rust_strings[] = {QT_TRANSLATE_NOOP("Timeline", "Sending to %1…"), // desktop/app/src/bridge/timeline.rsQT_TRANSLATE_NOOP("Timeline", "Sent clip to %1."), // desktop/app/src/bridge/timeline.rsQT_TRANSLATE_NOOP("Timeline", "Sent to %1"), // desktop/app/src/bridge/timeline.rs+ QT_TRANSLATE_NOOP("Timeline", "Session"), // desktop/app/src/bridge/timeline.rsQT_TRANSLATE_NOOP("Timeline", "That clip is no longer in clipboard history."), // desktop/app/src/bridge/timeline.rsQT_TRANSLATE_NOOP("Timeline", "That entry couldn't be removed. Try again."), // desktop/app/src/bridge/timeline.rsQT_TRANSLATE_NOOP("Timeline", "That file was moved or deleted."), // desktop/app/src/bridge/timeline.rsdiff --git a/desktop/app/src/bridge/timeline.rs b/desktop/app/src/bridge/timeline.rsindex e9201fd..2a7a741 100644--- a/desktop/app/src/bridge/timeline.rs+++ b/desktop/app/src/bridge/timeline.rs@@ -195,7 +195,7 @@ fn role_value(row: &Row, role: &str) -> QVariant {"deviceName" => text(&row.device_name),"timestamp" => QVariant::from(&(e.timestamp as f64)),"prevTimestamp" => QVariant::from(&(row.prev_timestamp as f64)),- "title" => text(&crate::i18n::timeline_title(&row.title)),+ "title" => text(&row.title),"subtitle" => text(&row.subtitle),"sizeBytes" => QVariant::from(&(e.size_bytes as f64)),"durationSecs" => QVariant::from(&(e.duration_secs as i32)),@@ -694,7 +694,11 @@ fn describe_entry((title, parts.join(" · "), String::new(), String::new(), 1, valid, false, !url.is_empty(), valid)}TimelineKind::Session => {- let title = if entry.title.is_empty() { "Session".into() } else { entry.title.clone() };+ let title = match entry.session_kind() {+ Some(kind) => crate::i18n::session_title(kind),+ None if entry.title.is_empty() => tr!("Timeline", "Session"),+ None => entry.title.clone(),+ };let mut parts = vec![who];if !entry.detail.is_empty() {parts.push(entry.detail.clone());@@ -756,7 +760,7 @@ pub fn preview_json() -> String {"incoming": r.entry.incoming,"deviceName": r.device_name,"timestamp": r.entry.timestamp,- "title": crate::i18n::timeline_title(&r.title),+ "title": r.title,"subtitle": r.subtitle,"thumbUrl": r.thumb_url,})diff --git a/desktop/app/src/i18n.rs b/desktop/app/src/i18n.rsindex fa04b45..6a468c4 100644--- a/desktop/app/src/i18n.rs+++ b/desktop/app/src/i18n.rs@@ -79,15 +79,15 @@ macro_rules! tr {}pub(crate) use tr;-/// A timeline entry's title in the app's language: the core names its-/// sessions in English ("Phone webcam"); anything else (a file's or a-/// person's name) stays as it is.-pub fn timeline_title(title: &str) -> String {- match title {- "Phone webcam" => tr!("Timeline", "Phone webcam"),- "Screen mirroring" => tr!("Timeline", "Screen mirroring"),- "Phone microphone" => tr!("Timeline", "Phone microphone"),- other => other.to_owned(),+/// A session's title in the app's language, by what it was (the core's own+/// title is English).+pub fn session_title(kind: nectarlink_core::SessionKind) -> String {+ use nectarlink_core::SessionKind;+ match kind {+ SessionKind::PhoneScreen | SessionKind::PcScreen => tr!("Timeline", "Screen mirroring"),+ SessionKind::AppWindow(n) => tr!("Timeline", "App window #%1", n),+ SessionKind::Webcam => tr!("Timeline", "Phone webcam"),+ SessionKind::Microphone => tr!("Timeline", "Phone microphone"),}}