feat: Add presetHomeserver config to enforce a homeserver for web

This commit is contained in:
Christian Kußowski 2026-02-22 11:14:45 +01:00
commit e9efce150e
No known key found for this signature in database
GPG key ID: E067ECD60F1A0652
11 changed files with 77 additions and 49 deletions

View file

@ -13,13 +13,17 @@ import 'package:fluffychat/widgets/layouts/login_scaffold.dart';
import 'package:fluffychat/widgets/matrix.dart';
class IntroPage extends StatelessWidget {
final bool isLoading;
final String? loggingInToHomeserver;
final bool isLoading, hasPresetHomeserver;
final String? loggingInToHomeserver, welcomeText;
final VoidCallback login;
const IntroPage({
required this.isLoading,
required this.loggingInToHomeserver,
super.key,
required this.hasPresetHomeserver,
required this.welcomeText,
required this.login,
});
@override
@ -119,7 +123,7 @@ class IntroPage extends StatelessWidget {
horizontal: 32.0,
),
child: SelectableLinkify(
text: L10n.of(context).appIntro,
text: welcomeText ?? L10n.of(context).appIntro,
textScaleFactor: MediaQuery.textScalerOf(
context,
).scale(1),
@ -138,41 +142,42 @@ class IntroPage extends StatelessWidget {
mainAxisSize: .min,
crossAxisAlignment: .stretch,
children: [
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor:
theme.colorScheme.secondary,
foregroundColor:
theme.colorScheme.onSecondary,
if (!hasPresetHomeserver)
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor:
theme.colorScheme.secondary,
foregroundColor:
theme.colorScheme.onSecondary,
),
onPressed: () => context.go(
'${GoRouterState.of(context).uri.path}/sign_up',
),
child: Text(
L10n.of(context).createNewAccount,
),
),
onPressed: () => context.go(
'${GoRouterState.of(context).uri.path}/sign_up',
),
child: Text(
L10n.of(context).createNewAccount,
),
),
SizedBox(height: 16),
ElevatedButton(
onPressed: () => context.go(
'${GoRouterState.of(context).uri.path}/sign_in',
),
onPressed: login,
child: Text(L10n.of(context).signIn),
),
TextButton(
onPressed: () async {
final client = await Matrix.of(
context,
).getLoginClient();
context.go(
'${GoRouterState.of(context).uri.path}/login',
extra: client,
);
},
child: Text(
L10n.of(context).loginWithMatrixId,
if (!hasPresetHomeserver)
TextButton(
onPressed: () async {
final client = await Matrix.of(
context,
).getLoginClient();
context.go(
'${GoRouterState.of(context).uri.path}/login',
extra: client,
);
},
child: Text(
L10n.of(context).loginWithMatrixId,
),
),
),
],
),
),

View file

@ -3,14 +3,18 @@ import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:matrix/matrix_api_lite/utils/logs.dart';
import 'package:matrix/msc_extensions/msc_2964_oidc_login_flow/msc_2964_oidc_login_flow.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:universal_html/universal_html.dart' as web;
import 'package:fluffychat/config/setting_keys.dart';
import 'package:fluffychat/pages/intro/intro_page.dart';
import 'package:fluffychat/pages/sign_in/view_model/model/public_homeserver_data.dart';
import 'package:fluffychat/utils/localized_exception_extension.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/oidc_session_json_extension.dart';
import 'package:fluffychat/utils/sign_in_flows/check_homeserver.dart';
import 'package:fluffychat/widgets/matrix.dart';
class IntroPagePresenter extends StatefulWidget {
@ -49,11 +53,13 @@ class _IntroPagePresenterState extends State<IntroPagePresenter> {
await store.remove(OidcSessionJsonExtension.storeKey);
await store.remove(OidcSessionJsonExtension.homeserverStoreKey);
if (!mounted) return;
if (homeserverUrl == null || session == null) {
setState(() {
isLoading = false;
});
return;
}
setState(() {
@ -87,11 +93,31 @@ class _IntroPagePresenterState extends State<IntroPagePresenter> {
}
}
void _login() {
final presetHomeserver = AppSettings.presetHomeserver.value;
if (presetHomeserver.isEmpty) {
context.go('${GoRouterState.of(context).uri.path}/sign_in');
return;
}
connectToHomeserverFlow(
PublicHomeserverData(name: presetHomeserver),
context,
(snapshot) {},
false,
);
}
@override
Widget build(BuildContext context) {
return IntroPage(
isLoading: isLoading,
loggingInToHomeserver: loggingInToHomeserver,
hasPresetHomeserver: AppSettings.presetHomeserver.value.isNotEmpty,
welcomeText: AppSettings.welcomeText.value.isEmpty
? null
: AppSettings.welcomeText.value,
login: _login,
);
}
}