Improved updater

This commit is contained in:
Juan Gilsanz Polo 2023-04-15 02:52:23 +02:00
parent 67b41b3382
commit f63ac9eb66
3 changed files with 21 additions and 25 deletions

View file

@ -13,9 +13,9 @@ class UpdateAvailable {
class UpdateAvailableData { class UpdateAvailableData {
String currentVersion; String currentVersion;
String? newVersion; String? newVersion;
final String announcement; final String? announcement;
final String announcementUrl; final String? announcementUrl;
final bool canAutoupdate; final bool? canAutoupdate;
final bool disabled; final bool disabled;
String? changelog; String? changelog;
bool? updateAvailable; bool? updateAvailable;

View file

@ -533,28 +533,24 @@ class ServersProvider with ChangeNotifier {
setUpdateAvailableLoadStatus(LoadStatus.loading, true); setUpdateAvailableLoadStatus(LoadStatus.loading, true);
final result = await checkServerUpdates(server: server); final result = await checkServerUpdates(server: server);
if (result['result'] == 'success') { if (result['result'] == 'success') {
try { UpdateAvailableData data = UpdateAvailableData.fromJson(result['data']);
UpdateAvailableData data = UpdateAvailableData.fromJson(result['data']); final gitHubResult = await getUpdateChangelog(server: server, releaseTag: data.newVersion ?? data.currentVersion);
final gitHubResult = await getUpdateChangelog(server: server, releaseTag: data.newVersion ?? data.currentVersion); if (gitHubResult['result'] == 'success') {
if (gitHubResult['result'] == 'success') { data.changelog = gitHubResult['body'];
data.changelog = gitHubResult['body'];
}
data.updateAvailable = data.newVersion != null
? data.newVersion!.contains('b')
? compareBetaVersions(
currentVersion: data.currentVersion.replaceAll('v', ''),
newVersion: data.newVersion!.replaceAll('v', ''),
)
: compareVersions(
currentVersion: data.currentVersion.replaceAll('v', ''),
newVersion: data.newVersion!.replaceAll('v', ''),
)
: false;
setUpdateAvailableData(data);
setUpdateAvailableLoadStatus(LoadStatus.loaded, true);
} catch (_) {
// AUTO UPDATE NOT AVAILABLE //
} }
data.updateAvailable = data.newVersion != null
? data.newVersion!.contains('b')
? compareBetaVersions(
currentVersion: data.currentVersion.replaceAll('v', ''),
newVersion: data.newVersion!.replaceAll('v', ''),
)
: compareVersions(
currentVersion: data.currentVersion.replaceAll('v', ''),
newVersion: data.newVersion!.replaceAll('v', ''),
)
: false;
setUpdateAvailableData(data);
setUpdateAvailableLoadStatus(LoadStatus.loaded, true);
} }
else { else {
setUpdateAvailableLoadStatus(LoadStatus.error, true); setUpdateAvailableLoadStatus(LoadStatus.error, true);

View file

@ -127,7 +127,7 @@ class Settings extends StatelessWidget {
) )
}, },
), ),
if (serversProvider.updateAvailable.data != null && serversProvider.updateAvailable.data!.canAutoupdate == true) CustomListTile( if (serversProvider.updateAvailable.data != null) CustomListTile(
icon: Icons.system_update_rounded, icon: Icons.system_update_rounded,
title: AppLocalizations.of(context)!.updates, title: AppLocalizations.of(context)!.updates,
subtitle: AppLocalizations.of(context)!.updatesDescription, subtitle: AppLocalizations.of(context)!.updatesDescription,