Skip to content

Commit

Permalink
[gui] refactor update entry in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-toterman committed Aug 5, 2024
1 parent e636f8e commit 145e60c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/client/gui/lib/settings/general_settings.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'package:basics/basics.dart';
import 'package:flutter/material.dart' hide Switch;
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../dropdown.dart';
import '../notifications.dart';
import '../providers.dart';
import '../switch.dart';
import '../update_available.dart';
import 'autostart_notifiers.dart';

final onAppCloseProvider = guiSettingProvider(onAppCloseKey);
Expand All @@ -14,6 +16,7 @@ class GeneralSettings extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final update = ref.watch(updateProvider).valueOrNull ?? UpdateInfo();
final autostart = ref.watch(autostartProvider).valueOrNull ?? false;
final onAppClose = ref.watch(onAppCloseProvider);

Expand All @@ -23,6 +26,10 @@ class GeneralSettings extends ConsumerWidget {
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
const SizedBox(height: 20),
if (update.version.isNotBlank) ...[
UpdateAvailable(update),
const SizedBox(height: 20),
],
Switch(
label: 'Open the Multipass GUI on startup',
value: autostart,
Expand Down
39 changes: 39 additions & 0 deletions src/client/gui/lib/update_available.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,45 @@ final installUrl = Uri.parse('https://multipass.run/install');

Future<void> launchInstallUrl() => launchUrl(installUrl);

class UpdateAvailable extends StatelessWidget {
final UpdateInfo updateInfo;

const UpdateAvailable(this.updateInfo, {super.key});

@override
Widget build(BuildContext context) {
final icon = Container(
alignment: Alignment.center,
color: _color,
height: 40,
width: 40,
child: SvgPicture.asset('assets/multipass.svg', width: 25),
);

final text = Text(
'Multipass ${updateInfo.version} is available',
style: const TextStyle(fontSize: 16),
);

const button = TextButton(
onPressed: launchInstallUrl,
child: Text('Upgrade now'),
);

return Container(
color: const Color(0xffF7F7F7),
padding: const EdgeInsets.all(12),
child: Row(children: [
icon,
const SizedBox(width: 12),
text,
const Spacer(),
button,
]),
);
}
}

class UpdateAvailableNotification extends StatelessWidget {
final UpdateInfo updateInfo;

Expand Down

0 comments on commit 145e60c

Please sign in to comment.