33 lines
972 B
Dart
33 lines
972 B
Dart
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import '../../mall/application/mall_tab_config.dart';
|
|
import '../data/ads_api_client.dart';
|
|
import 'splash_ad_controller.dart';
|
|
|
|
final adConfigForegroundRefresherProvider = Provider(
|
|
(ref) => AdConfigForegroundRefresher(
|
|
() => ref.invalidate(featuredAdsProvider(homeBannerAdPlacement)),
|
|
() => ref.read(splashAdControllerProvider).refresh(),
|
|
() => ref.read(mallTabConfigProvider.notifier).refresh(),
|
|
),
|
|
);
|
|
|
|
class AdConfigForegroundRefresher {
|
|
AdConfigForegroundRefresher(this._banner, this._splash, this._mall);
|
|
final void Function() _banner;
|
|
final Future<void> Function() _splash, _mall;
|
|
Future<void>? _running;
|
|
Future<void> refresh() =>
|
|
_running ??= _refresh().whenComplete(() => _running = null);
|
|
Future<void> _refresh() async {
|
|
try {
|
|
_banner();
|
|
} catch (_) {}
|
|
try {
|
|
await _splash();
|
|
} catch (_) {}
|
|
try {
|
|
await _mall();
|
|
} catch (_) {}
|
|
}
|
|
}
|