Enable auto-updates
This commit is contained in:
parent
32605dc708
commit
244d4d969a
4 changed files with 55 additions and 39 deletions
|
@ -10,7 +10,9 @@ import 'package:ente_auth/events/signed_in_event.dart';
|
|||
import 'package:ente_auth/events/signed_out_event.dart';
|
||||
import "package:ente_auth/l10n/l10n.dart";
|
||||
import "package:ente_auth/onboarding/view/onboarding_page.dart";
|
||||
import 'package:ente_auth/services/update_service.dart';
|
||||
import 'package:ente_auth/ui/home_page.dart';
|
||||
import 'package:ente_auth/ui/settings/app_update_dialog.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import "package:flutter/material.dart";
|
||||
import "package:flutter_localizations/flutter_localizations.dart";
|
||||
|
@ -38,6 +40,21 @@ class _AppState extends State<App> {
|
|||
setState(() {});
|
||||
}
|
||||
});
|
||||
UpdateService.instance.shouldUpdate().then((shouldUpdate) {
|
||||
if (shouldUpdate) {
|
||||
Future.delayed(Duration.zero, () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AppUpdateDialog(
|
||||
UpdateService.instance.getLatestVersionInfo(),
|
||||
);
|
||||
},
|
||||
barrierColor: Colors.black.withOpacity(0.85),
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
super.initState();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import 'package:ente_auth/core/network.dart';
|
|||
import 'package:ente_auth/ente_theme_data.dart';
|
||||
import 'package:ente_auth/services/authenticator_service.dart';
|
||||
import 'package:ente_auth/services/billing_service.dart';
|
||||
import 'package:ente_auth/services/notification_service.dart';
|
||||
import 'package:ente_auth/services/update_service.dart';
|
||||
import 'package:ente_auth/services/user_remote_flag_service.dart';
|
||||
import 'package:ente_auth/services/user_service.dart';
|
||||
|
@ -30,6 +31,7 @@ Future<void> _runInForeground() async {
|
|||
return await _runWithLogs(() async {
|
||||
_logger.info("Starting app in foreground");
|
||||
await _init(false, via: 'mainMethod');
|
||||
UpdateService.instance.showUpdateNotification();
|
||||
runApp(
|
||||
AppLock(
|
||||
builder: (args) => const App(),
|
||||
|
@ -64,7 +66,8 @@ Future<void> _init(bool bool, {String via}) async {
|
|||
await Network.instance.init();
|
||||
await UserService.instance.init();
|
||||
await UserRemoteFlagService.instance.init();
|
||||
await UpdateService.instance.init();
|
||||
await AuthenticatorService.instance.init();
|
||||
await BillingService.instance.init();
|
||||
await NotificationService.instance.init();
|
||||
await UpdateService.instance.init();
|
||||
}
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:ente_auth/core/constants.dart';
|
||||
import 'package:ente_auth/core/network.dart';
|
||||
import 'package:ente_auth/services/notification_service.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
|
@ -55,33 +57,33 @@ class UpdateService {
|
|||
return _latestVersion;
|
||||
}
|
||||
|
||||
// Future<void> showUpdateNotification() async {
|
||||
// if (!isIndependent()) {
|
||||
// return;
|
||||
// }
|
||||
// final shouldUpdate = await this.shouldUpdate();
|
||||
// final lastNotificationShownTime =
|
||||
// _prefs.getInt(kUpdateAvailableShownTimeKey) ?? 0;
|
||||
// final now = DateTime.now().microsecondsSinceEpoch;
|
||||
// final hasBeen3DaysSinceLastNotification =
|
||||
// (now - lastNotificationShownTime) > (3 * microSecondsInDay);
|
||||
// if (shouldUpdate &&
|
||||
// hasBeen3DaysSinceLastNotification &&
|
||||
// _latestVersion.shouldNotify) {
|
||||
// NotificationService.instance.showNotification(
|
||||
// "update available",
|
||||
// "click to install our best version yet",
|
||||
// );
|
||||
// await _prefs.setInt(kUpdateAvailableShownTimeKey, now);
|
||||
// } else {
|
||||
// _logger.info("Debouncing notification");
|
||||
// }
|
||||
// }
|
||||
Future<void> showUpdateNotification() async {
|
||||
if (!isIndependent()) {
|
||||
return;
|
||||
}
|
||||
final shouldUpdate = await this.shouldUpdate();
|
||||
final lastNotificationShownTime =
|
||||
_prefs.getInt(kUpdateAvailableShownTimeKey) ?? 0;
|
||||
final now = DateTime.now().microsecondsSinceEpoch;
|
||||
final hasBeen3DaysSinceLastNotification =
|
||||
(now - lastNotificationShownTime) > (3 * microSecondsInDay);
|
||||
if (shouldUpdate &&
|
||||
hasBeen3DaysSinceLastNotification &&
|
||||
_latestVersion.shouldNotify) {
|
||||
NotificationService.instance.showNotification(
|
||||
"Update available",
|
||||
"Click to install our best version yet",
|
||||
);
|
||||
await _prefs.setInt(kUpdateAvailableShownTimeKey, now);
|
||||
} else {
|
||||
_logger.info("Debouncing notification");
|
||||
}
|
||||
}
|
||||
|
||||
Future<LatestVersionInfo> _getLatestVersionInfo() async {
|
||||
final response = await Network.instance
|
||||
.getDio()
|
||||
.get("https://ente.io/release-info/independent.json");
|
||||
.get("https://ente.io/release-info/auth-independent.json");
|
||||
return LatestVersionInfo.fromMap(response.data["latestVersion"]);
|
||||
}
|
||||
|
||||
|
@ -89,18 +91,7 @@ class UpdateService {
|
|||
if (Platform.isIOS) {
|
||||
return false;
|
||||
}
|
||||
if (!kDebugMode &&
|
||||
_packageInfo.packageName != "io.ente.auth.independent") {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool isIndependentFlavor() {
|
||||
if (Platform.isIOS) {
|
||||
return false;
|
||||
}
|
||||
return _packageInfo.packageName.startsWith("io.ente.auth.independent");
|
||||
return kDebugMode || _packageInfo.packageName.endsWith("independent");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
// @dart=2.9
|
||||
|
||||
// import 'package:open_file/open_file.dart';
|
||||
import 'package:ente_auth/core/configuration.dart';
|
||||
import 'package:ente_auth/core/network.dart';
|
||||
import 'package:ente_auth/ente_theme_data.dart';
|
||||
import 'package:ente_auth/services/update_service.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:open_file/open_file.dart';
|
||||
|
||||
class AppUpdateDialog extends StatefulWidget {
|
||||
final LatestVersionInfo latestVersionInfo;
|
||||
|
@ -25,7 +25,12 @@ class _AppUpdateDialogState extends State<AppUpdateDialog> {
|
|||
changelog.add(
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(8, 4, 0, 4),
|
||||
child: Text("- " + log, style: Theme.of(context).textTheme.caption),
|
||||
child: Text(
|
||||
"- " + log,
|
||||
style: Theme.of(context).textTheme.caption.copyWith(
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -152,7 +157,7 @@ class _ApkDownloaderDialogState extends State<ApkDownloaderDialog> {
|
|||
},
|
||||
);
|
||||
Navigator.of(context, rootNavigator: true).pop('dialog');
|
||||
// OpenFile.open(_saveUrl);
|
||||
OpenFile.open(_saveUrl);
|
||||
} catch (e) {
|
||||
Logger("ApkDownloader").severe(e);
|
||||
final AlertDialog alert = AlertDialog(
|
||||
|
|
Loading…
Add table
Reference in a new issue