mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
Re-register push token at launch; refactor push_service
After a cold restart the app considered push enabled (from prefs) but never re-registered its FCM token, so a rotated token (or a backend that lost its token store) left the backend delivering to nothing while the test button still reported success. Re-register the current token at launch so the backend converges to the live token on every start, and re-attach the foreground display handler then too (it was previously only wired during enable()). Also tidy push_service.dart: a single initPushOnLaunch() startup entry point so main.dart needs no push internals, one owner for the persisted push-enabled flag (pushEnabledOnThisDevice / setPushEnabledOnThisDevice) instead of a hard-coded key in four places, private internal helpers, deduped platform checks, and section grouping. enable() now reuses the shared token-registration path. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
817ec5872c
commit
0075072196
@@ -42,7 +42,7 @@ class _SettingsState extends State<Settings> {
|
||||
_isFirstRun = _baseUrl.isEmpty;
|
||||
_selectedTheme = context.read<AppState>().themeKey;
|
||||
_pushService = widget.pushService ?? FirebasePushService();
|
||||
_pushEnabled = PrefUtil.getValue('push_enabled', false) as bool;
|
||||
_pushEnabled = pushEnabledOnThisDevice;
|
||||
_loadConfig();
|
||||
// First run / unconfigured: open the connection dialog immediately and keep
|
||||
// it open (non-dismissible) until the user saves a working configuration.
|
||||
@@ -96,7 +96,7 @@ class _SettingsState extends State<Settings> {
|
||||
final enabled = await _pushService.enable();
|
||||
if (!mounted) return;
|
||||
if (enabled) {
|
||||
await PrefUtil.setValue('push_enabled', true);
|
||||
await setPushEnabledOnThisDevice(enabled: true);
|
||||
if (!mounted) return;
|
||||
setState(() => _pushEnabled = true);
|
||||
UISnackbars.showSuccess(
|
||||
@@ -120,7 +120,7 @@ class _SettingsState extends State<Settings> {
|
||||
} else {
|
||||
await _pushService.disable();
|
||||
if (!mounted) return;
|
||||
await PrefUtil.setValue('push_enabled', false);
|
||||
await setPushEnabledOnThisDevice(enabled: false);
|
||||
if (!mounted) return;
|
||||
setState(() => _pushEnabled = false);
|
||||
UISnackbars.showSuccess(
|
||||
|
||||
Reference in New Issue
Block a user