native-update 5.0.1 → 5.0.3
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/README.md +2 -2
- package/android/build.gradle +13 -1
- package/android/src/foreground/java/com/aoneahsan/nativeupdate/BackgroundNotificationManager.kt +34 -0
- package/android/src/main/AndroidManifest.xml +6 -7
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdatePlugin.kt +16 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/LiveUpdatePlugin.kt +1 -1
- package/android/src/main/java/com/aoneahsan/nativeupdate/NotificationModels.kt +96 -0
- package/android/src/notifications/AndroidManifest.xml +13 -0
- package/android/src/{main → notifications}/java/com/aoneahsan/nativeupdate/BackgroundNotificationManager.kt +40 -135
- package/cli/commands/bundle-create.js +4 -21
- package/cli/commands/flutter-patch.js +2 -11
- package/cli/commands/remote-shared.js +8 -13
- package/cli/lib/archive-directory.js +54 -0
- package/cli/package.json +1 -1
- package/dist/esm/core/update-check.d.ts +1 -1
- package/dist/esm/core/update-check.js +1 -1
- package/dist/plugin.cjs +1 -1
- package/dist/plugin.esm.js +1 -1
- package/dist/plugin.js +2 -2
- package/docs/CHANGELOG.md +12 -0
- package/docs/MIGRATION.md +5 -1
- package/ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift +1 -1
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ are available as an HTTP API for CI and coding agents.
|
|
|
38
38
|
|
|
39
39
|
| | |
|
|
40
40
|
|---|---|
|
|
41
|
-
| **Version** | `5.0.
|
|
41
|
+
| **Version** | `5.0.3` |
|
|
42
42
|
| **License** | Proprietary — free to use in your apps ([Native Update License](https://unpkg.com/native-update@latest/LICENSE)) |
|
|
43
43
|
| **Node** | `>=24.16.0` (install + CLI toolchain) |
|
|
44
44
|
| **Platforms** | iOS 16+ (implementation pending device proof) · Android 8.0+ (API 26) · Web |
|
|
@@ -543,7 +543,7 @@ indexed at [`/raw/manifest.json`](https://nativeupdate-docs.aoneahsan.com/raw/ma
|
|
|
543
543
|
<a id="changelog"></a>
|
|
544
544
|
## 🔄 Changelog [#](#changelog)
|
|
545
545
|
|
|
546
|
-
Current release: **`5.0.
|
|
546
|
+
Current release: **`5.0.3`**. Foreground-only Android apps can build without notification permissions by setting `nativeUpdateNotificationsEnabled=false` in `android/gradle.properties`; the default keeps background notifications. CLI ZIP creation no longer depends on the vulnerable archive chain. Android now reads packaged Capacitor configuration, and flexible Play updates wait for a user-confirmed restart. The Capacitor 9 migration landed in v5; see the [migration guide](https://unpkg.com/native-update@latest/docs/MIGRATION.md). In 4.4.5, `set()` gained `applyOn: 'next-start'`, which stages a bundle for the next cold start instead of reloading the running app. Before that, 4.4.4: `--ota-tag` reads `versionName` only from a real statement in `build.gradle`
|
|
547
547
|
(comments and message strings are skipped, `versionName appVersionName` is followed to its value). **`4.4.3`**: Android logs `Built <id> from a N-byte patch` when an update arrives as a `NUDELTA/1`
|
|
548
548
|
patch, so you can see deltas working on a device. No API change.
|
|
549
549
|
|
package/android/build.gradle
CHANGED
|
@@ -23,14 +23,26 @@ ext {
|
|
|
23
23
|
|
|
24
24
|
apply plugin: 'com.android.library'
|
|
25
25
|
|
|
26
|
+
def notificationSetting = rootProject.findProperty('nativeUpdateNotificationsEnabled')?.toString() ?: 'true'
|
|
27
|
+
if (!(notificationSetting in ['true', 'false'])) {
|
|
28
|
+
throw new GradleException('nativeUpdateNotificationsEnabled must be true or false')
|
|
29
|
+
}
|
|
30
|
+
def notificationsEnabled = notificationSetting.toBoolean()
|
|
31
|
+
|
|
26
32
|
android {
|
|
27
33
|
namespace = "com.aoneahsan.nativeupdate"
|
|
28
34
|
compileSdk = project.compileSdkVersion
|
|
35
|
+
sourceSets {
|
|
36
|
+
main {
|
|
37
|
+
kotlin.srcDir notificationsEnabled ? 'src/notifications/java' : 'src/foreground/java'
|
|
38
|
+
manifest.srcFile notificationsEnabled ? 'src/notifications/AndroidManifest.xml' : 'src/main/AndroidManifest.xml'
|
|
39
|
+
}
|
|
40
|
+
}
|
|
29
41
|
|
|
30
42
|
defaultConfig {
|
|
31
43
|
minSdkVersion project.minSdkVersion
|
|
32
44
|
versionCode 1
|
|
33
|
-
versionName "5.0.
|
|
45
|
+
versionName "5.0.3"
|
|
34
46
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
35
47
|
// Shipped to every consuming app's R8 run (ISSUE-09).
|
|
36
48
|
consumerProguardFiles 'consumer-rules.pro'
|
package/android/src/foreground/java/com/aoneahsan/nativeupdate/BackgroundNotificationManager.kt
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
package com.aoneahsan.nativeupdate
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import com.getcapacitor.JSObject
|
|
5
|
+
|
|
6
|
+
/** Notification-free implementation selected for foreground-only consumers. */
|
|
7
|
+
class BackgroundNotificationManager(
|
|
8
|
+
private val context: Context,
|
|
9
|
+
private val eventListener: (String, JSObject) -> Unit
|
|
10
|
+
) {
|
|
11
|
+
val isSupported = false
|
|
12
|
+
|
|
13
|
+
companion object {
|
|
14
|
+
fun cancelNotificationStatic(context: Context) = Unit
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
fun createNotificationChannel() = Unit
|
|
18
|
+
|
|
19
|
+
fun setPreferences(preferencesData: JSObject) = Unit
|
|
20
|
+
|
|
21
|
+
fun getPermissionStatus() = NotificationPermissionStatus(
|
|
22
|
+
granted = false,
|
|
23
|
+
canRequest = false,
|
|
24
|
+
shouldShowRationale = false
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
fun requestPermissions() = false
|
|
28
|
+
|
|
29
|
+
fun sendUpdateNotification(appUpdate: AppUpdateStatus?, liveUpdate: LatestVersion?) = false
|
|
30
|
+
|
|
31
|
+
fun cancelNotification() = Unit
|
|
32
|
+
|
|
33
|
+
fun cancelUpdateNotification() = Unit
|
|
34
|
+
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
2
|
+
xmlns:tools="http://schemas.android.com/tools">
|
|
2
3
|
|
|
3
4
|
<!-- Required permissions -->
|
|
4
5
|
<uses-permission android:name="android.permission.INTERNET" />
|
|
5
6
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
|
9
|
-
<uses-permission android:name="android.permission.
|
|
10
|
-
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
|
11
|
-
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
|
7
|
+
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" tools:node="remove" />
|
|
8
|
+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" tools:node="remove" />
|
|
9
|
+
<uses-permission android:name="android.permission.WAKE_LOCK" tools:node="remove" />
|
|
10
|
+
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" tools:node="remove" />
|
|
12
11
|
|
|
13
12
|
</manifest>
|
|
@@ -37,6 +37,10 @@ class BackgroundUpdatePlugin(private val context: Context) {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
fun enableBackgroundUpdates(call: PluginCall) {
|
|
40
|
+
if (!notificationManager.isSupported) {
|
|
41
|
+
call.reject("Background updates require nativeUpdateNotificationsEnabled=true")
|
|
42
|
+
return
|
|
43
|
+
}
|
|
40
44
|
try {
|
|
41
45
|
val configData = call.data
|
|
42
46
|
val config = BackgroundUpdateConfig.fromJSObject(configData)
|
|
@@ -66,12 +70,20 @@ class BackgroundUpdatePlugin(private val context: Context) {
|
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
fun scheduleBackgroundCheck(call: PluginCall) {
|
|
73
|
+
if (!notificationManager.isSupported) {
|
|
74
|
+
call.reject("Background updates require nativeUpdateNotificationsEnabled=true")
|
|
75
|
+
return
|
|
76
|
+
}
|
|
69
77
|
val interval = call.getLong("interval") ?: (24 * 60 * 60 * 1000L) // Default 24 hours
|
|
70
78
|
scheduleBackgroundWork(interval)
|
|
71
79
|
call.resolve()
|
|
72
80
|
}
|
|
73
81
|
|
|
74
82
|
fun triggerBackgroundCheck(call: PluginCall) {
|
|
83
|
+
if (!notificationManager.isSupported) {
|
|
84
|
+
call.reject("Background updates require nativeUpdateNotificationsEnabled=true")
|
|
85
|
+
return
|
|
86
|
+
}
|
|
75
87
|
val workRequest = OneTimeWorkRequestBuilder<BackgroundUpdateWorker>()
|
|
76
88
|
.setInputData(createWorkData())
|
|
77
89
|
.addTag(WORK_TAG)
|
|
@@ -98,6 +110,10 @@ class BackgroundUpdatePlugin(private val context: Context) {
|
|
|
98
110
|
}
|
|
99
111
|
|
|
100
112
|
fun setNotificationPreferences(call: PluginCall) {
|
|
113
|
+
if (!notificationManager.isSupported) {
|
|
114
|
+
call.reject("Notifications require nativeUpdateNotificationsEnabled=true")
|
|
115
|
+
return
|
|
116
|
+
}
|
|
101
117
|
val preferences = call.data
|
|
102
118
|
notificationManager.setPreferences(preferences)
|
|
103
119
|
call.resolve()
|
|
@@ -62,7 +62,7 @@ class LiveUpdatePlugin(
|
|
|
62
62
|
|
|
63
63
|
companion object {
|
|
64
64
|
/** This plugin's version, sent as X-Sdk-Version. Kept equal to package.json by tests/sdk-version.test.ts. */
|
|
65
|
-
const val SDK_VERSION = "5.0.
|
|
65
|
+
const val SDK_VERSION = "5.0.3"
|
|
66
66
|
|
|
67
67
|
// SharedPreferences keys. Kept as constants so A2 (boot-time
|
|
68
68
|
// re-verification) and A3 (crash-loop auto-rollback) stay in sync
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
package com.aoneahsan.nativeupdate
|
|
2
|
+
|
|
3
|
+
import com.getcapacitor.JSObject
|
|
4
|
+
|
|
5
|
+
data class NotificationPreferences(
|
|
6
|
+
val title: String? = null,
|
|
7
|
+
val description: String? = null,
|
|
8
|
+
val iconName: String? = null,
|
|
9
|
+
val soundEnabled: Boolean = true,
|
|
10
|
+
val vibrationEnabled: Boolean = true,
|
|
11
|
+
val showActions: Boolean = true,
|
|
12
|
+
val actionLabels: ActionLabels? = null,
|
|
13
|
+
val channelId: String? = null,
|
|
14
|
+
val channelName: String? = null,
|
|
15
|
+
val priority: NotificationPriority = NotificationPriority.DEFAULT
|
|
16
|
+
) {
|
|
17
|
+
companion object {
|
|
18
|
+
fun default(): NotificationPreferences {
|
|
19
|
+
return NotificationPreferences(
|
|
20
|
+
title = "App Update Available",
|
|
21
|
+
description = "A new version of the app is available",
|
|
22
|
+
actionLabels = ActionLabels.default()
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
fun fromJSObject(obj: JSObject): NotificationPreferences {
|
|
27
|
+
val actionLabelsObj = obj.getJSObject("actionLabels")
|
|
28
|
+
val priorityString = obj.getString("priority", "default")
|
|
29
|
+
|
|
30
|
+
return NotificationPreferences(
|
|
31
|
+
title = obj.getString("title"),
|
|
32
|
+
description = obj.getString("description"),
|
|
33
|
+
iconName = obj.getString("iconName"),
|
|
34
|
+
soundEnabled = obj.getBoolean("soundEnabled", true) ?: true,
|
|
35
|
+
vibrationEnabled = obj.getBoolean("vibrationEnabled", true) ?: true,
|
|
36
|
+
showActions = obj.getBoolean("showActions", true) ?: true,
|
|
37
|
+
actionLabels = actionLabelsObj?.let { ActionLabels.fromJSObject(it) } ?: ActionLabels.default(),
|
|
38
|
+
channelId = obj.getString("channelId"),
|
|
39
|
+
channelName = obj.getString("channelName"),
|
|
40
|
+
priority = NotificationPriority.fromString(priorityString ?: "default")
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
data class ActionLabels(
|
|
47
|
+
val updateNow: String? = null,
|
|
48
|
+
val updateLater: String? = null,
|
|
49
|
+
val dismiss: String? = null
|
|
50
|
+
) {
|
|
51
|
+
companion object {
|
|
52
|
+
fun default(): ActionLabels {
|
|
53
|
+
return ActionLabels(
|
|
54
|
+
updateNow = "Update Now",
|
|
55
|
+
updateLater = "Later",
|
|
56
|
+
dismiss = "Dismiss"
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
fun fromJSObject(obj: JSObject): ActionLabels {
|
|
61
|
+
return ActionLabels(
|
|
62
|
+
updateNow = obj.getString("updateNow"),
|
|
63
|
+
updateLater = obj.getString("updateLater"),
|
|
64
|
+
dismiss = obj.getString("dismiss")
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
enum class NotificationPriority(val value: String) {
|
|
71
|
+
MIN("min"),
|
|
72
|
+
LOW("low"),
|
|
73
|
+
DEFAULT("default"),
|
|
74
|
+
HIGH("high"),
|
|
75
|
+
MAX("max");
|
|
76
|
+
|
|
77
|
+
companion object {
|
|
78
|
+
fun fromString(value: String): NotificationPriority {
|
|
79
|
+
return values().find { it.value == value } ?: DEFAULT
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
data class NotificationPermissionStatus(
|
|
85
|
+
val granted: Boolean,
|
|
86
|
+
val canRequest: Boolean,
|
|
87
|
+
val shouldShowRationale: Boolean? = null
|
|
88
|
+
) {
|
|
89
|
+
fun toJSObject(): JSObject {
|
|
90
|
+
val obj = JSObject()
|
|
91
|
+
obj.put("granted", granted)
|
|
92
|
+
obj.put("canRequest", canRequest)
|
|
93
|
+
shouldShowRationale?.let { obj.put("shouldShowRationale", it) }
|
|
94
|
+
return obj
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
2
|
+
|
|
3
|
+
<!-- Required permissions -->
|
|
4
|
+
<uses-permission android:name="android.permission.INTERNET" />
|
|
5
|
+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
|
6
|
+
|
|
7
|
+
<!-- Background update permissions -->
|
|
8
|
+
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
|
9
|
+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
|
10
|
+
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
|
11
|
+
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
|
12
|
+
|
|
13
|
+
</manifest>
|
|
@@ -3,7 +3,6 @@ package com.aoneahsan.nativeupdate
|
|
|
3
3
|
import android.app.NotificationChannel
|
|
4
4
|
import android.app.NotificationManager
|
|
5
5
|
import android.app.PendingIntent
|
|
6
|
-
import android.annotation.SuppressLint
|
|
7
6
|
import android.content.Context
|
|
8
7
|
import android.content.Intent
|
|
9
8
|
import android.content.pm.PackageManager
|
|
@@ -12,13 +11,13 @@ import androidx.core.app.NotificationCompat
|
|
|
12
11
|
import androidx.core.app.NotificationManagerCompat
|
|
13
12
|
import androidx.core.content.ContextCompat
|
|
14
13
|
import com.getcapacitor.JSObject
|
|
15
|
-
import com.getcapacitor.Plugin
|
|
16
14
|
|
|
17
15
|
class BackgroundNotificationManager(
|
|
18
16
|
private val context: Context,
|
|
19
17
|
private val eventListener: (String, JSObject) -> Unit
|
|
20
18
|
) {
|
|
21
|
-
|
|
19
|
+
val isSupported = true
|
|
20
|
+
|
|
22
21
|
companion object {
|
|
23
22
|
private const val CHANNEL_ID = "capacitor_native_update"
|
|
24
23
|
private const val CHANNEL_NAME = "App Updates"
|
|
@@ -29,7 +28,7 @@ class BackgroundNotificationManager(
|
|
|
29
28
|
private const val ACTION_UPDATE_NOW = NotificationActionReceiver.ACTION_INSTALL_NOW
|
|
30
29
|
private const val ACTION_UPDATE_LATER = NotificationActionReceiver.ACTION_INSTALL_LATER
|
|
31
30
|
private const val ACTION_DISMISS = NotificationActionReceiver.ACTION_DISMISS
|
|
32
|
-
|
|
31
|
+
|
|
33
32
|
/**
|
|
34
33
|
* Static method to cancel notification from BroadcastReceiver
|
|
35
34
|
*/
|
|
@@ -38,9 +37,9 @@ class BackgroundNotificationManager(
|
|
|
38
37
|
notificationManager.cancel(NOTIFICATION_ID)
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
|
-
|
|
40
|
+
|
|
42
41
|
private var preferences: NotificationPreferences = NotificationPreferences.default()
|
|
43
|
-
|
|
42
|
+
|
|
44
43
|
fun createNotificationChannel() {
|
|
45
44
|
val channel = NotificationChannel(
|
|
46
45
|
CHANNEL_ID,
|
|
@@ -55,10 +54,10 @@ class BackgroundNotificationManager(
|
|
|
55
54
|
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
56
55
|
notificationManager.createNotificationChannel(channel)
|
|
57
56
|
}
|
|
58
|
-
|
|
57
|
+
|
|
59
58
|
fun setPreferences(preferencesData: JSObject) {
|
|
60
59
|
preferences = NotificationPreferences.fromJSObject(preferencesData)
|
|
61
|
-
|
|
60
|
+
|
|
62
61
|
// Update channel if preferences changed
|
|
63
62
|
val channelId = preferences.channelId ?: CHANNEL_ID
|
|
64
63
|
val channelName = preferences.channelName ?: CHANNEL_NAME
|
|
@@ -80,18 +79,18 @@ class BackgroundNotificationManager(
|
|
|
80
79
|
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
81
80
|
notificationManager.createNotificationChannel(channel)
|
|
82
81
|
}
|
|
83
|
-
|
|
82
|
+
|
|
84
83
|
fun getPermissionStatus(): NotificationPermissionStatus {
|
|
85
84
|
val notificationManager = NotificationManagerCompat.from(context)
|
|
86
85
|
val areNotificationsEnabled = notificationManager.areNotificationsEnabled()
|
|
87
|
-
|
|
86
|
+
|
|
88
87
|
return NotificationPermissionStatus(
|
|
89
88
|
granted = areNotificationsEnabled,
|
|
90
89
|
canRequest = !areNotificationsEnabled,
|
|
91
90
|
shouldShowRationale = false // Android doesn't have this concept
|
|
92
91
|
)
|
|
93
92
|
}
|
|
94
|
-
|
|
93
|
+
|
|
95
94
|
fun requestPermissions(): Boolean {
|
|
96
95
|
// On Android 13+, notification permissions need to be requested
|
|
97
96
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
@@ -100,12 +99,11 @@ class BackgroundNotificationManager(
|
|
|
100
99
|
android.Manifest.permission.POST_NOTIFICATIONS
|
|
101
100
|
) == PackageManager.PERMISSION_GRANTED
|
|
102
101
|
}
|
|
103
|
-
|
|
102
|
+
|
|
104
103
|
// For older versions, notifications are enabled by default
|
|
105
104
|
return true
|
|
106
105
|
}
|
|
107
|
-
|
|
108
|
-
@SuppressLint("MissingPermission")
|
|
106
|
+
|
|
109
107
|
fun sendUpdateNotification(
|
|
110
108
|
appUpdate: AppUpdateStatus?,
|
|
111
109
|
liveUpdate: LatestVersion?
|
|
@@ -117,44 +115,44 @@ class BackgroundNotificationManager(
|
|
|
117
115
|
) {
|
|
118
116
|
return false
|
|
119
117
|
}
|
|
120
|
-
|
|
118
|
+
|
|
121
119
|
val notificationBuilder = createNotificationBuilder(appUpdate, liveUpdate)
|
|
122
|
-
|
|
120
|
+
|
|
123
121
|
try {
|
|
124
122
|
val notificationManager = NotificationManagerCompat.from(context)
|
|
125
123
|
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build())
|
|
126
|
-
|
|
124
|
+
|
|
127
125
|
// Notify listeners
|
|
128
126
|
val eventData = JSObject()
|
|
129
127
|
eventData.put("type", if (appUpdate?.updateAvailable == true) "app_update" else "live_update")
|
|
130
128
|
eventData.put("updateAvailable", true)
|
|
131
129
|
eventData.put("version", appUpdate?.availableVersion ?: liveUpdate?.version ?: "unknown")
|
|
132
130
|
eventData.put("action", "shown")
|
|
133
|
-
|
|
131
|
+
|
|
134
132
|
eventListener("backgroundUpdateNotification", eventData)
|
|
135
|
-
|
|
133
|
+
|
|
136
134
|
return true
|
|
137
135
|
} catch (_: SecurityException) {
|
|
138
136
|
return false
|
|
139
137
|
}
|
|
140
138
|
}
|
|
141
|
-
|
|
139
|
+
|
|
142
140
|
fun cancelNotification() {
|
|
143
141
|
val notificationManager = NotificationManagerCompat.from(context)
|
|
144
142
|
notificationManager.cancel(NOTIFICATION_ID)
|
|
145
143
|
}
|
|
146
|
-
|
|
144
|
+
|
|
147
145
|
fun cancelUpdateNotification() {
|
|
148
146
|
cancelNotification()
|
|
149
147
|
}
|
|
150
|
-
|
|
148
|
+
|
|
151
149
|
private fun createNotificationBuilder(
|
|
152
150
|
appUpdate: AppUpdateStatus?,
|
|
153
151
|
liveUpdate: LatestVersion?
|
|
154
152
|
): NotificationCompat.Builder {
|
|
155
153
|
val title = determineTitle(appUpdate, liveUpdate)
|
|
156
154
|
val content = determineContent(appUpdate, liveUpdate)
|
|
157
|
-
|
|
155
|
+
|
|
158
156
|
val builder = NotificationCompat.Builder(context, preferences.channelId ?: CHANNEL_ID)
|
|
159
157
|
.setSmallIcon(getNotificationIcon())
|
|
160
158
|
.setContentTitle(title)
|
|
@@ -163,29 +161,29 @@ class BackgroundNotificationManager(
|
|
|
163
161
|
.setPriority(getNotificationPriority(preferences.priority))
|
|
164
162
|
.setAutoCancel(true)
|
|
165
163
|
.setOnlyAlertOnce(true)
|
|
166
|
-
|
|
164
|
+
|
|
167
165
|
// Set sound
|
|
168
166
|
if (preferences.soundEnabled) {
|
|
169
167
|
builder.setDefaults(NotificationCompat.DEFAULT_SOUND)
|
|
170
168
|
}
|
|
171
|
-
|
|
169
|
+
|
|
172
170
|
// Set vibration
|
|
173
171
|
if (preferences.vibrationEnabled) {
|
|
174
172
|
builder.setVibrate(longArrayOf(0, 300, 300, 300))
|
|
175
173
|
}
|
|
176
|
-
|
|
174
|
+
|
|
177
175
|
// Set content intent (tap action)
|
|
178
176
|
val contentIntent = createContentIntent(appUpdate, liveUpdate)
|
|
179
177
|
builder.setContentIntent(contentIntent)
|
|
180
|
-
|
|
178
|
+
|
|
181
179
|
// Add action buttons if enabled
|
|
182
180
|
if (preferences.showActions) {
|
|
183
181
|
addActionButtons(builder, appUpdate, liveUpdate)
|
|
184
182
|
}
|
|
185
|
-
|
|
183
|
+
|
|
186
184
|
return builder
|
|
187
185
|
}
|
|
188
|
-
|
|
186
|
+
|
|
189
187
|
private fun determineTitle(appUpdate: AppUpdateStatus?, liveUpdate: LatestVersion?): String {
|
|
190
188
|
return when {
|
|
191
189
|
appUpdate?.updateAvailable == true && liveUpdate?.available == true -> "App Updates Available"
|
|
@@ -194,19 +192,19 @@ class BackgroundNotificationManager(
|
|
|
194
192
|
else -> preferences.title ?: "App Update Available"
|
|
195
193
|
}
|
|
196
194
|
}
|
|
197
|
-
|
|
195
|
+
|
|
198
196
|
private fun determineContent(appUpdate: AppUpdateStatus?, liveUpdate: LatestVersion?): String {
|
|
199
197
|
return when {
|
|
200
|
-
appUpdate?.updateAvailable == true && liveUpdate?.available == true ->
|
|
198
|
+
appUpdate?.updateAvailable == true && liveUpdate?.available == true ->
|
|
201
199
|
"App version ${appUpdate.availableVersion} and content updates are available"
|
|
202
|
-
appUpdate?.updateAvailable == true ->
|
|
200
|
+
appUpdate?.updateAvailable == true ->
|
|
203
201
|
"Version ${appUpdate.availableVersion} is available"
|
|
204
|
-
liveUpdate?.available == true ->
|
|
202
|
+
liveUpdate?.available == true ->
|
|
205
203
|
"New content version ${liveUpdate.version} is available"
|
|
206
204
|
else -> preferences.description ?: "A new version of the app is available"
|
|
207
205
|
}
|
|
208
206
|
}
|
|
209
|
-
|
|
207
|
+
|
|
210
208
|
private fun getNotificationIcon(): Int {
|
|
211
209
|
// Try to get custom icon, fallback to default
|
|
212
210
|
return try {
|
|
@@ -215,7 +213,7 @@ class BackgroundNotificationManager(
|
|
|
215
213
|
android.R.drawable.ic_dialog_info
|
|
216
214
|
}
|
|
217
215
|
}
|
|
218
|
-
|
|
216
|
+
|
|
219
217
|
private fun getNotificationPriority(priority: NotificationPriority): Int {
|
|
220
218
|
return when (priority) {
|
|
221
219
|
NotificationPriority.MIN -> NotificationCompat.PRIORITY_MIN
|
|
@@ -225,7 +223,7 @@ class BackgroundNotificationManager(
|
|
|
225
223
|
NotificationPriority.MAX -> NotificationCompat.PRIORITY_MAX
|
|
226
224
|
}
|
|
227
225
|
}
|
|
228
|
-
|
|
226
|
+
|
|
229
227
|
private fun getNotificationImportance(priority: NotificationPriority): Int {
|
|
230
228
|
return when (priority) {
|
|
231
229
|
NotificationPriority.MIN -> NotificationManager.IMPORTANCE_MIN
|
|
@@ -235,14 +233,14 @@ class BackgroundNotificationManager(
|
|
|
235
233
|
NotificationPriority.MAX -> NotificationManager.IMPORTANCE_MAX
|
|
236
234
|
}
|
|
237
235
|
}
|
|
238
|
-
|
|
236
|
+
|
|
239
237
|
private fun createContentIntent(appUpdate: AppUpdateStatus?, liveUpdate: LatestVersion?): PendingIntent {
|
|
240
238
|
val intent = context.packageManager.getLaunchIntentForPackage(context.packageName)
|
|
241
239
|
?: Intent()
|
|
242
|
-
|
|
240
|
+
|
|
243
241
|
intent.putExtra("notification_action", "tapped")
|
|
244
242
|
intent.putExtra("update_type", if (appUpdate?.updateAvailable == true) "app_update" else "live_update")
|
|
245
|
-
|
|
243
|
+
|
|
246
244
|
return PendingIntent.getActivity(
|
|
247
245
|
context,
|
|
248
246
|
0,
|
|
@@ -250,14 +248,14 @@ class BackgroundNotificationManager(
|
|
|
250
248
|
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
|
251
249
|
)
|
|
252
250
|
}
|
|
253
|
-
|
|
251
|
+
|
|
254
252
|
private fun addActionButtons(
|
|
255
253
|
builder: NotificationCompat.Builder,
|
|
256
254
|
appUpdate: AppUpdateStatus?,
|
|
257
255
|
liveUpdate: LatestVersion?
|
|
258
256
|
) {
|
|
259
257
|
val actionLabels = preferences.actionLabels ?: ActionLabels.default()
|
|
260
|
-
|
|
258
|
+
|
|
261
259
|
// Explicit intents (component set) — Android 8+ blocks implicit
|
|
262
260
|
// broadcasts to non-exported manifest receivers, which silently
|
|
263
261
|
// dropped these notifications before this fix.
|
|
@@ -303,7 +301,7 @@ class BackgroundNotificationManager(
|
|
|
303
301
|
dismissIntent,
|
|
304
302
|
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
|
305
303
|
)
|
|
306
|
-
|
|
304
|
+
|
|
307
305
|
builder.addAction(
|
|
308
306
|
android.R.drawable.ic_menu_close_clear_cancel,
|
|
309
307
|
actionLabels.dismiss ?: "Dismiss",
|
|
@@ -311,96 +309,3 @@ class BackgroundNotificationManager(
|
|
|
311
309
|
)
|
|
312
310
|
}
|
|
313
311
|
}
|
|
314
|
-
|
|
315
|
-
data class NotificationPreferences(
|
|
316
|
-
val title: String? = null,
|
|
317
|
-
val description: String? = null,
|
|
318
|
-
val iconName: String? = null,
|
|
319
|
-
val soundEnabled: Boolean = true,
|
|
320
|
-
val vibrationEnabled: Boolean = true,
|
|
321
|
-
val showActions: Boolean = true,
|
|
322
|
-
val actionLabels: ActionLabels? = null,
|
|
323
|
-
val channelId: String? = null,
|
|
324
|
-
val channelName: String? = null,
|
|
325
|
-
val priority: NotificationPriority = NotificationPriority.DEFAULT
|
|
326
|
-
) {
|
|
327
|
-
companion object {
|
|
328
|
-
fun default(): NotificationPreferences {
|
|
329
|
-
return NotificationPreferences(
|
|
330
|
-
title = "App Update Available",
|
|
331
|
-
description = "A new version of the app is available",
|
|
332
|
-
actionLabels = ActionLabels.default()
|
|
333
|
-
)
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
fun fromJSObject(obj: JSObject): NotificationPreferences {
|
|
337
|
-
val actionLabelsObj = obj.getJSObject("actionLabels")
|
|
338
|
-
val priorityString = obj.getString("priority", "default")
|
|
339
|
-
|
|
340
|
-
return NotificationPreferences(
|
|
341
|
-
title = obj.getString("title"),
|
|
342
|
-
description = obj.getString("description"),
|
|
343
|
-
iconName = obj.getString("iconName"),
|
|
344
|
-
soundEnabled = obj.getBoolean("soundEnabled", true) ?: true,
|
|
345
|
-
vibrationEnabled = obj.getBoolean("vibrationEnabled", true) ?: true,
|
|
346
|
-
showActions = obj.getBoolean("showActions", true) ?: true,
|
|
347
|
-
actionLabels = actionLabelsObj?.let { ActionLabels.fromJSObject(it) } ?: ActionLabels.default(),
|
|
348
|
-
channelId = obj.getString("channelId"),
|
|
349
|
-
channelName = obj.getString("channelName"),
|
|
350
|
-
priority = NotificationPriority.fromString(priorityString ?: "default")
|
|
351
|
-
)
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
data class ActionLabels(
|
|
357
|
-
val updateNow: String? = null,
|
|
358
|
-
val updateLater: String? = null,
|
|
359
|
-
val dismiss: String? = null
|
|
360
|
-
) {
|
|
361
|
-
companion object {
|
|
362
|
-
fun default(): ActionLabels {
|
|
363
|
-
return ActionLabels(
|
|
364
|
-
updateNow = "Update Now",
|
|
365
|
-
updateLater = "Later",
|
|
366
|
-
dismiss = "Dismiss"
|
|
367
|
-
)
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
fun fromJSObject(obj: JSObject): ActionLabels {
|
|
371
|
-
return ActionLabels(
|
|
372
|
-
updateNow = obj.getString("updateNow"),
|
|
373
|
-
updateLater = obj.getString("updateLater"),
|
|
374
|
-
dismiss = obj.getString("dismiss")
|
|
375
|
-
)
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
enum class NotificationPriority(val value: String) {
|
|
381
|
-
MIN("min"),
|
|
382
|
-
LOW("low"),
|
|
383
|
-
DEFAULT("default"),
|
|
384
|
-
HIGH("high"),
|
|
385
|
-
MAX("max");
|
|
386
|
-
|
|
387
|
-
companion object {
|
|
388
|
-
fun fromString(value: String): NotificationPriority {
|
|
389
|
-
return values().find { it.value == value } ?: DEFAULT
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
data class NotificationPermissionStatus(
|
|
395
|
-
val granted: Boolean,
|
|
396
|
-
val canRequest: Boolean,
|
|
397
|
-
val shouldShowRationale: Boolean? = null
|
|
398
|
-
) {
|
|
399
|
-
fun toJSObject(): JSObject {
|
|
400
|
-
val obj = JSObject()
|
|
401
|
-
obj.put("granted", granted)
|
|
402
|
-
obj.put("canRequest", canRequest)
|
|
403
|
-
shouldShowRationale?.let { obj.put("shouldShowRationale", it) }
|
|
404
|
-
return obj
|
|
405
|
-
}
|
|
406
|
-
}
|
|
@@ -2,8 +2,8 @@ import chalk from 'chalk';
|
|
|
2
2
|
import fs from 'fs/promises';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import crypto from 'crypto';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { createReadStream } from 'fs';
|
|
6
|
+
import { archiveDirectory } from '../lib/archive-directory.js';
|
|
7
7
|
import { fileURLToPath } from 'url';
|
|
8
8
|
import { dirname, join } from 'path';
|
|
9
9
|
|
|
@@ -87,24 +87,7 @@ export async function createBundle(webDir, options) {
|
|
|
87
87
|
console.log(chalk.gray(` Channel: ${options.channel}`));
|
|
88
88
|
console.log(chalk.gray(` Output: ${bundlePath}`));
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
const output = createWriteStream(bundlePath);
|
|
92
|
-
const archive = new ZipArchive({
|
|
93
|
-
zlib: { level: 9 }
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
const archivePromise = new Promise((resolve, reject) => {
|
|
97
|
-
output.on('close', resolve);
|
|
98
|
-
archive.on('error', reject);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
archive.pipe(output);
|
|
102
|
-
|
|
103
|
-
// Add all files from web directory
|
|
104
|
-
archive.directory(webDir, false);
|
|
105
|
-
|
|
106
|
-
await archive.finalize();
|
|
107
|
-
await archivePromise;
|
|
90
|
+
await archiveDirectory(webDir, bundlePath);
|
|
108
91
|
|
|
109
92
|
// Stream the bundle through the SHA-256 hasher so a 100MB+ bundle
|
|
110
93
|
// doesn't get slurped into RAM all at once. Size comes from fs.stat.
|
|
@@ -142,4 +125,4 @@ export async function createBundle(webDir, options) {
|
|
|
142
125
|
console.error(chalk.red('❌ Failed to create bundle:'), error.message);
|
|
143
126
|
process.exit(1);
|
|
144
127
|
}
|
|
145
|
-
}
|
|
128
|
+
}
|