feat(updater): download successful dialog (#938)

This commit is contained in:
Aabed Khan 2023-06-23 19:21:36 +05:45 committed by GitHub
parent 35e99cb014
commit d051ae576b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 121 additions and 58 deletions

View File

@ -24,11 +24,13 @@
"WIP": "Work in progress...", "WIP": "Work in progress...",
"noInstallations": "No patched applications installed", "noInstallations": "No patched applications installed",
"installed": "Installed", "installed": "Installed",
"installUpdate": "Continue to install the update?",
"updateDialogTitle": "Update Manager", "updateDialogTitle": "Update Manager",
"updateChangelogTitle": "Changelog", "updateChangelogTitle": "Changelog",
"notificationTitle": "Update downloaded", "notificationTitle": "Update downloaded",
"notificationText": "Tap to install the update", "notificationText": "Tap to install the update",
"downloadingMessage": "Downloading update...", "downloadingMessage": "Downloading update...",
"downloadedMessage": "Update downloaded!",
"installingMessage": "Installing update...", "installingMessage": "Installing update...",
"errorDownloadMessage": "Unable to download update", "errorDownloadMessage": "Unable to download update",
"errorInstallMessage": "Unable to install update", "errorInstallMessage": "Unable to install update",

View File

@ -170,6 +170,7 @@ class RevancedAPI {
updateManagerDownloadProgress(progress); updateManagerDownloadProgress(progress);
} else if (result is FileInfo) { } else if (result is FileInfo) {
disposeManagerUpdateProgress();
// The download is complete; convert the FileInfo object to a File object // The download is complete; convert the FileInfo object to a File object
outputFile = File(result.file.path); outputFile = File(result.file.path);
} }

View File

@ -1,7 +1,6 @@
// ignore_for_file: use_build_context_synchronously // ignore_for_file: use_build_context_synchronously
import 'dart:async'; import 'dart:async';
import 'dart:io'; import 'dart:io';
import 'package:app_installer/app_installer.dart'; import 'package:app_installer/app_installer.dart';
import 'package:cross_connectivity/cross_connectivity.dart'; import 'package:cross_connectivity/cross_connectivity.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
@ -39,6 +38,7 @@ class HomeViewModel extends BaseViewModel {
List<PatchedApplication> patchedInstalledApps = []; List<PatchedApplication> patchedInstalledApps = [];
List<PatchedApplication> patchedUpdatableApps = []; List<PatchedApplication> patchedUpdatableApps = [];
String? _latestManagerVersion = ''; String? _latestManagerVersion = '';
File? downloadedApk;
Future<void> initialize(BuildContext context) async { Future<void> initialize(BuildContext context) async {
_latestManagerVersion = await _managerAPI.getLatestManagerVersion(); _latestManagerVersion = await _managerAPI.getLatestManagerVersion();
@ -162,14 +162,20 @@ class HomeViewModel extends BaseViewModel {
} }
Future<void> updateManager(BuildContext context) async { Future<void> updateManager(BuildContext context) async {
final ValueNotifier<bool> downloaded = ValueNotifier(false);
try { try {
_toast.showBottom('homeView.downloadingMessage'); _toast.showBottom('homeView.downloadingMessage');
showDialog( showDialog(
context: context, context: context,
builder: (context) => SimpleDialog( builder: (context) => ValueListenableBuilder(
valueListenable: downloaded,
builder: (context, value, child) {
return SimpleDialog(
contentPadding: const EdgeInsets.all(16.0), contentPadding: const EdgeInsets.all(16.0),
title: I18nText( title: I18nText(
'homeView.downloadingMessage', !value
? 'homeView.downloadingMessage'
: 'homeView.downloadedMessage',
child: Text( child: Text(
'', '',
style: TextStyle( style: TextStyle(
@ -200,6 +206,10 @@ class HomeViewModel extends BaseViewModel {
], ],
), ),
const SizedBox(height: 16.0), const SizedBox(height: 16.0),
if (!value)
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
StreamBuilder<double>( StreamBuilder<double>(
initialData: 0.0, initialData: 0.0,
stream: _revancedAPI.managerUpdateProgress.stream, stream: _revancedAPI.managerUpdateProgress.stream,
@ -225,11 +235,61 @@ class HomeViewModel extends BaseViewModel {
), ),
], ],
), ),
if (value)
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
I18nText(
'homeView.installUpdate',
child: Text(
'',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w500,
color: Theme.of(context).colorScheme.secondary,
),
),
),
const SizedBox(height: 16.0),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Align(
alignment: Alignment.centerRight,
child: CustomMaterialButton(
isFilled: false,
label: I18nText('cancelButton'),
onPressed: () {
Navigator.of(context).pop();
},
),
),
const SizedBox(width: 8.0),
Align(
alignment: Alignment.centerRight,
child: CustomMaterialButton(
label: I18nText('updateButton'),
onPressed: () async {
await AppInstaller.installApk(
downloadedApk!.path,);
},
),
),
], ],
), ),
],
),
],
),
],
);
},
),
); );
final File? managerApk = await downloadManager(); final File? managerApk = await downloadManager();
if (managerApk != null) { if (managerApk != null) {
downloaded.value = true;
downloadedApk = managerApk;
// await flutterLocalNotificationsPlugin.zonedSchedule( // await flutterLocalNotificationsPlugin.zonedSchedule(
// 0, // 0,
// FlutterI18n.translate( // FlutterI18n.translate(