Skip to content

Commit

Permalink
Fix settings
Browse files Browse the repository at this point in the history
  • Loading branch information
LezdCS committed Jun 8, 2024
1 parent f4ad50b commit 4d06569
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
6 changes: 6 additions & 0 deletions lib/src/data/repositories/settings_repository_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,30 @@ import 'package:irllink/src/core/resources/data_state.dart';
import 'package:irllink/src/domain/repositories/settings_repository.dart';
import 'package:get_storage/get_storage.dart';
import 'dart:convert';
import 'package:irllink/src/core/utils/globals.dart' as globals;

class SettingsRepositoryImpl extends SettingsRepository {
@override
Future<DataState<Settings>> getSettings() async {
final box = GetStorage();
var settingsString = box.read('settings');
globals.talker?.info('Retrieving settings...');
if (settingsString != null) {
globals.talker?.info('Settings found.');
Map<String, dynamic> settingsJson = jsonDecode(settingsString);
SettingsDTO settings = SettingsDTO.fromJson(settingsJson);
globals.talker?.info('Settings: $settingsJson');
return DataSuccess(settings);
}
globals.talker?.info('No settings found.');
return DataSuccess(const Settings.defaultSettings());
}

@override
Future<void> setSettings(Settings settings) async {
final box = GetStorage();
String settingsJson = jsonEncode(settings.toJson());
globals.talker?.info('Saving settings: $settingsJson');
box.write('settings', settingsJson);
}
}
7 changes: 4 additions & 3 deletions lib/src/presentation/controllers/home_view_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,13 @@ class HomeViewController extends GetxController
}

Future<DataState<Settings>> getSettings() async {
DataState<Settings> settings = await homeEvents.getSettings();
DataState<Settings> settingsResult = await homeEvents.getSettings();
if (settings is DataFailed){
return DataFailed('');
}
await applySettings(settings.data!);
return DataSuccess(settings.data!);
settings.value = settingsResult.data!;
await applySettings(settingsResult.data!);
return DataSuccess(settingsResult.data!);
}

Future applySettings(Settings settings) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:irllink/src/presentation/events/settings_events.dart';
import 'package:irllink/src/presentation/events/streamelements_events.dart';

import '../../domain/entities/twitch/twitch_user.dart';
import 'package:irllink/src/core/utils/globals.dart' as globals;

class SettingsViewController extends GetxController {
SettingsViewController(
Expand Down Expand Up @@ -83,6 +84,7 @@ class SettingsViewController extends GetxController {
homeViewController.settings.value.streamElementsSettings!.jwt ?? '';
seOverlayTokenInputController.text = homeViewController
.settings.value.streamElementsSettings!.overlayToken ?? '';
globals.talker?.debug(homeViewController.settings.value);
rtIrlInputController.text =
homeViewController.settings.value.rtIrlPushKey ?? '';
getUsernames();
Expand All @@ -106,7 +108,7 @@ class SettingsViewController extends GetxController {
Future<void> loginStreamElements() async {
StreamelementsAuthParams params = const StreamelementsAuthParams();
await streamelementsEvents.login(params: params).then((value) {
if (value.error != null) {
if (value is DataFailed) {
Get.snackbar(
"Error",
"Login failed: ${value.error}",
Expand Down Expand Up @@ -135,7 +137,7 @@ class SettingsViewController extends GetxController {
if (homeViewController.seCredentials.value == null) return;
DataState<void> result = await streamelementsEvents
.disconnect(homeViewController.seCredentials.value!.accessToken);
if (result.error == null) {
if (result is DataSuccess) {
homeViewController.seCredentials.value = null;
homeViewController.seMe.value = null;
homeViewController.seCredentials.refresh();
Expand Down

0 comments on commit 4d06569

Please sign in to comment.