diff --git a/lib/core/auth/auth_store.dart b/lib/core/auth/auth_store.dart index f851ce88..5bf394ef 100644 --- a/lib/core/auth/auth_store.dart +++ b/lib/core/auth/auth_store.dart @@ -12,7 +12,7 @@ class AuthStore = _AuthBase with _$AuthStore; abstract class _AuthBase with Store { /// Secure storage to store tokens. - final _storage = const FlutterSecureStorage(); + static const _storage = FlutterSecureStorage(); final TwitchApi twitchApi; @@ -68,10 +68,7 @@ abstract class _AuthBase with Store { _tokenIsValid = await twitchApi.validateToken(token: _token!); // If the token is invalid, logout. - if (!_tokenIsValid) { - logout(); - return; - } + if (!_tokenIsValid) await logout(); _error = null; } catch (e) { @@ -160,6 +157,7 @@ abstract class _AuthBase with Store { _tokenIsValid = await twitchApi.validateToken(token: _token!); } } + // Set the login status to logged out. _isLoggedIn = false; diff --git a/lib/main.dart b/lib/main.dart index e59e0120..b39b6407 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; +import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:frosty/api/bttv_api.dart'; import 'package:frosty/api/ffz_api.dart'; import 'package:frosty/api/seventv_api.dart'; @@ -26,18 +27,27 @@ Future main() async { // Get the shared preferences instance and obtain the existing user settings if it exists. // If default settings don't exist, use an empty JSON string to use the default values. - final preferences = await SharedPreferences.getInstance(); - final userSettings = preferences.getString('settings') ?? '{}'; + final prefs = await SharedPreferences.getInstance(); + final userSettings = prefs.getString('settings') ?? '{}'; + + // Workaround for clearing stored tokens on uninstall. + // If first time running app, will clear all tokens in the secure storage. + if (prefs.getBool('FIRST_RUN') ?? true) { + debugPrint('Clearing secure storage...'); + const storage = FlutterSecureStorage(); + + await storage.deleteAll(); + + prefs.setBool('FIRST_RUN', false); + } // Initialize a settings store from the settings JSON string. final settingsStore = SettingsStore.fromJson(jsonDecode(userSettings)); // Create a MobX reaction that will save the settings on disk every time they are changed. - autorun((_) => preferences.setString('settings', jsonEncode(settingsStore))); + autorun((_) => prefs.setString('settings', jsonEncode(settingsStore))); - if (settingsStore.sendCrashLogs) { - await SentryFlutter.init((options) => options.tracesSampleRate = sampleRate); - } + if (settingsStore.sendCrashLogs) await SentryFlutter.init((options) => options.tracesSampleRate = sampleRate); /// Initialize API services with a common client. /// This will prevent every request from creating a new client instance. diff --git a/lib/screens/settings/sections/video_settings.dart b/lib/screens/settings/sections/video_settings.dart index c0a0dbb2..b096fe1f 100644 --- a/lib/screens/settings/sections/video_settings.dart +++ b/lib/screens/settings/sections/video_settings.dart @@ -33,8 +33,8 @@ class VideoSettings extends StatelessWidget { if (Platform.isIOS) SwitchListTile.adaptive( isThreeLine: true, - title: const Text('Picture-in-picture button'), - subtitle: const Text('Adds a button to enter PiP mode on the bottom right of the overlay.'), + title: const Text('Picture-in-picture button (experimental)'), + subtitle: const Text('Adds a button to enter PiP mode on the bottom right of the overlay. May cause freezes/crashes.'), value: settingsStore.pictureInPicture, onChanged: settingsStore.showVideo && settingsStore.showOverlay ? (newValue) => settingsStore.pictureInPicture = newValue : null, ), diff --git a/pubspec.lock b/pubspec.lock index f8b6f6a4..917dc8cd 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -21,7 +21,7 @@ packages: name: archive url: "https://pub.dartlang.org" source: hosted - version: "3.1.8" + version: "3.1.9" args: dependency: transitive description: @@ -320,7 +320,7 @@ packages: name: flutter_svg url: "https://pub.dartlang.org" source: hosted - version: "1.0.2" + version: "1.0.3" flutter_test: dependency: "direct dev" description: flutter @@ -923,7 +923,7 @@ packages: name: url_launcher_macos url: "https://pub.dartlang.org" source: hosted - version: "2.0.2" + version: "2.0.3" url_launcher_platform_interface: dependency: transitive description: @@ -1007,7 +1007,7 @@ packages: name: win32 url: "https://pub.dartlang.org" source: hosted - version: "2.3.6" + version: "2.3.8" xdg_directories: dependency: transitive description: