ok lets ship for now
This commit is contained in:
@@ -3,6 +3,7 @@ library;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../models/app_cloud_prefs.dart';
|
||||
import '../models/home_built_in_sections.dart';
|
||||
import '../models/home_filter_widget.dart';
|
||||
import '../models/overview_favourite.dart';
|
||||
@@ -28,9 +29,18 @@ class PreferencesController extends ChangeNotifier {
|
||||
/// Fired after Home widgets are persisted (for cloud push debounce).
|
||||
VoidCallback? onHomeWidgetsPersisted;
|
||||
|
||||
/// Fired after Home sections / Look ahead are persisted.
|
||||
VoidCallback? onAppPrefsPersisted;
|
||||
|
||||
/// Years ahead Look ahead can navigate (1–30, default 5).
|
||||
int get lookAheadMaxYears => _lookAheadMaxYears;
|
||||
|
||||
/// Snapshot used for PocketBase `app_prefs` sync.
|
||||
AppCloudPrefs get cloudPrefs => AppCloudPrefs(
|
||||
homeBuiltInSections: _homeBuiltInSections,
|
||||
lookAheadMaxYears: _lookAheadMaxYears,
|
||||
);
|
||||
|
||||
List<OverviewFavourite> get overviewFavourites =>
|
||||
List.unmodifiable(_overviewFavourites);
|
||||
|
||||
@@ -55,7 +65,10 @@ class PreferencesController extends ChangeNotifier {
|
||||
|
||||
HomeBuiltInSections get homeBuiltInSections => _homeBuiltInSections;
|
||||
|
||||
Future<void> setHomeBuiltInSections(HomeBuiltInSections sections) async {
|
||||
Future<void> setHomeBuiltInSections(
|
||||
HomeBuiltInSections sections, {
|
||||
bool schedulePush = true,
|
||||
}) async {
|
||||
if (sections.showTransactions == _homeBuiltInSections.showTransactions &&
|
||||
sections.showCategorized == _homeBuiltInSections.showCategorized &&
|
||||
sections.showRecent == _homeBuiltInSections.showRecent) {
|
||||
@@ -64,6 +77,7 @@ class PreferencesController extends ChangeNotifier {
|
||||
_homeBuiltInSections = sections;
|
||||
notifyListeners();
|
||||
await _storage.saveHomeBuiltInSections(sections);
|
||||
if (schedulePush) onAppPrefsPersisted?.call();
|
||||
}
|
||||
|
||||
Future<void> setHomeShowTransactions(bool value) => setHomeBuiltInSections(
|
||||
@@ -78,12 +92,29 @@ class PreferencesController extends ChangeNotifier {
|
||||
_homeBuiltInSections.copyWith(showRecent: value),
|
||||
);
|
||||
|
||||
Future<void> setLookAheadMaxYears(int years) async {
|
||||
Future<void> setLookAheadMaxYears(
|
||||
int years, {
|
||||
bool schedulePush = true,
|
||||
}) async {
|
||||
final next = years.clamp(1, 30);
|
||||
if (next == _lookAheadMaxYears) return;
|
||||
_lookAheadMaxYears = next;
|
||||
notifyListeners();
|
||||
await _storage.setLookAheadMaxYears(next);
|
||||
if (schedulePush) onAppPrefsPersisted?.call();
|
||||
}
|
||||
|
||||
Future<void> replaceCloudPrefs(
|
||||
AppCloudPrefs prefs, {
|
||||
bool notify = true,
|
||||
bool schedulePush = false,
|
||||
}) async {
|
||||
_homeBuiltInSections = prefs.homeBuiltInSections;
|
||||
_lookAheadMaxYears = prefs.lookAheadMaxYears.clamp(1, 30);
|
||||
if (notify) notifyListeners();
|
||||
await _storage.saveHomeBuiltInSections(_homeBuiltInSections);
|
||||
await _storage.setLookAheadMaxYears(_lookAheadMaxYears);
|
||||
if (schedulePush) onAppPrefsPersisted?.call();
|
||||
}
|
||||
|
||||
Future<void> addOverviewFavourite(OverviewFavourite favourite) async {
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../models/app_cloud_prefs.dart';
|
||||
import '../models/home_filter_widget.dart';
|
||||
import '../models/overview_favourite.dart';
|
||||
import '../services/pb_sync_service.dart';
|
||||
@@ -42,6 +43,7 @@ class SyncController extends ChangeNotifier {
|
||||
_meta.onPersisted = _scheduleMetaPush;
|
||||
_prefs.onFavouritesPersisted = _scheduleFavouritesPush;
|
||||
_prefs.onHomeWidgetsPersisted = _scheduleHomeWidgetsPush;
|
||||
_prefs.onAppPrefsPersisted = _scheduleAppPrefsPush;
|
||||
_auth.addListener(_onAuthChanged);
|
||||
_bank.onAfterSuccessfulLoad = _onBankDataLoaded;
|
||||
if (_auth.isLoggedIn) {
|
||||
@@ -61,6 +63,7 @@ class SyncController extends ChangeNotifier {
|
||||
bool _pushMetaPending = false;
|
||||
bool _pushFavouritesPending = false;
|
||||
bool _pushHomeWidgetsPending = false;
|
||||
bool _pushAppPrefsPending = false;
|
||||
Timer? _pushDebounce;
|
||||
Timer? _progressHold;
|
||||
Timer? _uiNotifyThrottle;
|
||||
@@ -194,6 +197,7 @@ class SyncController extends ChangeNotifier {
|
||||
_pushMetaPending = false;
|
||||
_pushFavouritesPending = false;
|
||||
_pushHomeWidgetsPending = false;
|
||||
_pushAppPrefsPending = false;
|
||||
_lastError = null;
|
||||
_statusDetail = '';
|
||||
_showProgressRing = false;
|
||||
@@ -256,6 +260,11 @@ class SyncController extends ChangeNotifier {
|
||||
_armPushDebounce();
|
||||
}
|
||||
|
||||
void _scheduleAppPrefsPush() {
|
||||
_pushAppPrefsPending = true;
|
||||
_armPushDebounce();
|
||||
}
|
||||
|
||||
void _armPushDebounce() {
|
||||
if (!_auth.isLoggedIn) return;
|
||||
if (_syncing) {
|
||||
@@ -332,6 +341,20 @@ class SyncController extends ChangeNotifier {
|
||||
_prefs.homeFilterWidgets,
|
||||
remoteHomeWidgets,
|
||||
);
|
||||
AppCloudPrefs? remoteAppPrefs;
|
||||
try {
|
||||
remoteAppPrefs = await service.pullAppPrefs(onStatus: _setStatus);
|
||||
} catch (error) {
|
||||
debugPrint('SyncController: app_prefs pull skipped ($error)');
|
||||
}
|
||||
// Prefer local when this device has pending prefs edits; otherwise
|
||||
// take remote so a new install picks up cloud Home section toggles.
|
||||
final preferLocalAppPrefs = _pushAppPrefsPending;
|
||||
final mergedAppPrefs = mergeAppCloudPrefs(
|
||||
local: _prefs.cloudPrefs,
|
||||
remote: remoteAppPrefs,
|
||||
preferLocal: preferLocalAppPrefs,
|
||||
);
|
||||
// Apply without notifying — one rebuild after both stores are ready.
|
||||
await _meta.replaceStore(mergedMeta, notify: false);
|
||||
await _bank.applySyncedTransactions(remoteTxs, notify: false);
|
||||
@@ -343,6 +366,7 @@ class SyncController extends ChangeNotifier {
|
||||
mergedHomeWidgets,
|
||||
notify: false,
|
||||
);
|
||||
await _prefs.replaceCloudPrefs(mergedAppPrefs, notify: false);
|
||||
_meta.notifyListeners();
|
||||
_bank.notifyListeners();
|
||||
_prefs.notifyListeners();
|
||||
@@ -375,6 +399,15 @@ class SyncController extends ChangeNotifier {
|
||||
'SyncController: home_filter_widgets push skipped ($error)',
|
||||
);
|
||||
}
|
||||
try {
|
||||
await service.pushAppPrefs(
|
||||
mergedAppPrefs,
|
||||
onStatus: _setStatus,
|
||||
);
|
||||
_pushAppPrefsPending = false;
|
||||
} catch (error) {
|
||||
debugPrint('SyncController: app_prefs push skipped ($error)');
|
||||
}
|
||||
final bankSummary = await service.pushTransactions(
|
||||
_bank.transactions,
|
||||
progressStart: 0.82,
|
||||
@@ -420,20 +453,31 @@ class SyncController extends ChangeNotifier {
|
||||
final pushMeta = _pushMetaPending;
|
||||
final pushFavourites = _pushFavouritesPending;
|
||||
final pushHomeWidgets = _pushHomeWidgetsPending;
|
||||
final pushAppPrefs = _pushAppPrefsPending;
|
||||
_pushMetaPending = false;
|
||||
_pushFavouritesPending = false;
|
||||
_pushHomeWidgetsPending = false;
|
||||
if (!pushMeta && !pushFavourites && !pushHomeWidgets) return;
|
||||
_pushAppPrefsPending = false;
|
||||
if (!pushMeta && !pushFavourites && !pushHomeWidgets && !pushAppPrefs) {
|
||||
return;
|
||||
}
|
||||
|
||||
_progressHold?.cancel();
|
||||
_syncing = true;
|
||||
_progressSuccess = false;
|
||||
|
||||
final label = switch ((pushMeta, pushFavourites, pushHomeWidgets)) {
|
||||
(false, false, true) => 'Home widgets',
|
||||
(false, true, false) => 'Favourites',
|
||||
(false, true, true) => 'Home layout',
|
||||
(true, false, false) => 'Annotations',
|
||||
final label = switch ((
|
||||
pushMeta,
|
||||
pushFavourites,
|
||||
pushHomeWidgets,
|
||||
pushAppPrefs,
|
||||
)) {
|
||||
(false, false, false, true) => 'App prefs',
|
||||
(false, false, true, false) => 'Home widgets',
|
||||
(false, false, true, true) => 'Home layout',
|
||||
(false, true, false, false) => 'Favourites',
|
||||
(false, true, true, _) => 'Home layout',
|
||||
(true, false, false, false) => 'Annotations',
|
||||
_ => 'Changes',
|
||||
};
|
||||
_statusDetail = 'Pushing $label…';
|
||||
@@ -446,7 +490,8 @@ class SyncController extends ChangeNotifier {
|
||||
var done = 0;
|
||||
final total = (pushMeta ? 1 : 0) +
|
||||
(pushFavourites ? 1 : 0) +
|
||||
(pushHomeWidgets ? 1 : 0);
|
||||
(pushHomeWidgets ? 1 : 0) +
|
||||
(pushAppPrefs ? 1 : 0);
|
||||
void bump() {
|
||||
done++;
|
||||
_setProgress(done / total);
|
||||
@@ -494,6 +539,22 @@ class SyncController extends ChangeNotifier {
|
||||
}
|
||||
bump();
|
||||
}
|
||||
if (pushAppPrefs) {
|
||||
_setStatus('Pushing app prefs…');
|
||||
try {
|
||||
await service.pushAppPrefs(
|
||||
_prefs.cloudPrefs,
|
||||
onStatus: _setStatus,
|
||||
);
|
||||
parts.add('App prefs updated');
|
||||
} catch (error) {
|
||||
debugPrint('SyncController: app_prefs push skipped ($error)');
|
||||
// Re-queue so a missing collection doesn't drop the edit forever
|
||||
// until the next manual full sync after migrate.
|
||||
_pushAppPrefsPending = true;
|
||||
}
|
||||
bump();
|
||||
}
|
||||
|
||||
_setProgress(1.0);
|
||||
_lastSyncedAt = DateTime.now();
|
||||
@@ -530,6 +591,7 @@ class SyncController extends ChangeNotifier {
|
||||
_meta.onPersisted = null;
|
||||
_prefs.onFavouritesPersisted = null;
|
||||
_prefs.onHomeWidgetsPersisted = null;
|
||||
_prefs.onAppPrefsPersisted = null;
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user