Bugfix - update checking on app load was broken

This commit is contained in:
Imran Remtulla
2022-08-28 18:17:03 -04:00
parent 285da7545b
commit c2a7e4a0d2
2 changed files with 21 additions and 10 deletions

View File

@@ -17,10 +17,10 @@ const String currentReleaseTag =
void bgTaskCallback() { void bgTaskCallback() {
// Background update checking process // Background update checking process
Workmanager().executeTask((task, taskName) async { Workmanager().executeTask((task, taskName) async {
var appsProvider = AppsProvider(bg: true);
var notificationsProvider = NotificationsProvider(); var notificationsProvider = NotificationsProvider();
await notificationsProvider.notify(checkingUpdatesNotification); await notificationsProvider.notify(checkingUpdatesNotification);
try { try {
var appsProvider = AppsProvider();
await notificationsProvider await notificationsProvider
.cancel(ErrorCheckingUpdatesNotification('').id); .cancel(ErrorCheckingUpdatesNotification('').id);
await appsProvider.loadApps(); await appsProvider.loadApps();
@@ -52,7 +52,11 @@ void main() async {
); );
runApp(MultiProvider( runApp(MultiProvider(
providers: [ providers: [
ChangeNotifierProvider(create: (context) => AppsProvider()), ChangeNotifierProvider(
create: (context) => AppsProvider(
shouldLoadApps: true,
shouldCheckUpdatesAfterLoad: true,
shouldDeleteAPKs: true)),
ChangeNotifierProvider(create: (context) => SettingsProvider()), ChangeNotifierProvider(create: (context) => SettingsProvider()),
Provider(create: (context) => NotificationsProvider()) Provider(create: (context) => NotificationsProvider())
], ],
@@ -71,12 +75,7 @@ class MyApp extends StatelessWidget {
AppsProvider appsProvider = context.read<AppsProvider>(); AppsProvider appsProvider = context.read<AppsProvider>();
if (settingsProvider.prefs == null) { if (settingsProvider.prefs == null) {
settingsProvider.initializeSettings().then((value) { settingsProvider.initializeSettings();
// Delete past downloads and check for updates every time the app is launched
// Only runs once as the settings are only initialized once (so not on every build)
appsProvider.deleteSavedAPKs();
appsProvider.checkUpdates();
});
} else { } else {
// Register the background update task according to the user's setting // Register the background update task according to the user's setting
Workmanager().registerPeriodicTask('bg-update-check', 'bg-update-check', Workmanager().registerPeriodicTask('bg-update-check', 'bg-update-check',

View File

@@ -39,14 +39,26 @@ class AppsProvider with ChangeNotifier {
late Stream<FGBGType> foregroundStream; late Stream<FGBGType> foregroundStream;
late StreamSubscription<FGBGType> foregroundSubscription; late StreamSubscription<FGBGType> foregroundSubscription;
AppsProvider({bool bg = false}) { AppsProvider(
{bool shouldLoadApps = false,
bool shouldCheckUpdatesAfterLoad = false,
bool shouldDeleteAPKs = false}) {
// Subscribe to changes in the app foreground status // Subscribe to changes in the app foreground status
foregroundStream = FGBGEvents.stream.asBroadcastStream(); foregroundStream = FGBGEvents.stream.asBroadcastStream();
foregroundSubscription = foregroundStream.listen((event) async { foregroundSubscription = foregroundStream.listen((event) async {
isForeground = event == FGBGType.foreground; isForeground = event == FGBGType.foreground;
if (isForeground) await loadApps(); if (isForeground) await loadApps();
}); });
loadApps(); if (shouldDeleteAPKs) {
deleteSavedAPKs();
}
if (shouldLoadApps) {
loadApps().then((_) {
if (shouldCheckUpdatesAfterLoad) {
checkUpdates();
}
});
}
} }
Future<ApkFile> downloadApp(String apkUrl, String appId) async { Future<ApkFile> downloadApp(String apkUrl, String appId) async {