expo-task-manager 11.8.1 → 11.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -10,6 +10,12 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 11.8.2 — 2024-05-29
14
+
15
+ ### 🐛 Bug fixes
16
+
17
+ - [Android] Fix the task manager events not being sent to the JS side. ([#29024](https://github.com/expo/expo/pull/29024) by [@behenate](https://github.com/behenate))
18
+
13
19
  ## 11.8.1 — 2024-04-23
14
20
 
15
21
  _This version does not introduce any user-facing changes._
@@ -1,7 +1,7 @@
1
1
  apply plugin: 'com.android.library'
2
2
 
3
3
  group = 'host.exp.exponent'
4
- version = '11.8.1'
4
+ version = '11.8.2'
5
5
 
6
6
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
7
7
  apply from: expoModulesCorePlugin
@@ -14,7 +14,7 @@ android {
14
14
  namespace "expo.modules.taskManager"
15
15
  defaultConfig {
16
16
  versionCode 23
17
- versionName "11.8.1"
17
+ versionName "11.8.2"
18
18
  }
19
19
  }
20
20
 
@@ -0,0 +1,9 @@
1
+ package expo.modules.taskManager;
2
+
3
+ import android.os.Bundle;
4
+
5
+ // Wrapper used for passing the emit function from the EventEmitter between Kotlin and Java
6
+ @FunctionalInterface
7
+ interface EmitEventWrapper {
8
+ void emit(String name, Bundle body);
9
+ }
@@ -2,11 +2,11 @@ package expo.modules.taskManager;
2
2
 
3
3
  import android.content.Context;
4
4
  import android.os.Bundle;
5
+ import android.util.Log;
5
6
 
6
7
  import expo.modules.core.ModuleRegistry;
7
8
  import expo.modules.core.interfaces.InternalModule;
8
9
  import expo.modules.core.interfaces.LifecycleEventListener;
9
- import expo.modules.core.interfaces.services.EventEmitter;
10
10
  import expo.modules.core.interfaces.services.UIManager;
11
11
 
12
12
  import java.lang.ref.WeakReference;
@@ -22,11 +22,11 @@ import expo.modules.interfaces.taskManager.TaskServiceInterface;
22
22
 
23
23
  public class TaskManagerInternalModule implements InternalModule, TaskManagerInterface, LifecycleEventListener {
24
24
  private UIManager mUIManager;
25
- private EventEmitter mEventEmitter;
26
25
  private ConstantsInterface mConstants;
27
26
  private TaskServiceInterface mTaskService;
28
27
  private WeakReference<Context> mContextRef;
29
28
  private List<Bundle> mEventsQueue = new ArrayList<>();
29
+ private EmitEventWrapper mEmitEventWrapper;
30
30
 
31
31
  public TaskManagerInternalModule(Context context) {
32
32
  mContextRef = new WeakReference<>(context);
@@ -39,13 +39,16 @@ public class TaskManagerInternalModule implements InternalModule, TaskManagerInt
39
39
  return Collections.singletonList(TaskManagerInterface.class);
40
40
  }
41
41
 
42
+ public void setEmitEventWrapper(EmitEventWrapper emitEventWrapper) {
43
+ mEmitEventWrapper = emitEventWrapper;
44
+ }
45
+
42
46
  //endregion
43
47
  //region ModuleRegistryConsumer
44
48
 
45
49
  @Override
46
50
  public void onCreate(ModuleRegistry moduleRegistry) {
47
51
  mUIManager = moduleRegistry.getModule(UIManager.class);
48
- mEventEmitter = moduleRegistry.getModule(EventEmitter.class);
49
52
  mConstants = moduleRegistry.getModule(ConstantsInterface.class);
50
53
  mTaskService = moduleRegistry.getSingletonModule("TaskService", TaskServiceInterface.class);
51
54
 
@@ -83,7 +86,7 @@ public class TaskManagerInternalModule implements InternalModule, TaskManagerInt
83
86
  mEventsQueue.add(body);
84
87
  } else {
85
88
  // Manager is already being observed by JS app, so we can execute the event immediately.
86
- mEventEmitter.emit(TaskManagerInterface.EVENT_NAME, body);
89
+ emitEvent(body);
87
90
  }
88
91
  }
89
92
 
@@ -100,7 +103,7 @@ public class TaskManagerInternalModule implements InternalModule, TaskManagerInt
100
103
  // Execute any events that came before this call.
101
104
  if (mEventsQueue != null) {
102
105
  for (Bundle body : mEventsQueue) {
103
- mEventEmitter.emit(TaskManagerInterface.EVENT_NAME, body);
106
+ emitEvent(body);
104
107
  }
105
108
  mEventsQueue = null;
106
109
  }
@@ -183,5 +186,13 @@ public class TaskManagerInternalModule implements InternalModule, TaskManagerInt
183
186
  }
184
187
  }
185
188
 
189
+ private void emitEvent(Bundle body) {
190
+ if (mEmitEventWrapper != null) {
191
+ mEmitEventWrapper.emit(TaskManagerInterface.EVENT_NAME, body);
192
+ } else {
193
+ Log.e("ExpoTaskManager", "EmitEventWrapper is not set. Failed to emit the TaskManager Event.");
194
+ }
195
+ }
196
+
186
197
  //endregion
187
198
  }
@@ -3,11 +3,13 @@ package expo.modules.taskManager
3
3
  import android.os.Bundle
4
4
  import android.os.Handler
5
5
  import android.os.Looper
6
+ import android.util.Log
6
7
  import expo.modules.core.errors.ModuleNotFoundException
7
8
  import expo.modules.interfaces.taskManager.TaskManagerInterface
8
9
  import expo.modules.interfaces.taskManager.TaskServiceInterface
9
10
  import expo.modules.kotlin.modules.Module
10
11
  import expo.modules.kotlin.modules.ModuleDefinition
12
+ import java.lang.ref.WeakReference
11
13
 
12
14
  class TaskManagerModule : Module() {
13
15
  private val _taskService: TaskServiceInterface? by lazy {
@@ -30,6 +32,26 @@ class TaskManagerModule : Module() {
30
32
  "EVENT_NAME" to TaskManagerInterface.EVENT_NAME
31
33
  )
32
34
 
35
+ OnCreate {
36
+ // Slightly hacky way to be able to emit events using the new event emitter from legacy modules.
37
+ val weakModule = WeakReference(this@TaskManagerModule)
38
+ val emitEvent = { name: String, body: Bundle ->
39
+ try {
40
+ // It may throw, because RN event emitter may not be available
41
+ // we can just ignore those cases
42
+ weakModule.get()?.sendEvent(name, body)
43
+ } catch (error: Throwable) {
44
+ Log.e("ExpoTaskManager", "Failed to emit event $name using the module's event emitter: ${error.message}")
45
+ }
46
+ Unit
47
+ }
48
+
49
+ // For compatibility reasons, we don't want to edit TaskManagerInterface, as it's in the expo-modules-core package.
50
+ // There is only one usage of the TaskManagerInterface and it's the TaskManagerInternalModule, so we can safely cast
51
+ // to it and set it's emitEventWrapper.
52
+ (appContext.legacyModule<TaskManagerInterface>() as? TaskManagerInternalModule)?.setEmitEventWrapper(emitEvent)
53
+ }
54
+
33
55
  AsyncFunction<Boolean>("isAvailableAsync") {
34
56
  return@AsyncFunction true
35
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-task-manager",
3
- "version": "11.8.1",
3
+ "version": "11.8.2",
4
4
  "description": "Expo module that provides support for tasks that can run in the background.",
5
5
  "main": "build/TaskManager.js",
6
6
  "types": "build/TaskManager.d.ts",
@@ -41,5 +41,5 @@
41
41
  "peerDependencies": {
42
42
  "expo": "*"
43
43
  },
44
- "gitHead": "ee4f30ef3b5fa567ad1bf94794197f7683fdd481"
44
+ "gitHead": "979e9f1fc3cfa9c827700dcf99992e671cfdf63e"
45
45
  }