2023-09-30 11:15:20 +03:30
|
|
|
import 'package:hiddify/core/prefs/general_prefs.dart';
|
2023-07-15 18:00:44 +03:30
|
|
|
import 'package:hiddify/features/common/connectivity/connectivity_controller.dart';
|
|
|
|
|
import 'package:hiddify/features/common/window/window_controller.dart';
|
2023-09-30 11:15:20 +03:30
|
|
|
import 'package:hiddify/features/profiles/notifier/notifier.dart';
|
2023-11-01 22:02:13 +03:30
|
|
|
import 'package:hiddify/features/system_tray/system_tray_controller.dart';
|
2023-09-30 11:15:20 +03:30
|
|
|
import 'package:hiddify/services/service_providers.dart';
|
2023-07-15 18:00:44 +03:30
|
|
|
import 'package:hiddify/utils/platform_utils.dart';
|
|
|
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
|
|
|
|
|
|
|
|
part 'common_controllers.g.dart';
|
|
|
|
|
|
|
|
|
|
// this is a temporary solution to keep providers running even when there are no active listeners
|
|
|
|
|
// https://github.com/rrousselGit/riverpod/discussions/2730
|
|
|
|
|
@Riverpod(keepAlive: true)
|
|
|
|
|
void commonControllers(CommonControllersRef ref) {
|
2023-09-30 11:15:20 +03:30
|
|
|
ref.listen(
|
|
|
|
|
introCompletedProvider,
|
|
|
|
|
(_, completed) async {
|
|
|
|
|
if (completed) {
|
2023-10-04 18:06:48 +03:30
|
|
|
await ref.read(cronServiceProvider).startScheduler();
|
2023-09-30 11:15:20 +03:30
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
fireImmediately: true,
|
|
|
|
|
);
|
2023-07-15 18:00:44 +03:30
|
|
|
ref.listen(
|
|
|
|
|
connectivityControllerProvider,
|
|
|
|
|
(previous, next) {},
|
|
|
|
|
fireImmediately: true,
|
|
|
|
|
);
|
2023-09-30 11:15:20 +03:30
|
|
|
ref.listen(
|
|
|
|
|
profilesUpdateNotifierProvider,
|
|
|
|
|
(previous, next) {},
|
|
|
|
|
fireImmediately: true,
|
|
|
|
|
);
|
2023-07-15 18:00:44 +03:30
|
|
|
if (PlatformUtils.isDesktop) {
|
|
|
|
|
ref.listen(
|
|
|
|
|
windowControllerProvider,
|
|
|
|
|
(previous, next) {},
|
|
|
|
|
fireImmediately: true,
|
|
|
|
|
);
|
|
|
|
|
ref.listen(
|
|
|
|
|
systemTrayControllerProvider,
|
|
|
|
|
(previous, next) {},
|
|
|
|
|
fireImmediately: true,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|