This is a plug-in that supports Shorebird
to customize the patch download address and to keep an eye on the download progress.
Of course, in addition to the download function, you still need to get the other patch status related to Shorebird through the shorebird_code_push
plugin.
⚠️ At present, an error will be reported when downloading the Android patch through this library and starting it. -> https://github.com/shorebirdtech/shorebird/issues/1449
flutter pub add shorebird_downloader
Now you can use the following methods to detect patches, download, pop-up prompts to restart, etc.
ShorebirdCheckDownloader(
customShowUpdateDialog: (currentPatchNumber, nextPatchNumber) =>
ShorebirdCheckDownloader.showUpdateDialog(
Get.context!,
currentPatchNumber,
nextPatchNumber,
),
).checkPatch();
final downloader =
ShorebirdUrlDownloader(appid: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx');
await downloader.downloadPatch((size,totol) => print("$size/$totol"));
If you feel that shorebird's CDN access is still slow or inaccessible, you can upload the patch to your own server in advance.
You can customize the following code to implement it.
class ShorebirdCustomUrlDownloader extends ShorebirdDownloader {
ShorebirdUrlDownloader({required super.appid});
@override
Future<Patch?> requestPatchInfo() async {
// TODO: http request custom your server url
// [number] represents the latest patch number
// [downloadUrl] represents the latest patch number
return Patch(number: number, downloadUrl: downloadUrl);
}
}
Then you can use it as usual.
final downloader =
ShorebirdCustomUrlDownloader(appid: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx');
await downloader.downloadPatch((size,totol) => print("$size/$totol"));
We now support uploading to the Appwrite server
dart pub global activate shorebird_downloader
The first step is to configure your factory files
# pubspec.yaml
appwrite:
key: xxxxxx
projectId: xxxxx
bucketId: xxxx
# shorebird.yaml
app_id: xxxxx
You can use the following command to upload the latest patch to Appwrite.
# in current shorebird project
shorebird_patch_uploader appwrite --platform [ios/android]
To download updates directly from appwrite, you need to use the following code
final downloader =
ShorebirdAppwriteDownloader(
appid: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
projectId: 'xxxxx',
bucketId: 'bucketId',
key: 'key',
// endPoint: 'custom appwrite endpoint normal is https://cloud.appwrite.io/v1'
);
await downloader.downloadPatch((size,totol) => print("$size/$totol"));