native-update 3.4.1 → 4.0.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/AI-INTEGRATION-GUIDE.md +26 -16
- package/NativeUpdate.podspec +2 -2
- package/README.md +554 -0
- package/android/build.gradle +43 -34
- package/android/gradle/wrapper/gradle-wrapper.properties +2 -2
- package/android/proguard-rules.pro +0 -3
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundNotificationManager.kt +45 -49
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateManager.kt +12 -10
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdatePlugin.kt +12 -21
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateWorker.kt +3 -34
- package/android/src/main/java/com/aoneahsan/nativeupdate/LiveUpdatePlugin.kt +206 -72
- package/android/src/main/java/com/aoneahsan/nativeupdate/NativeUpdatePlugin.kt +74 -37
- package/android/src/main/java/com/aoneahsan/nativeupdate/SecurityManager.kt +169 -179
- package/android/variables.gradle +2 -2
- package/cli/.yarn/install-state.gz +0 -0
- package/cli/commands/bundle-verify.js +4 -1
- package/cli/commands/keys-generate.js +12 -46
- package/cli/index.js +4 -7
- package/cli/package.json +2 -1
- package/dist/esm/core/config.d.ts +3 -0
- package/dist/esm/core/config.js +17 -0
- package/dist/esm/core/plugin-manager.js +4 -2
- package/dist/esm/core/security.js +2 -5
- package/dist/esm/core/update-check.d.ts +2 -0
- package/dist/esm/core/update-check.js +5 -3
- package/dist/esm/definitions.d.ts +43 -2
- package/dist/esm/live-update/delta-processor.d.ts +6 -20
- package/dist/esm/live-update/delta-processor.js +75 -119
- package/dist/esm/plugin.d.ts +0 -3
- package/dist/esm/plugin.js +172 -12
- package/dist/esm/security/crypto.js +2 -5
- package/dist/esm/web.d.ts +1 -9
- package/dist/esm/web.js +4 -56
- package/dist/plugin.cjs +1 -1
- package/dist/plugin.esm.js +1 -1
- package/dist/plugin.js +2 -2
- package/docs/CHANGELOG.md +66 -0
- package/docs/KNOWN_LIMITATIONS.md +4 -3
- package/docs/MIGRATION.md +32 -3
- package/docs/server-requirements.md +40 -29
- package/ios/Plugin/BackgroundUpdate/BackgroundNotificationManager.swift +6 -2
- package/ios/Plugin/BackgroundUpdate/BackgroundUpdatePlugin.swift +21 -30
- package/ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift +269 -61
- package/ios/Plugin/NativeUpdatePlugin.m +8 -1
- package/ios/Plugin/NativeUpdatePlugin.swift +71 -34
- package/ios/Plugin/Security/SecurityManager.swift +100 -99
- package/package.json +27 -15
- package/Readme.md +0 -565
package/android/build.gradle
CHANGED
|
@@ -4,32 +4,35 @@ buildscript {
|
|
|
4
4
|
mavenCentral()
|
|
5
5
|
}
|
|
6
6
|
dependencies {
|
|
7
|
-
classpath 'com.android.tools.build:gradle:8.
|
|
8
|
-
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:
|
|
7
|
+
classpath 'com.android.tools.build:gradle:8.13.2'
|
|
8
|
+
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:2.2.20'
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
ext {
|
|
13
|
-
kotlinVersion = '
|
|
13
|
+
kotlinVersion = '2.2.20'
|
|
14
14
|
compileSdkVersion = 36
|
|
15
15
|
targetSdkVersion = 36
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
// Capacitor Android 8.5 declares API 26; the plugin cannot advertise or
|
|
17
|
+
// assemble against a lower manifest floor than its required peer.
|
|
18
|
+
minSdkVersion = 26
|
|
19
|
+
androidxAppCompatVersion = '1.7.1'
|
|
20
|
+
// 1.19 requires compileSdk 37 + AGP 9.1; Capacitor 8's supported line is AGP 8/API 36.
|
|
21
|
+
androidxCoreVersion = '1.17.0'
|
|
22
|
+
androidxWorkVersion = '2.11.2'
|
|
20
23
|
playAppUpdateVersion = '2.1.0'
|
|
21
24
|
playAppUpdateKtxVersion = '2.1.0'
|
|
22
|
-
playReviewVersion = '2.0.
|
|
23
|
-
playReviewKtxVersion = '2.0.
|
|
24
|
-
okhttpVersion = '4.
|
|
25
|
+
playReviewVersion = '2.0.2'
|
|
26
|
+
playReviewKtxVersion = '2.0.2'
|
|
27
|
+
okhttpVersion = '5.4.0'
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
apply plugin: 'com.android.library'
|
|
28
31
|
apply plugin: 'kotlin-android'
|
|
29
32
|
|
|
30
33
|
android {
|
|
31
|
-
namespace "com.aoneahsan.nativeupdate"
|
|
32
|
-
|
|
34
|
+
namespace = "com.aoneahsan.nativeupdate"
|
|
35
|
+
compileSdk = project.compileSdkVersion
|
|
33
36
|
|
|
34
37
|
defaultConfig {
|
|
35
38
|
minSdkVersion project.minSdkVersion
|
|
@@ -42,21 +45,30 @@ android {
|
|
|
42
45
|
buildTypes {
|
|
43
46
|
release {
|
|
44
47
|
minifyEnabled false
|
|
45
|
-
|
|
48
|
+
// MUST be the -optimize variant. The current Android Gradle Plugin hard-rejects
|
|
49
|
+
// 'proguard-android.txt' (it bundles -dontoptimize), and the call is evaluated at
|
|
50
|
+
// CONFIGURATION time - so a consuming app's release build fails at evaluation of
|
|
51
|
+
// :native-update even with minifyEnabled false. Every other Capacitor plugin already
|
|
52
|
+
// uses the -optimize file. See docs/REPORTED-ISSUES.md ISSUE-01.
|
|
53
|
+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
|
46
54
|
}
|
|
47
55
|
}
|
|
48
56
|
|
|
49
57
|
lint {
|
|
50
|
-
abortOnError
|
|
58
|
+
abortOnError = true
|
|
59
|
+
warningsAsErrors = true
|
|
60
|
+
// Capacitor 8 consumers are still on AGP 8; AGP 9 is a deliberate v5 migration.
|
|
61
|
+
// KTX preference hints are style-only and do not affect correctness.
|
|
62
|
+
disable += ['AndroidGradlePluginVersion', 'GradleDependency', 'NewerVersionAvailable', 'UseKtx']
|
|
51
63
|
}
|
|
52
64
|
|
|
53
65
|
compileOptions {
|
|
54
|
-
sourceCompatibility JavaVersion.
|
|
55
|
-
targetCompatibility JavaVersion.
|
|
66
|
+
sourceCompatibility JavaVersion.VERSION_21
|
|
67
|
+
targetCompatibility JavaVersion.VERSION_21
|
|
56
68
|
}
|
|
57
69
|
|
|
58
70
|
kotlinOptions {
|
|
59
|
-
jvmTarget = '
|
|
71
|
+
jvmTarget = '21'
|
|
60
72
|
}
|
|
61
73
|
|
|
62
74
|
testOptions {
|
|
@@ -77,9 +89,9 @@ dependencies {
|
|
|
77
89
|
implementation project(':capacitor-android')
|
|
78
90
|
|
|
79
91
|
// Kotlin
|
|
80
|
-
implementation 'org.jetbrains.kotlin:kotlin-stdlib:
|
|
81
|
-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.
|
|
82
|
-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.
|
|
92
|
+
implementation 'org.jetbrains.kotlin:kotlin-stdlib:2.2.20'
|
|
93
|
+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.11.0'
|
|
94
|
+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.11.0'
|
|
83
95
|
|
|
84
96
|
// AndroidX
|
|
85
97
|
implementation "androidx.appcompat:appcompat:${androidxAppCompatVersion}"
|
|
@@ -89,26 +101,23 @@ dependencies {
|
|
|
89
101
|
// Google Play Services - Using explicit versions to avoid resolution issues
|
|
90
102
|
implementation 'com.google.android.play:app-update:2.1.0'
|
|
91
103
|
implementation 'com.google.android.play:app-update-ktx:2.1.0'
|
|
92
|
-
implementation
|
|
93
|
-
implementation
|
|
104
|
+
implementation "com.google.android.play:review:${playReviewVersion}"
|
|
105
|
+
implementation "com.google.android.play:review-ktx:${playReviewKtxVersion}"
|
|
94
106
|
|
|
95
107
|
// OkHttp for secure network requests
|
|
96
108
|
implementation "com.squareup.okhttp3:okhttp:${okhttpVersion}"
|
|
97
109
|
implementation "com.squareup.okhttp3:okhttp-tls:${okhttpVersion}"
|
|
98
110
|
|
|
99
|
-
// Security
|
|
100
|
-
implementation 'androidx.security:security-crypto:1.1.0-alpha06'
|
|
101
|
-
|
|
102
111
|
// JSON parsing
|
|
103
|
-
implementation 'com.google.code.gson:gson:2.
|
|
112
|
+
implementation 'com.google.code.gson:gson:2.14.0'
|
|
104
113
|
|
|
105
114
|
// Testing
|
|
106
115
|
testImplementation 'junit:junit:4.13.2'
|
|
107
|
-
testImplementation 'org.mockito:mockito-core:5.
|
|
108
|
-
testImplementation 'org.mockito.kotlin:mockito-kotlin:
|
|
109
|
-
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.
|
|
110
|
-
testImplementation 'com.google.truth:truth:1.
|
|
111
|
-
testImplementation 'org.robolectric:robolectric:4.
|
|
112
|
-
androidTestImplementation 'androidx.test.ext:junit:1.
|
|
113
|
-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.
|
|
114
|
-
}
|
|
116
|
+
testImplementation 'org.mockito:mockito-core:5.23.0'
|
|
117
|
+
testImplementation 'org.mockito.kotlin:mockito-kotlin:6.3.0'
|
|
118
|
+
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.11.0'
|
|
119
|
+
testImplementation 'com.google.truth:truth:1.4.5'
|
|
120
|
+
testImplementation 'org.robolectric:robolectric:4.16.1'
|
|
121
|
+
androidTestImplementation 'androidx.test.ext:junit:1.3.0'
|
|
122
|
+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.7.0'
|
|
123
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Gradle Wrapper Properties
|
|
2
2
|
distributionBase=GRADLE_USER_HOME
|
|
3
3
|
distributionPath=wrapper/dists
|
|
4
|
-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.
|
|
4
|
+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.5-all.zip
|
|
5
5
|
networkTimeout=10000
|
|
6
6
|
validateDistributionUrl=true
|
|
7
7
|
zipStoreBase=GRADLE_USER_HOME
|
|
8
|
-
zipStorePath=wrapper/dists
|
|
8
|
+
zipStorePath=wrapper/dists
|
|
@@ -3,6 +3,7 @@ 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
|
|
6
7
|
import android.content.Context
|
|
7
8
|
import android.content.Intent
|
|
8
9
|
import android.content.pm.PackageManager
|
|
@@ -15,7 +16,7 @@ import com.getcapacitor.Plugin
|
|
|
15
16
|
|
|
16
17
|
class BackgroundNotificationManager(
|
|
17
18
|
private val context: Context,
|
|
18
|
-
private val
|
|
19
|
+
private val eventListener: (String, JSObject) -> Unit
|
|
19
20
|
) {
|
|
20
21
|
|
|
21
22
|
companion object {
|
|
@@ -41,47 +42,43 @@ class BackgroundNotificationManager(
|
|
|
41
42
|
private var preferences: NotificationPreferences = NotificationPreferences.default()
|
|
42
43
|
|
|
43
44
|
fun createNotificationChannel() {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
enableVibration(true)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
56
|
-
notificationManager.createNotificationChannel(channel)
|
|
45
|
+
val channel = NotificationChannel(
|
|
46
|
+
CHANNEL_ID,
|
|
47
|
+
CHANNEL_NAME,
|
|
48
|
+
NotificationManager.IMPORTANCE_DEFAULT
|
|
49
|
+
).apply {
|
|
50
|
+
description = "Notifications for app updates"
|
|
51
|
+
enableLights(true)
|
|
52
|
+
enableVibration(true)
|
|
57
53
|
}
|
|
54
|
+
|
|
55
|
+
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
56
|
+
notificationManager.createNotificationChannel(channel)
|
|
58
57
|
}
|
|
59
58
|
|
|
60
59
|
fun setPreferences(preferencesData: JSObject) {
|
|
61
60
|
preferences = NotificationPreferences.fromJSObject(preferencesData)
|
|
62
61
|
|
|
63
62
|
// Update channel if preferences changed
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
setSound(null, null)
|
|
79
|
-
}
|
|
63
|
+
val channelId = preferences.channelId ?: CHANNEL_ID
|
|
64
|
+
val channelName = preferences.channelName ?: CHANNEL_NAME
|
|
65
|
+
|
|
66
|
+
val channel = NotificationChannel(
|
|
67
|
+
channelId,
|
|
68
|
+
channelName,
|
|
69
|
+
getNotificationImportance(preferences.priority)
|
|
70
|
+
).apply {
|
|
71
|
+
description = "Notifications for app updates"
|
|
72
|
+
enableLights(true)
|
|
73
|
+
enableVibration(preferences.vibrationEnabled)
|
|
74
|
+
|
|
75
|
+
if (!preferences.soundEnabled) {
|
|
76
|
+
setSound(null, null)
|
|
80
77
|
}
|
|
81
|
-
|
|
82
|
-
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
83
|
-
notificationManager.createNotificationChannel(channel)
|
|
84
78
|
}
|
|
79
|
+
|
|
80
|
+
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
81
|
+
notificationManager.createNotificationChannel(channel)
|
|
85
82
|
}
|
|
86
83
|
|
|
87
84
|
fun getPermissionStatus(): NotificationPermissionStatus {
|
|
@@ -108,12 +105,16 @@ class BackgroundNotificationManager(
|
|
|
108
105
|
return true
|
|
109
106
|
}
|
|
110
107
|
|
|
108
|
+
@SuppressLint("MissingPermission")
|
|
111
109
|
fun sendUpdateNotification(
|
|
112
110
|
appUpdate: AppUpdateStatus?,
|
|
113
111
|
liveUpdate: LatestVersion?
|
|
114
112
|
): Boolean {
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
if (!getPermissionStatus().granted ||
|
|
114
|
+
(Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&
|
|
115
|
+
ContextCompat.checkSelfPermission(context, android.Manifest.permission.POST_NOTIFICATIONS) !=
|
|
116
|
+
PackageManager.PERMISSION_GRANTED)
|
|
117
|
+
) {
|
|
117
118
|
return false
|
|
118
119
|
}
|
|
119
120
|
|
|
@@ -130,11 +131,10 @@ class BackgroundNotificationManager(
|
|
|
130
131
|
eventData.put("version", appUpdate?.availableVersion ?: liveUpdate?.version ?: "unknown")
|
|
131
132
|
eventData.put("action", "shown")
|
|
132
133
|
|
|
133
|
-
|
|
134
|
+
eventListener("backgroundUpdateNotification", eventData)
|
|
134
135
|
|
|
135
136
|
return true
|
|
136
|
-
} catch (
|
|
137
|
-
android.util.Log.e("BackgroundNotificationManager", "Failed to send notification", e)
|
|
137
|
+
} catch (_: SecurityException) {
|
|
138
138
|
return false
|
|
139
139
|
}
|
|
140
140
|
}
|
|
@@ -227,16 +227,12 @@ class BackgroundNotificationManager(
|
|
|
227
227
|
}
|
|
228
228
|
|
|
229
229
|
private fun getNotificationImportance(priority: NotificationPriority): Int {
|
|
230
|
-
return
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
NotificationPriority.MAX -> NotificationManager.IMPORTANCE_MAX
|
|
237
|
-
}
|
|
238
|
-
} else {
|
|
239
|
-
NotificationManager.IMPORTANCE_DEFAULT
|
|
230
|
+
return when (priority) {
|
|
231
|
+
NotificationPriority.MIN -> NotificationManager.IMPORTANCE_MIN
|
|
232
|
+
NotificationPriority.LOW -> NotificationManager.IMPORTANCE_LOW
|
|
233
|
+
NotificationPriority.DEFAULT -> NotificationManager.IMPORTANCE_DEFAULT
|
|
234
|
+
NotificationPriority.HIGH -> NotificationManager.IMPORTANCE_HIGH
|
|
235
|
+
NotificationPriority.MAX -> NotificationManager.IMPORTANCE_MAX
|
|
240
236
|
}
|
|
241
237
|
}
|
|
242
238
|
|
|
@@ -407,4 +403,4 @@ data class NotificationPermissionStatus(
|
|
|
407
403
|
shouldShowRationale?.let { obj.put("shouldShowRationale", it) }
|
|
408
404
|
return obj
|
|
409
405
|
}
|
|
410
|
-
}
|
|
406
|
+
}
|
|
@@ -1,41 +1,43 @@
|
|
|
1
1
|
package com.aoneahsan.nativeupdate
|
|
2
2
|
|
|
3
|
+
import java.lang.ref.WeakReference
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* Singleton manager to maintain references to plugin instances
|
|
5
7
|
* This allows background workers to access plugin functionality
|
|
6
8
|
*/
|
|
7
9
|
object BackgroundUpdateManager {
|
|
8
10
|
@Volatile
|
|
9
|
-
private var backgroundUpdatePlugin: BackgroundUpdatePlugin
|
|
11
|
+
private var backgroundUpdatePlugin: WeakReference<BackgroundUpdatePlugin>? = null
|
|
10
12
|
|
|
11
13
|
@Volatile
|
|
12
|
-
private var liveUpdatePlugin: LiveUpdatePlugin
|
|
14
|
+
private var liveUpdatePlugin: WeakReference<LiveUpdatePlugin>? = null
|
|
13
15
|
|
|
14
16
|
@Volatile
|
|
15
|
-
private var appUpdatePlugin: AppUpdatePlugin
|
|
17
|
+
private var appUpdatePlugin: WeakReference<AppUpdatePlugin>? = null
|
|
16
18
|
|
|
17
19
|
fun registerBackgroundUpdatePlugin(plugin: BackgroundUpdatePlugin) {
|
|
18
|
-
backgroundUpdatePlugin = plugin
|
|
20
|
+
backgroundUpdatePlugin = WeakReference(plugin)
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
fun registerLiveUpdatePlugin(plugin: LiveUpdatePlugin) {
|
|
22
|
-
liveUpdatePlugin = plugin
|
|
24
|
+
liveUpdatePlugin = WeakReference(plugin)
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
fun registerAppUpdatePlugin(plugin: AppUpdatePlugin) {
|
|
26
|
-
appUpdatePlugin = plugin
|
|
28
|
+
appUpdatePlugin = WeakReference(plugin)
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
fun getBackgroundUpdatePlugin(): BackgroundUpdatePlugin? {
|
|
30
|
-
return backgroundUpdatePlugin
|
|
32
|
+
return backgroundUpdatePlugin?.get()
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
fun getLiveUpdatePlugin(): LiveUpdatePlugin? {
|
|
34
|
-
return liveUpdatePlugin
|
|
36
|
+
return liveUpdatePlugin?.get()
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
fun getAppUpdatePlugin(): AppUpdatePlugin? {
|
|
38
|
-
return appUpdatePlugin
|
|
40
|
+
return appUpdatePlugin?.get()
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
fun clear() {
|
|
@@ -43,4 +45,4 @@ object BackgroundUpdateManager {
|
|
|
43
45
|
liveUpdatePlugin = null
|
|
44
46
|
appUpdatePlugin = null
|
|
45
47
|
}
|
|
46
|
-
}
|
|
48
|
+
}
|
|
@@ -1,43 +1,41 @@
|
|
|
1
1
|
package com.aoneahsan.nativeupdate
|
|
2
2
|
|
|
3
3
|
import android.content.Context
|
|
4
|
-
import android.content.pm.PackageManager
|
|
5
4
|
import androidx.work.*
|
|
6
5
|
import com.getcapacitor.JSObject
|
|
7
|
-
import com.getcapacitor.Plugin
|
|
8
6
|
import com.getcapacitor.PluginCall
|
|
9
|
-
import com.getcapacitor.PluginMethod
|
|
10
|
-
import com.getcapacitor.annotation.CapacitorPlugin
|
|
11
7
|
import java.util.concurrent.TimeUnit
|
|
12
8
|
import org.json.JSONObject
|
|
13
9
|
import org.json.JSONArray
|
|
14
10
|
|
|
15
|
-
|
|
16
|
-
class BackgroundUpdatePlugin : Plugin() {
|
|
11
|
+
class BackgroundUpdatePlugin(private val context: Context) {
|
|
17
12
|
|
|
18
13
|
private lateinit var notificationManager: BackgroundNotificationManager
|
|
19
14
|
private var backgroundUpdateConfig: BackgroundUpdateConfig? = null
|
|
20
15
|
private var backgroundUpdateStatus: BackgroundUpdateStatus = BackgroundUpdateStatus()
|
|
16
|
+
private var eventListener: ((String, JSObject) -> Unit)? = null
|
|
21
17
|
|
|
22
18
|
companion object {
|
|
23
19
|
private const val WORK_NAME = "background_update_work"
|
|
24
20
|
private const val WORK_TAG = "capacitor_native_update"
|
|
25
21
|
}
|
|
26
22
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
init {
|
|
24
|
+
notificationManager = BackgroundNotificationManager(context) { event, data ->
|
|
25
|
+
eventListener?.invoke(event, data)
|
|
26
|
+
}
|
|
30
27
|
notificationManager.createNotificationChannel()
|
|
31
|
-
|
|
32
|
-
// Register this plugin instance with the manager
|
|
33
28
|
BackgroundUpdateManager.registerBackgroundUpdatePlugin(this)
|
|
34
29
|
}
|
|
30
|
+
|
|
31
|
+
fun setEventListener(listener: (String, JSObject) -> Unit) {
|
|
32
|
+
eventListener = listener
|
|
33
|
+
}
|
|
35
34
|
|
|
36
35
|
fun notifyBackgroundUpdateListeners(event: String, data: JSObject) {
|
|
37
|
-
|
|
36
|
+
eventListener?.invoke(event, data)
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
@PluginMethod
|
|
41
39
|
fun enableBackgroundUpdates(call: PluginCall) {
|
|
42
40
|
try {
|
|
43
41
|
val configData = call.data
|
|
@@ -58,25 +56,21 @@ class BackgroundUpdatePlugin : Plugin() {
|
|
|
58
56
|
}
|
|
59
57
|
}
|
|
60
58
|
|
|
61
|
-
@PluginMethod
|
|
62
59
|
fun disableBackgroundUpdates(call: PluginCall) {
|
|
63
60
|
cancelAllBackgroundWork()
|
|
64
61
|
call.resolve()
|
|
65
62
|
}
|
|
66
63
|
|
|
67
|
-
@PluginMethod
|
|
68
64
|
fun getBackgroundUpdateStatus(call: PluginCall) {
|
|
69
65
|
call.resolve(backgroundUpdateStatus.toJSObject())
|
|
70
66
|
}
|
|
71
67
|
|
|
72
|
-
@PluginMethod
|
|
73
68
|
fun scheduleBackgroundCheck(call: PluginCall) {
|
|
74
69
|
val interval = call.getLong("interval") ?: (24 * 60 * 60 * 1000L) // Default 24 hours
|
|
75
70
|
scheduleBackgroundWork(interval)
|
|
76
71
|
call.resolve()
|
|
77
72
|
}
|
|
78
73
|
|
|
79
|
-
@PluginMethod
|
|
80
74
|
fun triggerBackgroundCheck(call: PluginCall) {
|
|
81
75
|
val workRequest = OneTimeWorkRequestBuilder<BackgroundUpdateWorker>()
|
|
82
76
|
.setInputData(createWorkData())
|
|
@@ -103,20 +97,17 @@ class BackgroundUpdatePlugin : Plugin() {
|
|
|
103
97
|
call.resolve(JSObject().put("triggered", true))
|
|
104
98
|
}
|
|
105
99
|
|
|
106
|
-
@PluginMethod
|
|
107
100
|
fun setNotificationPreferences(call: PluginCall) {
|
|
108
101
|
val preferences = call.data
|
|
109
102
|
notificationManager.setPreferences(preferences)
|
|
110
103
|
call.resolve()
|
|
111
104
|
}
|
|
112
105
|
|
|
113
|
-
@PluginMethod
|
|
114
106
|
fun getNotificationPermissions(call: PluginCall) {
|
|
115
107
|
val status = notificationManager.getPermissionStatus()
|
|
116
108
|
call.resolve(status.toJSObject())
|
|
117
109
|
}
|
|
118
110
|
|
|
119
|
-
@PluginMethod
|
|
120
111
|
fun requestNotificationPermissions(call: PluginCall) {
|
|
121
112
|
val granted = notificationManager.requestPermissions()
|
|
122
113
|
call.resolve(JSObject().put("granted", granted))
|
|
@@ -349,4 +340,4 @@ data class LatestVersion(
|
|
|
349
340
|
version?.let { obj.put("version", it) }
|
|
350
341
|
return obj
|
|
351
342
|
}
|
|
352
|
-
}
|
|
343
|
+
}
|
|
@@ -2,7 +2,6 @@ package com.aoneahsan.nativeupdate
|
|
|
2
2
|
|
|
3
3
|
import android.content.Context
|
|
4
4
|
import androidx.work.*
|
|
5
|
-
import com.getcapacitor.Bridge
|
|
6
5
|
import com.getcapacitor.JSObject
|
|
7
6
|
import com.google.gson.Gson
|
|
8
7
|
import kotlinx.coroutines.Dispatchers
|
|
@@ -122,17 +121,7 @@ class BackgroundUpdateWorker(
|
|
|
122
121
|
if (appUpdatePlugin != null) {
|
|
123
122
|
// Use actual plugin to check for updates
|
|
124
123
|
appUpdatePlugin.getAppUpdateInfoAsync()
|
|
125
|
-
} else
|
|
126
|
-
// Fallback to basic implementation
|
|
127
|
-
val currentVersion = getCurrentAppVersion()
|
|
128
|
-
val availableVersion = getAvailableAppVersion()
|
|
129
|
-
|
|
130
|
-
AppUpdateStatus(
|
|
131
|
-
updateAvailable = availableVersion != currentVersion,
|
|
132
|
-
currentVersion = currentVersion,
|
|
133
|
-
availableVersion = if (availableVersion != currentVersion) availableVersion else null
|
|
134
|
-
)
|
|
135
|
-
}
|
|
124
|
+
} else null
|
|
136
125
|
} catch (e: Exception) {
|
|
137
126
|
android.util.Log.e(TAG, "App update check failed", e)
|
|
138
127
|
null
|
|
@@ -147,15 +136,7 @@ class BackgroundUpdateWorker(
|
|
|
147
136
|
if (liveUpdatePlugin != null) {
|
|
148
137
|
// Use actual plugin to check for updates
|
|
149
138
|
liveUpdatePlugin.getLatestVersionAsync()
|
|
150
|
-
} else
|
|
151
|
-
// Fallback to basic implementation
|
|
152
|
-
val hasUpdate = checkForLiveUpdateAvailable()
|
|
153
|
-
|
|
154
|
-
LatestVersion(
|
|
155
|
-
available = hasUpdate,
|
|
156
|
-
version = if (hasUpdate) "2.0.0" else null
|
|
157
|
-
)
|
|
158
|
-
}
|
|
139
|
+
} else null
|
|
159
140
|
} catch (e: Exception) {
|
|
160
141
|
android.util.Log.e(TAG, "Live update check failed", e)
|
|
161
142
|
null
|
|
@@ -172,18 +153,6 @@ class BackgroundUpdateWorker(
|
|
|
172
153
|
}
|
|
173
154
|
}
|
|
174
155
|
|
|
175
|
-
private fun getAvailableAppVersion(): String {
|
|
176
|
-
// This would typically check Google Play Store API
|
|
177
|
-
// For demo purposes, we'll return a mock version
|
|
178
|
-
return "1.0.1"
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
private fun checkForLiveUpdateAvailable(): Boolean {
|
|
182
|
-
// This would typically check the live update server
|
|
183
|
-
// For demo purposes, we'll return false
|
|
184
|
-
return false
|
|
185
|
-
}
|
|
186
|
-
|
|
187
156
|
private fun sendNotification(result: BackgroundCheckResult) {
|
|
188
157
|
try {
|
|
189
158
|
val plugin = getBackgroundUpdatePlugin()
|
|
@@ -264,4 +233,4 @@ class BackgroundUpdateWorker(
|
|
|
264
233
|
null
|
|
265
234
|
}
|
|
266
235
|
}
|
|
267
|
-
}
|
|
236
|
+
}
|