Runtime API
Runtime update checking functionality.
Functions
checkForUpdates
Perform a synchronous update check.
pub fn checkForUpdates(allocator: std.mem.Allocator, config: UpdateConfig) !UpdateResult;Parameters
allocator: Memory allocator for HTTP request and parsingconfig: Update check configuration
Returns
An UpdateResult with the check outcome.
Errors
- Network errors
- Parse errors
- Configuration errors
Example
const result = try updater.checkForUpdates(allocator, .{
.provider = updater.providers.github,
.owner = "username",
.repo = "project",
.current_version = "1.0.0",
});
if (result.has_update) {
std.debug.print("Update: {s}\n", .{result.latest_version.?});
}checkGitHub
Convenience function for GitHub checks.
pub fn checkGitHub(
allocator: std.mem.Allocator,
owner: []const u8,
repo: []const u8,
current_version: []const u8,
) !UpdateResult;checkGitLab
Convenience function for GitLab checks.
pub fn checkGitLab(
allocator: std.mem.Allocator,
owner: []const u8,
repo: []const u8,
current_version: []const u8,
) !UpdateResult;checkCodeberg
Convenience function for Codeberg checks.
pub fn checkCodeberg(
allocator: std.mem.Allocator,
owner: []const u8,
repo: []const u8,
current_version: []const u8,
) !UpdateResult;startBackgroundChecker
Start a background update checker.
pub fn startBackgroundChecker(
allocator: std.mem.Allocator,
config: UpdateConfig,
) !*BackgroundChecker;Parameters
allocator: Memory allocatorconfig: Configuration withbackground = true
Returns
A pointer to a BackgroundChecker that runs periodically.
Errors
GloballyDisabled: Update checking is globally disabledBackgroundCheckingDisabled: Background mode not enabled in config
Example
const checker = try updater.startBackgroundChecker(allocator, .{
.enabled = true,
.background = true,
.interval_seconds = 3600,
.provider = updater.providers.github,
.owner = "username",
.repo = "project",
.current_version = "1.0.0",
.on_update = onUpdateCallback,
});
defer checker.stop();
// Application runs...isGloballyDisabled
Check if update checking is globally disabled.
pub fn isGloballyDisabled() bool;Returns true if ZIG_UPDATE_CHECK_DISABLE is set.
isCI
Check if running in a CI environment.
pub fn isCI() bool;Returns true if any CI environment variable is detected.
Types
BackgroundChecker
Background update checker that runs in a separate thread.
pub const BackgroundChecker = struct {
/// Start the background checker
pub fn start(allocator: std.mem.Allocator, config: UpdateConfig) !*BackgroundChecker;
/// Stop the background checker and clean up
pub fn stop(self: *BackgroundChecker) void;
/// Get the last check result (if any)
pub fn getLastResult(self: *BackgroundChecker) ?UpdateResult;
};Methods
start
pub fn start(allocator: std.mem.Allocator, config: UpdateConfig) !*BackgroundChecker;Start the background checker. Spawns a thread that:
- Performs an immediate check
- Waits for
interval_seconds - Repeats until
stop()is called
stop
pub fn stop(self: *BackgroundChecker) void;Stop the background checker and free resources.
getLastResult
pub fn getLastResult(self: *BackgroundChecker) ?UpdateResult;Get the result of the last check, or null if no check has completed.
Callback
When using background mode with a callback:
fn onUpdateFound(result: UpdateResult) void {
std.debug.print("Update found: {s}\n", .{result.latest_version.?});
// Notify user, log, etc.
}
const checker = try updater.startBackgroundChecker(allocator, .{
// ...
.on_update = onUpdateFound,
});The callback is called from the background thread when an update is found.