From 5d4e9c339636fc2f67cbe9892026d9e10b0888bc Mon Sep 17 00:00:00 2001 From: Tony Date: Thu, 25 Jun 2026 15:50:24 +0800 Subject: [PATCH] refactor: improve comments for clarity and update privacy references Signed-off-by: Tony --- library/include/updater_dart.h | 3 +-- library/src/android.rs | 5 +++-- library/src/c_api/mod.rs | 2 +- library/src/cache/updater_state.rs | 2 +- library/src/config.rs | 30 ++++++++++++++++++++++++------ library/src/events.rs | 5 ++--- library/src/network.rs | 8 +++----- library/src/updater.rs | 3 ++- 8 files changed, 37 insertions(+), 21 deletions(-) diff --git a/library/include/updater_dart.h b/library/include/updater_dart.h index 4769c39..0e79381 100644 --- a/library/include/updater_dart.h +++ b/library/include/updater_dart.h @@ -89,8 +89,7 @@ bool shorebird_check_for_downloadable_update(const char *c_channel); * to their own stable account/device identifier. The updater persists this * value in state.json after a successful call. */ -SHOREBIRD_EXPORT -bool shorebird_set_device_id_override(const char *c_device_id); +SHOREBIRD_EXPORT bool shorebird_set_device_id_override(const char *c_device_id); /** * Synchronously download an update on the first non-null channel of: diff --git a/library/src/android.rs b/library/src/android.rs index eb26e9b..25c6700 100644 --- a/library/src/android.rs +++ b/library/src/android.rs @@ -169,7 +169,8 @@ pub(crate) fn open_base_lib(apks_dir: &Path, lib_name: &str) -> anyhow::Result Result. +// in the open Flutter fork: . use std::ffi::{CStr, CString}; use std::os::raw::c_char; diff --git a/library/src/cache/updater_state.rs b/library/src/cache/updater_state.rs index 48f882d..18844cd 100644 --- a/library/src/cache/updater_state.rs +++ b/library/src/cache/updater_state.rs @@ -72,7 +72,7 @@ pub struct UpdaterState { struct SerializedState { /// Stable per-install ID. Survives release-version changes; only /// reset when the app is uninstalled. Used for analytics. - /// + /// Treat this as privacy-sensitive update-server metadata. client_id: String, /// The release version this cache corresponds to. Mismatch with the /// app's reported release version triggers a wipe of all per-release diff --git a/library/src/config.rs b/library/src/config.rs index 2e535cd..05d0579 100644 --- a/library/src/config.rs +++ b/library/src/config.rs @@ -13,12 +13,7 @@ use std::sync::Mutex; // cbindgen looks for const, ignore these so it doesn't warn about them. /// cbindgen:ignore -#[cfg(test)] -const DEFAULT_BASE_URL: &str = "DEFAULT_BASE_URL should be mocked using mockito::Server"; - -/// cbindgen:ignore -#[cfg(not(test))] -const DEFAULT_BASE_URL: &str = "https://api.shorebird.dev"; +const DEFAULT_BASE_URL: &str = "http://localhost:8080"; /// cbindgen:ignore const DEFAULT_CHANNEL: &str = "stable"; @@ -279,6 +274,29 @@ mod tests { Ok(()) } + // These tests are serial because they modify global state. + #[serial] + #[test] + fn set_config_defaults_to_open_self_hosted_server() -> Result<()> { + testing_reset_config(); + + let mut yaml = fake_yaml(); + yaml.base_url = None; + + set_config( + fake_app_config(), + Box::new(FakeExternalFileProvider {}), + "first_path".into(), + &yaml, + NetworkHooks::default(), + )?; + + let config = super::with_config(|config| Ok(config.clone())).unwrap(); + assert_eq!(config.base_url, super::DEFAULT_BASE_URL); + + Ok(()) + } + // These tests are serial because they modify global state. #[serial] #[test] diff --git a/library/src/events.rs b/library/src/events.rs index 1d83f93..5ad2431 100644 --- a/library/src/events.rs +++ b/library/src/events.rs @@ -46,9 +46,8 @@ impl<'de> Deserialize<'de> for EventType { } } } -/// Any edits to this struct should be made carefully and in accordance -/// with our privacy policy: -/// +/// Any edits to this struct should be made carefully and in accordance with +/// the configured update server's privacy policy. /// An event that is sent to the server when a patch is successfully installed. #[derive(Debug, Serialize, Deserialize, Clone)] pub struct PatchEvent { diff --git a/library/src/network.rs b/library/src/network.rs index 1504bc8..1bf71f0 100644 --- a/library/src/network.rs +++ b/library/src/network.rs @@ -219,17 +219,15 @@ pub struct Patch { pub hash_signature: Option, } -/// Any edits to this struct should be made carefully and in accordance -/// with our privacy policy: -/// +/// Any edits to this struct should be made carefully and in accordance with +/// the configured update server's privacy policy. /// The request body for the patch check endpoint. #[derive(Debug, Serialize)] pub struct PatchCheckRequest { /// The Shorebird app_id built into the shorebird.yaml in the app. /// app_ids are unique to each app and are used to identify the app - /// within Shorebird's system (similar to a bundle identifier). They + /// within the update server (similar to a bundle identifier). They /// are not secret and are safe to share publicly. - /// pub app_id: String, /// The Shorebird channel built into the shorebird.yaml in the app. /// This is not currently used, but intended for future use to allow diff --git a/library/src/updater.rs b/library/src/updater.rs index fb3aead..e0bf11d 100644 --- a/library/src/updater.rs +++ b/library/src/updater.rs @@ -338,7 +338,8 @@ fn check_hash(path: &Path, expected_string: &str) -> anyhow::Result<()> { // This is a common error for developers. We could avoid it entirely // by sending the hash of `libapp.so` to the server and having the // server only send updates when the hash matches. - // https://github.com/shorebirdtech/updater/issues/56 + // A hash mismatch usually means the same version number was reused with a + // different app binary. if !hash_matches { bail!( "Update rejected: hash mismatch. Update was downloaded but \