From fdf72099b29f6de051f692f70073e4bdb20c88eb Mon Sep 17 00:00:00 2001 From: Bruno D'Luka <45696119+bdlukaa@users.noreply.github.com> Date: Fri, 11 Aug 2023 12:40:55 -0300 Subject: [PATCH] fix linux env; add "running on" label --- lib/l10n/app_en.arb | 8 +++++++- lib/main.dart | 2 +- lib/providers/update_provider.dart | 28 +++++++++++++++++++++------- lib/widgets/settings/settings.dart | 16 +++++++++++++++- lib/widgets/settings/update.dart | 8 ++++---- 5 files changed, 48 insertions(+), 14 deletions(-) diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index ce9c9677..d2d2ab2e 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -265,5 +265,11 @@ "downloadVersion": "Download", "learnMore": "Learn more", "failedToUpdate": "Failed to update", - "executableNotFound": "Executable not found" + "executableNotFound": "Executable not found", + "runningOn": "Running on {platform}", + "@runningOn": { + "placeholders": { + "platform": {} + } + } } diff --git a/lib/main.dart b/lib/main.dart index d7c29ef0..18cf9ab2 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -63,7 +63,7 @@ Future main(List args) async { // To create a splash screen effect while the dependencies are loading, we // can run the [SplashScreen] widget as the app. if (isDesktop) { - configureWindow(); + await configureWindow(); runApp(const SplashScreen()); } diff --git a/lib/providers/update_provider.dart b/lib/providers/update_provider.dart index 1a939bf7..da04e512 100644 --- a/lib/providers/update_provider.dart +++ b/lib/providers/update_provider.dart @@ -102,8 +102,10 @@ class UpdateManager extends ChangeNotifier { /// /// If false, the user is up to date with the latest version. bool get hasUpdateAvailable { + if (this.latestVersion == null) return false; + final currentVersion = Version.parse(packageInfo.version); - final latestVersion = Version.parse(this.latestVersion.version); + final latestVersion = Version.parse(this.latestVersion!.version); assert( latestVersion >= currentVersion, @@ -114,7 +116,9 @@ class UpdateManager extends ChangeNotifier { } List versions = []; - UpdateVersion get latestVersion => versions.last; + UpdateVersion? get latestVersion { + return versions.isEmpty ? null : versions.last; + } Future initialize() async { final data = await downloads.read() as Map; @@ -134,7 +138,7 @@ class UpdateManager extends ChangeNotifier { ]); if (hasUpdateAvailable && automaticDownloads) { - download(latestVersion.version); + download(latestVersion!.version); } } @@ -315,9 +319,9 @@ class UpdateManager extends ChangeNotifier { 'This should never be reached on unsupported platforms', ); - assert(latestVersion.version != packageInfo.version, 'Already up to date'); + assert(hasUpdateAvailable, 'Already up to date'); - final executable = executableFor(latestVersion.version); + final executable = executableFor(latestVersion!.version); assert(executable != null, 'Executable not found'); if (executable == null) { @@ -363,9 +367,19 @@ class UpdateManager extends ChangeNotifier { loading = true; notifyListeners(); + final response = await http.get(Uri.parse(appCastUrl)); + + if (response.statusCode != 200) { + debugPrint( + 'Failed to check for updates (${response.statusCode}): ${response.body}', + ); + loading = false; + notifyListeners(); + return; + } + final versions = []; - // Parse the versions from the server - final doc = XmlDocument.parse((await http.get(Uri.parse(appCastUrl))).body); + final doc = XmlDocument.parse(response.body); for (final item in doc.findAllElements('item')) { late String version; late String description; diff --git a/lib/widgets/settings/settings.dart b/lib/widgets/settings/settings.dart index 3d578fb8..fa2a8c17 100644 --- a/lib/widgets/settings/settings.dart +++ b/lib/widgets/settings/settings.dart @@ -31,6 +31,7 @@ import 'package:bluecherry_client/widgets/edit_server.dart'; import 'package:bluecherry_client/widgets/misc.dart'; import 'package:bluecherry_client/widgets/settings/update.dart'; import 'package:file_picker/file_picker.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:intl/intl.dart'; @@ -126,7 +127,20 @@ class _SettingsState extends State { }).toList()), if (update.isUpdatingSupported) ...[ divider, - SliverToBoxAdapter(child: SubHeader(loc.updates)), + SliverToBoxAdapter( + child: SubHeader( + loc.updates, + subtext: loc.runningOn(() { + if (Platform.isLinux) { + return 'Linux ${update.linuxEnvironment}'; + } else if (Platform.isWindows) { + return 'Windows'; + } + + return defaultTargetPlatform.name; + }()), + ), + ), const SliverToBoxAdapter(child: AppUpdateCard()), const SliverToBoxAdapter(child: AppUpdateOptions()), ], diff --git a/lib/widgets/settings/update.dart b/lib/widgets/settings/update.dart index b78fe852..fd9716b8 100644 --- a/lib/widgets/settings/update.dart +++ b/lib/widgets/settings/update.dart @@ -38,7 +38,7 @@ class AppUpdateCard extends StatelessWidget { final update = context.watch(); if (update.hasUpdateAvailable) { - final executable = update.executableFor(update.latestVersion.version); + final executable = update.executableFor(update.latestVersion!.version); return Card( margin: const EdgeInsetsDirectional.only( start: 10.0, @@ -64,7 +64,7 @@ class AppUpdateCard extends StatelessWidget { loc.newVersionAvailable, style: theme.textTheme.titleMedium, ), - Text(update.latestVersion.description), + Text(update.latestVersion!.description), ], ), ), @@ -72,7 +72,7 @@ class AppUpdateCard extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( - update.latestVersion.version, + update.latestVersion!.version, style: theme.textTheme.labelLarge, ), const SizedBox(height: 6.0), @@ -95,7 +95,7 @@ class AppUpdateCard extends StatelessWidget { else FilledButton( onPressed: () => update.download( - update.latestVersion.version, + update.latestVersion!.version, ), child: Text(loc.downloadVersion), ),