-
-
Notifications
You must be signed in to change notification settings - Fork 96
feat(server): let packaged builds override the reported version #656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ErikBjare
merged 2 commits into
ActivityWatch:master
from
TimeToBuildBob:fix/version-override
Aug 25, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| //! Version string reported by `GET /api/0/info`. | ||
| //! | ||
| //! By default this is the aw-server-rust package version. That is wrong for | ||
| //! builds that embed aw-server-rust as a component of a larger product: on | ||
| //! Android the webui footer showed `v0.14.0 (rust)` (the Cargo.toml version) | ||
| //! while the installed app was `v0.14.0b2`. | ||
| //! | ||
| //! Such builds call [`set_version_override`] at startup to report their own | ||
| //! release version instead. | ||
|
|
||
| use std::sync::RwLock; | ||
|
|
||
| static VERSION_OVERRIDE: RwLock<Option<String>> = RwLock::new(None); | ||
|
|
||
| /// Report `version` from `/api/0/info` instead of the package version. | ||
| /// | ||
| /// The string is used verbatim, so the caller controls the exact format | ||
| /// (including any `v` prefix). | ||
| pub fn set_version_override(version: &str) { | ||
| let mut guard = VERSION_OVERRIDE.write().unwrap(); | ||
| *guard = Some(version.to_string()); | ||
| } | ||
|
|
||
| /// The version string to report from `/api/0/info`. | ||
| pub fn version_string() -> String { | ||
| if let Some(version) = VERSION_OVERRIDE.read().unwrap().as_ref() { | ||
| return version.clone(); | ||
| } | ||
| const VERSION: Option<&str> = option_env!("CARGO_PKG_VERSION"); | ||
| format!("v{} (rust)", VERSION.unwrap_or("(unknown)")) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| struct VersionGuard; | ||
| impl Drop for VersionGuard { | ||
| fn drop(&mut self) { | ||
| *VERSION_OVERRIDE.write().unwrap() = None; | ||
| } | ||
| } | ||
|
|
||
| // These share process-global state, so they run as one test. | ||
| #[test] | ||
| fn override_replaces_package_version() { | ||
| let _guard = VersionGuard; // resets VERSION_OVERRIDE on exit, even on panic | ||
|
|
||
| assert!( | ||
| version_string().ends_with(" (rust)"), | ||
| "default should report the package version, got {:?}", | ||
| version_string() | ||
| ); | ||
|
|
||
| set_version_override("v0.14.0b2"); | ||
| assert_eq!(version_string(), "v0.14.0b2"); | ||
|
|
||
| // Used verbatim: the caller owns the format. | ||
| set_version_override("1.2.3-custom"); | ||
| assert_eq!(version_string(), "1.2.3-custom"); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.