Serve the installed interface from the app and let a release replace itself.

A production build was treated as development, so the window stayed on localhost:5173. Release builds now carry the updater key and install a newer signed shell on their own.
This commit is contained in:
spark committed 2026-11-26 14:45:06 +00:00
1 parent 452d84bff2
commit af63ea5673
11 files changed
+9147 -17

No files matched your search

+3 -1
View File
@@ -41,7 +41,9 @@ signed shell at once; the API reads the latest
installer through, so the private repository stays private. Installers are signed with the release key
(`tauri signer generate`): the private key and its password are the Gitea secrets `TAURI_SIGNING_PRIVATE_KEY` and
`TAURI_SIGNING_PRIVATE_KEY_PASSWORD`, the public key is the variable `TAURI_UPDATER_PUBKEY` (compiled into the app
as `PHOTOREPORT_UPDATER_PUBKEY`). A build without the public key never updates itself.
as `PHOTOREPORT_UPDATER_PUBKEY`). A release build also reads that same public key from `updater-pubkey.txt` when the
variable is unset, and checks again in the background, so the installed app replaces itself. A debug build without
the variable never updates itself.
## Local FTP (camera → this computer → event)
+9032
View File
File diff suppressed because it is too large. Load diff
+7
View File
@@ -9,6 +9,13 @@ description = "PhotoReport desktop: the web app in a native shell, with keychain
name = "photoreport_desktop_lib"
crate-type = ["staticlib", "cdylib", "rlib"]
# Production serves the interface from this computer. Without this feature Tauri treats every
# build as development and the window opens http://localhost:5173, which stays blank unless
# `tauri dev` is running. `tauri dev` turns the feature off and uses the dev server.
[features]
default = ["custom-protocol"]
custom-protocol = ["tauri/custom-protocol"]
[build-dependencies]
tauri-build = { version = "2", features = [] }
cc = "1"
+28 -1
View File
@@ -1,4 +1,5 @@
fn main() {
publish_updater_key();
let target = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
if target == "macos" {
// ImageCaptureCore: PTP cameras (they never mount as a volume).
@@ -87,6 +88,27 @@ fn main() {
link_coreml_compiler_rt();
}
/// Release builds always carry the official update key, so an installed app can replace itself from the API.
/// `option_env!` is not a cargo fingerprint: the key has to be passed with `cargo:rustc-env` or a later compile
/// keeps the previous value. A debug build stays without it unless the variable is set for that compile.
fn publish_updater_key() {
println!("cargo:rerun-if-env-changed=PHOTOREPORT_UPDATER_PUBKEY");
let manifest = std::env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| ".".to_string());
let path = std::path::Path::new(&manifest).join("updater-pubkey.txt");
println!("cargo:rerun-if-changed={}", path.display());
let from_env = std::env::var("PHOTOREPORT_UPDATER_PUBKEY").unwrap_or_default();
let mut key = from_env.trim().to_string();
let profile = std::env::var("PROFILE").unwrap_or_default();
if key.is_empty() && profile == "release" {
let from_file = std::fs::read_to_string(&path).unwrap_or_default();
key = from_file.trim().to_string();
}
if key.is_empty() {
return;
}
println!("cargo:rustc-env=PHOTOREPORT_UPDATER_PUBKEY={key}");
}
/// ONNX Runtime's Core ML objects call `___isPlatformVersionAtLeast`. That helper lives in compiler-rt, which Rust's
/// linker does not pull in, so the desktop build (deployment target 11) fails on the arm64 slice.
fn link_coreml_compiler_rt() {
@@ -96,7 +118,12 @@ fn link_coreml_compiler_rt() {
return;
}
let Ok(output) = std::process::Command::new("xcrun")
.args(["--sdk", "macosx", "clang", "-print-file-name=libclang_rt.osx.a"])
.args([
"--sdk",
"macosx",
"clang",
"-print-file-name=libclang_rt.osx.a",
])
.output()
else {
return;
+13 -3
View File
@@ -74,7 +74,11 @@ enum CameraEvent {
files: Vec<CameraFile>,
},
#[serde(rename = "file")]
File { path: String, name: String, size: u64 },
File {
path: String,
name: String,
size: u64,
},
}
struct Inner {
@@ -211,7 +215,10 @@ fn apply_event(inner: &mut Inner, line: &str) {
};
match event {
CameraEvent::Devices { devices } => inner.devices = devices,
CameraEvent::Catalog { camera_id: _, files } => {
CameraEvent::Catalog {
camera_id: _,
files,
} => {
inner.files = files;
inner.catalog_gen = inner.catalog_gen.wrapping_add(1);
}
@@ -424,7 +431,10 @@ mod tests {
catalog_gen: 1,
};
apply_event(&mut inner, r#"{"kind":"devices","devices":[]}"#);
apply_event(&mut inner, r#"{"kind":"catalog","cameraId":"abc","files":[]}"#);
apply_event(
&mut inner,
r#"{"kind":"catalog","cameraId":"abc","files":[]}"#,
);
assert!(inner.devices.is_empty());
assert!(inner.files.is_empty());
assert_eq!(inner.catalog_gen, 2);
+4 -1
View File
@@ -932,7 +932,10 @@ mod tests {
let (take, held) = days_that_fit(days, Some(55));
assert_eq!(take.len(), 1);
assert_eq!(take[0].key, "2026-11-03");
assert_eq!(held, vec!["2026-11-04".to_string(), "2026-11-05".to_string()]);
assert_eq!(
held,
vec!["2026-11-04".to_string(), "2026-11-05".to_string()]
);
let (all, none) = days_that_fit(
vec![DayPlan {
key: "2026-11-04".into(),
+1 -5
View File
@@ -126,11 +126,7 @@ impl Deliveries {
Path::new(f)
.canonicalize()
.ok()
.and_then(|root| {
canon
.parent()
.map(|p| p.starts_with(&root))
})
.and_then(|root| canon.parent().map(|p| p.starts_with(&root)))
.unwrap_or(false)
});
if !allowed && !allowed_xmp {
+1
View File
@@ -102,6 +102,7 @@ pub fn run() {
// `tauri dev` serves the dev server: nothing to update.
if !cfg!(debug_assertions) {
ui::watch(app.handle().clone());
updater::watch(app.handle().clone());
}
// Always the interface on this computer (`tauri dev`: the dev server). No download to start, and it
// works without a network; new versions arrive in the background (see `ui`).
+53 -3
View File
@@ -4,8 +4,10 @@
//!
//! The app asks the API (`/v1/desktop/update/{target}/{arch}/{version}`), which reads the latest `desktop-v*`
//! release. Installers are signed at build time with the release key; the matching public key is compiled in
//! (`PHOTOREPORT_UPDATER_PUBKEY`). A build without it (a developer's) never updates itself: there is nothing to
//! check a download against.
//! (`PHOTOREPORT_UPDATER_PUBKEY`, from the environment or `updater-pubkey.txt` on a release build). A debug build
//! without that variable never updates itself: there is nothing to check a download against.
use std::sync::atomic::{AtomicBool, Ordering};
use serde::Serialize;
use tauri_plugin_updater::UpdaterExt;
@@ -61,9 +63,22 @@ pub async fn update_check(app: tauri::AppHandle) -> Result<Option<UpdateInfo>, S
}
/// Downloads the new shell, checks its signature, installs it and restarts the app.
/// The page and the background check both call this; only one download runs.
#[tauri::command]
pub async fn update_install(app: tauri::AppHandle) -> Result<(), String> {
let update = updater(&app)?
let started = INSTALLING.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst);
if started.is_err() {
return Ok(());
}
let result = install_now(&app).await;
if result.is_err() {
INSTALLING.store(false, Ordering::SeqCst);
}
result
}
async fn install_now(app: &tauri::AppHandle) -> Result<(), String> {
let update = updater(app)?
.check()
.await
.map_err(|e| e.to_string())?
@@ -75,6 +90,33 @@ pub async fn update_install(app: tauri::AppHandle) -> Result<(), String> {
app.restart();
}
static INSTALLING: AtomicBool = AtomicBool::new(false);
const FIRST: std::time::Duration = std::time::Duration::from_secs(3);
const EVERY: std::time::Duration = std::time::Duration::from_secs(60);
/// Checks for a newer shell while the app runs and installs it. The window does not have to ask.
pub fn watch(app: tauri::AppHandle) {
if PUBKEY.is_none() {
return;
}
tauri::async_runtime::spawn(async move {
tokio::time::sleep(FIRST).await;
loop {
match update_check(app.clone()).await {
Ok(Some(_)) => {
if let Err(err) = update_install(app.clone()).await {
eprintln!("shell update: {err}");
}
}
Ok(None) => {}
Err(err) => eprintln!("shell update: {err}"),
}
tokio::time::sleep(EVERY).await;
}
});
}
#[cfg(test)]
mod tests {
use super::*;
@@ -88,4 +130,12 @@ mod tests {
);
assert!(url.starts_with("http"));
}
#[test]
fn release_builds_ship_the_update_key() {
let key = include_str!("../updater-pubkey.txt").trim();
assert!(key.starts_with("dW50cnVzdGVk"));
assert!(key.len() > 80);
assert!(!key.chars().any(|c| c.is_whitespace()));
}
}
@@ -0,0 +1 @@
dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IEExODYxQ0JERTgzQzIwMTkKUldRWklEem92UnlHb2RUc0RRN2plalV0bndQVTVySFJQOGtuM3pQNDFtaDZFSld6ZnZya1FCeFEK
+4 -3
View File
@@ -131,9 +131,10 @@ downloads only the files that changed, checks each hash and uses the new version
photographer reloads). The installer's own copy is the fallback, and wins when it is newer.
macOS builds on a Mac registered once as a runner (`bash infra/desktop/macos-runner.sh`, with a registration token
from Gitea → Actions → Runners; label `macos`, a launchd service of that user). Its builds carry the updater key, so
apps installed from a release update themselves; an app compiled by hand without the key never does. A release made
while the Mac is off waits for it.
from Gitea → Actions → Runners; label `macos`, a launchd service of that user). Release builds carry the updater
public key (`updater-pubkey.txt`, or `TAURI_UPDATER_PUBKEY` when CI sets it), so an installed app replaces itself
from the next signed `desktop-v*` release. A debug build without the variable never does. A release made while the
Mac is off waits for it.
## Importing the old app.photoreport.pt