2023-09-09 16:47:11 +03:30
|
|
|
import 'dart:io';
|
|
|
|
|
|
2026-01-17 13:09:20 +03:00
|
|
|
import 'package:umbrix/core/app_info/app_info_provider.dart';
|
|
|
|
|
import 'package:umbrix/utils/utils.dart';
|
2023-09-09 16:47:11 +03:30
|
|
|
import 'package:launch_at_startup/launch_at_startup.dart';
|
|
|
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
|
|
|
|
2023-12-28 23:16:56 +03:30
|
|
|
part 'auto_start_notifier.g.dart';
|
2023-09-09 16:47:11 +03:30
|
|
|
|
|
|
|
|
@Riverpod(keepAlive: true)
|
2023-12-28 23:16:56 +03:30
|
|
|
class AutoStartNotifier extends _$AutoStartNotifier with InfraLogger {
|
2023-09-09 16:47:11 +03:30
|
|
|
@override
|
|
|
|
|
Future<bool> build() async {
|
|
|
|
|
if (!PlatformUtils.isDesktop) return false;
|
2023-12-28 23:16:56 +03:30
|
|
|
|
2023-12-01 12:56:24 +03:30
|
|
|
final appInfo = ref.watch(appInfoProvider).requireValue;
|
2023-09-09 16:47:11 +03:30
|
|
|
launchAtStartup.setup(
|
2023-09-12 15:22:58 +03:30
|
|
|
appName: appInfo.name,
|
2023-09-09 16:47:11 +03:30
|
|
|
appPath: Platform.resolvedExecutable,
|
|
|
|
|
);
|
|
|
|
|
final isEnabled = await launchAtStartup.isEnabled();
|
|
|
|
|
loggy.info("auto start is [${isEnabled ? "Enabled" : "Disabled"}]");
|
|
|
|
|
return isEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> enable() async {
|
|
|
|
|
loggy.debug("enabling auto start");
|
|
|
|
|
await launchAtStartup.enable();
|
|
|
|
|
state = const AsyncValue.data(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> disable() async {
|
|
|
|
|
loggy.debug("disabling auto start");
|
|
|
|
|
await launchAtStartup.disable();
|
|
|
|
|
state = const AsyncValue.data(false);
|
|
|
|
|
}
|
|
|
|
|
}
|