Added changelog dialog

This commit is contained in:
JHubi1 2024-06-05 20:42:37 +02:00
parent 00db49f3e8
commit a96550863d
No known key found for this signature in database
GPG Key ID: 7BF82570CBBBD050
2 changed files with 97 additions and 16 deletions

View File

@ -343,16 +343,41 @@
} }
} }
}, },
"settingsUpdateRateLimit": "API rate limit exceeded. Not able to check for updates", "settingsUpdateRateLimit": "Can't check, API rate limit exceeded",
"@settingsUpdateRateLimit": { "@settingsUpdateRateLimit": {
"description": "Text displayed when the API rate limit is exceeded", "description": "Text displayed when the API rate limit is exceeded",
"context": "Visible in the settings view" "context": "Visible in the settings view"
}, },
"settingsUpdateIssue": "An issue occurred while checking for updates. Click to retry", "settingsUpdateIssue": "An issue occurred",
"@settingsUpdateIssue": { "@settingsUpdateIssue": {
"description": "Text displayed when an issue occurs while checking for updates", "description": "Text displayed when an issue occurs while checking for updates",
"context": "Visible in the settings view" "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": "Check for update on settings open",
"@settingsCheckForUpdates": { "@settingsCheckForUpdates": {
"description": "Text displayed as description for check for updates toggle", "description": "Text displayed as description for check for updates toggle",

View File

@ -19,6 +19,7 @@ import 'package:intl/intl.dart';
import 'package:install_referrer/install_referrer.dart'; import 'package:install_referrer/install_referrer.dart';
import 'package:package_info_plus/package_info_plus.dart'; import 'package:package_info_plus/package_info_plus.dart';
import 'package:version/version.dart'; import 'package:version/version.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
class ScreenSettings extends StatefulWidget { class ScreenSettings extends StatefulWidget {
const ScreenSettings({super.key}); const ScreenSettings({super.key});
@ -99,6 +100,7 @@ class _ScreenSettingsState extends State<ScreenSettings> {
String? updateUrl; String? updateUrl;
String? latestVersion; String? latestVersion;
String? currentVersion; String? currentVersion;
String? updateChangeLog;
Future<bool> updatesSupported([bool takeAction = false]) async { Future<bool> updatesSupported([bool takeAction = false]) async {
bool returnValue = true; bool returnValue = true;
var installerApps = [ var installerApps = [
@ -110,14 +112,22 @@ class _ScreenSettingsState extends State<ScreenSettings> {
"com.machiav3lli.fdroid", "com.machiav3lli.fdroid",
"nya.kitsunyan.foxydroid" "nya.kitsunyan.foxydroid"
]; ];
if ((await InstallReferrer.referrer != if (!(Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
InstallationAppReferrer.androidManually) && if ((await InstallReferrer.referrer !=
!(installerApps InstallationAppReferrer.androidManually) &&
.contains((await InstallReferrer.app).packageName ?? ""))) { !(installerApps
returnValue = false; .contains((await InstallReferrer.app).packageName ?? ""))) {
} returnValue = false;
if (!repoUrl.startsWith("https://github.com")) { if (await InstallReferrer.referrer ==
returnValue = false; InstallationAppReferrer.androidDebug ||
await InstallReferrer.referrer ==
InstallationAppReferrer.iosDebug) {
returnValue = true;
}
}
if (!repoUrl.startsWith("https://github.com")) {
returnValue = false;
}
} }
if (!returnValue && takeAction) { if (!returnValue && takeAction) {
@ -152,7 +162,7 @@ class _ScreenSettingsState extends State<ScreenSettings> {
try { try {
var request = await http var request = await http
.get(Uri.parse( .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)); .timeout(const Duration(seconds: 5));
if (request.statusCode == 403) { if (request.statusCode == 403) {
setState(() { setState(() {
@ -161,7 +171,9 @@ class _ScreenSettingsState extends State<ScreenSettings> {
}); });
return; 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 (_) { } catch (_) {
setState(() { setState(() {
updateStatus = "error"; updateStatus = "error";
@ -171,7 +183,6 @@ class _ScreenSettingsState extends State<ScreenSettings> {
} }
latestVersion = version; latestVersion = version;
updateUrl = "$repoUrl/releases/tag/$latestVersion";
updateStatus = "ok"; updateStatus = "ok";
setState(() { setState(() {
@ -629,6 +640,7 @@ class _ScreenSettingsState extends State<ScreenSettings> {
actions: [ actions: [
TextButton( TextButton(
onPressed: () { onPressed: () {
HapticFeedback.selectionClick();
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
child: Text( child: Text(
@ -636,6 +648,7 @@ class _ScreenSettingsState extends State<ScreenSettings> {
.settingsImportChatsCancel)), .settingsImportChatsCancel)),
TextButton( TextButton(
onPressed: () async { onPressed: () async {
HapticFeedback.selectionClick();
FilePickerResult? result = FilePickerResult? result =
await FilePicker.platform await FilePicker.platform
.pickFiles( .pickFiles(
@ -706,9 +719,52 @@ class _ScreenSettingsState extends State<ScreenSettings> {
if ((Version.parse(latestVersion ?? "1.0.0") > if ((Version.parse(latestVersion ?? "1.0.0") >
Version.parse(currentVersion ?? "2.0.0")) && Version.parse(currentVersion ?? "2.0.0")) &&
(updateStatus == "ok")) { (updateStatus == "ok")) {
launchUrl( showDialog(
mode: LaunchMode.inAppBrowserView, context: context,
Uri.parse(updateUrl!)); 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 { } else {
checkUpdate(); checkUpdate();
return; return;