mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-19 06:43:42 +00:00
feat: new ui (#1455)
This commit is contained in:
742 files changed
+59951
-5934
No files matched your search
@@ -0,0 +1,49 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_foreground_task/flutter_foreground_task.dart';
|
||||
|
||||
import '../../l10n/l10n.dart';
|
||||
|
||||
/// Keeps the Android process alive while Gopeed is available for downloads.
|
||||
class AndroidForegroundService {
|
||||
const AndroidForegroundService._();
|
||||
|
||||
static Future<void> ensureRunning(AppLocalizations l10n) async {
|
||||
if (!Platform.isAndroid) return;
|
||||
|
||||
FlutterForegroundTask.init(
|
||||
androidNotificationOptions: AndroidNotificationOptions(
|
||||
channelId: 'gopeed_service',
|
||||
channelName: l10n.androidForegroundServiceChannel,
|
||||
channelImportance: NotificationChannelImportance.LOW,
|
||||
showWhen: true,
|
||||
priority: NotificationPriority.LOW,
|
||||
),
|
||||
iosNotificationOptions: const IOSNotificationOptions(showNotification: false, playSound: false),
|
||||
foregroundTaskOptions: ForegroundTaskOptions(
|
||||
eventAction: ForegroundTaskEventAction.nothing(),
|
||||
autoRunOnBoot: true,
|
||||
allowWakeLock: true,
|
||||
allowWifiLock: true,
|
||||
),
|
||||
);
|
||||
|
||||
if (await FlutterForegroundTask.isRunningService) {
|
||||
_throwOnFailure(await FlutterForegroundTask.restartService());
|
||||
return;
|
||||
}
|
||||
|
||||
_throwOnFailure(
|
||||
await FlutterForegroundTask.startService(
|
||||
notificationTitle: l10n.androidForegroundNotificationTitle,
|
||||
notificationText: l10n.androidForegroundNotificationText,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
static void _throwOnFailure(ServiceRequestResult result) {
|
||||
if (result case ServiceRequestFailure(:final error)) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user