Skip to content

Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.

fix(desktop): Linux updates don't vanish the app when it can't restart, and the service never fakes an install

Beea0f3bdd3aae5
diff --git a/desktop/app/i18n/nectarlink_de.ts b/desktop/app/i18n/nectarlink_de.ts
index 5f6d47b..0e637de 100644
--- a/desktop/app/i18n/nectarlink_de.ts
+++ b/desktop/app/i18n/nectarlink_de.ts
@@ -8801,11 +8801,16 @@ Voraussetzungen
</message>
<message>
<location filename="rust_strings.h" line="485"/>
+ <source>The update is installed. Restart NectarLink to use it.</source>
+ <translation>Das Update ist installiert. Starte NectarLink neu, um es zu verwenden.</translation>
+ </message>
+ <message>
+ <location filename="rust_strings.h" line="486"/>
<source>Update now, or later from Settings.</source>
<translation>Jetzt oder später über die Einstellungen aktualisieren.</translation>
</message>
<message>
- <location filename="rust_strings.h" line="486"/>
+ <location filename="rust_strings.h" line="487"/>
<source>Your phone reconnects on its own.</source>
<translation>Dein Gerät verbindet sich automatisch wieder.</translation>
</message>
@@ -9016,12 +9021,12 @@ Voraussetzungen
<context>
<name>Webcam</name>
<message>
- <location filename="rust_strings.h" line="487"/>
+ <location filename="rust_strings.h" line="488"/>
<source>Starting camera on %1…</source>
<translation>Kamera auf %1 wird gestartet…</translation>
</message>
<message>
- <location filename="rust_strings.h" line="488"/>
+ <location filename="rust_strings.h" line="489"/>
<source>Streaming %1 × %2 · %3 fps from %4</source>
<translation>Streamt %1 × %2 · %3 FPS von %4</translation>
</message>
@@ -9052,17 +9057,17 @@ Voraussetzungen
<context>
<name>Widget</name>
<message>
- <location filename="rust_strings.h" line="489"/>
+ <location filename="rust_strings.h" line="490"/>
<source>No phone connected</source>
<translation>Kein Gerät verbunden</translation>
</message>
<message>
- <location filename="rust_strings.h" line="490"/>
+ <location filename="rust_strings.h" line="491"/>
<source>No recent clipboard items</source>
<translation>Keine aktuellen Einträge in der Zwischenablage</translation>
</message>
<message>
- <location filename="rust_strings.h" line="491"/>
+ <location filename="rust_strings.h" line="492"/>
<source>Not available</source>
<translation>Nicht verfügbar</translation>
</message>
diff --git a/desktop/app/i18n/nectarlink_zh_CN.ts b/desktop/app/i18n/nectarlink_zh_CN.ts
index 9879964..3d18b1a 100644
--- a/desktop/app/i18n/nectarlink_zh_CN.ts
+++ b/desktop/app/i18n/nectarlink_zh_CN.ts
@@ -8797,11 +8797,16 @@ What it needs
</message>
<message>
<location filename="rust_strings.h" line="485"/>
+ <source>The update is installed. Restart NectarLink to use it.</source>
+ <translation>更新已安装。请重新启动 NectarLink 以使用新版本。</translation>
+ </message>
+ <message>
+ <location filename="rust_strings.h" line="486"/>
<source>Update now, or later from Settings.</source>
<translation>立即更新,或稍后在设置中更新。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="486"/>
+ <location filename="rust_strings.h" line="487"/>
<source>Your phone reconnects on its own.</source>
<translation>手机会自动重新连接。</translation>
</message>
@@ -9012,12 +9017,12 @@ What it needs
<context>
<name>Webcam</name>
<message>
- <location filename="rust_strings.h" line="487"/>
+ <location filename="rust_strings.h" line="488"/>
<source>Starting camera on %1…</source>
<translation>正在启动 %1 上的相机…</translation>
</message>
<message>
- <location filename="rust_strings.h" line="488"/>
+ <location filename="rust_strings.h" line="489"/>
<source>Streaming %1 × %2 · %3 fps from %4</source>
<translation>正在从 %4 传输 %1 × %2 · %3 fps</translation>
</message>
@@ -9048,17 +9053,17 @@ What it needs
<context>
<name>Widget</name>
<message>
- <location filename="rust_strings.h" line="489"/>
+ <location filename="rust_strings.h" line="490"/>
<source>No phone connected</source>
<translation>未连接手机</translation>
</message>
<message>
- <location filename="rust_strings.h" line="490"/>
+ <location filename="rust_strings.h" line="491"/>
<source>No recent clipboard items</source>
<translation>没有最近的剪贴板内容</translation>
</message>
<message>
- <location filename="rust_strings.h" line="491"/>
+ <location filename="rust_strings.h" line="492"/>
<source>Not available</source>
<translation>不可用</translation>
</message>
diff --git a/desktop/app/i18n/rust_strings.h b/desktop/app/i18n/rust_strings.h
index 4bcc8d9..7d9f397 100644
--- a/desktop/app/i18n/rust_strings.h
+++ b/desktop/app/i18n/rust_strings.h
@@ -482,6 +482,7 @@ static const char *const nectarlink_rust_strings[] = {
QT_TRANSLATE_NOOP("Updater", "The update couldn't be saved. Check that there's free space and try again."), // desktop/app/src/updater.rs
QT_TRANSLATE_NOOP("Updater", "The update couldn't be started. Try again."), // desktop/app/src/updater.rs
QT_TRANSLATE_NOOP("Updater", "The update didn't install"), // desktop/app/src/updater.rs
+ QT_TRANSLATE_NOOP("Updater", "The update is installed. Restart NectarLink to use it."), // desktop/app/src/updater.rs
QT_TRANSLATE_NOOP("Updater", "Update now, or later from Settings."), // desktop/app/src/updater.rs
QT_TRANSLATE_NOOP("Updater", "Your phone reconnects on its own."), // desktop/app/src/updater.rs
QT_TRANSLATE_NOOP("Webcam", "Starting camera on %1…"), // desktop/app/src/bridge/webcam.rs
diff --git a/desktop/app/i18n/template/nectarlink.ts b/desktop/app/i18n/template/nectarlink.ts
index a8f7bbc..c5547d3 100644
--- a/desktop/app/i18n/template/nectarlink.ts
+++ b/desktop/app/i18n/template/nectarlink.ts
@@ -8528,11 +8528,16 @@ What it needs
</message>
<message>
<location filename="../rust_strings.h" line="485"/>
- <source>Update now, or later from Settings.</source>
+ <source>The update is installed. Restart NectarLink to use it.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../rust_strings.h" line="486"/>
+ <source>Update now, or later from Settings.</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="../rust_strings.h" line="487"/>
<source>Your phone reconnects on its own.</source>
<translation type="unfinished"></translation>
</message>
@@ -8743,12 +8748,12 @@ What it needs
<context>
<name>Webcam</name>
<message>
- <location filename="../rust_strings.h" line="487"/>
+ <location filename="../rust_strings.h" line="488"/>
<source>Starting camera on %1…</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="../rust_strings.h" line="488"/>
+ <location filename="../rust_strings.h" line="489"/>
<source>Streaming %1 × %2 · %3 fps from %4</source>
<translation type="unfinished"></translation>
</message>
@@ -8779,17 +8784,17 @@ What it needs
<context>
<name>Widget</name>
<message>
- <location filename="../rust_strings.h" line="489"/>
+ <location filename="../rust_strings.h" line="490"/>
<source>No phone connected</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="../rust_strings.h" line="490"/>
+ <location filename="../rust_strings.h" line="491"/>
<source>No recent clipboard items</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="../rust_strings.h" line="491"/>
+ <location filename="../rust_strings.h" line="492"/>
<source>Not available</source>
<translation type="unfinished"></translation>
</message>
diff --git a/desktop/app/src/updater.rs b/desktop/app/src/updater.rs
index 9fc11bf..a189874 100644
--- a/desktop/app/src/updater.rs
+++ b/desktop/app/src/updater.rs
@@ -771,7 +771,8 @@ pub fn run_service() -> ExitCode {
.stderr(std::process::Stdio::null())
.spawn()
} else {
- std::process::Command::new(&path).arg("/S").spawn()
+ // An AppImage replaces itself from the app; the service can't.
+ Err(std::io::Error::other(format!("{name} isn't installed by the update service")))
}
};
match spawned {
@@ -796,23 +797,27 @@ fn unix_seconds_now() -> String {
/// can change: Windows' `SystemTemp` (older Windows: the SYSTEM account's
/// temp folder, whose new subfolders users can't write to). Earlier ones are
/// removed first (in `SystemTemp` only, where nobody else can create them).
+/// Removes the folders earlier runs downloaded into. Links are left alone;
+/// only SYSTEM (or root) can create entries where these live.
+fn remove_old_service_dirs(parent: &Path) {
+ let Ok(entries) = std::fs::read_dir(parent) else { return };
+ for entry in entries.flatten() {
+ let is_dir = entry.file_type().is_ok_and(|t| t.is_dir() && !t.is_symlink());
+ if is_dir && entry.file_name().to_string_lossy().starts_with("nectarlink-update-") {
+ let _ = std::fs::remove_dir_all(entry.path());
+ }
+ }
+}
+
#[cfg(windows)]
fn service_dir() -> std::io::Result<PathBuf> {
let windows =
std::env::var_os("SystemRoot").map(PathBuf::from).unwrap_or_else(|| PathBuf::from(r"C:\Windows"));
let system_temp = windows.join("SystemTemp");
- let parent = if system_temp.is_dir() {
- if let Ok(entries) = std::fs::read_dir(&system_temp) {
- for entry in entries.flatten() {
- if entry.file_name().to_string_lossy().starts_with("nectarlink-update-") {
- let _ = std::fs::remove_dir_all(entry.path());
- }
- }
- }
- system_temp
- } else {
- std::env::temp_dir()
- };
+ // Older Windows: the SYSTEM account's temp folder, whose subfolders users
+ // can't change either.
+ let parent = if system_temp.is_dir() { system_temp } else { std::env::temp_dir() };
+ remove_old_service_dirs(&parent);
let mut random = [0u8; 8];
if !crate::win::secure_random(&mut random) {
return Err(std::io::Error::other("no secure random source"));
@@ -827,6 +832,7 @@ fn service_dir() -> std::io::Result<PathBuf> {
fn service_dir() -> std::io::Result<PathBuf> {
use std::os::unix::fs::DirBuilderExt;
let parent = PathBuf::from("/var/cache");
+ remove_old_service_dirs(&parent);
let mut random = [0u8; 8];
if !crate::win::secure_random(&mut random) {
return Err(std::io::Error::other("no secure random source"));
@@ -939,6 +945,17 @@ tar -C \"$dir\" -xzf \"$dst\"\n\
set -- \"$dir\"/Nectarlink-*/install.sh\n\
[ -x \"$1\" ] && \"$1\"\n";
+/// Starts the new version once this one has quit. If that can't be arranged
+/// the app stays open (it would otherwise just disappear) and says the update
+/// is in place.
+#[cfg(target_os = "linux")]
+fn relaunch_after_install(exe: &Path, version: &str) -> Result<(), String> {
+ spawn_relauncher(exe, version, true).map_err(|e| {
+ tracing::warn!(error = e, "installed, but can't start the new version");
+ tr!("Updater", "The update is installed. Restart NectarLink to use it.")
+ })
+}
+
#[cfg(target_os = "linux")]
fn install_with_prompt(update: &Update, staged: &Path) -> Result<(), String> {
use std::os::unix::fs::{DirBuilderExt, PermissionsExt};
@@ -982,7 +999,7 @@ fn install_with_prompt(update: &Update, staged: &Path) -> Result<(), String> {
return Err(failed(format!("privileged .deb install exited with status {code}")));
}
if let Ok(exe) = std::env::current_exe() {
- let _ = spawn_relauncher(&exe, &update.version, true);
+ relaunch_after_install(&exe, &update.version)?;
}
crate::bridge::app::request_quit();
return Ok(());
@@ -999,7 +1016,7 @@ fn install_with_prompt(update: &Update, staged: &Path) -> Result<(), String> {
return Err(failed(format!("privileged .rpm install exited with status {code}")));
}
if let Ok(exe) = std::env::current_exe() {
- let _ = spawn_relauncher(&exe, &update.version, true);
+ relaunch_after_install(&exe, &update.version)?;
}
crate::bridge::app::request_quit();
return Ok(());
@@ -1047,7 +1064,7 @@ fn install_with_prompt(update: &Update, staged: &Path) -> Result<(), String> {
}
}
if let Some(exe) = exe {
- let _ = spawn_relauncher(&exe, &update.version, true);
+ relaunch_after_install(&exe, &update.version)?;
}
crate::bridge::app::request_quit();
return Ok(());