mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-20 05:19:28 +02:00
Don't init the foreground service unless it is needed (#2437)
This commit is contained in:
@@ -185,7 +185,6 @@ class _ObtainiumState extends State<Obtainium> {
|
|||||||
initPlatformState();
|
initPlatformState();
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
requestNonOptionalPermissions();
|
requestNonOptionalPermissions();
|
||||||
initForegroundService();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,28 +200,32 @@ class _ObtainiumState extends State<Obtainium> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void initForegroundService() {
|
void initForegroundService() {
|
||||||
FlutterForegroundTask.init(
|
// ignore: invalid_use_of_visible_for_testing_member
|
||||||
androidNotificationOptions: AndroidNotificationOptions(
|
if (!FlutterForegroundTask.isInitialized) {
|
||||||
channelId: 'bg_update',
|
FlutterForegroundTask.init(
|
||||||
channelName: tr('foregroundService'),
|
androidNotificationOptions: AndroidNotificationOptions(
|
||||||
channelDescription: tr('foregroundService'),
|
channelId: 'bg_update',
|
||||||
onlyAlertOnce: true,
|
channelName: tr('foregroundService'),
|
||||||
),
|
channelDescription: tr('foregroundService'),
|
||||||
iosNotificationOptions: const IOSNotificationOptions(
|
onlyAlertOnce: true,
|
||||||
showNotification: false,
|
),
|
||||||
playSound: false,
|
iosNotificationOptions: const IOSNotificationOptions(
|
||||||
),
|
showNotification: false,
|
||||||
foregroundTaskOptions: ForegroundTaskOptions(
|
playSound: false,
|
||||||
eventAction: ForegroundTaskEventAction.repeat(900000),
|
),
|
||||||
autoRunOnBoot: true,
|
foregroundTaskOptions: ForegroundTaskOptions(
|
||||||
autoRunOnMyPackageReplaced: true,
|
eventAction: ForegroundTaskEventAction.repeat(900000),
|
||||||
allowWakeLock: true,
|
autoRunOnBoot: true,
|
||||||
allowWifiLock: true,
|
autoRunOnMyPackageReplaced: true,
|
||||||
),
|
allowWakeLock: true,
|
||||||
);
|
allowWifiLock: true,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<ServiceRequestResult?> startForegroundService(bool restart) async {
|
Future<ServiceRequestResult?> startForegroundService(bool restart) async {
|
||||||
|
initForegroundService();
|
||||||
if (await FlutterForegroundTask.isRunningService) {
|
if (await FlutterForegroundTask.isRunningService) {
|
||||||
if (restart) {
|
if (restart) {
|
||||||
return FlutterForegroundTask.restartService();
|
return FlutterForegroundTask.restartService();
|
||||||
|
Reference in New Issue
Block a user