fix: Routing glitch when using SSO on desktop

This commit is contained in:
krille-chan 2023-11-05 10:24:59 +01:00
parent 9f0bcd5523
commit 2d7301ea50
No known key found for this signature in database
3 changed files with 54 additions and 29 deletions

View file

@ -50,6 +50,7 @@ class HomeserverAppBar extends StatelessWidget {
controller.checkHomeserverAction();
},
textFieldConfiguration: TextFieldConfiguration(
enabled: !controller.isLoggingIn,
controller: controller.homeserverController,
decoration: InputDecoration(
prefixIcon: Navigator.of(context).canPop()

View file

@ -8,7 +8,6 @@ import 'package:collection/collection.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_web_auth_2/flutter_web_auth_2.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:go_router/go_router.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:matrix/matrix.dart';
@ -33,6 +32,8 @@ class HomeserverPicker extends StatefulWidget {
class HomeserverPickerController extends State<HomeserverPicker> {
bool isLoading = false;
bool isLoggingIn = false;
final TextEditingController homeserverController = TextEditingController(
text: AppConfig.defaultHomeserver,
);
@ -135,14 +136,27 @@ class HomeserverPickerController extends State<HomeserverPicker> {
final token = Uri.parse(result).queryParameters['loginToken'];
if (token?.isEmpty ?? false) return;
await showFutureLoadingDialog(
context: context,
future: () => Matrix.of(context).getLoginClient().login(
setState(() {
error = null;
isLoading = isLoggingIn = true;
});
try {
await Matrix.of(context).getLoginClient().login(
LoginType.mLoginToken,
token: token,
initialDeviceDisplayName: PlatformInfos.clientName,
),
);
);
} catch (e) {
setState(() {
error = e.toLocalizedString(context);
});
} finally {
if (mounted) {
setState(() {
isLoading = isLoggingIn = false;
});
}
}
}
List<IdentityProvider>? get identityProviders {
@ -181,18 +195,25 @@ class HomeserverPickerController extends State<HomeserverPicker> {
);
final file = picked?.files.firstOrNull;
if (file == null) return;
await showFutureLoadingDialog(
context: context,
future: () async {
try {
final client = Matrix.of(context).getLoginClient();
await client.importDump(String.fromCharCodes(file.bytes!));
Matrix.of(context).initMatrix();
} catch (e, s) {
Logs().e('Future error:', e, s);
}
},
);
setState(() {
error = null;
isLoading = isLoggingIn = true;
});
try {
final client = Matrix.of(context).getLoginClient();
await client.importDump(String.fromCharCodes(file.bytes!));
Matrix.of(context).initMatrix();
} catch (e) {
setState(() {
error = e.toLocalizedString(context);
});
} finally {
if (mounted) {
setState(() {
isLoading = isLoggingIn = false;
});
}
}
}
}

View file

@ -57,15 +57,6 @@ class HomeserverPickerView extends StatelessWidget {
? const Center(child: CircularProgressIndicator.adaptive())
: ListView(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: FluffyThemes.isColumnMode(context)
? Image.asset(
'assets/info-logo.png',
height: 96,
)
: Image.asset('assets/banner_transparent.png'),
),
const SizedBox(height: 12),
if (errorText != null) ...[
const Center(
@ -97,8 +88,18 @@ class HomeserverPickerView extends StatelessWidget {
),
),
),
const SizedBox(height: 12),
],
const SizedBox(height: 36),
] else
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 8.0),
child: FluffyThemes.isColumnMode(context)
? Image.asset(
'assets/info-logo.png',
height: 96,
)
: Image.asset('assets/banner_transparent.png'),
),
if (identityProviders != null) ...[
...identityProviders.map(
(provider) => _LoginButton(
@ -143,6 +144,8 @@ class HomeserverPickerView extends StatelessWidget {
style: TextButton.styleFrom(
padding:
const EdgeInsets.symmetric(vertical: 12),
foregroundColor:
Theme.of(context).colorScheme.secondary,
),
onPressed: controller.restoreBackup,
child: Text(