Skip to content

Commit

Permalink
feat: check for update in app
Browse files Browse the repository at this point in the history
  • Loading branch information
Anxcye committed May 23, 2024
1 parent 4c83fd5 commit cad87fc
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 24 deletions.
4 changes: 3 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@
"settings_advanced_log_export_log": "Export Log",
"settings_advanced_clear_log_when_start": "Clear log when start",

"about_check_for_updates": "Check for updates"
"about_check_for_updates": "Check for updates",
"update_new_version": "New version: ",
"update_current_version": "Current version: "



Expand Down
8 changes: 5 additions & 3 deletions lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"appName": "安读",
"app_about": "关于安读",
"app_version": "版本",
"app_license": "许可",
"app_author": "作者",
"app_license": "开源许可",
"app_author": "开发者",

"navBar_bookshelf": "书架",
"navBar_statistics": "统计",
Expand Down Expand Up @@ -118,6 +118,8 @@
"settings_advanced_log_export_log": "导出日志",
"settings_advanced_clear_log_when_start": "启动时清空日志",

"about_check_for_updates": "检查更新"
"about_check_for_updates": "检查更新",
"update_new_version": "新版本:",
"update_current_version": "当前版本:"

}
2 changes: 2 additions & 0 deletions lib/l10n/localization_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,6 @@ extension LocalizationExtension on BuildContext {
String get settingsAdvancedLogExportLog => AppLocalizations.of(this)?.settings_advanced_log_export_log ?? '';
String get settingsAdvancedClearLogWhenStart => AppLocalizations.of(this)?.settings_advanced_clear_log_when_start ?? '';
String get aboutCheckForUpdates => AppLocalizations.of(this)?.about_check_for_updates ?? '';
String get updateNewVersion => AppLocalizations.of(this)?.update_new_version ?? '';
String get updateCurrentVersion => AppLocalizations.of(this)?.update_current_version ?? '';
}
22 changes: 16 additions & 6 deletions lib/utils/check_update.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ Future<void> checkUpdate(bool manualCheck) async {
if (manualCheck) {
AnxToast.show(context.commonFailed);
}
throw Exception('Failed to check for updates');
throw Exception('Update: Failed to check for updates $e');
}
AnxLog.info(response.toString());
String newVersion = response.data['tag_name'].toString().substring(1);
String currentVersion =
(await getAppVersion()).substring(0, newVersion.length);
AnxLog.info(newVersion);
AnxLog.info('Update: new version $newVersion');
if (newVersion != currentVersion) {
if (manualCheck) {
Navigator.of(context).pop();
Expand All @@ -42,7 +41,16 @@ Future<void> checkUpdate(bool manualCheck) async {
builder: (BuildContext context) {
return AlertDialog(
title: Text(context.commonNewVersion),
content: Text(response.data['body'].toString()),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(context.updateCurrentVersion + currentVersion),
Text(context.updateNewVersion + newVersion),
const Divider(),
Text(response.data['body'].toString()),
],
),
actions: <Widget>[
TextButton(
onPressed: () {
Expand All @@ -52,8 +60,10 @@ Future<void> checkUpdate(bool manualCheck) async {
),
TextButton(
onPressed: () {
launchUrl(Uri.parse(
'https://github.com/Anxcye/anx-reader/releases/latest'));
launchUrl(
Uri.parse(
'https://github.com/Anxcye/anx-reader/releases/latest'),
mode: LaunchMode.externalApplication);
},
child: Text(context.commonUpdate),
),
Expand Down
32 changes: 18 additions & 14 deletions lib/widgets/settings/about.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ class _AboutState extends State<About> {

// title: Text(context.appName),
content: ConstrainedBox(
constraints: const BoxConstraints(
maxWidth: 500,
minWidth: 300,
),
child: SizedBox(
width: MediaQuery.of(context).size.width * 0.8,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
constraints: const BoxConstraints(
maxWidth: 500,
minWidth: 300,
),
child: SizedBox(
width: MediaQuery.of(context).size.width * 0.8,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 0, 5),
child: Center(
Expand Down Expand Up @@ -94,7 +94,11 @@ class _AboutState extends State<About> {
ListTile(
title: Text(context.appAuthor),
onTap: () {
launchUrl(Uri.parse('https://github.com/Anxcye/anx-reader/graphs/contributors'));
launchUrl(
Uri.parse(
'https://github.com/Anxcye/anx-reader/graphs/contributors'),
mode: LaunchMode.externalApplication,
);
},
),
const Divider(),
Expand All @@ -111,10 +115,10 @@ class _AboutState extends State<About> {
mode: LaunchMode.externalApplication),
],
),
],
),
),
));
],
),
),
));
},
);
}
Expand Down

0 comments on commit cad87fc

Please sign in to comment.