feat: Add presetHomeserver config to enforce a homeserver for web
This commit is contained in:
parent
df847abbeb
commit
e9efce150e
11 changed files with 77 additions and 49 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
{
|
{
|
||||||
"applicationName": "FluffyChat",
|
"applicationName": "FluffyChat",
|
||||||
"defaultHomeserver": "matrix.org",
|
"defaultHomeserver": "matrix.org",
|
||||||
|
"presetHomeserver": "",
|
||||||
|
"welcomeText": "",
|
||||||
"privacyUrl": "https://github.com/krille-chan/fluffychat/blob/main/PRIVACY.md",
|
"privacyUrl": "https://github.com/krille-chan/fluffychat/blob/main/PRIVACY.md",
|
||||||
"audioRecordingNumChannels": 1,
|
"audioRecordingNumChannels": 1,
|
||||||
"audioRecordingAutoGain": true,
|
"audioRecordingAutoGain": true,
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,9 @@ enum AppSettings<T> {
|
||||||
// colorSchemeSeed stored as ARGB int
|
// colorSchemeSeed stored as ARGB int
|
||||||
colorSchemeSeedInt<int>('chat.fluffy.color_scheme_seed', 0xFF5625BA),
|
colorSchemeSeedInt<int>('chat.fluffy.color_scheme_seed', 0xFF5625BA),
|
||||||
emojiSuggestionLocale<String>('emoji_suggestion_locale', ''),
|
emojiSuggestionLocale<String>('emoji_suggestion_locale', ''),
|
||||||
enableSoftLogout<bool>('chat.fluffy.enable_soft_logout', false);
|
enableSoftLogout<bool>('chat.fluffy.enable_soft_logout', false),
|
||||||
|
presetHomeserver<String>('chat.fluffy.preset_homeserver', ''),
|
||||||
|
welcomeText<String>('chat.fluffy.welcome_text', '');
|
||||||
|
|
||||||
final String key;
|
final String key;
|
||||||
final T defaultValue;
|
final T defaultValue;
|
||||||
|
|
|
||||||
|
|
@ -13,13 +13,17 @@ import 'package:fluffychat/widgets/layouts/login_scaffold.dart';
|
||||||
import 'package:fluffychat/widgets/matrix.dart';
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
|
|
||||||
class IntroPage extends StatelessWidget {
|
class IntroPage extends StatelessWidget {
|
||||||
final bool isLoading;
|
final bool isLoading, hasPresetHomeserver;
|
||||||
final String? loggingInToHomeserver;
|
final String? loggingInToHomeserver, welcomeText;
|
||||||
|
final VoidCallback login;
|
||||||
|
|
||||||
const IntroPage({
|
const IntroPage({
|
||||||
required this.isLoading,
|
required this.isLoading,
|
||||||
required this.loggingInToHomeserver,
|
required this.loggingInToHomeserver,
|
||||||
super.key,
|
super.key,
|
||||||
|
required this.hasPresetHomeserver,
|
||||||
|
required this.welcomeText,
|
||||||
|
required this.login,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -119,7 +123,7 @@ class IntroPage extends StatelessWidget {
|
||||||
horizontal: 32.0,
|
horizontal: 32.0,
|
||||||
),
|
),
|
||||||
child: SelectableLinkify(
|
child: SelectableLinkify(
|
||||||
text: L10n.of(context).appIntro,
|
text: welcomeText ?? L10n.of(context).appIntro,
|
||||||
textScaleFactor: MediaQuery.textScalerOf(
|
textScaleFactor: MediaQuery.textScalerOf(
|
||||||
context,
|
context,
|
||||||
).scale(1),
|
).scale(1),
|
||||||
|
|
@ -138,41 +142,42 @@ class IntroPage extends StatelessWidget {
|
||||||
mainAxisSize: .min,
|
mainAxisSize: .min,
|
||||||
crossAxisAlignment: .stretch,
|
crossAxisAlignment: .stretch,
|
||||||
children: [
|
children: [
|
||||||
ElevatedButton(
|
if (!hasPresetHomeserver)
|
||||||
style: ElevatedButton.styleFrom(
|
ElevatedButton(
|
||||||
backgroundColor:
|
style: ElevatedButton.styleFrom(
|
||||||
theme.colorScheme.secondary,
|
backgroundColor:
|
||||||
foregroundColor:
|
theme.colorScheme.secondary,
|
||||||
theme.colorScheme.onSecondary,
|
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),
|
SizedBox(height: 16),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () => context.go(
|
onPressed: login,
|
||||||
'${GoRouterState.of(context).uri.path}/sign_in',
|
|
||||||
),
|
|
||||||
child: Text(L10n.of(context).signIn),
|
child: Text(L10n.of(context).signIn),
|
||||||
),
|
),
|
||||||
TextButton(
|
|
||||||
onPressed: () async {
|
if (!hasPresetHomeserver)
|
||||||
final client = await Matrix.of(
|
TextButton(
|
||||||
context,
|
onPressed: () async {
|
||||||
).getLoginClient();
|
final client = await Matrix.of(
|
||||||
context.go(
|
context,
|
||||||
'${GoRouterState.of(context).uri.path}/login',
|
).getLoginClient();
|
||||||
extra: client,
|
context.go(
|
||||||
);
|
'${GoRouterState.of(context).uri.path}/login',
|
||||||
},
|
extra: client,
|
||||||
child: Text(
|
);
|
||||||
L10n.of(context).loginWithMatrixId,
|
},
|
||||||
|
child: Text(
|
||||||
|
L10n.of(context).loginWithMatrixId,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,18 @@ import 'dart:convert';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.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/matrix_api_lite/utils/logs.dart';
|
||||||
import 'package:matrix/msc_extensions/msc_2964_oidc_login_flow/msc_2964_oidc_login_flow.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:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:universal_html/universal_html.dart' as web;
|
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/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/localized_exception_extension.dart';
|
||||||
import 'package:fluffychat/utils/matrix_sdk_extensions/oidc_session_json_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';
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
|
|
||||||
class IntroPagePresenter extends StatefulWidget {
|
class IntroPagePresenter extends StatefulWidget {
|
||||||
|
|
@ -49,11 +53,13 @@ class _IntroPagePresenterState extends State<IntroPagePresenter> {
|
||||||
|
|
||||||
await store.remove(OidcSessionJsonExtension.storeKey);
|
await store.remove(OidcSessionJsonExtension.storeKey);
|
||||||
await store.remove(OidcSessionJsonExtension.homeserverStoreKey);
|
await store.remove(OidcSessionJsonExtension.homeserverStoreKey);
|
||||||
|
if (!mounted) return;
|
||||||
|
|
||||||
if (homeserverUrl == null || session == null) {
|
if (homeserverUrl == null || session == null) {
|
||||||
setState(() {
|
setState(() {
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setState(() {
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return IntroPage(
|
return IntroPage(
|
||||||
isLoading: isLoading,
|
isLoading: isLoading,
|
||||||
loggingInToHomeserver: loggingInToHomeserver,
|
loggingInToHomeserver: loggingInToHomeserver,
|
||||||
|
hasPresetHomeserver: AppSettings.presetHomeserver.value.isNotEmpty,
|
||||||
|
welcomeText: AppSettings.welcomeText.value.isEmpty
|
||||||
|
? null
|
||||||
|
: AppSettings.welcomeText.value,
|
||||||
|
login: _login,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,10 @@ import 'package:url_launcher/url_launcher_string.dart';
|
||||||
import 'package:fluffychat/config/app_config.dart';
|
import 'package:fluffychat/config/app_config.dart';
|
||||||
import 'package:fluffychat/config/themes.dart';
|
import 'package:fluffychat/config/themes.dart';
|
||||||
import 'package:fluffychat/l10n/l10n.dart';
|
import 'package:fluffychat/l10n/l10n.dart';
|
||||||
import 'package:fluffychat/pages/sign_in/view_model/flows/check_homeserver.dart';
|
|
||||||
import 'package:fluffychat/pages/sign_in/view_model/model/public_homeserver_data.dart';
|
import 'package:fluffychat/pages/sign_in/view_model/model/public_homeserver_data.dart';
|
||||||
import 'package:fluffychat/pages/sign_in/view_model/sign_in_view_model.dart';
|
import 'package:fluffychat/pages/sign_in/view_model/sign_in_view_model.dart';
|
||||||
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
||||||
|
import 'package:fluffychat/utils/sign_in_flows/check_homeserver.dart';
|
||||||
import 'package:fluffychat/widgets/layouts/login_scaffold.dart';
|
import 'package:fluffychat/widgets/layouts/login_scaffold.dart';
|
||||||
import 'package:fluffychat/widgets/matrix.dart';
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
import 'package:fluffychat/widgets/view_model_builder.dart';
|
import 'package:fluffychat/widgets/view_model_builder.dart';
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import 'package:matrix/matrix_api_lite/utils/logs.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/config/app_config.dart';
|
import 'package:fluffychat/config/app_config.dart';
|
||||||
import 'package:fluffychat/config/setting_keys.dart';
|
import 'package:fluffychat/config/setting_keys.dart';
|
||||||
import 'package:fluffychat/pages/sign_in/view_model/flows/sort_homeservers.dart';
|
import 'package:fluffychat/pages/sign_in/utils/sort_homeservers.dart';
|
||||||
import 'package:fluffychat/pages/sign_in/view_model/model/public_homeserver_data.dart';
|
import 'package:fluffychat/pages/sign_in/view_model/model/public_homeserver_data.dart';
|
||||||
import 'package:fluffychat/pages/sign_in/view_model/sign_in_state.dart';
|
import 'package:fluffychat/pages/sign_in/view_model/sign_in_state.dart';
|
||||||
import 'package:fluffychat/widgets/matrix.dart';
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@ import 'package:go_router/go_router.dart';
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
import 'package:url_launcher/url_launcher_string.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/l10n/l10n.dart';
|
import 'package:fluffychat/l10n/l10n.dart';
|
||||||
import 'package:fluffychat/pages/sign_in/view_model/flows/oidc_login.dart';
|
|
||||||
import 'package:fluffychat/pages/sign_in/view_model/flows/sso_login.dart';
|
|
||||||
import 'package:fluffychat/pages/sign_in/view_model/model/public_homeserver_data.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/localized_exception_extension.dart';
|
||||||
import 'package:fluffychat/utils/platform_infos.dart';
|
import 'package:fluffychat/utils/platform_infos.dart';
|
||||||
|
import 'package:fluffychat/utils/sign_in_flows/oidc_login.dart';
|
||||||
|
import 'package:fluffychat/utils/sign_in_flows/sso_login.dart';
|
||||||
import 'package:fluffychat/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
|
import 'package:fluffychat/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
|
||||||
import 'package:fluffychat/widgets/matrix.dart';
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
|
|
||||||
|
|
@ -40,10 +40,7 @@ PODS:
|
||||||
- FlutterMacOS
|
- FlutterMacOS
|
||||||
- package_info_plus (0.0.1):
|
- package_info_plus (0.0.1):
|
||||||
- FlutterMacOS
|
- FlutterMacOS
|
||||||
- path_provider_foundation (0.0.1):
|
- record_macos (1.2.0):
|
||||||
- Flutter
|
|
||||||
- FlutterMacOS
|
|
||||||
- record_macos (1.1.0):
|
|
||||||
- FlutterMacOS
|
- FlutterMacOS
|
||||||
- screen_retriever_macos (0.0.1):
|
- screen_retriever_macos (0.0.1):
|
||||||
- FlutterMacOS
|
- FlutterMacOS
|
||||||
|
|
@ -98,7 +95,6 @@ DEPENDENCIES:
|
||||||
- geolocator_apple (from `Flutter/ephemeral/.symlinks/plugins/geolocator_apple/darwin`)
|
- geolocator_apple (from `Flutter/ephemeral/.symlinks/plugins/geolocator_apple/darwin`)
|
||||||
- just_audio (from `Flutter/ephemeral/.symlinks/plugins/just_audio/darwin`)
|
- just_audio (from `Flutter/ephemeral/.symlinks/plugins/just_audio/darwin`)
|
||||||
- package_info_plus (from `Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos`)
|
- package_info_plus (from `Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos`)
|
||||||
- path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`)
|
|
||||||
- record_macos (from `Flutter/ephemeral/.symlinks/plugins/record_macos/macos`)
|
- record_macos (from `Flutter/ephemeral/.symlinks/plugins/record_macos/macos`)
|
||||||
- screen_retriever_macos (from `Flutter/ephemeral/.symlinks/plugins/screen_retriever_macos/macos`)
|
- screen_retriever_macos (from `Flutter/ephemeral/.symlinks/plugins/screen_retriever_macos/macos`)
|
||||||
- share_plus (from `Flutter/ephemeral/.symlinks/plugins/share_plus/macos`)
|
- share_plus (from `Flutter/ephemeral/.symlinks/plugins/share_plus/macos`)
|
||||||
|
|
@ -156,8 +152,6 @@ EXTERNAL SOURCES:
|
||||||
:path: Flutter/ephemeral/.symlinks/plugins/just_audio/darwin
|
:path: Flutter/ephemeral/.symlinks/plugins/just_audio/darwin
|
||||||
package_info_plus:
|
package_info_plus:
|
||||||
:path: Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos
|
:path: Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos
|
||||||
path_provider_foundation:
|
|
||||||
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin
|
|
||||||
record_macos:
|
record_macos:
|
||||||
:path: Flutter/ephemeral/.symlinks/plugins/record_macos/macos
|
:path: Flutter/ephemeral/.symlinks/plugins/record_macos/macos
|
||||||
screen_retriever_macos:
|
screen_retriever_macos:
|
||||||
|
|
@ -203,16 +197,15 @@ SPEC CHECKSUMS:
|
||||||
geolocator_apple: ab36aa0e8b7d7a2d7639b3b4e48308394e8cef5e
|
geolocator_apple: ab36aa0e8b7d7a2d7639b3b4e48308394e8cef5e
|
||||||
just_audio: 4e391f57b79cad2b0674030a00453ca5ce817eed
|
just_audio: 4e391f57b79cad2b0674030a00453ca5ce817eed
|
||||||
package_info_plus: f0052d280d17aa382b932f399edf32507174e870
|
package_info_plus: f0052d280d17aa382b932f399edf32507174e870
|
||||||
path_provider_foundation: 080d55be775b7414fd5a5ef3ac137b97b097e564
|
record_macos: 7f227161b93c49e7e34fe681c5891c8622c8cc8b
|
||||||
record_macos: 43194b6c06ca6f8fa132e2acea72b202b92a0f5b
|
|
||||||
screen_retriever_macos: 452e51764a9e1cdb74b3c541238795849f21557f
|
screen_retriever_macos: 452e51764a9e1cdb74b3c541238795849f21557f
|
||||||
share_plus: 510bf0af1a42cd602274b4629920c9649c52f4cc
|
share_plus: 510bf0af1a42cd602274b4629920c9649c52f4cc
|
||||||
shared_preferences_foundation: 9e1978ff2562383bd5676f64ec4e9aa8fa06a6f7
|
shared_preferences_foundation: 7036424c3d8ec98dfe75ff1667cb0cd531ec82bb
|
||||||
SQLCipher: eb79c64049cb002b4e9fcb30edb7979bf4706dfc
|
SQLCipher: eb79c64049cb002b4e9fcb30edb7979bf4706dfc
|
||||||
sqlcipher_flutter_libs: 01ead34db27ae5e49987cae46c8a34199eb22cfe
|
sqlcipher_flutter_libs: 01ead34db27ae5e49987cae46c8a34199eb22cfe
|
||||||
url_launcher_macos: 0fba8ddabfc33ce0a9afe7c5fef5aab3d8d2d673
|
url_launcher_macos: f87a979182d112f911de6820aefddaf56ee9fbfd
|
||||||
video_compress: 752b161da855df2492dd1a8fa899743cc8fe9534
|
video_compress: 752b161da855df2492dd1a8fa899743cc8fe9534
|
||||||
video_player_avfoundation: 2cef49524dd1f16c5300b9cd6efd9611ce03639b
|
video_player_avfoundation: dd410b52df6d2466a42d28550e33e4146928280a
|
||||||
wakelock_plus: 917609be14d812ddd9e9528876538b2263aaa03b
|
wakelock_plus: 917609be14d812ddd9e9528876538b2263aaa03b
|
||||||
webcrypto: a5f5eb3e375cf0a99993e207e97cdcab5c94ce2e
|
webcrypto: a5f5eb3e375cf0a99993e207e97cdcab5c94ce2e
|
||||||
WebRTC-SDK: 40d4f5ba05cadff14e4db5614aec402a633f007e
|
WebRTC-SDK: 40d4f5ba05cadff14e4db5614aec402a633f007e
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue