Added changelog dialog
This commit is contained in:
parent
00db49f3e8
commit
a96550863d
|
@ -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",
|
||||
|
|
|
@ -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<ScreenSettings> {
|
|||
String? updateUrl;
|
||||
String? latestVersion;
|
||||
String? currentVersion;
|
||||
String? updateChangeLog;
|
||||
Future<bool> updatesSupported([bool takeAction = false]) async {
|
||||
bool returnValue = true;
|
||||
var installerApps = [
|
||||
|
@ -110,14 +112,22 @@ class _ScreenSettingsState extends State<ScreenSettings> {
|
|||
"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<ScreenSettings> {
|
|||
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<ScreenSettings> {
|
|||
});
|
||||
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<ScreenSettings> {
|
|||
}
|
||||
|
||||
latestVersion = version;
|
||||
updateUrl = "$repoUrl/releases/tag/$latestVersion";
|
||||
updateStatus = "ok";
|
||||
|
||||
setState(() {
|
||||
|
@ -629,6 +640,7 @@ class _ScreenSettingsState extends State<ScreenSettings> {
|
|||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
HapticFeedback.selectionClick();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text(
|
||||
|
@ -636,6 +648,7 @@ class _ScreenSettingsState extends State<ScreenSettings> {
|
|||
.settingsImportChatsCancel)),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
HapticFeedback.selectionClick();
|
||||
FilePickerResult? result =
|
||||
await FilePicker.platform
|
||||
.pickFiles(
|
||||
|
@ -706,9 +719,52 @@ class _ScreenSettingsState extends State<ScreenSettings> {
|
|||
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;
|
||||
|
|
Loading…
Reference in New Issue