62ed676140
* feat: add shorebird_current_boot_patch_number function * Continue support for next_patch_version * rename, return null in case of 0 * feat(shorebird_code_push): add download update functionality * rename defaultValue to fallbackValue * add forTest constructor to ShorebirdCodePush
33 lines
1.1 KiB
Dart
33 lines
1.1 KiB
Dart
import 'dart:ffi' as ffi;
|
|
|
|
import 'package:meta/meta.dart';
|
|
import 'package:shorebird_code_push/src/generated/updater_bindings.g.dart';
|
|
|
|
/// {@template updater}
|
|
/// A wrapper around the generated [UpdaterBindings] that, when necessary,
|
|
/// translates ffi types into easier to use Dart types.
|
|
/// {@endtemplate}
|
|
class Updater {
|
|
/// Creates an [Updater] instance using the currently loaded dynamic library.
|
|
Updater() {
|
|
bindings = UpdaterBindings(ffi.DynamicLibrary.process());
|
|
}
|
|
|
|
/// The ffi bindings to the Updater library.
|
|
@visibleForTesting
|
|
static late UpdaterBindings bindings;
|
|
|
|
/// The currently active patch number.
|
|
int currentPatchNumber() => bindings.shorebird_current_boot_patch_number();
|
|
|
|
/// Whether a new patch is available.
|
|
bool checkForUpdate() => bindings.shorebird_check_for_update();
|
|
|
|
/// The next patch number that will be loaded. Will be the same as
|
|
/// currentPatchNumber if no new patch is available.
|
|
int nextPatchNumber() => bindings.shorebird_next_boot_patch_number();
|
|
|
|
/// Downloads the latest patch, if available.
|
|
void downloadUpdate() => bindings.shorebird_update();
|
|
}
|