feat: add shorebird_current_boot_patch_number function (#36)

* feat: add shorebird_current_boot_patch_number function

* Continue support for next_patch_version

* rename, return null in case of 0
This commit is contained in:
Bryan Oltman
2023-06-20 16:45:43 -04:00
committed by GitHub
parent 0057c7ea8d
commit 318d86e13f
9 changed files with 131 additions and 20 deletions
@@ -2084,6 +2084,18 @@ class UpdaterBindings {
late final _shorebird_init = _shorebird_initPtr.asFunction<
bool Function(ffi.Pointer<AppParameters>, ffi.Pointer<ffi.Char>)>();
/// The currently running patch number, or 0 if the release has not been
/// patched.
int shorebird_current_boot_patch_number() {
return _shorebird_current_boot_patch_number();
}
late final _shorebird_current_boot_patch_numberPtr =
_lookup<ffi.NativeFunction<ffi.UintPtr Function()>>(
'shorebird_current_boot_patch_number');
late final _shorebird_current_boot_patch_number =
_shorebird_current_boot_patch_numberPtr.asFunction<int Function()>();
/// The patch number that will boot on the next run of the app, or 0 if there is
/// no next patch.
int shorebird_next_boot_patch_number() {
@@ -2157,8 +2169,9 @@ class UpdaterBindings {
_shorebird_start_update_threadPtr.asFunction<void Function()>();
/// Tell the updater that we're launching from what it told us was the
/// next patch to boot from. This will copy the next_boot patch to be
/// the current_boot patch.
/// next patch to boot from. This will copy the next_boot patch to be the
/// current_boot patch.
///
/// It is required to call this function before calling
/// shorebird_report_launch_success or shorebird_report_launch_failure.
void shorebird_report_launch_start() {
@@ -2188,6 +2201,7 @@ class UpdaterBindings {
/// as having been launched successfully. We don't currently do anything
/// with this information, but it could be used to record a point at which
/// we will not roll back from.
///
/// This is not currently wired up to be called from the Engine. It's unclear
/// where best to connect it. Expo waits 5 seconds after the app launches
/// and then marks the launch as successful. We could do something similar.
@@ -22,8 +22,21 @@ class ShorebirdCodePush {
/// The version of the currently-installed patch. Null if no patch is
/// installed (i.e., the app is running the release version).
Future<int?> currentPatchVersion() {
return _runInIsolate((updater) => updater.currentPatchNumber());
Future<int?> currentPatchNumber() {
return _runInIsolate((updater) {
final patchNumber = updater.currentPatchNumber();
return patchNumber == 0 ? null : patchNumber;
});
}
/// The version of the patch that will be run on the next app launch. If no
/// new patch has been downloaded, this will be the same as
/// [currentPatchNumber].
Future<int?> nextPatchNumber() {
return _runInIsolate((updater) {
final patchNumber = updater.nextPatchNumber();
return patchNumber == 0 ? null : patchNumber;
});
}
/// Creates an [Updater] in a separate isolate and runs the given function.
+11 -3
View File
@@ -18,11 +18,9 @@ class Updater {
static late UpdaterBindings bindings;
/// The currently active patch number.
// TODO(bryanoltman): this will return the current number + 1 if an update is
// available. It should instead always return the current patch version.
int currentPatchNumber() {
try {
return bindings.shorebird_next_boot_patch_number();
return bindings.shorebird_current_boot_patch_number();
} catch (e) {
return 0;
}
@@ -36,4 +34,14 @@ class Updater {
return false;
}
}
/// The next patch number that will be loaded. Will be the same as
/// currentPatchNumber if no new patch is available.
int nextPatchNumber() {
try {
return bindings.shorebird_next_boot_patch_number();
} catch (e) {
return 0;
}
}
}