diff --git a/filcnaplo/lib/helpers/update_helper.dart b/filcnaplo/lib/helpers/update_helper.dart index 96c26d7..bd88b58 100644 --- a/filcnaplo/lib/helpers/update_helper.dart +++ b/filcnaplo/lib/helpers/update_helper.dart @@ -7,24 +7,26 @@ import 'package:filcnaplo/helpers/storage_helper.dart'; import 'package:filcnaplo/models/release.dart'; import 'package:open_file/open_file.dart'; -enum UpdateState { prepare, downloading, installing } +enum UpdateState { none, preparing, downloading, installing } typedef UpdateCallback = Function(double progress, UpdateState state); // TODO: cleanup old apk files extension UpdateHelper on Release { Future install({UpdateCallback? updateCallback}) async { + updateCallback!(-1, UpdateState.preparing); + String downloads = await StorageHelper.downloadsPath(); File apk = File("$downloads/filcnaplo-${version}.apk"); if (!await apk.exists()) { - updateCallback!(-1, UpdateState.downloading); + updateCallback(-1, UpdateState.downloading); var bytes = await download(updateCallback: updateCallback); if (!await StorageHelper.write(apk.path, bytes)) throw "failed to write apk: permission denied"; } - updateCallback!(-1, UpdateState.installing); + updateCallback(-1, UpdateState.installing); var result = await OpenFile.open(apk.path); @@ -33,7 +35,7 @@ extension UpdateHelper on Release { throw result.message; } - updateCallback(-1, UpdateState.prepare); + updateCallback(-1, UpdateState.none); } Future download({UpdateCallback? updateCallback}) async { diff --git a/filcnaplo/lib/utils/format.dart b/filcnaplo/lib/utils/format.dart index 3a9878f..3ec11f6 100644 --- a/filcnaplo/lib/utils/format.dart +++ b/filcnaplo/lib/utils/format.dart @@ -33,13 +33,13 @@ extension StringFormatUtils on String { } extension DateFormatUtils on DateTime { - String format(BuildContext context, {bool timeOnly = false, bool weekday = false}) { + String format(BuildContext context, {bool timeOnly = false, bool forceToday = false, bool weekday = false}) { // Time only if (timeOnly) return DateFormat("HH:mm").format(this); DateTime now = DateTime.now(); if (now.year == this.year && now.month == this.month && now.day == this.day) { - if (this.hour == 0 && this.minute == 0 && this.second == 0) return "Today".i18n; + if (this.hour == 0 && this.minute == 0 && this.second == 0 || forceToday) return "Today".i18n; return DateFormat("HH:mm").format(this); } if (now.year == this.year && now.month == this.month && now.subtract(Duration(days: 1)).day == this.day) return "Yesterday".i18n;