feat: implement session dump
Signed-off-by: TheOneWithTheBraid <the-one@with-the-braid.cf>
This commit is contained in:
parent
ec74524234
commit
56ba2341f4
10 changed files with 203 additions and 5 deletions
|
|
@ -1,7 +1,13 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:file_picker_cross/file_picker_cross.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:matrix_homeserver_recommendations/matrix_homeserver_recommendations.dart';
|
||||
import 'package:vrouter/vrouter.dart';
|
||||
|
|
@ -12,6 +18,9 @@ import 'package:fluffychat/pages/homeserver_picker/homeserver_picker_view.dart';
|
|||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import '../../utils/localized_exception_extension.dart';
|
||||
|
||||
import 'package:fluffychat/utils/tor_stub.dart'
|
||||
if (dart.library.html) 'package:tor_detector_web/tor_detector_web.dart';
|
||||
|
||||
class HomeserverPicker extends StatefulWidget {
|
||||
const HomeserverPicker({Key? key}) : super(key: key);
|
||||
|
||||
|
|
@ -33,6 +42,26 @@ class HomeserverPickerController extends State<HomeserverPicker> {
|
|||
AppConfig.allowOtherHomeservers && benchmarkResults == null;
|
||||
String searchTerm = '';
|
||||
|
||||
bool isTorBrowser = false;
|
||||
|
||||
Future<void> _checkTorBrowser() async {
|
||||
if (!kIsWeb) return;
|
||||
|
||||
Hive.openBox('test').then((value) => null).catchError(
|
||||
(e, s) async {
|
||||
await showOkAlertDialog(
|
||||
context: context,
|
||||
title: L10n.of(context)!.indexedDbErrorTitle,
|
||||
message: L10n.of(context)!.indexedDbErrorLong,
|
||||
onWillPop: () async => false);
|
||||
_checkTorBrowser();
|
||||
},
|
||||
);
|
||||
|
||||
final isTor = await TorBrowserDetector.isTorBrowser;
|
||||
setState(() => isTorBrowser = isTor);
|
||||
}
|
||||
|
||||
void _updateFocus() {
|
||||
if (benchmarkResults == null) _loadHomeserverList();
|
||||
if (homeserverFocusNode.hasFocus) {
|
||||
|
|
@ -139,6 +168,7 @@ class HomeserverPickerController extends State<HomeserverPicker> {
|
|||
@override
|
||||
void initState() {
|
||||
homeserverFocusNode.addListener(_updateFocus);
|
||||
_checkTorBrowser();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
|
|
@ -147,4 +177,20 @@ class HomeserverPickerController extends State<HomeserverPicker> {
|
|||
Matrix.of(context).navigatorContext = context;
|
||||
return HomeserverPickerView(this);
|
||||
}
|
||||
|
||||
Future<void> restoreBackup() async {
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () async {
|
||||
try {
|
||||
final file = await FilePickerCross.importFromStorage(
|
||||
fileExtension: '.fluffybackup');
|
||||
final client = Matrix.of(context).getLoginClient();
|
||||
await client.importDump(file.toString());
|
||||
Matrix.of(context).initMatrix();
|
||||
} catch (e, s) {
|
||||
Logs().e('Future error:', e, s);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,29 @@ class HomeserverPickerView extends StatelessWidget {
|
|||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
// display a prominent banner to import session for TOR browser
|
||||
// users. This feature is just some UX sugar as TOR users are
|
||||
// usually forced to logout as TOR browser is non-persistent
|
||||
AnimatedContainer(
|
||||
height: controller.isTorBrowser ? 64 : 0,
|
||||
duration: const Duration(milliseconds: 300),
|
||||
clipBehavior: Clip.hardEdge,
|
||||
curve: Curves.bounceInOut,
|
||||
decoration: const BoxDecoration(),
|
||||
child: Material(
|
||||
clipBehavior: Clip.hardEdge,
|
||||
borderRadius:
|
||||
const BorderRadius.vertical(bottom: Radius.circular(8)),
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.vpn_key),
|
||||
title: Text(L10n.of(context)!.hydrateTor),
|
||||
subtitle: Text(L10n.of(context)!.hydrateTorLong),
|
||||
trailing: const Icon(Icons.chevron_right_outlined),
|
||||
onTap: controller.restoreBackup,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: [
|
||||
|
|
@ -140,6 +163,30 @@ class HomeserverPickerView extends StatelessWidget {
|
|||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: ExpansionTile(
|
||||
title: Text(L10n.of(context)!.advanced),
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: TextButton(
|
||||
onPressed: controller.isLoading
|
||||
? () {}
|
||||
: controller.restoreBackup,
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: Colors.white.withAlpha(200),
|
||||
onPrimary: Colors.black,
|
||||
shadowColor: Colors.white,
|
||||
),
|
||||
child: controller.isLoading
|
||||
? const LinearProgressIndicator()
|
||||
: Text(L10n.of(context)!.hydrate),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue