Add option to check for updates
This commit is contained in:
parent
4c2721af20
commit
1cba327147
3 changed files with 52 additions and 7 deletions
|
@ -14,6 +14,7 @@ import 'package:photos/services/collections_service.dart';
|
|||
import 'package:photos/services/memories_service.dart';
|
||||
import 'package:photos/services/notification_service.dart';
|
||||
import 'package:photos/services/sync_service.dart';
|
||||
import 'package:photos/services/update_service.dart';
|
||||
import 'package:photos/ui/app_lock.dart';
|
||||
import 'package:photos/ui/home_widget.dart';
|
||||
import 'package:photos/ui/lock_screen.dart';
|
||||
|
@ -122,6 +123,7 @@ Future<void> _init(bool isBackground) async {
|
|||
await NotificationService.instance.init();
|
||||
await Network.instance.init();
|
||||
await Configuration.instance.init();
|
||||
await UpdateService.instance.init();
|
||||
await BillingService.instance.init();
|
||||
await CollectionsService.instance.init();
|
||||
await FileUploader.instance.init(isBackground);
|
||||
|
|
|
@ -10,18 +10,19 @@ class UpdateService {
|
|||
static final UpdateService instance = UpdateService._privateConstructor();
|
||||
|
||||
LatestVersionInfo _latestVersion;
|
||||
PackageInfo _packageInfo;
|
||||
|
||||
Future<void> init() async {
|
||||
_packageInfo = await PackageInfo.fromPlatform();
|
||||
}
|
||||
|
||||
Future<bool> shouldUpdate() async {
|
||||
final platform = await PackageInfo.fromPlatform();
|
||||
Logger("UpdateService").info(platform.packageName);
|
||||
if (Platform.isIOS) {
|
||||
return false;
|
||||
}
|
||||
if (!kDebugMode && platform.packageName != "io.ente.photos.independent") {
|
||||
Logger("UpdateService").info(_packageInfo.packageName);
|
||||
if (!isIndependent()) {
|
||||
return false;
|
||||
}
|
||||
_latestVersion = await _getLatestVersionInfo();
|
||||
final currentVersionCode = int.parse(platform.buildNumber);
|
||||
final currentVersionCode = int.parse(_packageInfo.buildNumber);
|
||||
return currentVersionCode < _latestVersion.code;
|
||||
}
|
||||
|
||||
|
@ -35,6 +36,17 @@ class UpdateService {
|
|||
.get("https://static.ente.io/independent-release-info.json");
|
||||
return LatestVersionInfo.fromMap(response.data["latestVersion"]);
|
||||
}
|
||||
|
||||
bool isIndependent() {
|
||||
if (Platform.isIOS) {
|
||||
return false;
|
||||
}
|
||||
if (!kDebugMode &&
|
||||
_packageInfo.packageName != "io.ente.photos.independent") {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class LatestVersionInfo {
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:photos/services/update_service.dart';
|
||||
import 'package:photos/ui/app_update_dialog.dart';
|
||||
import 'package:photos/ui/settings/settings_section_title.dart';
|
||||
import 'package:photos/ui/settings/settings_text_item.dart';
|
||||
import 'package:photos/ui/web_page.dart';
|
||||
import 'package:photos/utils/dialog_util.dart';
|
||||
import 'package:photos/utils/toast_util.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class InfoSectionWidget extends StatelessWidget {
|
||||
|
@ -62,6 +66,33 @@ class InfoSectionWidget extends StatelessWidget {
|
|||
child:
|
||||
SettingsTextItem(text: "source code", icon: Icons.navigate_next),
|
||||
),
|
||||
UpdateService.instance.isIndependent()
|
||||
? Divider(height: 4)
|
||||
: Container(),
|
||||
UpdateService.instance.isIndependent()
|
||||
? GestureDetector(
|
||||
behavior: HitTestBehavior.translucent,
|
||||
onTap: () async {
|
||||
final dialog = createProgressDialog(context, "checking...");
|
||||
await dialog.show();
|
||||
final shouldUpdate =
|
||||
await UpdateService.instance.shouldUpdate();
|
||||
await dialog.hide();
|
||||
if (shouldUpdate) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AppUpdateDialog(
|
||||
UpdateService.instance.getLatestVersionInfo());
|
||||
});
|
||||
} else {
|
||||
showToast("you are on the latest version");
|
||||
}
|
||||
},
|
||||
child: SettingsTextItem(
|
||||
text: "check for updates", icon: Icons.navigate_next),
|
||||
)
|
||||
: Container(),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue