Line data Source code
1 : import 'package:plugin_platform_interface/plugin_platform_interface.dart';
2 :
3 : import 'constraints.dart';
4 : import 'events.dart';
5 : import 'method_channel.dart';
6 : import 'remote_trigger.dart';
7 : import 'task_trigger.dart';
8 : import 'worker.dart';
9 :
10 : /// Platform interface for native_workmanager plugin.
11 : abstract class NativeWorkManagerPlatform extends PlatformInterface {
12 21 : NativeWorkManagerPlatform() : super(token: _token);
13 :
14 21 : static final Object _token = Object();
15 :
16 14 : static NativeWorkManagerPlatform _instance = MethodChannelNativeWorkManager();
17 :
18 : /// The default instance of [NativeWorkManagerPlatform].
19 12 : static NativeWorkManagerPlatform get instance => _instance;
20 :
21 : /// Platform-specific implementations should set this.
22 2 : static set instance(NativeWorkManagerPlatform instance) {
23 4 : PlatformInterface.verifyToken(instance, _token);
24 : _instance = instance;
25 : }
26 :
27 : /// Initialize the work manager.
28 : ///
29 : /// [callbackHandle] - Handle of the Dart callback dispatcher for Dart workers.
30 : /// If null, only native workers can be used.
31 : ///
32 : /// [debugMode] - Enable debug notifications for task events.
33 : /// Only works in debug builds.
34 : ///
35 : /// [maxConcurrentTasks] - Maximum number of worker tasks that may run
36 : /// simultaneously. Defaults to 4. On iOS this is enforced by a semaphore
37 : /// in the plugin; on Android WorkManager's own thread pool handles it.
38 : ///
39 : /// [diskSpaceBufferMB] - Minimum free disk space (in MB) the OS must have
40 : /// before any download worker is allowed to run. Defaults to 20 MB.
41 : ///
42 : /// [cleanupAfterDays] - Automatically delete completed/failed/cancelled task
43 : /// records older than this many days on each initialize(). 0 = disabled.
44 : /// Defaults to 30 days to prevent unbounded SQLite growth.
45 : ///
46 : /// [enforceHttps] - When true, all HTTP workers reject plain-HTTP URLs and
47 : /// only allow HTTPS. Defaults to false for backward compatibility.
48 : ///
49 : /// [blockPrivateIPs] - When true, HTTP workers block requests to
50 : /// private/loopback IP ranges (10.x, 172.16-31.x, 192.168.x, 127.x, ::1)
51 : /// to prevent SSRF attacks. Defaults to false for backward compatibility.
52 : ///
53 : /// [registerPlugins] - When true, the background Flutter Engine will
54 : /// automatically register all plugins. Required for using other plugins
55 : /// in the background. Defaults to false. If false, you can still register
56 : /// plugins manually on the native side via `NativeWorkmanagerPlugin.setPluginRegistrantCallback`.
57 0 : Future<void> initialize({
58 : int? callbackHandle,
59 : bool debugMode = false,
60 : int maxConcurrentTasks = 4,
61 : int diskSpaceBufferMB = 20,
62 : int cleanupAfterDays = 30,
63 : bool enforceHttps = false,
64 : bool blockPrivateIPs = false,
65 : bool registerPlugins = false,
66 : }) {
67 0 : throw UnimplementedError('initialize() has not been implemented.');
68 : }
69 :
70 : /// Schedule a task.
71 0 : Future<ScheduleResult> enqueue({
72 : required String taskId,
73 : required TaskTrigger trigger,
74 : required Worker worker,
75 : required Constraints constraints,
76 : required ExistingTaskPolicy existingPolicy,
77 : String? tag,
78 : }) {
79 0 : throw UnimplementedError('enqueue() has not been implemented.');
80 : }
81 :
82 : /// Cancel all tasks with a specific tag.
83 0 : Future<void> cancelByTag({required String tag}) {
84 0 : throw UnimplementedError('cancelByTag() has not been implemented.');
85 : }
86 :
87 : /// Get all tasks with a specific tag.
88 0 : Future<List<String>> getTasksByTag({required String tag}) {
89 0 : throw UnimplementedError('getTasksByTag() has not been implemented.');
90 : }
91 :
92 : /// Get all tags currently in use.
93 0 : Future<List<String>> getAllTags() {
94 0 : throw UnimplementedError('getAllTags() has not been implemented.');
95 : }
96 :
97 : /// Cancel a task by ID.
98 0 : Future<void> cancel({required String taskId}) {
99 0 : throw UnimplementedError('cancel() has not been implemented.');
100 : }
101 :
102 : /// Cancel all tasks.
103 0 : Future<void> cancelAll() {
104 0 : throw UnimplementedError('cancelAll() has not been implemented.');
105 : }
106 :
107 : /// Get task status.
108 0 : Future<TaskStatus?> getTaskStatus({required String taskId}) {
109 0 : throw UnimplementedError('getTaskStatus() has not been implemented.');
110 : }
111 :
112 : /// Get detailed task record.
113 0 : Future<TaskRecord?> getTaskRecord({required String taskId}) {
114 0 : throw UnimplementedError('getTaskRecord() has not been implemented.');
115 : }
116 :
117 : /// Schedule a task chain.
118 0 : Future<ScheduleResult> enqueueChain(Map<String, dynamic> chainData) {
119 0 : throw UnimplementedError('enqueueChain() has not been implemented.');
120 : }
121 :
122 : /// Stream of task completion events.
123 0 : Stream<TaskEvent> get events {
124 0 : throw UnimplementedError('events has not been implemented.');
125 : }
126 :
127 : /// Stream of task progress updates.
128 0 : Stream<TaskProgress> get progress {
129 0 : throw UnimplementedError('progress has not been implemented.');
130 : }
131 :
132 : /// Stream of system-level errors (e.g. Disk Full).
133 0 : Stream<SystemError> get systemErrors {
134 0 : throw UnimplementedError('systemErrors has not been implemented.');
135 : }
136 :
137 : /// Pause a running task (best-effort; saves resume data where possible).
138 0 : Future<void> pauseTask({required String taskId}) {
139 0 : throw UnimplementedError('pauseTask() has not been implemented.');
140 : }
141 :
142 : /// Resume a previously paused task.
143 0 : Future<void> resumeTask({required String taskId}) {
144 0 : throw UnimplementedError('resumeTask() has not been implemented.');
145 : }
146 :
147 : /// Return all tasks from the persistent task store.
148 0 : Future<List<TaskRecord>> allTasks() {
149 0 : throw UnimplementedError('allTasks() has not been implemented.');
150 : }
151 :
152 : /// Fetch the server-suggested filename for a URL by sending a HEAD request
153 : /// and parsing the Content-Disposition header (RFC 6266).
154 : ///
155 : /// Returns the sanitized filename, or `null` if the server did not provide one.
156 0 : Future<String?> getServerFilename({
157 : required String url,
158 : Map<String, String>? headers,
159 : int timeoutMs = 30000,
160 : }) {
161 0 : throw UnimplementedError('getServerFilename() has not been implemented.');
162 : }
163 :
164 : /// Get the current progress of all running tasks.
165 : ///
166 : /// Returns a map of task IDs to their latest progress update.
167 : /// Useful for "re-attaching" to progress streams when the app restarts.
168 0 : Future<Map<String, dynamic>> getRunningProgress() {
169 0 : throw UnimplementedError('getRunningProgress() has not been implemented.');
170 : }
171 :
172 : /// Open a file with the OS default viewer/handler.
173 : ///
174 : /// On Android, uses `Intent.ACTION_VIEW` via `FileProvider`.
175 : /// On iOS, presents a `UIDocumentInteractionController`.
176 : ///
177 : /// [path] — absolute path to the file.
178 : /// [mimeType] — optional MIME type hint. If null, the OS infers from extension.
179 0 : Future<void> openFile(String path, {String? mimeType}) {
180 0 : throw UnimplementedError('openFile() has not been implemented.');
181 : }
182 :
183 : /// Set the maximum number of concurrent downloads per host.
184 : ///
185 : /// When multiple downloads target the same host, this limits how many run
186 : /// simultaneously. Defaults to 2.
187 0 : Future<void> setMaxConcurrentPerHost(int max) {
188 0 : throw UnimplementedError(
189 : 'setMaxConcurrentPerHost() has not been implemented.');
190 : }
191 :
192 : /// Register a remote trigger for background task execution.
193 : ///
194 : /// This allows the plugin to automatically enqueue native workers when a
195 : /// remote message (FCM/APNs) is received, without waking the Flutter Engine.
196 : ///
197 : /// Rules are persisted on the native side.
198 0 : Future<void> registerRemoteTrigger({
199 : required RemoteTriggerSource source,
200 : required RemoteTriggerRule rule,
201 : }) {
202 0 : throw UnimplementedError(
203 : 'registerRemoteTrigger() has not been implemented.');
204 : }
205 :
206 : /// Enqueue a task graph for native execution.
207 : ///
208 : /// This moves graph orchestration to the native layer, allowing it to
209 : /// survive app termination.
210 0 : Future<String> enqueueGraph(Map<String, dynamic> graphMap) {
211 0 : throw UnimplementedError('enqueueGraph() has not been implemented.');
212 : }
213 :
214 : /// Enqueue a task to the native offline queue.
215 : ///
216 : /// This moves queue management to the native layer, allowing tasks to
217 : /// be enqueued while offline and automatically processed when network
218 : /// is restored, even if the app is killed.
219 0 : Future<void> offlineQueueEnqueue(
220 : String queueId, Map<String, dynamic> entryMap) {
221 0 : throw UnimplementedError('offlineQueueEnqueue() has not been implemented.');
222 : }
223 :
224 : /// Register a middleware for background tasks.
225 : ///
226 : /// Middleware allows you to intercept and modify tasks globally on the
227 : /// native side.
228 0 : Future<void> registerMiddleware(Map<String, dynamic> middlewareMap) {
229 0 : throw UnimplementedError('registerMiddleware() has not been implemented.');
230 : }
231 :
232 : /// Set the Dart callback executor.
233 0 : void setCallbackExecutor(
234 : Future<bool> Function(String callbackId, Map<String, dynamic>? input)
235 : executor) {
236 0 : throw UnimplementedError('setCallbackExecutor() has not been implemented.');
237 : }
238 :
239 : /// Get real-time metrics from the native task store for DevTools.
240 : /// Returns a map with activeTasks, offlineQueueSize, failedTasks, completedTasks.
241 0 : Future<Map<String, dynamic>> getMetrics() {
242 0 : throw UnimplementedError('getMetrics() has not been implemented.');
243 : }
244 :
245 : /// Manually trigger processing of the native offline queue.
246 0 : Future<bool> syncOfflineQueue() {
247 0 : throw UnimplementedError('syncOfflineQueue() has not been implemented.');
248 : }
249 : }
|