@sigx/lynx-updates 0.7.0 → 0.8.0
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/LICENSE +21 -21
- package/README.md +199 -162
- package/android/com/sigx/updates/UpdateDownloader.kt +154 -154
- package/android/com/sigx/updates/UpdateStore.kt +367 -367
- package/android/com/sigx/updates/UpdatesActivityHook.kt +25 -25
- package/android/com/sigx/updates/UpdatesBundleResolver.kt +18 -18
- package/android/com/sigx/updates/UpdatesEventBus.kt +54 -54
- package/android/com/sigx/updates/UpdatesLifecyclePublisher.kt +42 -42
- package/android/com/sigx/updates/UpdatesModule.kt +235 -235
- package/dist/controller.js +1 -1
- package/dist/controller.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/native.d.ts.map +1 -1
- package/dist/native.js +4 -2
- package/dist/native.js.map +1 -1
- package/dist/provider/static-manifest.d.ts +41 -10
- package/dist/provider/static-manifest.d.ts.map +1 -1
- package/dist/provider/static-manifest.js +39 -5
- package/dist/provider/static-manifest.js.map +1 -1
- package/dist/types.d.ts +6 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/updates.d.ts +11 -20
- package/dist/updates.d.ts.map +1 -1
- package/dist/updates.js +13 -22
- package/dist/updates.js.map +1 -1
- package/ios/UpdateDownloader.swift +152 -152
- package/ios/UpdateStore.swift +286 -286
- package/ios/UpdatesBundleResolver.swift +15 -15
- package/ios/UpdatesEventBus.swift +59 -59
- package/ios/UpdatesLifecyclePublisher.swift +48 -48
- package/ios/UpdatesModule.swift +178 -178
- package/package.json +3 -3
- package/signalx-module.json +35 -35
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
package com.sigx.updates
|
|
2
|
-
|
|
3
|
-
import android.app.Activity
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Activity hook (declared in signalx-module.json) that turns resume-after-
|
|
7
|
-
* pause into a `foreground` event for JS `checkOn: ['foreground']` re-checks.
|
|
8
|
-
* The first onResume of a launch is swallowed — cold start is covered by
|
|
9
|
-
* the `launch` trigger and would otherwise double-check.
|
|
10
|
-
*/
|
|
11
|
-
object UpdatesActivityHook {
|
|
12
|
-
|
|
13
|
-
private var sawPause = false
|
|
14
|
-
|
|
15
|
-
fun onResume(activity: Activity) {
|
|
16
|
-
if (sawPause) {
|
|
17
|
-
sawPause = false
|
|
18
|
-
UpdatesEventBus.emitForeground()
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
fun onPause(activity: Activity) {
|
|
23
|
-
sawPause = true
|
|
24
|
-
}
|
|
25
|
-
}
|
|
1
|
+
package com.sigx.updates
|
|
2
|
+
|
|
3
|
+
import android.app.Activity
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Activity hook (declared in signalx-module.json) that turns resume-after-
|
|
7
|
+
* pause into a `foreground` event for JS `checkOn: ['foreground']` re-checks.
|
|
8
|
+
* The first onResume of a launch is swallowed — cold start is covered by
|
|
9
|
+
* the `launch` trigger and would otherwise double-check.
|
|
10
|
+
*/
|
|
11
|
+
object UpdatesActivityHook {
|
|
12
|
+
|
|
13
|
+
private var sawPause = false
|
|
14
|
+
|
|
15
|
+
fun onResume(activity: Activity) {
|
|
16
|
+
if (sawPause) {
|
|
17
|
+
sawPause = false
|
|
18
|
+
UpdatesEventBus.emitForeground()
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
fun onPause(activity: Activity) {
|
|
23
|
+
sawPause = true
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
package com.sigx.updates
|
|
2
|
-
|
|
3
|
-
import android.content.Context
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Startup bundle resolver — the host's `GeneratedBundleResolver` delegates
|
|
7
|
-
* here (declared as `android.bundleResolverClass` in signalx-module.json).
|
|
8
|
-
*
|
|
9
|
-
* Runs synchronously in MainActivity.onCreate BEFORE any LynxView is built,
|
|
10
|
-
* and mutates rollback state (the launch-attempt counter), so it must be
|
|
11
|
-
* called exactly once per process launch — which the generated host
|
|
12
|
-
* guarantees.
|
|
13
|
-
*/
|
|
14
|
-
object UpdatesBundleResolver {
|
|
15
|
-
|
|
16
|
-
fun resolveStartupBundlePath(context: Context): String? =
|
|
17
|
-
UpdateStore.resolveStartupBundlePath(context)
|
|
18
|
-
}
|
|
1
|
+
package com.sigx.updates
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Startup bundle resolver — the host's `GeneratedBundleResolver` delegates
|
|
7
|
+
* here (declared as `android.bundleResolverClass` in signalx-module.json).
|
|
8
|
+
*
|
|
9
|
+
* Runs synchronously in MainActivity.onCreate BEFORE any LynxView is built,
|
|
10
|
+
* and mutates rollback state (the launch-attempt counter), so it must be
|
|
11
|
+
* called exactly once per process launch — which the generated host
|
|
12
|
+
* guarantees.
|
|
13
|
+
*/
|
|
14
|
+
object UpdatesBundleResolver {
|
|
15
|
+
|
|
16
|
+
fun resolveStartupBundlePath(context: Context): String? =
|
|
17
|
+
UpdateStore.resolveStartupBundlePath(context)
|
|
18
|
+
}
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
package com.sigx.updates
|
|
2
|
-
|
|
3
|
-
import com.lynx.react.bridge.JavaOnlyMap
|
|
4
|
-
import java.util.UUID
|
|
5
|
-
import java.util.concurrent.ConcurrentHashMap
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Module → publisher event bus (the `BackgroundEventBus` pattern). The
|
|
9
|
-
* module emits download progress / foreground events here; the per-LynxView
|
|
10
|
-
* [UpdatesLifecyclePublisher] pumps them into JS via `sendGlobalEvent` on
|
|
11
|
-
* the `__sigxUpdatesEvent` channel.
|
|
12
|
-
*/
|
|
13
|
-
object UpdatesEventBus {
|
|
14
|
-
|
|
15
|
-
const val CHANNEL = "__sigxUpdatesEvent"
|
|
16
|
-
|
|
17
|
-
private val listeners = ConcurrentHashMap<UUID, (JavaOnlyMap) -> Unit>()
|
|
18
|
-
|
|
19
|
-
fun addListener(listener: (JavaOnlyMap) -> Unit): UUID {
|
|
20
|
-
val token = UUID.randomUUID()
|
|
21
|
-
listeners[token] = listener
|
|
22
|
-
return token
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
fun removeListener(token: UUID) {
|
|
26
|
-
listeners.remove(token)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
fun emit(payload: JavaOnlyMap) {
|
|
30
|
-
for (listener in listeners.values) {
|
|
31
|
-
try {
|
|
32
|
-
listener(payload)
|
|
33
|
-
} catch (_: Throwable) {
|
|
34
|
-
// A broken publisher must not break the others.
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
fun emitProgress(receivedBytes: Long, totalBytes: Long?) {
|
|
40
|
-
val map = JavaOnlyMap()
|
|
41
|
-
map.putString("kind", "progress")
|
|
42
|
-
map.putDouble("receivedBytes", receivedBytes.toDouble())
|
|
43
|
-
if (totalBytes != null && totalBytes >= 0) {
|
|
44
|
-
map.putDouble("totalBytes", totalBytes.toDouble())
|
|
45
|
-
}
|
|
46
|
-
emit(map)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
fun emitForeground() {
|
|
50
|
-
val map = JavaOnlyMap()
|
|
51
|
-
map.putString("kind", "foreground")
|
|
52
|
-
emit(map)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
1
|
+
package com.sigx.updates
|
|
2
|
+
|
|
3
|
+
import com.lynx.react.bridge.JavaOnlyMap
|
|
4
|
+
import java.util.UUID
|
|
5
|
+
import java.util.concurrent.ConcurrentHashMap
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Module → publisher event bus (the `BackgroundEventBus` pattern). The
|
|
9
|
+
* module emits download progress / foreground events here; the per-LynxView
|
|
10
|
+
* [UpdatesLifecyclePublisher] pumps them into JS via `sendGlobalEvent` on
|
|
11
|
+
* the `__sigxUpdatesEvent` channel.
|
|
12
|
+
*/
|
|
13
|
+
object UpdatesEventBus {
|
|
14
|
+
|
|
15
|
+
const val CHANNEL = "__sigxUpdatesEvent"
|
|
16
|
+
|
|
17
|
+
private val listeners = ConcurrentHashMap<UUID, (JavaOnlyMap) -> Unit>()
|
|
18
|
+
|
|
19
|
+
fun addListener(listener: (JavaOnlyMap) -> Unit): UUID {
|
|
20
|
+
val token = UUID.randomUUID()
|
|
21
|
+
listeners[token] = listener
|
|
22
|
+
return token
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
fun removeListener(token: UUID) {
|
|
26
|
+
listeners.remove(token)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
fun emit(payload: JavaOnlyMap) {
|
|
30
|
+
for (listener in listeners.values) {
|
|
31
|
+
try {
|
|
32
|
+
listener(payload)
|
|
33
|
+
} catch (_: Throwable) {
|
|
34
|
+
// A broken publisher must not break the others.
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
fun emitProgress(receivedBytes: Long, totalBytes: Long?) {
|
|
40
|
+
val map = JavaOnlyMap()
|
|
41
|
+
map.putString("kind", "progress")
|
|
42
|
+
map.putDouble("receivedBytes", receivedBytes.toDouble())
|
|
43
|
+
if (totalBytes != null && totalBytes >= 0) {
|
|
44
|
+
map.putDouble("totalBytes", totalBytes.toDouble())
|
|
45
|
+
}
|
|
46
|
+
emit(map)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
fun emitForeground() {
|
|
50
|
+
val map = JavaOnlyMap()
|
|
51
|
+
map.putString("kind", "foreground")
|
|
52
|
+
emit(map)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
package com.sigx.updates
|
|
2
|
-
|
|
3
|
-
import android.util.Log
|
|
4
|
-
import com.lynx.react.bridge.JavaOnlyArray
|
|
5
|
-
import com.lynx.react.bridge.JavaOnlyMap
|
|
6
|
-
import com.lynx.tasm.LynxView
|
|
7
|
-
import java.util.UUID
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Per-LynxView publisher: pumps [UpdatesEventBus] payloads into JS
|
|
11
|
-
* (`__sigxUpdatesEvent`) and registers the view with [UpdateStore] so
|
|
12
|
-
* `applyNow` has a reload target. Instantiated by the generated
|
|
13
|
-
* `GeneratedLifecyclePublishers.attachAll(lynxView)`.
|
|
14
|
-
*/
|
|
15
|
-
class UpdatesLifecyclePublisher(private val lynxView: LynxView) {
|
|
16
|
-
|
|
17
|
-
private var token: UUID? = null
|
|
18
|
-
|
|
19
|
-
fun attach() {
|
|
20
|
-
UpdateStore.attachView(lynxView)
|
|
21
|
-
token = UpdatesEventBus.addListener { payload -> publish(payload) }
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
fun detach() {
|
|
25
|
-
token?.let { UpdatesEventBus.removeListener(it) }
|
|
26
|
-
token = null
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
private fun publish(payload: JavaOnlyMap) {
|
|
30
|
-
try {
|
|
31
|
-
val params = JavaOnlyArray()
|
|
32
|
-
params.pushMap(payload)
|
|
33
|
-
lynxView.sendGlobalEvent(UpdatesEventBus.CHANNEL, params)
|
|
34
|
-
} catch (e: Throwable) {
|
|
35
|
-
Log.w(TAG, "publish failed: ${e.message}")
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
private companion object {
|
|
40
|
-
const val TAG = "SigxUpdates"
|
|
41
|
-
}
|
|
42
|
-
}
|
|
1
|
+
package com.sigx.updates
|
|
2
|
+
|
|
3
|
+
import android.util.Log
|
|
4
|
+
import com.lynx.react.bridge.JavaOnlyArray
|
|
5
|
+
import com.lynx.react.bridge.JavaOnlyMap
|
|
6
|
+
import com.lynx.tasm.LynxView
|
|
7
|
+
import java.util.UUID
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Per-LynxView publisher: pumps [UpdatesEventBus] payloads into JS
|
|
11
|
+
* (`__sigxUpdatesEvent`) and registers the view with [UpdateStore] so
|
|
12
|
+
* `applyNow` has a reload target. Instantiated by the generated
|
|
13
|
+
* `GeneratedLifecyclePublishers.attachAll(lynxView)`.
|
|
14
|
+
*/
|
|
15
|
+
class UpdatesLifecyclePublisher(private val lynxView: LynxView) {
|
|
16
|
+
|
|
17
|
+
private var token: UUID? = null
|
|
18
|
+
|
|
19
|
+
fun attach() {
|
|
20
|
+
UpdateStore.attachView(lynxView)
|
|
21
|
+
token = UpdatesEventBus.addListener { payload -> publish(payload) }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
fun detach() {
|
|
25
|
+
token?.let { UpdatesEventBus.removeListener(it) }
|
|
26
|
+
token = null
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private fun publish(payload: JavaOnlyMap) {
|
|
30
|
+
try {
|
|
31
|
+
val params = JavaOnlyArray()
|
|
32
|
+
params.pushMap(payload)
|
|
33
|
+
lynxView.sendGlobalEvent(UpdatesEventBus.CHANNEL, params)
|
|
34
|
+
} catch (e: Throwable) {
|
|
35
|
+
Log.w(TAG, "publish failed: ${e.message}")
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private companion object {
|
|
40
|
+
const val TAG = "SigxUpdates"
|
|
41
|
+
}
|
|
42
|
+
}
|