@capawesome/capacitor-live-update 7.2.2 → 7.4.0-dev.f18299f8.1767510052
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 +289 -28
- package/android/build.gradle +2 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdate.java +623 -220
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdateConfig.java +23 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdateHttpClient.java +42 -5
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdatePlugin.java +185 -15
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdatePreferences.java +42 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/api/GetLatestBundleResponse.java +2 -2
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/events/NextBundleSetEvent.java +26 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/options/SetConfigOptions.java +19 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/options/SyncOptions.java +4 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/results/GetBlockedBundlesResult.java +27 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/results/GetConfigResult.java +40 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/results/GetDownloadedBundlesResult.java +27 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/results/IsSyncingResult.java +26 -0
- package/dist/docs.json +428 -1
- package/dist/esm/definitions.d.ts +230 -2
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +8 -1
- package/dist/esm/web.js +21 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +21 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +21 -0
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/Classes/Events/NextBundleSetEvent.swift +16 -0
- package/ios/Plugin/Classes/Options/SetConfigOptions.swift +14 -0
- package/ios/Plugin/Classes/Options/SyncOptions.swift +4 -0
- package/ios/Plugin/Classes/Results/GetBlockedBundlesResult.swift +16 -0
- package/ios/Plugin/Classes/Results/GetConfigResult.swift +19 -0
- package/ios/Plugin/Classes/Results/GetDownloadedBundlesResult.swift +16 -0
- package/ios/Plugin/Classes/Results/IsSyncingResult.swift +16 -0
- package/ios/Plugin/LiveUpdate.swift +178 -4
- package/ios/Plugin/LiveUpdateConfig.swift +2 -0
- package/ios/Plugin/LiveUpdateHttpClient.swift +4 -2
- package/ios/Plugin/LiveUpdatePlugin.swift +106 -11
- package/ios/Plugin/LiveUpdatePreferences.swift +56 -0
- package/package.json +1 -1
package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdateConfig.java
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
package io.capawesome.capacitorjs.plugins.liveupdate;
|
|
2
2
|
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
3
4
|
import androidx.annotation.Nullable;
|
|
4
5
|
import java.security.Key;
|
|
5
6
|
|
|
@@ -8,8 +9,13 @@ public class LiveUpdateConfig {
|
|
|
8
9
|
@Nullable
|
|
9
10
|
private String appId = null;
|
|
10
11
|
|
|
12
|
+
private boolean autoBlockRolledBackBundles = false;
|
|
13
|
+
|
|
11
14
|
private boolean autoDeleteBundles = false;
|
|
12
15
|
|
|
16
|
+
@NonNull
|
|
17
|
+
private String autoUpdateStrategy = "none";
|
|
18
|
+
|
|
13
19
|
@Nullable
|
|
14
20
|
private String defaultChannel = null;
|
|
15
21
|
|
|
@@ -26,10 +32,19 @@ public class LiveUpdateConfig {
|
|
|
26
32
|
return appId;
|
|
27
33
|
}
|
|
28
34
|
|
|
35
|
+
public boolean getAutoBlockRolledBackBundles() {
|
|
36
|
+
return autoBlockRolledBackBundles;
|
|
37
|
+
}
|
|
38
|
+
|
|
29
39
|
public boolean getAutoDeleteBundles() {
|
|
30
40
|
return autoDeleteBundles;
|
|
31
41
|
}
|
|
32
42
|
|
|
43
|
+
@NonNull
|
|
44
|
+
public String getAutoUpdateStrategy() {
|
|
45
|
+
return autoUpdateStrategy;
|
|
46
|
+
}
|
|
47
|
+
|
|
33
48
|
@Nullable
|
|
34
49
|
public String getDefaultChannel() {
|
|
35
50
|
return defaultChannel;
|
|
@@ -56,10 +71,18 @@ public class LiveUpdateConfig {
|
|
|
56
71
|
this.appId = appId;
|
|
57
72
|
}
|
|
58
73
|
|
|
74
|
+
public void setAutoBlockRolledBackBundles(boolean autoBlockRolledBackBundles) {
|
|
75
|
+
this.autoBlockRolledBackBundles = autoBlockRolledBackBundles;
|
|
76
|
+
}
|
|
77
|
+
|
|
59
78
|
public void setAutoDeleteBundles(boolean autoDeleteBundles) {
|
|
60
79
|
this.autoDeleteBundles = autoDeleteBundles;
|
|
61
80
|
}
|
|
62
81
|
|
|
82
|
+
public void setAutoUpdateStrategy(@NonNull String autoUpdateStrategy) {
|
|
83
|
+
this.autoUpdateStrategy = autoUpdateStrategy;
|
|
84
|
+
}
|
|
85
|
+
|
|
63
86
|
public void setDefaultChannel(@Nullable String defaultChannel) {
|
|
64
87
|
this.defaultChannel = defaultChannel;
|
|
65
88
|
}
|
package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdateHttpClient.java
CHANGED
|
@@ -4,9 +4,14 @@ import androidx.annotation.NonNull;
|
|
|
4
4
|
import androidx.annotation.Nullable;
|
|
5
5
|
import com.getcapacitor.Logger;
|
|
6
6
|
import io.capawesome.capacitorjs.plugins.liveupdate.interfaces.DownloadProgressCallback;
|
|
7
|
+
import io.capawesome.capacitorjs.plugins.liveupdate.interfaces.EmptyCallback;
|
|
8
|
+
import io.capawesome.capacitorjs.plugins.liveupdate.interfaces.NonEmptyCallback;
|
|
7
9
|
import java.io.File;
|
|
8
10
|
import java.io.IOException;
|
|
11
|
+
import java.security.Security;
|
|
9
12
|
import java.util.concurrent.TimeUnit;
|
|
13
|
+
import okhttp3.Call;
|
|
14
|
+
import okhttp3.Callback;
|
|
10
15
|
import okhttp3.OkHttpClient;
|
|
11
16
|
import okhttp3.Request;
|
|
12
17
|
import okhttp3.Response;
|
|
@@ -15,12 +20,16 @@ import okio.Buffer;
|
|
|
15
20
|
import okio.BufferedSink;
|
|
16
21
|
import okio.BufferedSource;
|
|
17
22
|
import okio.Okio;
|
|
23
|
+
import org.conscrypt.Conscrypt;
|
|
18
24
|
|
|
19
25
|
public class LiveUpdateHttpClient {
|
|
20
26
|
|
|
21
27
|
@NonNull
|
|
22
28
|
private final LiveUpdateConfig config;
|
|
23
29
|
|
|
30
|
+
@NonNull
|
|
31
|
+
private final OkHttpClient okHttpClient;
|
|
32
|
+
|
|
24
33
|
@Nullable
|
|
25
34
|
public static String getChecksumFromResponse(Response response) {
|
|
26
35
|
String checksum = response.header("X-Checksum");
|
|
@@ -41,17 +50,45 @@ public class LiveUpdateHttpClient {
|
|
|
41
50
|
|
|
42
51
|
public LiveUpdateHttpClient(@NonNull LiveUpdateConfig config) {
|
|
43
52
|
this.config = config;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public Response execute(String url) throws IOException {
|
|
47
53
|
int httpTimeout = config.getHttpTimeout();
|
|
48
|
-
|
|
54
|
+
|
|
55
|
+
// Install Conscrypt as the preferred security provider for better SSL/TLS support on older Android versions
|
|
56
|
+
try {
|
|
57
|
+
Security.insertProviderAt(Conscrypt.newProvider(), 1);
|
|
58
|
+
} catch (Exception e) {
|
|
59
|
+
Logger.warn("LiveUpdateHttpClient", "Failed to install Conscrypt security provider: " + e.getMessage());
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Increase max requests per host to allow multiple parallel downloads from the same host
|
|
63
|
+
okhttp3.Dispatcher dispatcher = new okhttp3.Dispatcher();
|
|
64
|
+
dispatcher.setMaxRequestsPerHost(30);
|
|
65
|
+
|
|
66
|
+
this.okHttpClient = new OkHttpClient.Builder()
|
|
67
|
+
.dispatcher(dispatcher)
|
|
49
68
|
.connectTimeout(httpTimeout, TimeUnit.MILLISECONDS)
|
|
50
69
|
.readTimeout(httpTimeout, TimeUnit.MILLISECONDS)
|
|
51
70
|
.writeTimeout(httpTimeout, TimeUnit.MILLISECONDS)
|
|
52
71
|
.build();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public Call enqueue(String url, NonEmptyCallback<Response> callback) {
|
|
53
75
|
Request request = new Request.Builder().url(url).build();
|
|
54
|
-
|
|
76
|
+
|
|
77
|
+
Call call = okHttpClient.newCall(request);
|
|
78
|
+
call.enqueue(
|
|
79
|
+
new Callback() {
|
|
80
|
+
@Override
|
|
81
|
+
public void onResponse(@NonNull Call call, @NonNull Response response) {
|
|
82
|
+
callback.success(response);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@Override
|
|
86
|
+
public void onFailure(@NonNull Call call, @NonNull IOException e) {
|
|
87
|
+
callback.error(new Exception(e));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
return call;
|
|
55
92
|
}
|
|
56
93
|
|
|
57
94
|
public static void writeResponseBodyToFile(ResponseBody body, File file, @Nullable DownloadProgressCallback callback)
|
package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdatePlugin.java
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
package io.capawesome.capacitorjs.plugins.liveupdate;
|
|
2
2
|
|
|
3
|
+
import android.webkit.WebView;
|
|
3
4
|
import androidx.annotation.NonNull;
|
|
4
5
|
import androidx.annotation.Nullable;
|
|
5
6
|
import com.getcapacitor.JSObject;
|
|
@@ -7,17 +8,25 @@ import com.getcapacitor.Logger;
|
|
|
7
8
|
import com.getcapacitor.Plugin;
|
|
8
9
|
import com.getcapacitor.PluginCall;
|
|
9
10
|
import com.getcapacitor.PluginMethod;
|
|
11
|
+
import com.getcapacitor.WebViewListener;
|
|
10
12
|
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
11
13
|
import io.capawesome.capacitorjs.plugins.liveupdate.classes.events.DownloadBundleProgressEvent;
|
|
14
|
+
import io.capawesome.capacitorjs.plugins.liveupdate.classes.events.NextBundleSetEvent;
|
|
12
15
|
import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.DeleteBundleOptions;
|
|
13
16
|
import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.DownloadBundleOptions;
|
|
14
17
|
import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.FetchLatestBundleOptions;
|
|
15
18
|
import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.SetChannelOptions;
|
|
19
|
+
import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.SetConfigOptions;
|
|
16
20
|
import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.SetCustomIdOptions;
|
|
17
21
|
import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.SetNextBundleOptions;
|
|
18
22
|
import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.SyncOptions;
|
|
23
|
+
import io.capawesome.capacitorjs.plugins.liveupdate.classes.results.FetchLatestBundleResult;
|
|
24
|
+
import io.capawesome.capacitorjs.plugins.liveupdate.classes.results.GetBlockedBundlesResult;
|
|
25
|
+
import io.capawesome.capacitorjs.plugins.liveupdate.classes.results.GetConfigResult;
|
|
19
26
|
import io.capawesome.capacitorjs.plugins.liveupdate.classes.results.GetCurrentBundleResult;
|
|
27
|
+
import io.capawesome.capacitorjs.plugins.liveupdate.classes.results.GetDownloadedBundlesResult;
|
|
20
28
|
import io.capawesome.capacitorjs.plugins.liveupdate.classes.results.GetNextBundleResult;
|
|
29
|
+
import io.capawesome.capacitorjs.plugins.liveupdate.classes.results.IsSyncingResult;
|
|
21
30
|
import io.capawesome.capacitorjs.plugins.liveupdate.interfaces.EmptyCallback;
|
|
22
31
|
import io.capawesome.capacitorjs.plugins.liveupdate.interfaces.NonEmptyCallback;
|
|
23
32
|
import io.capawesome.capacitorjs.plugins.liveupdate.interfaces.Result;
|
|
@@ -26,7 +35,7 @@ import io.capawesome.capacitorjs.plugins.liveupdate.interfaces.Result;
|
|
|
26
35
|
public class LiveUpdatePlugin extends Plugin {
|
|
27
36
|
|
|
28
37
|
public static final String TAG = "LiveUpdate";
|
|
29
|
-
public static final String VERSION = "7.
|
|
38
|
+
public static final String VERSION = "7.4.0";
|
|
30
39
|
public static final String SHARED_PREFERENCES_NAME = "CapawesomeLiveUpdate"; // DO NOT CHANGE
|
|
31
40
|
public static final String ERROR_APP_ID_MISSING = "appId must be configured.";
|
|
32
41
|
public static final String ERROR_BUNDLE_EXISTS = "bundle already exists.";
|
|
@@ -45,8 +54,8 @@ public class LiveUpdatePlugin extends Plugin {
|
|
|
45
54
|
public static final String ERROR_SYNC_IN_PROGRESS = "Sync is already in progress.";
|
|
46
55
|
public static final String ERROR_UNKNOWN_ERROR = "An unknown error has occurred.";
|
|
47
56
|
public static final String EVENT_DOWNLOAD_BUNDLE_PROGRESS = "downloadBundleProgress";
|
|
48
|
-
|
|
49
|
-
|
|
57
|
+
public static final String EVENT_NEXT_BUNDLE_SET = "nextBundleSet";
|
|
58
|
+
public static final String EVENT_RELOADED = "reloaded";
|
|
50
59
|
|
|
51
60
|
@Nullable
|
|
52
61
|
private LiveUpdateConfig config;
|
|
@@ -54,6 +63,8 @@ public class LiveUpdatePlugin extends Plugin {
|
|
|
54
63
|
@Nullable
|
|
55
64
|
private LiveUpdate implementation;
|
|
56
65
|
|
|
66
|
+
private boolean webViewListenerRegistered = false;
|
|
67
|
+
|
|
57
68
|
public void load() {
|
|
58
69
|
try {
|
|
59
70
|
config = getLiveUpdateConfig();
|
|
@@ -63,6 +74,46 @@ public class LiveUpdatePlugin extends Plugin {
|
|
|
63
74
|
}
|
|
64
75
|
}
|
|
65
76
|
|
|
77
|
+
@Override
|
|
78
|
+
protected void handleOnResume() {
|
|
79
|
+
super.handleOnResume();
|
|
80
|
+
try {
|
|
81
|
+
// Notify the implementation that the app has resumed
|
|
82
|
+
if (implementation != null) {
|
|
83
|
+
implementation.handleOnResume();
|
|
84
|
+
}
|
|
85
|
+
// Register WebView listener to trigger auto-update when page is loaded
|
|
86
|
+
// Important: For some reason, the listener CANNOT be registered in the load() method
|
|
87
|
+
// or constructor, it MUST be done here in onResume().
|
|
88
|
+
if (!webViewListenerRegistered) {
|
|
89
|
+
webViewListenerRegistered = true;
|
|
90
|
+
getBridge()
|
|
91
|
+
.addWebViewListener(
|
|
92
|
+
new WebViewListener() {
|
|
93
|
+
@Override
|
|
94
|
+
public void onPageLoaded(WebView webView) {
|
|
95
|
+
if (implementation != null) {
|
|
96
|
+
implementation.handleOnPageLoaded();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
} catch (Exception exception) {
|
|
103
|
+
Logger.error(TAG, exception.getMessage(), exception);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@PluginMethod
|
|
108
|
+
public void clearBlockedBundles(PluginCall call) {
|
|
109
|
+
try {
|
|
110
|
+
implementation.clearBlockedBundles();
|
|
111
|
+
resolveCall(call);
|
|
112
|
+
} catch (Exception exception) {
|
|
113
|
+
rejectCall(call, exception);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
66
117
|
@PluginMethod
|
|
67
118
|
public void deleteBundle(PluginCall call) {
|
|
68
119
|
try {
|
|
@@ -130,10 +181,16 @@ public class LiveUpdatePlugin extends Plugin {
|
|
|
130
181
|
@PluginMethod
|
|
131
182
|
public void fetchLatestBundle(PluginCall call) {
|
|
132
183
|
try {
|
|
184
|
+
String appId = config.getAppId();
|
|
185
|
+
if (appId == null || appId.isEmpty()) {
|
|
186
|
+
call.reject(ERROR_APP_ID_MISSING);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
133
190
|
FetchLatestBundleOptions options = new FetchLatestBundleOptions(call);
|
|
134
|
-
NonEmptyCallback<
|
|
191
|
+
NonEmptyCallback<FetchLatestBundleResult> callback = new NonEmptyCallback<>() {
|
|
135
192
|
@Override
|
|
136
|
-
public void success(
|
|
193
|
+
public void success(FetchLatestBundleResult result) {
|
|
137
194
|
resolveCall(call, result.toJSObject());
|
|
138
195
|
}
|
|
139
196
|
|
|
@@ -149,6 +206,28 @@ public class LiveUpdatePlugin extends Plugin {
|
|
|
149
206
|
}
|
|
150
207
|
}
|
|
151
208
|
|
|
209
|
+
@PluginMethod
|
|
210
|
+
public void getBlockedBundles(PluginCall call) {
|
|
211
|
+
try {
|
|
212
|
+
NonEmptyCallback<GetBlockedBundlesResult> callback = new NonEmptyCallback<>() {
|
|
213
|
+
@Override
|
|
214
|
+
public void success(GetBlockedBundlesResult result) {
|
|
215
|
+
resolveCall(call, result.toJSObject());
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
@Override
|
|
219
|
+
public void error(Exception exception) {
|
|
220
|
+
rejectCall(call, exception);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
assert implementation != null;
|
|
225
|
+
implementation.getBlockedBundles(callback);
|
|
226
|
+
} catch (Exception exception) {
|
|
227
|
+
rejectCall(call, exception);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
152
231
|
@PluginMethod
|
|
153
232
|
public void getBundles(PluginCall call) {
|
|
154
233
|
try {
|
|
@@ -170,6 +249,28 @@ public class LiveUpdatePlugin extends Plugin {
|
|
|
170
249
|
}
|
|
171
250
|
}
|
|
172
251
|
|
|
252
|
+
@PluginMethod
|
|
253
|
+
public void getDownloadedBundles(PluginCall call) {
|
|
254
|
+
try {
|
|
255
|
+
NonEmptyCallback<GetDownloadedBundlesResult> callback = new NonEmptyCallback<>() {
|
|
256
|
+
@Override
|
|
257
|
+
public void success(GetDownloadedBundlesResult result) {
|
|
258
|
+
resolveCall(call, result.toJSObject());
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
@Override
|
|
262
|
+
public void error(Exception exception) {
|
|
263
|
+
rejectCall(call, exception);
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
assert implementation != null;
|
|
268
|
+
implementation.getDownloadedBundles(callback);
|
|
269
|
+
} catch (Exception exception) {
|
|
270
|
+
rejectCall(call, exception);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
173
274
|
@PluginMethod
|
|
174
275
|
public void getChannel(PluginCall call) {
|
|
175
276
|
try {
|
|
@@ -191,6 +292,28 @@ public class LiveUpdatePlugin extends Plugin {
|
|
|
191
292
|
}
|
|
192
293
|
}
|
|
193
294
|
|
|
295
|
+
@PluginMethod
|
|
296
|
+
public void getConfig(PluginCall call) {
|
|
297
|
+
try {
|
|
298
|
+
NonEmptyCallback<GetConfigResult> callback = new NonEmptyCallback<>() {
|
|
299
|
+
@Override
|
|
300
|
+
public void success(GetConfigResult result) {
|
|
301
|
+
resolveCall(call, result.toJSObject());
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
@Override
|
|
305
|
+
public void error(Exception exception) {
|
|
306
|
+
rejectCall(call, exception);
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
assert implementation != null;
|
|
311
|
+
implementation.getConfig(callback);
|
|
312
|
+
} catch (Exception exception) {
|
|
313
|
+
rejectCall(call, exception);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
194
317
|
@PluginMethod
|
|
195
318
|
public void getCurrentBundle(PluginCall call) {
|
|
196
319
|
try {
|
|
@@ -319,6 +442,28 @@ public class LiveUpdatePlugin extends Plugin {
|
|
|
319
442
|
}
|
|
320
443
|
}
|
|
321
444
|
|
|
445
|
+
@PluginMethod
|
|
446
|
+
public void isSyncing(PluginCall call) {
|
|
447
|
+
try {
|
|
448
|
+
NonEmptyCallback<IsSyncingResult> callback = new NonEmptyCallback<>() {
|
|
449
|
+
@Override
|
|
450
|
+
public void success(IsSyncingResult result) {
|
|
451
|
+
resolveCall(call, result.toJSObject());
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
@Override
|
|
455
|
+
public void error(Exception exception) {
|
|
456
|
+
rejectCall(call, exception);
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
assert implementation != null;
|
|
461
|
+
implementation.isSyncing(callback);
|
|
462
|
+
} catch (Exception exception) {
|
|
463
|
+
rejectCall(call, exception);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
322
467
|
@PluginMethod
|
|
323
468
|
public void ready(PluginCall call) {
|
|
324
469
|
try {
|
|
@@ -360,6 +505,16 @@ public class LiveUpdatePlugin extends Plugin {
|
|
|
360
505
|
}
|
|
361
506
|
}
|
|
362
507
|
|
|
508
|
+
@PluginMethod
|
|
509
|
+
public void resetConfig(PluginCall call) {
|
|
510
|
+
try {
|
|
511
|
+
implementation.resetConfig();
|
|
512
|
+
resolveCall(call);
|
|
513
|
+
} catch (Exception exception) {
|
|
514
|
+
rejectCall(call, exception);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
363
518
|
@PluginMethod
|
|
364
519
|
public void setChannel(PluginCall call) {
|
|
365
520
|
try {
|
|
@@ -384,6 +539,17 @@ public class LiveUpdatePlugin extends Plugin {
|
|
|
384
539
|
}
|
|
385
540
|
}
|
|
386
541
|
|
|
542
|
+
@PluginMethod
|
|
543
|
+
public void setConfig(PluginCall call) {
|
|
544
|
+
try {
|
|
545
|
+
SetConfigOptions options = new SetConfigOptions(call);
|
|
546
|
+
implementation.setConfig(options);
|
|
547
|
+
resolveCall(call);
|
|
548
|
+
} catch (Exception exception) {
|
|
549
|
+
rejectCall(call, exception);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
387
553
|
@PluginMethod
|
|
388
554
|
public void setCustomId(PluginCall call) {
|
|
389
555
|
try {
|
|
@@ -438,35 +604,26 @@ public class LiveUpdatePlugin extends Plugin {
|
|
|
438
604
|
public void sync(PluginCall call) {
|
|
439
605
|
try {
|
|
440
606
|
String appId = config.getAppId();
|
|
441
|
-
if (appId == null) {
|
|
607
|
+
if (appId == null || appId.isEmpty()) {
|
|
442
608
|
call.reject(ERROR_APP_ID_MISSING);
|
|
443
609
|
return;
|
|
444
610
|
}
|
|
445
611
|
|
|
446
|
-
if (syncInProgress) {
|
|
447
|
-
call.reject(ERROR_SYNC_IN_PROGRESS);
|
|
448
|
-
return;
|
|
449
|
-
}
|
|
450
|
-
syncInProgress = true;
|
|
451
|
-
|
|
452
612
|
SyncOptions options = new SyncOptions(call);
|
|
453
613
|
NonEmptyCallback<Result> callback = new NonEmptyCallback<>() {
|
|
454
614
|
@Override
|
|
455
615
|
public void success(Result result) {
|
|
456
|
-
syncInProgress = false;
|
|
457
616
|
resolveCall(call, result.toJSObject());
|
|
458
617
|
}
|
|
459
618
|
|
|
460
619
|
@Override
|
|
461
620
|
public void error(Exception exception) {
|
|
462
|
-
syncInProgress = false;
|
|
463
621
|
rejectCall(call, exception);
|
|
464
622
|
}
|
|
465
623
|
};
|
|
466
624
|
|
|
467
625
|
implementation.sync(options, callback);
|
|
468
626
|
} catch (Exception exception) {
|
|
469
|
-
syncInProgress = false;
|
|
470
627
|
rejectCall(call, exception);
|
|
471
628
|
}
|
|
472
629
|
}
|
|
@@ -475,13 +632,26 @@ public class LiveUpdatePlugin extends Plugin {
|
|
|
475
632
|
notifyListeners(EVENT_DOWNLOAD_BUNDLE_PROGRESS, event.toJSObject(), false);
|
|
476
633
|
}
|
|
477
634
|
|
|
635
|
+
public void notifyNextBundleSetListeners(@NonNull NextBundleSetEvent event) {
|
|
636
|
+
notifyListeners(EVENT_NEXT_BUNDLE_SET, event.toJSObject(), false);
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
public void notifyReloadedListeners() {
|
|
640
|
+
JSObject event = new JSObject();
|
|
641
|
+
notifyListeners(EVENT_RELOADED, event, true);
|
|
642
|
+
}
|
|
643
|
+
|
|
478
644
|
private LiveUpdateConfig getLiveUpdateConfig() {
|
|
479
645
|
LiveUpdateConfig config = new LiveUpdateConfig();
|
|
480
646
|
|
|
481
647
|
String appId = getConfig().getString("appId", config.getAppId());
|
|
482
648
|
config.setAppId(appId);
|
|
649
|
+
boolean autoBlockRolledBackBundles = getConfig().getBoolean("autoBlockRolledBackBundles", config.getAutoBlockRolledBackBundles());
|
|
650
|
+
config.setAutoBlockRolledBackBundles(autoBlockRolledBackBundles);
|
|
483
651
|
boolean autoDeleteBundles = getConfig().getBoolean("autoDeleteBundles", config.getAutoDeleteBundles());
|
|
484
652
|
config.setAutoDeleteBundles(autoDeleteBundles);
|
|
653
|
+
String autoUpdateStrategy = getConfig().getString("autoUpdateStrategy", config.getAutoUpdateStrategy());
|
|
654
|
+
config.setAutoUpdateStrategy(autoUpdateStrategy);
|
|
485
655
|
String defaultChannel = getConfig().getString("defaultChannel", config.getDefaultChannel());
|
|
486
656
|
config.setDefaultChannel(defaultChannel);
|
|
487
657
|
int httpTimeout = getConfig().getInt("httpTimeout", config.getHttpTimeout());
|
|
@@ -15,9 +15,12 @@ public class LiveUpdatePreferences {
|
|
|
15
15
|
@NonNull
|
|
16
16
|
private final SharedPreferences.Editor settingsEditor;
|
|
17
17
|
|
|
18
|
+
private final String appIdKey = "appId"; // DO NOT CHANGE
|
|
19
|
+
private final String blockedBundleIdsKey = "blockedBundleIds"; // DO NOT CHANGE
|
|
18
20
|
private final String channelKey = "channel"; // DO NOT CHANGE
|
|
19
21
|
private final String deviceIdKey = "deviceId"; // DO NOT CHANGE
|
|
20
22
|
private final String customIdKey = "customId"; // DO NOT CHANGE
|
|
23
|
+
private final String lastVersionCodeKey = "lastVersionCode"; // DO NOT CHANGE
|
|
21
24
|
private final String previousBundleIdKey = "previousBundleId"; // DO NOT CHANGE
|
|
22
25
|
|
|
23
26
|
public LiveUpdatePreferences(@NonNull Context context) {
|
|
@@ -25,6 +28,11 @@ public class LiveUpdatePreferences {
|
|
|
25
28
|
this.settingsEditor = context.getSharedPreferences(LiveUpdatePlugin.SHARED_PREFERENCES_NAME, Activity.MODE_PRIVATE).edit();
|
|
26
29
|
}
|
|
27
30
|
|
|
31
|
+
@Nullable
|
|
32
|
+
public String getAppId() {
|
|
33
|
+
return context.getSharedPreferences(LiveUpdatePlugin.SHARED_PREFERENCES_NAME, Activity.MODE_PRIVATE).getString(appIdKey, null);
|
|
34
|
+
}
|
|
35
|
+
|
|
28
36
|
@Nullable
|
|
29
37
|
public String getChannel() {
|
|
30
38
|
return context.getSharedPreferences(LiveUpdatePlugin.SHARED_PREFERENCES_NAME, Activity.MODE_PRIVATE).getString(channelKey, null);
|
|
@@ -48,6 +56,10 @@ public class LiveUpdatePreferences {
|
|
|
48
56
|
}
|
|
49
57
|
}
|
|
50
58
|
|
|
59
|
+
public int getLastVersionCode() {
|
|
60
|
+
return context.getSharedPreferences(LiveUpdatePlugin.SHARED_PREFERENCES_NAME, Activity.MODE_PRIVATE).getInt(lastVersionCodeKey, -1);
|
|
61
|
+
}
|
|
62
|
+
|
|
51
63
|
@Nullable
|
|
52
64
|
public String getPreviousBundleId() {
|
|
53
65
|
return context
|
|
@@ -55,6 +67,31 @@ public class LiveUpdatePreferences {
|
|
|
55
67
|
.getString(previousBundleIdKey, null);
|
|
56
68
|
}
|
|
57
69
|
|
|
70
|
+
@Nullable
|
|
71
|
+
public String getBlockedBundleIds() {
|
|
72
|
+
return context
|
|
73
|
+
.getSharedPreferences(LiveUpdatePlugin.SHARED_PREFERENCES_NAME, Activity.MODE_PRIVATE)
|
|
74
|
+
.getString(blockedBundleIdsKey, null);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public void setAppId(@Nullable String appId) {
|
|
78
|
+
if (appId == null) {
|
|
79
|
+
settingsEditor.remove(appIdKey);
|
|
80
|
+
} else {
|
|
81
|
+
settingsEditor.putString(appIdKey, appId);
|
|
82
|
+
}
|
|
83
|
+
settingsEditor.apply();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public void setBlockedBundleIds(@Nullable String blockedBundleIds) {
|
|
87
|
+
if (blockedBundleIds == null) {
|
|
88
|
+
settingsEditor.remove(blockedBundleIdsKey);
|
|
89
|
+
} else {
|
|
90
|
+
settingsEditor.putString(blockedBundleIdsKey, blockedBundleIds);
|
|
91
|
+
}
|
|
92
|
+
settingsEditor.apply();
|
|
93
|
+
}
|
|
94
|
+
|
|
58
95
|
public void setChannel(@Nullable String channel) {
|
|
59
96
|
if (channel == null) {
|
|
60
97
|
settingsEditor.remove(channelKey);
|
|
@@ -82,6 +119,11 @@ public class LiveUpdatePreferences {
|
|
|
82
119
|
settingsEditor.apply();
|
|
83
120
|
}
|
|
84
121
|
|
|
122
|
+
public void setLastVersionCode(int versionCode) {
|
|
123
|
+
settingsEditor.putInt(lastVersionCodeKey, versionCode);
|
|
124
|
+
settingsEditor.apply();
|
|
125
|
+
}
|
|
126
|
+
|
|
85
127
|
public void setPreviousBundleId(@Nullable String bundleId) {
|
|
86
128
|
if (bundleId == null) {
|
|
87
129
|
settingsEditor.remove(previousBundleIdKey);
|
|
@@ -36,9 +36,9 @@ public class GetLatestBundleResponse {
|
|
|
36
36
|
this.artifactType = ArtifactType.ZIP;
|
|
37
37
|
}
|
|
38
38
|
this.bundleId = responseJson.optString("bundleId");
|
|
39
|
-
this.checksum = responseJson.optString("checksum");
|
|
39
|
+
this.checksum = responseJson.isNull("checksum") ? null : responseJson.optString("checksum");
|
|
40
40
|
this.customProperties = responseJson.optJSONObject("customProperties");
|
|
41
|
-
this.signature = responseJson.optString("signature");
|
|
41
|
+
this.signature = responseJson.isNull("signature") ? null : responseJson.optString("signature");
|
|
42
42
|
this.url = responseJson.optString("url");
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.liveupdate.classes.events;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.Nullable;
|
|
4
|
+
import com.getcapacitor.JSObject;
|
|
5
|
+
import org.json.JSONObject;
|
|
6
|
+
|
|
7
|
+
public class NextBundleSetEvent {
|
|
8
|
+
|
|
9
|
+
@Nullable
|
|
10
|
+
private final String bundleId;
|
|
11
|
+
|
|
12
|
+
public NextBundleSetEvent(@Nullable String bundleId) {
|
|
13
|
+
this.bundleId = bundleId;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@Nullable
|
|
17
|
+
public String getBundleId() {
|
|
18
|
+
return bundleId;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public JSObject toJSObject() {
|
|
22
|
+
JSObject result = new JSObject();
|
|
23
|
+
result.put("bundleId", bundleId == null ? JSONObject.NULL : bundleId);
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.liveupdate.classes.options;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.Nullable;
|
|
4
|
+
import com.getcapacitor.PluginCall;
|
|
5
|
+
|
|
6
|
+
public class SetConfigOptions {
|
|
7
|
+
|
|
8
|
+
@Nullable
|
|
9
|
+
private final String appId;
|
|
10
|
+
|
|
11
|
+
public SetConfigOptions(PluginCall call) {
|
|
12
|
+
this.appId = call.getString("appId");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@Nullable
|
|
16
|
+
public String getAppId() {
|
|
17
|
+
return appId;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.liveupdate.classes.results;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.getcapacitor.JSArray;
|
|
5
|
+
import com.getcapacitor.JSObject;
|
|
6
|
+
import io.capawesome.capacitorjs.plugins.liveupdate.interfaces.Result;
|
|
7
|
+
|
|
8
|
+
public class GetBlockedBundlesResult implements Result {
|
|
9
|
+
|
|
10
|
+
@NonNull
|
|
11
|
+
private String[] bundleIds;
|
|
12
|
+
|
|
13
|
+
public GetBlockedBundlesResult(@NonNull String[] bundleIds) {
|
|
14
|
+
this.bundleIds = bundleIds;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public JSObject toJSObject() {
|
|
18
|
+
JSArray bundleIdsResult = new JSArray();
|
|
19
|
+
for (String bundleId : bundleIds) {
|
|
20
|
+
bundleIdsResult.put(bundleId);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
JSObject result = new JSObject();
|
|
24
|
+
result.put("bundleIds", bundleIdsResult);
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
}
|