velopack
Version:
Velopack is an installation and auto-update framework for cross-platform applications. It's opinionated, extremely easy to use with zero config needed. With just one command you can be up and running with an installable application, and it's lightning fas
141 lines (140 loc) • 7.45 kB
TypeScript
import type { UpdateInfo, UpdateOptions, VelopackLocatorConfig, VelopackAsset } from "./types";
export { UpdateInfo, UpdateOptions, VelopackLocatorConfig, VelopackAsset };
type UpdateManagerOpaque = {};
declare module "./load" {
function js_new_update_manager(urlOrPath: string, options: string | null, locator: string | null): UpdateManagerOpaque;
function js_get_current_version(um: UpdateManagerOpaque): string;
function js_get_app_id(um: UpdateManagerOpaque): string;
function js_is_portable(um: UpdateManagerOpaque): boolean;
function js_update_pending_restart(um: UpdateManagerOpaque): string | null;
function js_check_for_updates_async(um: UpdateManagerOpaque): Promise<string | null>;
function js_download_update_async(um: UpdateManagerOpaque, update: string, progress: (perc: number) => void): Promise<void>;
function js_wait_exit_then_apply_update(um: UpdateManagerOpaque, update: string, silent?: boolean, restart?: boolean, restartArgs?: string[]): void;
function js_appbuilder_run(cb: (hook_name: string, current_version: string) => void, customArgs: string[] | null, locator: string | null, autoApply: boolean): void;
function js_set_logger_callback(cb: (loglevel: LogLevel, msg: string) => void): void;
}
type VelopackHook = (version: string) => void;
type LogLevel = "info" | "warn" | "error" | "debug" | "trace";
/**
* VelopackApp helps you to handle app activation events correctly.
* This should be used as early as possible in your application startup code.
* (eg. the beginning of main() or wherever your entry point is)
*/
export declare class VelopackApp {
private _hooks;
private _customArgs;
private _customLocator;
private _autoApply;
/**
* Build a new VelopackApp instance.
*/
static build(): VelopackApp;
/**
* WARNING: FastCallback hooks are run during critical stages of Velopack operations.
* Your code will be run and then the process will exit.
* If your code has not completed within 30 seconds, it will be terminated.
* Only supported on windows; On other operating systems, this will never be called.
*/
onAfterInstallFastCallback(callback: VelopackHook): VelopackApp;
/**
* WARNING: FastCallback hooks are run during critical stages of Velopack operations.
* Your code will be run and then the process will exit.
* If your code has not completed within 30 seconds, it will be terminated.
* Only supported on windows; On other operating systems, this will never be called.
*/
onBeforeUninstallFastCallback(callback: VelopackHook): VelopackApp;
/**
* WARNING: FastCallback hooks are run during critical stages of Velopack operations.
* Your code will be run and then the process will exit.
* If your code has not completed within 15 seconds, it will be terminated.
* Only supported on windows; On other operating systems, this will never be called.
*/
onBeforeUpdateFastCallback(callback: VelopackHook): VelopackApp;
/**
* WARNING: FastCallback hooks are run during critical stages of Velopack operations.
* Your code will be run and then the process will exit.
* If your code has not completed within 15 seconds, it will be terminated.
* Only supported on windows; On other operating systems, this will never be called.
*/
onAfterUpdateFastCallback(callback: VelopackHook): VelopackApp;
/**
* This hook is triggered when the application is restarted by Velopack after installing updates.
*/
onRestarted(callback: VelopackHook): VelopackApp;
/**
* This hook is triggered when the application is started for the first time after installation.
*/
onFirstRun(callback: VelopackHook): VelopackApp;
/**
* Override the command line arguments used by VelopackApp. (by default this is env::args().skip(1))
*/
setArgs(args: string[]): VelopackApp;
/**
* VelopackLocator provides some utility functions for locating the current app important paths (eg. path to packages, update binary, and so forth).
*/
setLocator(locator: VelopackLocatorConfig): VelopackApp;
/**
* Set a callback to receive log messages from VelopackApp.
*/
setLogger(callback: (loglevel: LogLevel, msg: string) => void): VelopackApp;
/**
* Set whether to automatically apply downloaded updates on startup. This is ON by default.
*/
setAutoApplyOnStartup(autoApply: boolean): VelopackApp;
/**
* Runs the Velopack startup logic. This should be the first thing to run in your app.
* In some circumstances it may terminate/restart the process to perform tasks.
*/
run(): void;
}
/**
* Provides functionality for checking for updates, downloading updates, and applying updates to the current application.
*/
export declare class UpdateManager {
private readonly opaque;
/**
* Create a new UpdateManager instance.
* @param urlOrPath Location of the update server or path to the local update directory.
* @param options Optional extra configuration for update manager.
* @param locator Override the default locator configuration (usually used for testing / mocks).
*/
constructor(urlOrPath: string, options?: UpdateOptions, locator?: VelopackLocatorConfig);
/**
* Returns the currently installed version of the app.
*/
getCurrentVersion(): string;
/**
* Returns the currently installed app id.
*/
getAppId(): string;
/**
* Returns whether the app is in portable mode. On Windows this can be true or false.
* On MacOS and Linux this will always be true.
*/
isPortable(): boolean;
/**
* Returns an VelopackAsset object if there is an update downloaded which still needs to be applied.
* You can pass the VelopackAsset object to waitExitThenApplyUpdate to apply the update.
*/
getUpdatePendingRestart(): VelopackAsset | null;
/**
* Checks for updates, returning None if there are none available. If there are updates available, this method will return an
* UpdateInfo object containing the latest available release, and any delta updates that can be applied if they are available.
*/
checkForUpdatesAsync(): Promise<UpdateInfo | null>;
/**
* Downloads the specified updates to the local app packages directory. Progress is reported back to the caller via an optional Sender.
* This function will acquire a global update lock so may fail if there is already another update operation in progress.
* - If the update contains delta packages and the delta feature is enabled
* this method will attempt to unpack and prepare them.
* - If there is no delta update available, or there is an error preparing delta
* packages, this method will fall back to downloading the full version of the update.
*/
downloadUpdateAsync(update: UpdateInfo, progress?: (perc: number) => void): Promise<void>;
/**
* This will launch the Velopack updater and tell it to wait for this program to exit gracefully.
* You should then clean up any state and exit your app. The updater will apply updates and then
* optionally restart your app. The updater will only wait for 60 seconds before giving up.
*/
waitExitThenApplyUpdate(update: UpdateInfo | VelopackAsset, silent?: boolean, restart?: boolean, restartArgs?: string[]): void;
}