fix: LocalStorage location on desktop

This commit is contained in:
Christian Pauly 2020-10-13 12:20:13 +02:00
parent 441aca1331
commit 81e32c5ee4
6 changed files with 19 additions and 11 deletions

1
.gitignore vendored
View File

@ -11,6 +11,7 @@
.svn/ .svn/
lib/generated_plugin_registrant.dart lib/generated_plugin_registrant.dart
google-services.json google-services.json
prime
# libolm package # libolm package
/assets/js/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/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.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:universal_html/prefer_universal/html.dart' as html;
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
@ -78,8 +77,7 @@ class MatrixState extends State<Matrix> {
void clean() async { void clean() async {
if (!kIsWeb) return; if (!kIsWeb) return;
final storage = LocalStorage('LocalStorage'); final storage = await getLocalStorage();
await storage.ready;
await storage.deleteItem(widget.clientName); await storage.deleteItem(widget.clientName);
} }

View File

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

View File

@ -6,12 +6,22 @@ import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:localstorage/localstorage.dart'; import 'package:localstorage/localstorage.dart';
import 'package:path_provider/path_provider.dart';
import 'dart:async'; import 'dart:async';
import 'dart:core'; import 'dart:core';
import './database/shared.dart'; import './database/shared.dart';
import 'package:olm/olm.dart' as olm; // needed for migration import 'package:olm/olm.dart' as olm; // needed for migration
import 'package:random_string/random_string.dart'; 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 { Future<Database> getDatabase(Client client) async {
while (_generateDatabaseLock) { while (_generateDatabaseLock) {
await Future.delayed(Duration(milliseconds: 50)); 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:fluffychat/components/dialogs/simple_dialogs.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:localstorage/localstorage.dart';
import 'famedlysdk_store.dart';
abstract class SentryController { abstract class SentryController {
static LocalStorage storage = LocalStorage('LocalStorage');
static Future<void> toggleSentryAction(BuildContext context) async { static Future<void> toggleSentryAction(BuildContext context) async {
final enableSentry = await SimpleDialogs(context).askConfirmation( final enableSentry = await SimpleDialogs(context).askConfirmation(
titleText: L10n.of(context).sendBugReports, titleText: L10n.of(context).sendBugReports,
@ -13,14 +13,14 @@ abstract class SentryController {
confirmText: L10n.of(context).ok, confirmText: L10n.of(context).ok,
cancelText: L10n.of(context).no, cancelText: L10n.of(context).no,
); );
await storage.ready; final storage = await getLocalStorage();
await storage.setItem('sentry', enableSentry); await storage.setItem('sentry', enableSentry);
BotToast.showText(text: L10n.of(context).changesHaveBeenSaved); BotToast.showText(text: L10n.of(context).changesHaveBeenSaved);
return; return;
} }
static Future<bool> getSentryStatus() async { static Future<bool> getSentryStatus() async {
await storage.ready; final storage = await getLocalStorage();
return storage.getItem('sentry') as bool; return storage.getItem('sentry') as bool;
} }
} }

View File

@ -1074,5 +1074,5 @@ packages:
source: hosted source: hosted
version: "0.1.2" version: "0.1.2"
sdks: 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" flutter: ">=1.20.0 <2.0.0"