Add clear old tokens on install, upgrade packages

This commit is contained in:
tommyxchow 2022-01-25 01:02:08 -05:00
parent 063f5edb5a
commit 6ac35bfd10
4 changed files with 25 additions and 17 deletions

View file

@ -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;

View file

@ -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<void> 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.

View file

@ -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,
),

View file

@ -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: