From a96550863dcb366a82d95a7f655bd34c081b369a Mon Sep 17 00:00:00 2001 From: JHubi1 Date: Wed, 5 Jun 2024 20:42:37 +0200 Subject: [PATCH] Added changelog dialog --- lib/l10n/app_en.arb | 29 +++++++++++++- lib/screen_settings.dart | 84 +++++++++++++++++++++++++++++++++------- 2 files changed, 97 insertions(+), 16 deletions(-) diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 047a262..8c87e74 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -343,16 +343,41 @@ } } }, - "settingsUpdateRateLimit": "API rate limit exceeded. Not able to check for updates", + "settingsUpdateRateLimit": "Can't check, API rate limit exceeded", "@settingsUpdateRateLimit": { "description": "Text displayed when the API rate limit is exceeded", "context": "Visible in the settings view" }, - "settingsUpdateIssue": "An issue occurred while checking for updates. Click to retry", + "settingsUpdateIssue": "An issue occurred", "@settingsUpdateIssue": { "description": "Text displayed when an issue occurs while checking for updates", "context": "Visible in the settings view" }, + "settingsUpdateDialogTitle": "New version available", + "@settingsUpdateDialogTitle": { + "description": "Title of the update dialog", + "context": "Visible in the settings view" + }, + "settingsUpdateDialogDescription": "A new version of Ollama is available. Do you want to download and install it now?", + "@settingsUpdateDialogDescription": { + "description": "Description of the update dialog", + "context": "Visible in the settings view" + }, + "settingsUpdateChangeLog": "Change Log", + "@settingsUpdateChangeLog": { + "description": "Text displayed as description for change log button", + "context": "Visible in the settings view" + }, + "settingsUpdateDialogUpdate": "Update", + "@settingsUpdateDialogUpdate": { + "description": "Text displayed for update button, should be capitalized", + "context": "Visible in the settings view" + }, + "settingsUpdateDialogCancel": "Cancel", + "@settingsUpdateDialogCancel": { + "description": "Text displayed for cancel button, should be capitalized", + "context": "Visible in the settings view" + }, "settingsCheckForUpdates": "Check for update on settings open", "@settingsCheckForUpdates": { "description": "Text displayed as description for check for updates toggle", diff --git a/lib/screen_settings.dart b/lib/screen_settings.dart index 32574ce..f9d3d5e 100644 --- a/lib/screen_settings.dart +++ b/lib/screen_settings.dart @@ -19,6 +19,7 @@ import 'package:intl/intl.dart'; import 'package:install_referrer/install_referrer.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:version/version.dart'; +import 'package:flutter_markdown/flutter_markdown.dart'; class ScreenSettings extends StatefulWidget { const ScreenSettings({super.key}); @@ -99,6 +100,7 @@ class _ScreenSettingsState extends State { String? updateUrl; String? latestVersion; String? currentVersion; + String? updateChangeLog; Future updatesSupported([bool takeAction = false]) async { bool returnValue = true; var installerApps = [ @@ -110,14 +112,22 @@ class _ScreenSettingsState extends State { "com.machiav3lli.fdroid", "nya.kitsunyan.foxydroid" ]; - if ((await InstallReferrer.referrer != - InstallationAppReferrer.androidManually) && - !(installerApps - .contains((await InstallReferrer.app).packageName ?? ""))) { - returnValue = false; - } - if (!repoUrl.startsWith("https://github.com")) { - returnValue = false; + if (!(Platform.isWindows || Platform.isLinux || Platform.isMacOS)) { + if ((await InstallReferrer.referrer != + InstallationAppReferrer.androidManually) && + !(installerApps + .contains((await InstallReferrer.app).packageName ?? ""))) { + returnValue = false; + if (await InstallReferrer.referrer == + InstallationAppReferrer.androidDebug || + await InstallReferrer.referrer == + InstallationAppReferrer.iosDebug) { + returnValue = true; + } + } + if (!repoUrl.startsWith("https://github.com")) { + returnValue = false; + } } if (!returnValue && takeAction) { @@ -152,7 +162,7 @@ class _ScreenSettingsState extends State { try { var request = await http .get(Uri.parse( - "https://api.github.com/repos/${repo[3]}/${repo[4]}/tags")) + "https://api.github.com/repos/${repo[3]}/${repo[4]}/releases")) .timeout(const Duration(seconds: 5)); if (request.statusCode == 403) { setState(() { @@ -161,7 +171,9 @@ class _ScreenSettingsState extends State { }); return; } - version = jsonDecode(request.body)[0]["name"]; + version = jsonDecode(request.body)[0]["tag_name"]; + updateChangeLog = jsonDecode(request.body)[0]["body"]; + updateUrl = jsonDecode(request.body)[0]["html_url"]; } catch (_) { setState(() { updateStatus = "error"; @@ -171,7 +183,6 @@ class _ScreenSettingsState extends State { } latestVersion = version; - updateUrl = "$repoUrl/releases/tag/$latestVersion"; updateStatus = "ok"; setState(() { @@ -629,6 +640,7 @@ class _ScreenSettingsState extends State { actions: [ TextButton( onPressed: () { + HapticFeedback.selectionClick(); Navigator.of(context).pop(); }, child: Text( @@ -636,6 +648,7 @@ class _ScreenSettingsState extends State { .settingsImportChatsCancel)), TextButton( onPressed: () async { + HapticFeedback.selectionClick(); FilePickerResult? result = await FilePicker.platform .pickFiles( @@ -706,9 +719,52 @@ class _ScreenSettingsState extends State { if ((Version.parse(latestVersion ?? "1.0.0") > Version.parse(currentVersion ?? "2.0.0")) && (updateStatus == "ok")) { - launchUrl( - mode: LaunchMode.inAppBrowserView, - Uri.parse(updateUrl!)); + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: Text( + AppLocalizations.of(context)! + .settingsUpdateDialogTitle), + content: SizedBox( + width: 200, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Text(AppLocalizations.of(context)! + .settingsUpdateDialogDescription), + title( + AppLocalizations.of(context)! + .settingsUpdateChangeLog), + MarkdownBody( + data: updateChangeLog ?? + "Nothing"), + ], + ), + ), + actions: [ + TextButton( + onPressed: () { + HapticFeedback.selectionClick(); + Navigator.of(context).pop(); + }, + child: Text(AppLocalizations.of( + context)! + .settingsUpdateDialogCancel)), + TextButton( + onPressed: () { + HapticFeedback.selectionClick(); + Navigator.of(context).pop(); + launchUrl( + mode: LaunchMode + .inAppBrowserView, + Uri.parse(updateUrl!)); + }, + child: Text(AppLocalizations.of( + context)! + .settingsUpdateDialogUpdate)) + ]); + }); } else { checkUpdate(); return;