Skip to content

Commit

Permalink
design: Add snackbar with link to changelog on new version
Browse files Browse the repository at this point in the history
  • Loading branch information
krille-chan committed Jul 31, 2024
1 parent 21e7c3f commit e5bbb75
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 6 deletions.
10 changes: 9 additions & 1 deletion assets/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2746,5 +2746,13 @@
"changeTheCanonicalRoomAlias": "Change the main public chat address",
"sendRoomNotifications": "Send a @room notifications",
"changeTheDescriptionOfTheGroup": "Change the description of the chat",
"chatPermissionsDescription": "Define which power level is necessary for certain actions in this chat. The power levels 0, 50 and 100 are usually representing users, moderators and admins, but any gradation is possible."
"chatPermissionsDescription": "Define which power level is necessary for certain actions in this chat. The power levels 0, 50 and 100 are usually representing users, moderators and admins, but any gradation is possible.",
"updateInstalled": "🎉 Update {version} installed!",
"@updateInstalled": {
"type": "text",
"placeholders": {
"version": {}
}
},
"changelog": "Changelog"
}
2 changes: 2 additions & 0 deletions lib/config/app_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ abstract class AppConfig {
'https://github.com/krille-chan/fluffychat';
static const String supportUrl =
'https://github.com/krille-chan/fluffychat/issues';
static const String changelogUrl =
'https://github.com/krille-chan/fluffychat/blob/main/CHANGELOG.md';
static final Uri newIssueUrl = Uri(
scheme: 'https',
host: 'github.com',
Expand Down
3 changes: 0 additions & 3 deletions lib/config/themes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ abstract class FluffyThemes {
? Typography.material2018().black.merge(fallbackTextTheme)
: Typography.material2018().white.merge(fallbackTextTheme)
: null,
snackBarTheme: const SnackBarThemeData(
behavior: SnackBarBehavior.floating,
),
dividerColor: brightness == Brightness.light
? Colors.blueGrey.shade50
: Colors.blueGrey.shade900,
Expand Down
2 changes: 2 additions & 0 deletions lib/pages/chat_list/chat_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import 'package:fluffychat/pages/chat_list/chat_list_view.dart';
import 'package:fluffychat/utils/localized_exception_extension.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/utils/show_update_snackbar.dart';
import 'package:fluffychat/widgets/avatar.dart';
import '../../../utils/account_bundles.dart';
import '../../config/setting_keys.dart';
Expand Down Expand Up @@ -511,6 +512,7 @@ class ChatListController extends State<ChatList>
searchServer =
Matrix.of(context).store.getString(_serverStoreNamespace);
Matrix.of(context).backgroundPush?.setupPush();
UpdateNotifier.showUpdateSnackBar(context);
}

// Workaround for system UI overlay style not applied on app start
Expand Down
6 changes: 4 additions & 2 deletions lib/pages/chat_list/client_chooser_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ class ClientChooserButton extends StatelessWidget {
],
),
),
PopupMenuItem(
// Currently disabled because of:
// https://github.com/matrix-org/matrix-react-sdk/pull/12286
/*PopupMenuItem(
value: SettingsAction.archive,
child: Row(
children: [
Expand All @@ -77,7 +79,7 @@ class ClientChooserButton extends StatelessWidget {
Text(L10n.of(context)!.archive),
],
),
),
),*/
PopupMenuItem(
value: SettingsAction.settings,
child: Row(
Expand Down
52 changes: 52 additions & 0 deletions lib/utils/show_update_snackbar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'package:flutter/material.dart';

import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_launcher/url_launcher_string.dart';

import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/utils/platform_infos.dart';

abstract class UpdateNotifier {
static const String versionStoreKey = 'last_known_version';

static void showUpdateSnackBar(BuildContext context) async {
final scaffoldMessenger = ScaffoldMessenger.of(context);
final currentVersion = await PlatformInfos.getVersion();
final store = await SharedPreferences.getInstance();
final storedVersion = store.getString(versionStoreKey);

if (currentVersion != storedVersion) {
if (storedVersion != null) {
ScaffoldFeatureController? controller;
controller = scaffoldMessenger.showSnackBar(
SnackBar(
duration: const Duration(seconds: 30),
content: Row(
children: [
IconButton(
icon: Icon(
Icons.close_outlined,
size: 20,
color: Theme.of(context).colorScheme.onPrimary,
),
onPressed: () => controller?.close(),
),
Expanded(
child: Text(
L10n.of(context)!.updateInstalled(currentVersion),
),
),
],
),
action: SnackBarAction(
label: L10n.of(context)!.changelog,
onPressed: () => launchUrlString(AppConfig.changelogUrl),
),
),
);
}
await store.setString(versionStoreKey, currentVersion);
}
}
}

0 comments on commit e5bbb75

Please sign in to comment.