Skip to content

Commit

Permalink
fix linux env; add "running on" label
Browse files Browse the repository at this point in the history
  • Loading branch information
bdlukaa committed Aug 11, 2023
1 parent b0c4778 commit fdf7209
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 14 deletions.
8 changes: 7 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
}
}
}
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Future<void> main(List<String> 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());
}

Expand Down
28 changes: 21 additions & 7 deletions lib/providers/update_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -114,7 +116,9 @@ class UpdateManager extends ChangeNotifier {
}

List<UpdateVersion> versions = [];
UpdateVersion get latestVersion => versions.last;
UpdateVersion? get latestVersion {
return versions.isEmpty ? null : versions.last;
}

Future<void> initialize() async {
final data = await downloads.read() as Map;
Expand All @@ -134,7 +138,7 @@ class UpdateManager extends ChangeNotifier {
]);

if (hasUpdateAvailable && automaticDownloads) {
download(latestVersion.version);
download(latestVersion!.version);
}
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 = <UpdateVersion>[];
// 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;
Expand Down
16 changes: 15 additions & 1 deletion lib/widgets/settings/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -126,7 +127,20 @@ class _SettingsState extends State<Settings> {
}).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()),
],
Expand Down
8 changes: 4 additions & 4 deletions lib/widgets/settings/update.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AppUpdateCard extends StatelessWidget {
final update = context.watch<UpdateManager>();

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,
Expand All @@ -64,15 +64,15 @@ class AppUpdateCard extends StatelessWidget {
loc.newVersionAvailable,
style: theme.textTheme.titleMedium,
),
Text(update.latestVersion.description),
Text(update.latestVersion!.description),
],
),
),
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
update.latestVersion.version,
update.latestVersion!.version,
style: theme.textTheme.labelLarge,
),
const SizedBox(height: 6.0),
Expand All @@ -95,7 +95,7 @@ class AppUpdateCard extends StatelessWidget {
else
FilledButton(
onPressed: () => update.download(
update.latestVersion.version,
update.latestVersion!.version,
),
child: Text(loc.downloadVersion),
),
Expand Down

0 comments on commit fdf7209

Please sign in to comment.