feat: Open account manage url when using MAS

This commit is contained in:
krille-chan 2024-11-02 10:51:57 +01:00
commit be7a7fb671
No known key found for this signature in database
4 changed files with 171 additions and 144 deletions

View file

@ -2793,5 +2793,6 @@
"welcomeText": "Hey Hey 👋 This is FluffyChat. You can sign in to any homeserver, which is compatible with https://matrix.org. And then chat with anyone. It's a huge decentralized messaging network!", "welcomeText": "Hey Hey 👋 This is FluffyChat. You can sign in to any homeserver, which is compatible with https://matrix.org. And then chat with anyone. It's a huge decentralized messaging network!",
"blur": "Blur:", "blur": "Blur:",
"opacity": "Opacity:", "opacity": "Opacity:",
"setWallpaper": "Set wallpaper" "setWallpaper": "Set wallpaper",
"manageAccount": "Manage account"
} }

View file

@ -160,6 +160,7 @@ class HomeserverPickerController extends State<HomeserverPicker> {
final result = await FlutterWebAuth2.authenticate( final result = await FlutterWebAuth2.authenticate(
url: url.toString(), url: url.toString(),
callbackUrlScheme: urlScheme, callbackUrlScheme: urlScheme,
options: FlutterWebAuth2Options(useWebview: !isDefaultPlatform),
); );
final token = Uri.parse(result).queryParameters['loginToken']; final token = Uri.parse(result).queryParameters['loginToken'];
if (token?.isEmpty ?? false) return; if (token?.isEmpty ?? false) return;

View file

@ -201,6 +201,13 @@ class SettingsController extends State<Settings> {
checkBootstrap(); checkBootstrap();
} }
Future<String?> getOidcAccountManageUrl() async {
final wellKnown = await Matrix.of(context).client.getWellknown();
return wellKnown.additionalProperties
.tryGetMap<String, Object?>('org.matrix.msc2965.authentication')
?.tryGet<String>('account');
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final client = Matrix.of(context).client; final client = Matrix.of(context).client;

View file

@ -32,154 +32,172 @@ class SettingsView extends StatelessWidget {
), ),
body: ListTileTheme( body: ListTileTheme(
iconColor: theme.colorScheme.onSurface, iconColor: theme.colorScheme.onSurface,
child: ListView( child: FutureBuilder(
key: const Key('SettingsListViewContent'), future: controller.getOidcAccountManageUrl(),
children: <Widget>[ builder: (context, snapshot) {
FutureBuilder<Profile>( final accountManageUrl = snapshot.data;
future: controller.profileFuture, return ListView(
builder: (context, snapshot) { key: const Key('SettingsListViewContent'),
final profile = snapshot.data; children: <Widget>[
final mxid = FutureBuilder<Profile>(
Matrix.of(context).client.userID ?? L10n.of(context).user; future: controller.profileFuture,
final displayname = builder: (context, snapshot) {
profile?.displayName ?? mxid.localpart ?? mxid; final profile = snapshot.data;
return Row( final mxid = Matrix.of(context).client.userID ??
children: [ L10n.of(context).user;
Padding( final displayname =
padding: const EdgeInsets.all(32.0), profile?.displayName ?? mxid.localpart ?? mxid;
child: Stack( return Row(
children: [ children: [
Avatar( Padding(
mxContent: profile?.avatarUrl, padding: const EdgeInsets.all(32.0),
name: displayname, child: Stack(
size: Avatar.defaultSize * 2.5, children: [
), Avatar(
if (profile != null) mxContent: profile?.avatarUrl,
Positioned( name: displayname,
bottom: 0, size: Avatar.defaultSize * 2.5,
right: 0,
child: FloatingActionButton.small(
elevation: 2,
onPressed: controller.setAvatarAction,
heroTag: null,
child: const Icon(Icons.camera_alt_outlined),
), ),
), if (profile != null)
], Positioned(
), bottom: 0,
), right: 0,
Expanded( child: FloatingActionButton.small(
child: Column( elevation: 2,
mainAxisAlignment: MainAxisAlignment.center, onPressed: controller.setAvatarAction,
crossAxisAlignment: CrossAxisAlignment.start, heroTag: null,
children: [ child:
TextButton.icon( const Icon(Icons.camera_alt_outlined),
onPressed: controller.setDisplaynameAction, ),
icon: const Icon( ),
Icons.edit_outlined, ],
size: 16, ),
), ),
style: TextButton.styleFrom( Expanded(
foregroundColor: theme.colorScheme.onSurface, child: Column(
), mainAxisAlignment: MainAxisAlignment.center,
label: Text( crossAxisAlignment: CrossAxisAlignment.start,
displayname, children: [
maxLines: 1, TextButton.icon(
overflow: TextOverflow.ellipsis, onPressed: controller.setDisplaynameAction,
style: const TextStyle( icon: const Icon(
fontSize: 18, Icons.edit_outlined,
size: 16,
),
style: TextButton.styleFrom(
foregroundColor: theme.colorScheme.onSurface,
),
label: Text(
displayname,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 18,
),
),
), ),
), TextButton.icon(
onPressed: () =>
FluffyShare.share(mxid, context),
icon: const Icon(
Icons.copy_outlined,
size: 14,
),
style: TextButton.styleFrom(
foregroundColor: theme.colorScheme.secondary,
),
label: Text(
mxid,
maxLines: 1,
overflow: TextOverflow.ellipsis,
// style: const TextStyle(fontSize: 12),
),
),
],
), ),
TextButton.icon( ),
onPressed: () => FluffyShare.share(mxid, context), ],
icon: const Icon( );
Icons.copy_outlined, },
size: 14, ),
), if (accountManageUrl != null)
style: TextButton.styleFrom( ListTile(
foregroundColor: theme.colorScheme.secondary, leading: const Icon(Icons.account_circle_outlined),
), title: Text(L10n.of(context).manageAccount),
label: Text( trailing: const Icon(Icons.open_in_new_outlined),
mxid, onTap: () => launchUrlString(
maxLines: 1, accountManageUrl,
overflow: TextOverflow.ellipsis, mode: LaunchMode.inAppBrowserView,
// style: const TextStyle(fontSize: 12),
),
),
],
),
), ),
], ),
); Divider(color: theme.dividerColor),
}, if (showChatBackupBanner == null)
), ListTile(
Divider(color: theme.dividerColor), leading: const Icon(Icons.backup_outlined),
if (showChatBackupBanner == null) title: Text(L10n.of(context).chatBackup),
ListTile( trailing: const CircularProgressIndicator.adaptive(),
leading: const Icon(Icons.backup_outlined), )
title: Text(L10n.of(context).chatBackup), else
trailing: const CircularProgressIndicator.adaptive(), SwitchListTile.adaptive(
) controlAffinity: ListTileControlAffinity.trailing,
else value: controller.showChatBackupBanner == false,
SwitchListTile.adaptive( secondary: const Icon(Icons.backup_outlined),
controlAffinity: ListTileControlAffinity.trailing, title: Text(L10n.of(context).chatBackup),
value: controller.showChatBackupBanner == false, onChanged: controller.firstRunBootstrapAction,
secondary: const Icon(Icons.backup_outlined), ),
title: Text(L10n.of(context).chatBackup), Divider(
onChanged: controller.firstRunBootstrapAction, color: theme.dividerColor,
), ),
Divider( ListTile(
color: theme.dividerColor, leading: const Icon(Icons.format_paint_outlined),
), title: Text(L10n.of(context).changeTheme),
ListTile( onTap: () => context.go('/rooms/settings/style'),
leading: const Icon(Icons.format_paint_outlined), ),
title: Text(L10n.of(context).changeTheme), ListTile(
onTap: () => context.go('/rooms/settings/style'), leading: const Icon(Icons.notifications_outlined),
), title: Text(L10n.of(context).notifications),
ListTile( onTap: () => context.go('/rooms/settings/notifications'),
leading: const Icon(Icons.notifications_outlined), ),
title: Text(L10n.of(context).notifications), ListTile(
onTap: () => context.go('/rooms/settings/notifications'), leading: const Icon(Icons.devices_outlined),
), title: Text(L10n.of(context).devices),
ListTile( onTap: () => context.go('/rooms/settings/devices'),
leading: const Icon(Icons.devices_outlined), ),
title: Text(L10n.of(context).devices), ListTile(
onTap: () => context.go('/rooms/settings/devices'), leading: const Icon(Icons.forum_outlined),
), title: Text(L10n.of(context).chat),
ListTile( onTap: () => context.go('/rooms/settings/chat'),
leading: const Icon(Icons.forum_outlined), ),
title: Text(L10n.of(context).chat), ListTile(
onTap: () => context.go('/rooms/settings/chat'), leading: const Icon(Icons.shield_outlined),
), title: Text(L10n.of(context).security),
ListTile( onTap: () => context.go('/rooms/settings/security'),
leading: const Icon(Icons.shield_outlined), ),
title: Text(L10n.of(context).security), Divider(color: theme.dividerColor),
onTap: () => context.go('/rooms/settings/security'), ListTile(
), leading: const Icon(Icons.help_outline_outlined),
Divider(color: theme.dividerColor), title: Text(L10n.of(context).help),
ListTile( onTap: () => launchUrlString(AppConfig.supportUrl),
leading: const Icon(Icons.help_outline_outlined), ),
title: Text(L10n.of(context).help), ListTile(
onTap: () => launchUrlString(AppConfig.supportUrl), leading: const Icon(Icons.shield_sharp),
), title: Text(L10n.of(context).privacy),
ListTile( onTap: () => launchUrlString(AppConfig.privacyUrl),
leading: const Icon(Icons.shield_sharp), ),
title: Text(L10n.of(context).privacy), ListTile(
onTap: () => launchUrlString(AppConfig.privacyUrl), leading: const Icon(Icons.info_outline_rounded),
), title: Text(L10n.of(context).about),
ListTile( onTap: () => PlatformInfos.showDialog(context),
leading: const Icon(Icons.info_outline_rounded), ),
title: Text(L10n.of(context).about), Divider(color: theme.dividerColor),
onTap: () => PlatformInfos.showDialog(context), ListTile(
), leading: const Icon(Icons.logout_outlined),
Divider(color: theme.dividerColor), title: Text(L10n.of(context).logout),
ListTile( onTap: controller.logoutAction,
leading: const Icon(Icons.logout_outlined), ),
title: Text(L10n.of(context).logout), ],
onTap: controller.logoutAction, );
), },
],
), ),
), ),
); );