From 81e32c5ee421474a504dab6bc7f29be0fc3921b6 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Tue, 13 Oct 2020 12:20:13 +0200 Subject: [PATCH] fix: LocalStorage location on desktop --- .gitignore | 1 + lib/components/matrix.dart | 4 +--- lib/main.dart | 5 ++--- lib/utils/famedlysdk_store.dart | 10 ++++++++++ lib/utils/sentry_controller.dart | 8 ++++---- pubspec.lock | 2 +- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index e0598155..4511167f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ .svn/ lib/generated_plugin_registrant.dart google-services.json +prime # libolm package /assets/js/package/* diff --git a/lib/components/matrix.dart b/lib/components/matrix.dart index 8c0cf952..17b1fe4a 100644 --- a/lib/components/matrix.dart +++ b/lib/components/matrix.dart @@ -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 { void clean() async { if (!kIsWeb) return; - final storage = LocalStorage('LocalStorage'); - await storage.ready; + final storage = await getLocalStorage(); await storage.deleteItem(widget.clientName); } diff --git a/lib/main.dart b/lib/main.dart index 334eb968..a08f0015 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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, diff --git a/lib/utils/famedlysdk_store.dart b/lib/utils/famedlysdk_store.dart index 52b18fc9..d305ade5 100644 --- a/lib/utils/famedlysdk_store.dart +++ b/lib/utils/famedlysdk_store.dart @@ -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 getLocalStorage() async { + final directory = PlatformInfos.isBetaDesktop + ? await getApplicationSupportDirectory() + : await getApplicationDocumentsDirectory(); + final localStorage = LocalStorage('LocalStorage', directory.path); + await localStorage.ready; + return localStorage; +} + Future getDatabase(Client client) async { while (_generateDatabaseLock) { await Future.delayed(Duration(milliseconds: 50)); diff --git a/lib/utils/sentry_controller.dart b/lib/utils/sentry_controller.dart index 1557262d..970a4193 100644 --- a/lib/utils/sentry_controller.dart +++ b/lib/utils/sentry_controller.dart @@ -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 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 getSentryStatus() async { - await storage.ready; + final storage = await getLocalStorage(); return storage.getItem('sentry') as bool; } } diff --git a/pubspec.lock b/pubspec.lock index fea4cbd8..eda8463e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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"