Skip to content

Commit

Permalink
Merge pull request #437 from lamarios/fix/sponsorblock-unsetting
Browse files Browse the repository at this point in the history
fix issue where sponsor block settings would not save
  • Loading branch information
lamarios authored Dec 26, 2023
2 parents 0320e1b + df1b1d7 commit f1710fe
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ class Service {

if (categories.isNotEmpty) {
url +=
'&categories=[${categories.map((e) => '"${e.name}"').join(",")}]';
'&categories=[${categories.map((e) => '"${e.segmentName}"').join(",")}]';
}

log.info('Calling $url');
Expand Down
1 change: 1 addition & 0 deletions lib/settings/states/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ class SettingsCubit extends Cubit<SettingsState> {
}

saveSetting(SettingsValue settings) {
db.saveSetting(settings);
var newSettings = Map<String, SettingsValue>.from(state.settings);
newSettings[settings.name] = settings;
emit(state.copyWith(settings: newSettings));
Expand Down
19 changes: 11 additions & 8 deletions lib/videos/models/sponsor_segment_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:invidious/database.dart';

enum SponsorSegmentType {
sponsor,
selfpromo,
interaction,
intro,
outro,
preview,
musicOffTopic,
filler;
sponsor('sponsor'),
selfpromo('selfpromo'),
interaction('interaction'),
intro('intro'),
outro('outro'),
preview('preview'),
musicOffTopic('music_offtopic'),
filler('filler');

final String segmentName;

const SponsorSegmentType(this.segmentName);
String settingsName() => '$sponsorBlockPrefix$name';

static String getLabel(SponsorSegmentType type, AppLocalizations locals) {
Expand Down
2 changes: 1 addition & 1 deletion test/settings/state/server_list_settings_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:invidious/globals.dart';
import 'package:invidious/settings/states/server_list_settings.dart';

import '../../globals.dart';
import '../../testAppCubit.dart';
import '../../test_app_cubit.dart';
import '../../utils/memorydb.dart';

void main() {
Expand Down
2 changes: 1 addition & 1 deletion test/settings/state/server_settings_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:invidious/settings/models/db/server.dart';
import 'package:invidious/settings/states/server_settings.dart';

import '../../globals.dart';
import '../../testAppCubit.dart';
import '../../test_app_cubit.dart';
import '../../utils/memorydb.dart';

main() {
Expand Down
26 changes: 20 additions & 6 deletions test/settings/state/settings_test.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:invidious/app/states/app.dart';
import 'package:invidious/database.dart';
import 'package:invidious/globals.dart';
import 'package:invidious/settings/models/db/settings.dart';
import 'package:invidious/settings/states/settings.dart';

import '../../test_app_cubit.dart';
import '../../test_settings_cubit.dart';
import '../../utils/memorydb.dart';

Future<void> main() async {
TestWidgetsFlutterBinding.ensureInitialized();
db = MemoryDB();
test('setting and reading settings', () {
var appCubit = AppCubit(AppState.init());
var settingsCubit = SettingsCubit(SettingsState.init(), appCubit);
late SettingsCubit settingsCubit;
setUp(() {
db = MemoryDB();
var appCubit = TestAppCubit(AppState.init());
settingsCubit = TestSettingsCubit(SettingsState.init(), appCubit);
});

test('setting and reading settings', () {
// testing boolean setting
settingsCubit.useSearchHistory = true;
expect(settingsCubit.state.useSearchHistory, true);
Expand Down Expand Up @@ -45,4 +49,14 @@ Future<void> main() async {
expect(settingsCubit.state.skipStep, skipSteps[i]);
}
});

test('Generic set settings method', () {
var setting = db.getSettings('test');
expect(setting, null);

SettingsValue s = SettingsValue('test', 'yo');
settingsCubit.saveSetting(s);
expect(db.getSettings('test')?.value, 'yo');

});
}
File renamed without changes.
9 changes: 9 additions & 0 deletions test/test_settings_cubit.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:invidious/settings/states/settings.dart';

class TestSettingsCubit extends SettingsCubit{
TestSettingsCubit(super.initialState, super.appCubit);

@override
onReady() {
}
}

0 comments on commit f1710fe

Please sign in to comment.