Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 38 additions & 21 deletions lib/data/services/plugin_sync_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,7 @@ class PluginSyncService extends ChangeNotifier {
}
_appendDisabledBuiltinSections(sections, order);
await _prefs.setHomeSectionsConfig(sections);
await _syncSeerrHomeRowsWithSections(sections);
appliedHomeSections = true;
}
}
Expand Down Expand Up @@ -1201,6 +1202,7 @@ class PluginSyncService extends ChangeNotifier {
sections.add(entry.copyWith(order: order++));
}
await _prefs.setHomeSectionsConfig(sections);
await _syncSeerrHomeRowsWithSections(sections);
}
}
}
Expand Down Expand Up @@ -1302,10 +1304,16 @@ class PluginSyncService extends ChangeNotifier {
}

await _prefs.setHomeSectionsConfig(sections);
await _syncSeerrHomeRowsWithSections(sections);
}

/// Appends a disabled entry for every built-in HomeSectionType not already in
/// [sections] so the settings UI shows every toggle. Returns the next order.
///
/// A section the profile doesn't mention carries no opinion, so it lands
/// disabled rather than being re-derived from a toggle preference that
/// defaults to on. The preferences stay untouched because the profile's own
/// synced fields already set them, and writing false would push that back.
int _appendDisabledBuiltinSections(
List<HomeSectionConfig> sections,
int order,
Expand All @@ -1315,33 +1323,32 @@ class PluginSyncService extends ChangeNotifier {
if (type == prefs.HomeSectionType.none || present.contains(type)) {
continue;
}

var isEnabled = false;
if (type == prefs.HomeSectionType.rewatch) {
isEnabled = _prefs.get(UserPreferences.displayRewatchRow);
} else if (type == prefs.HomeSectionType.sinceYouWatched1 ||
type == prefs.HomeSectionType.sinceYouWatched2 ||
type == prefs.HomeSectionType.sinceYouWatched3 ||
type == prefs.HomeSectionType.sinceYouWatched4 ||
type == prefs.HomeSectionType.sinceYouWatched5) {
final localPref = switch (type) {
prefs.HomeSectionType.sinceYouWatched1 => UserPreferences.sinceYouWatched1Enabled,
prefs.HomeSectionType.sinceYouWatched2 => UserPreferences.sinceYouWatched2Enabled,
prefs.HomeSectionType.sinceYouWatched3 => UserPreferences.sinceYouWatched3Enabled,
prefs.HomeSectionType.sinceYouWatched4 => UserPreferences.sinceYouWatched4Enabled,
prefs.HomeSectionType.sinceYouWatched5 => UserPreferences.sinceYouWatched5Enabled,
_ => throw StateError('Invalid type'),
};
isEnabled = _prefs.get(localPref);
}

sections.add(
HomeSectionConfig(type: type, enabled: isEnabled, order: order++),
HomeSectionConfig(type: type, enabled: false, order: order++),
);
}
return order;
}

/// Seerr home rows keep their own copy of the enabled state that the settings
/// screens write alongside the section layout, so mirror it here too. Without
/// this the home view gates Seerr rows on stale values after a sync.
Future<void> _syncSeerrHomeRowsWithSections(
List<HomeSectionConfig> sections,
) async {
final enabledByType = {
for (final section in sections) section.type: section.enabled,
};
final updated = _seerrPrefs.homeRowsConfig
.map(
(row) => row.copyWith(
enabled: enabledByType[row.type.homeSectionType] ?? false,
),
)
.toList();
await _seerrPrefs.setHomeRowsConfig(updated);
}

/// Applies one table-driven field from an incoming profile.
void _applySyncedField(Map<String, dynamic> data, SyncedField field) {
switch (field.codec) {
Expand Down Expand Up @@ -1715,6 +1722,16 @@ class PluginSyncService extends ChangeNotifier {
prefs.HomeSectionType.sonarrCalendar =>
UserPreferences.enableSonarrCalendar,
prefs.HomeSectionType.rewatch => UserPreferences.displayRewatchRow,
prefs.HomeSectionType.sinceYouWatched1 =>
UserPreferences.sinceYouWatched1Enabled,
prefs.HomeSectionType.sinceYouWatched2 =>
UserPreferences.sinceYouWatched2Enabled,
prefs.HomeSectionType.sinceYouWatched3 =>
UserPreferences.sinceYouWatched3Enabled,
prefs.HomeSectionType.sinceYouWatched4 =>
UserPreferences.sinceYouWatched4Enabled,
prefs.HomeSectionType.sinceYouWatched5 =>
UserPreferences.sinceYouWatched5Enabled,
_ => null,
};
}
Expand Down
33 changes: 33 additions & 0 deletions lib/preference/home_section_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,39 @@ class HomeSectionConfig {
enabled: false,
order: 39,
),
// These carry a toggle preference too, but they still need a section entry.
// Without one there was nowhere for turning the row off to persist, so the
// next sync kept bringing it back.
HomeSectionConfig(
type: HomeSectionType.sinceYouWatched1,
enabled: false,
order: 40,
),
HomeSectionConfig(
type: HomeSectionType.sinceYouWatched2,
enabled: false,
order: 41,
),
HomeSectionConfig(
type: HomeSectionType.sinceYouWatched3,
enabled: false,
order: 42,
),
HomeSectionConfig(
type: HomeSectionType.sinceYouWatched4,
enabled: false,
order: 43,
),
HomeSectionConfig(
type: HomeSectionType.sinceYouWatched5,
enabled: false,
order: 44,
),
HomeSectionConfig(
type: HomeSectionType.rewatch,
enabled: false,
order: 45,
),
];

static bool isSupportedJson(Map<String, dynamic> json) {
Expand Down
2 changes: 1 addition & 1 deletion lib/preference/seerr_preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class SeerrPreferences {
if (seerrType == null || !enabled) return false;
final config = homeRowsConfig.firstWhere(
(c) => c.type == seerrType,
orElse: () => SeerrRowConfig(type: seerrType, enabled: true, order: 0),
orElse: () => SeerrRowConfig(type: seerrType, enabled: false, order: 0),
);
return config.enabled;
}
Expand Down
Loading