mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-07-13 05:16:43 +02:00
Updates
This commit is contained in:
@ -330,6 +330,8 @@
|
|||||||
"documentationLinksNote": "The Obtainium GitHub page linked below contains links to videos, articles, discussions and other resources that will help you understand how to use the app.",
|
"documentationLinksNote": "The Obtainium GitHub page linked below contains links to videos, articles, discussions and other resources that will help you understand how to use the app.",
|
||||||
"batteryOptimizationNote": "Note that background downloads may work more reliably if you disable OS battery optimizations for Obtainium.",
|
"batteryOptimizationNote": "Note that background downloads may work more reliably if you disable OS battery optimizations for Obtainium.",
|
||||||
"fileDeletionError": "Failed to delete file (try deleting it manually then try again): \"{}\"",
|
"fileDeletionError": "Failed to delete file (try deleting it manually then try again): \"{}\"",
|
||||||
|
"foregroundService": "Obtainium foreground service",
|
||||||
|
"fgServiceNotice": "This notification is required for background update checking (it can be hidden in the OS settings)",
|
||||||
"removeAppQuestion": {
|
"removeAppQuestion": {
|
||||||
"one": "Remove app?",
|
"one": "Remove app?",
|
||||||
"other": "Remove apps?"
|
"other": "Remove apps?"
|
||||||
|
@ -92,26 +92,22 @@ void startCallback() {
|
|||||||
class MyTaskHandler extends TaskHandler {
|
class MyTaskHandler extends TaskHandler {
|
||||||
static const String incrementCountCommand = 'incrementCount';
|
static const String incrementCountCommand = 'incrementCount';
|
||||||
|
|
||||||
// Called when the task is started.
|
|
||||||
@override
|
@override
|
||||||
Future<void> onStart(DateTime timestamp, TaskStarter starter) async {
|
Future<void> onStart(DateTime timestamp, TaskStarter starter) async {
|
||||||
print('onStart(starter: ${starter.name})');
|
print('onStart(starter: ${starter.name})');
|
||||||
bgUpdateCheck('bg_check', null);
|
bgUpdateCheck('bg_check', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called based on the eventAction set in ForegroundTaskOptions.
|
|
||||||
@override
|
@override
|
||||||
void onRepeatEvent(DateTime timestamp) {
|
void onRepeatEvent(DateTime timestamp) {
|
||||||
bgUpdateCheck('Foreground service bg_check', null);
|
bgUpdateCheck('bg_check', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when the task is destroyed.
|
|
||||||
@override
|
@override
|
||||||
Future<void> onDestroy(DateTime timestamp, bool isTimeout) async {
|
Future<void> onDestroy(DateTime timestamp, bool isTimeout) async {
|
||||||
print('Foreground service onDestroy(isTimeout: $isTimeout)');
|
print('Foreground service onDestroy(isTimeout: $isTimeout)');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when data is sent using `FlutterForegroundTask.sendDataToTask`.
|
|
||||||
@override
|
@override
|
||||||
void onReceiveData(Object data) {}
|
void onReceiveData(Object data) {}
|
||||||
}
|
}
|
||||||
@ -192,8 +188,8 @@ class _ObtainiumState extends State<Obtainium> {
|
|||||||
FlutterForegroundTask.init(
|
FlutterForegroundTask.init(
|
||||||
androidNotificationOptions: AndroidNotificationOptions(
|
androidNotificationOptions: AndroidNotificationOptions(
|
||||||
channelId: 'bg_update',
|
channelId: 'bg_update',
|
||||||
channelName: tr('placeholder'),
|
channelName: tr('foregroundService'),
|
||||||
channelDescription: tr('placeholder'),
|
channelDescription: tr('foregroundService'),
|
||||||
onlyAlertOnce: true,
|
onlyAlertOnce: true,
|
||||||
),
|
),
|
||||||
iosNotificationOptions: const IOSNotificationOptions(
|
iosNotificationOptions: const IOSNotificationOptions(
|
||||||
@ -210,21 +206,30 @@ class _ObtainiumState extends State<Obtainium> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<ServiceRequestResult> startForegroundService() async {
|
Future<ServiceRequestResult?> startForegroundService(bool restart) async {
|
||||||
if (await FlutterForegroundTask.isRunningService) {
|
if (await FlutterForegroundTask.isRunningService) {
|
||||||
return FlutterForegroundTask.restartService();
|
if (restart) {
|
||||||
|
return FlutterForegroundTask.restartService();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return FlutterForegroundTask.startService(
|
return FlutterForegroundTask.startService(
|
||||||
serviceTypes: [ForegroundServiceTypes.specialUse],
|
serviceTypes: [ForegroundServiceTypes.specialUse],
|
||||||
serviceId: 666,
|
serviceId: 666,
|
||||||
notificationTitle: tr('placeholder'),
|
notificationTitle: tr('foregroundService'),
|
||||||
notificationText: tr('placeholder'),
|
notificationText: tr('fgServiceNotice'),
|
||||||
notificationIcon: NotificationIcon(
|
notificationIcon: NotificationIcon(
|
||||||
metaDataName: 'dev.imranr.obtainium.service.NOTIFICATION_ICON',
|
metaDataName: 'dev.imranr.obtainium.service.NOTIFICATION_ICON',
|
||||||
),
|
),
|
||||||
callback: startCallback,
|
callback: startCallback,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
stopForegroundService() async {
|
||||||
|
if (await FlutterForegroundTask.isRunningService) {
|
||||||
|
return FlutterForegroundTask.stopService();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// void onReceiveForegroundServiceData(Object data) {
|
// void onReceiveForegroundServiceData(Object data) {
|
||||||
@ -244,7 +249,11 @@ class _ObtainiumState extends State<Obtainium> {
|
|||||||
AppsProvider appsProvider = context.read<AppsProvider>();
|
AppsProvider appsProvider = context.read<AppsProvider>();
|
||||||
LogsProvider logs = context.read<LogsProvider>();
|
LogsProvider logs = context.read<LogsProvider>();
|
||||||
NotificationsProvider notifs = context.read<NotificationsProvider>();
|
NotificationsProvider notifs = context.read<NotificationsProvider>();
|
||||||
startForegroundService();
|
if (settingsProvider.updateInterval == 0) {
|
||||||
|
stopForegroundService();
|
||||||
|
} else {
|
||||||
|
startForegroundService(false);
|
||||||
|
}
|
||||||
if (settingsProvider.prefs == null) {
|
if (settingsProvider.prefs == null) {
|
||||||
settingsProvider.initializeSettings();
|
settingsProvider.initializeSettings();
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user