Skip to content

Commit

Permalink
fix: Routing glitch when using SSO on desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
krille-chan committed Nov 5, 2023
1 parent 9f0bcd5 commit 2d7301e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 29 deletions.
1 change: 1 addition & 0 deletions lib/pages/homeserver_picker/homeserver_app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
57 changes: 39 additions & 18 deletions lib/pages/homeserver_picker/homeserver_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
});
}
}
}
}

Expand Down
25 changes: 14 additions & 11 deletions lib/pages/homeserver_picker/homeserver_picker_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 2d7301e

Please sign in to comment.