Merge branch 'krille/fix-localstorage-desktop' into 'main'

fix: LocalStorage location on desktop

See merge request ChristianPauly/fluffychat-flutter!223
This commit is contained in:
Christian Pauly 2020-10-13 10:34:03 +00:00
commit 7e378cbf02
6 changed files with 19 additions and 11 deletions

1
.gitignore vendored
View file

@ -11,6 +11,7 @@
.svn/
lib/generated_plugin_registrant.dart
google-services.json
prime
# libolm package
/assets/js/package/*

View file

@ -11,7 +11,6 @@ import 'package:fluffychat/utils/user_status.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:localstorage/localstorage.dart';
import 'package:universal_html/prefer_universal/html.dart' as html;
import 'package:url_launcher/url_launcher.dart';
@ -78,8 +77,7 @@ class MatrixState extends State<Matrix> {
void clean() async {
if (!kIsWeb) return;
final storage = LocalStorage('LocalStorage');
await storage.ready;
final storage = await getLocalStorage();
await storage.deleteItem(widget.clientName);
}

View file

@ -8,12 +8,12 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:localstorage/localstorage.dart';
import 'package:sentry/sentry.dart';
import 'package:universal_html/prefer_universal/html.dart' as html;
import 'components/matrix.dart';
import 'components/theme_switcher.dart';
import 'utils/famedlysdk_store.dart';
import 'views/chat_list.dart';
final sentry = SentryClient(dsn: '8591d0d863b646feb4f3dda7e5dcab38');
@ -21,8 +21,7 @@ final sentry = SentryClient(dsn: '8591d0d863b646feb4f3dda7e5dcab38');
void captureException(error, stackTrace) async {
debugPrint(error.toString());
debugPrint(stackTrace.toString());
final storage = LocalStorage('LocalStorage');
await storage.ready;
final storage = await getLocalStorage();
if (storage.getItem('sentry') == true) {
await sentry.captureException(
exception: error,

View file

@ -6,12 +6,22 @@ import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:localstorage/localstorage.dart';
import 'package:path_provider/path_provider.dart';
import 'dart:async';
import 'dart:core';
import './database/shared.dart';
import 'package:olm/olm.dart' as olm; // needed for migration
import 'package:random_string/random_string.dart';
Future<LocalStorage> getLocalStorage() async {
final directory = PlatformInfos.isBetaDesktop
? await getApplicationSupportDirectory()
: await getApplicationDocumentsDirectory();
final localStorage = LocalStorage('LocalStorage', directory.path);
await localStorage.ready;
return localStorage;
}
Future<Database> getDatabase(Client client) async {
while (_generateDatabaseLock) {
await Future.delayed(Duration(milliseconds: 50));

View file

@ -2,10 +2,10 @@ import 'package:bot_toast/bot_toast.dart';
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:localstorage/localstorage.dart';
import 'famedlysdk_store.dart';
abstract class SentryController {
static LocalStorage storage = LocalStorage('LocalStorage');
static Future<void> toggleSentryAction(BuildContext context) async {
final enableSentry = await SimpleDialogs(context).askConfirmation(
titleText: L10n.of(context).sendBugReports,
@ -13,14 +13,14 @@ abstract class SentryController {
confirmText: L10n.of(context).ok,
cancelText: L10n.of(context).no,
);
await storage.ready;
final storage = await getLocalStorage();
await storage.setItem('sentry', enableSentry);
BotToast.showText(text: L10n.of(context).changesHaveBeenSaved);
return;
}
static Future<bool> getSentryStatus() async {
await storage.ready;
final storage = await getLocalStorage();
return storage.getItem('sentry') as bool;
}
}

View file

@ -1074,5 +1074,5 @@ packages:
source: hosted
version: "0.1.2"
sdks:
dart: ">=2.10.0-110 <=2.11.0-161.0.dev"
dart: ">=2.10.0-110 <2.11.0"
flutter: ">=1.20.0 <2.0.0"