@capgo/capacitor-updater 7.2.19 → 7.2.20
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/android/src/main/java/ee/forgr/capacitor_updater/BundleInfo.java +22 -8
- package/android/src/main/java/ee/forgr/capacitor_updater/Callback.java +2 -2
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdater.java +32 -31
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +60 -57
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +1 -1
- package/package.json +1 -1
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
|
|
7
7
|
package ee.forgr.capacitor_updater;
|
|
8
8
|
|
|
9
|
-
import com.getcapacitor.JSObject;
|
|
10
9
|
import java.text.SimpleDateFormat;
|
|
11
10
|
import java.util.Date;
|
|
11
|
+
import java.util.HashMap;
|
|
12
|
+
import java.util.Map;
|
|
12
13
|
import java.util.Objects;
|
|
13
14
|
import java.util.TimeZone;
|
|
14
15
|
import org.json.JSONException;
|
|
@@ -109,10 +110,6 @@ public class BundleInfo {
|
|
|
109
110
|
return new BundleInfo(this.id, this.version, status, this.downloaded, this.checksum);
|
|
110
111
|
}
|
|
111
112
|
|
|
112
|
-
public static BundleInfo fromJSON(final JSObject json) throws JSONException {
|
|
113
|
-
return BundleInfo.fromJSON(json.toString());
|
|
114
|
-
}
|
|
115
|
-
|
|
116
113
|
public static BundleInfo fromJSON(final String jsonString) throws JSONException {
|
|
117
114
|
JSONObject json = new JSONObject(new JSONTokener(jsonString));
|
|
118
115
|
return new BundleInfo(
|
|
@@ -124,8 +121,8 @@ public class BundleInfo {
|
|
|
124
121
|
);
|
|
125
122
|
}
|
|
126
123
|
|
|
127
|
-
public
|
|
128
|
-
final
|
|
124
|
+
public Map<String, Object> toJSONMap() {
|
|
125
|
+
final Map<String, Object> result = new HashMap<>();
|
|
129
126
|
result.put("id", this.getId());
|
|
130
127
|
result.put("version", this.getVersionName());
|
|
131
128
|
result.put("downloaded", this.getDownloaded());
|
|
@@ -149,6 +146,23 @@ public class BundleInfo {
|
|
|
149
146
|
|
|
150
147
|
@Override
|
|
151
148
|
public String toString() {
|
|
152
|
-
return
|
|
149
|
+
return (
|
|
150
|
+
"BundleInfo{" +
|
|
151
|
+
"id='" +
|
|
152
|
+
getId() +
|
|
153
|
+
'\'' +
|
|
154
|
+
", version='" +
|
|
155
|
+
getVersionName() +
|
|
156
|
+
'\'' +
|
|
157
|
+
", downloaded='" +
|
|
158
|
+
getDownloaded() +
|
|
159
|
+
'\'' +
|
|
160
|
+
", checksum='" +
|
|
161
|
+
getChecksum() +
|
|
162
|
+
'\'' +
|
|
163
|
+
", status=" +
|
|
164
|
+
getStatus() +
|
|
165
|
+
'}'
|
|
166
|
+
);
|
|
153
167
|
}
|
|
154
168
|
}
|
|
@@ -16,8 +16,6 @@ import androidx.lifecycle.LifecycleOwner;
|
|
|
16
16
|
import androidx.work.Data;
|
|
17
17
|
import androidx.work.WorkInfo;
|
|
18
18
|
import androidx.work.WorkManager;
|
|
19
|
-
import com.getcapacitor.JSObject;
|
|
20
|
-
import com.getcapacitor.plugin.WebView;
|
|
21
19
|
import com.google.common.util.concurrent.Futures;
|
|
22
20
|
import com.google.common.util.concurrent.ListenableFuture;
|
|
23
21
|
import java.io.BufferedInputStream;
|
|
@@ -30,8 +28,10 @@ import java.io.IOException;
|
|
|
30
28
|
import java.security.SecureRandom;
|
|
31
29
|
import java.util.ArrayList;
|
|
32
30
|
import java.util.Date;
|
|
31
|
+
import java.util.HashMap;
|
|
33
32
|
import java.util.Iterator;
|
|
34
33
|
import java.util.List;
|
|
34
|
+
import java.util.Map;
|
|
35
35
|
import java.util.Objects;
|
|
36
36
|
import java.util.zip.ZipEntry;
|
|
37
37
|
import java.util.zip.ZipInputStream;
|
|
@@ -64,6 +64,7 @@ public class CapacitorUpdater {
|
|
|
64
64
|
public String versionBuild = "";
|
|
65
65
|
public String versionCode = "";
|
|
66
66
|
public String versionOs = "";
|
|
67
|
+
public String CAP_SERVER_PATH = "";
|
|
67
68
|
|
|
68
69
|
public String customId = "";
|
|
69
70
|
public String statsUrl = "";
|
|
@@ -117,7 +118,7 @@ public class CapacitorUpdater {
|
|
|
117
118
|
|
|
118
119
|
void directUpdateFinish(final BundleInfo latest) {}
|
|
119
120
|
|
|
120
|
-
void notifyListeners(final String id, final
|
|
121
|
+
void notifyListeners(final String id, final Map<String, Object> res) {}
|
|
121
122
|
|
|
122
123
|
private String randomString() {
|
|
123
124
|
final StringBuilder sb = new StringBuilder(10);
|
|
@@ -240,7 +241,7 @@ public class CapacitorUpdater {
|
|
|
240
241
|
id,
|
|
241
242
|
new BundleInfo(id, version, BundleStatus.ERROR, new Date(System.currentTimeMillis()), "")
|
|
242
243
|
);
|
|
243
|
-
|
|
244
|
+
Map<String, Object> ret = new HashMap<>();
|
|
244
245
|
ret.put("version", getCurrentBundle().getVersionName());
|
|
245
246
|
ret.put("error", "finish_download_fail");
|
|
246
247
|
sendStats("finish_download_fail", version);
|
|
@@ -256,7 +257,7 @@ public class CapacitorUpdater {
|
|
|
256
257
|
id,
|
|
257
258
|
new BundleInfo(id, failedVersion, BundleStatus.ERROR, new Date(System.currentTimeMillis()), "")
|
|
258
259
|
);
|
|
259
|
-
|
|
260
|
+
Map<String, Object> ret = new HashMap<>();
|
|
260
261
|
ret.put("version", getCurrentBundle().getVersionName());
|
|
261
262
|
if ("low_mem_fail".equals(error)) {
|
|
262
263
|
sendStats("low_mem_fail", failedVersion);
|
|
@@ -350,7 +351,7 @@ public class CapacitorUpdater {
|
|
|
350
351
|
Log.i(CapacitorUpdater.TAG, "Double error, cannot cleanup: " + version);
|
|
351
352
|
}
|
|
352
353
|
|
|
353
|
-
final
|
|
354
|
+
final Map<String, Object> ret = new HashMap<>();
|
|
354
355
|
ret.put("version", CapacitorUpdater.this.getCurrentBundle().getVersionName());
|
|
355
356
|
|
|
356
357
|
CapacitorUpdater.this.notifyListeners("downloadFailed", ret);
|
|
@@ -375,8 +376,8 @@ public class CapacitorUpdater {
|
|
|
375
376
|
BundleInfo next = new BundleInfo(id, version, BundleStatus.PENDING, new Date(System.currentTimeMillis()), checksum);
|
|
376
377
|
this.saveBundleInfo(id, next);
|
|
377
378
|
|
|
378
|
-
final
|
|
379
|
-
ret.put("bundle", next.
|
|
379
|
+
final Map<String, Object> ret = new HashMap<>();
|
|
380
|
+
ret.put("bundle", next.toJSONMap());
|
|
380
381
|
CapacitorUpdater.this.notifyListeners("updateAvailable", ret);
|
|
381
382
|
if (setNext) {
|
|
382
383
|
if (this.directUpdate) {
|
|
@@ -388,7 +389,7 @@ public class CapacitorUpdater {
|
|
|
388
389
|
}
|
|
389
390
|
} catch (IOException e) {
|
|
390
391
|
e.printStackTrace();
|
|
391
|
-
final
|
|
392
|
+
final Map<String, Object> ret = new HashMap<>();
|
|
392
393
|
ret.put("version", CapacitorUpdater.this.getCurrentBundle().getVersionName());
|
|
393
394
|
CapacitorUpdater.this.notifyListeners("downloadFailed", ret);
|
|
394
395
|
CapacitorUpdater.this.sendStats("download_fail");
|
|
@@ -412,7 +413,7 @@ public class CapacitorUpdater {
|
|
|
412
413
|
}
|
|
413
414
|
|
|
414
415
|
private void setCurrentBundle(final File bundle) {
|
|
415
|
-
this.editor.putString(
|
|
416
|
+
this.editor.putString(this.CAP_SERVER_PATH, bundle.getPath());
|
|
416
417
|
Log.i(TAG, "Current bundle set to: " + bundle);
|
|
417
418
|
this.editor.commit();
|
|
418
419
|
}
|
|
@@ -658,7 +659,7 @@ public class CapacitorUpdater {
|
|
|
658
659
|
new okhttp3.Callback() {
|
|
659
660
|
@Override
|
|
660
661
|
public void onFailure(@NonNull Call call, @NonNull IOException e) {
|
|
661
|
-
|
|
662
|
+
Map<String, Object> retError = new HashMap<>();
|
|
662
663
|
retError.put("message", "Request failed: " + e.getMessage());
|
|
663
664
|
retError.put("error", "network_error");
|
|
664
665
|
callback.callback(retError);
|
|
@@ -668,7 +669,7 @@ public class CapacitorUpdater {
|
|
|
668
669
|
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
|
|
669
670
|
try (ResponseBody responseBody = response.body()) {
|
|
670
671
|
if (!response.isSuccessful()) {
|
|
671
|
-
|
|
672
|
+
Map<String, Object> retError = new HashMap<>();
|
|
672
673
|
retError.put("message", "Server error: " + response.code());
|
|
673
674
|
retError.put("error", "response_error");
|
|
674
675
|
callback.callback(retError);
|
|
@@ -678,7 +679,7 @@ public class CapacitorUpdater {
|
|
|
678
679
|
assert responseBody != null;
|
|
679
680
|
String responseData = responseBody.string();
|
|
680
681
|
JSONObject jsonResponse = new JSONObject(responseData);
|
|
681
|
-
|
|
682
|
+
Map<String, Object> ret = new HashMap<>();
|
|
682
683
|
|
|
683
684
|
Iterator<String> keys = jsonResponse.keys();
|
|
684
685
|
while (keys.hasNext()) {
|
|
@@ -693,7 +694,7 @@ public class CapacitorUpdater {
|
|
|
693
694
|
}
|
|
694
695
|
callback.callback(ret);
|
|
695
696
|
} catch (JSONException e) {
|
|
696
|
-
|
|
697
|
+
Map<String, Object> retError = new HashMap<>();
|
|
697
698
|
retError.put("message", "JSON parse error: " + e.getMessage());
|
|
698
699
|
retError.put("error", "parse_error");
|
|
699
700
|
callback.callback(retError);
|
|
@@ -712,7 +713,7 @@ public class CapacitorUpdater {
|
|
|
712
713
|
}
|
|
713
714
|
} catch (JSONException e) {
|
|
714
715
|
Log.e(TAG, "Error getLatest JSONException", e);
|
|
715
|
-
final
|
|
716
|
+
final Map<String, Object> retError = new HashMap<>();
|
|
716
717
|
retError.put("message", "Cannot get info: " + e);
|
|
717
718
|
retError.put("error", "json_error");
|
|
718
719
|
callback.callback(retError);
|
|
@@ -728,7 +729,7 @@ public class CapacitorUpdater {
|
|
|
728
729
|
String channelUrl = this.channelUrl;
|
|
729
730
|
if (channelUrl == null || channelUrl.isEmpty()) {
|
|
730
731
|
Log.e(TAG, "Channel URL is not set");
|
|
731
|
-
final
|
|
732
|
+
final Map<String, Object> retError = new HashMap<>();
|
|
732
733
|
retError.put("message", "channelUrl missing");
|
|
733
734
|
retError.put("error", "missing_config");
|
|
734
735
|
callback.callback(retError);
|
|
@@ -739,7 +740,7 @@ public class CapacitorUpdater {
|
|
|
739
740
|
json = this.createInfoObject();
|
|
740
741
|
} catch (JSONException e) {
|
|
741
742
|
Log.e(TAG, "Error unsetChannel JSONException", e);
|
|
742
|
-
final
|
|
743
|
+
final Map<String, Object> retError = new HashMap<>();
|
|
743
744
|
retError.put("message", "Cannot get info: " + e);
|
|
744
745
|
retError.put("error", "json_error");
|
|
745
746
|
callback.callback(retError);
|
|
@@ -757,7 +758,7 @@ public class CapacitorUpdater {
|
|
|
757
758
|
new okhttp3.Callback() {
|
|
758
759
|
@Override
|
|
759
760
|
public void onFailure(@NonNull Call call, @NonNull IOException e) {
|
|
760
|
-
|
|
761
|
+
Map<String, Object> retError = new HashMap<>();
|
|
761
762
|
retError.put("message", "Request failed: " + e.getMessage());
|
|
762
763
|
retError.put("error", "network_error");
|
|
763
764
|
callback.callback(retError);
|
|
@@ -767,7 +768,7 @@ public class CapacitorUpdater {
|
|
|
767
768
|
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
|
|
768
769
|
try (ResponseBody responseBody = response.body()) {
|
|
769
770
|
if (!response.isSuccessful()) {
|
|
770
|
-
|
|
771
|
+
Map<String, Object> retError = new HashMap<>();
|
|
771
772
|
retError.put("message", "Server error: " + response.code());
|
|
772
773
|
retError.put("error", "response_error");
|
|
773
774
|
callback.callback(retError);
|
|
@@ -777,7 +778,7 @@ public class CapacitorUpdater {
|
|
|
777
778
|
assert responseBody != null;
|
|
778
779
|
String responseData = responseBody.string();
|
|
779
780
|
JSONObject jsonResponse = new JSONObject(responseData);
|
|
780
|
-
|
|
781
|
+
Map<String, Object> ret = new HashMap<>();
|
|
781
782
|
|
|
782
783
|
Iterator<String> keys = jsonResponse.keys();
|
|
783
784
|
while (keys.hasNext()) {
|
|
@@ -789,7 +790,7 @@ public class CapacitorUpdater {
|
|
|
789
790
|
Log.i(TAG, "Channel unset");
|
|
790
791
|
callback.callback(ret);
|
|
791
792
|
} catch (JSONException e) {
|
|
792
|
-
|
|
793
|
+
Map<String, Object> retError = new HashMap<>();
|
|
793
794
|
retError.put("message", "JSON parse error: " + e.getMessage());
|
|
794
795
|
retError.put("error", "parse_error");
|
|
795
796
|
callback.callback(retError);
|
|
@@ -803,7 +804,7 @@ public class CapacitorUpdater {
|
|
|
803
804
|
String channelUrl = this.channelUrl;
|
|
804
805
|
if (channelUrl == null || channelUrl.isEmpty()) {
|
|
805
806
|
Log.e(TAG, "Channel URL is not set");
|
|
806
|
-
final
|
|
807
|
+
final Map<String, Object> retError = new HashMap<>();
|
|
807
808
|
retError.put("message", "channelUrl missing");
|
|
808
809
|
retError.put("error", "missing_config");
|
|
809
810
|
callback.callback(retError);
|
|
@@ -815,7 +816,7 @@ public class CapacitorUpdater {
|
|
|
815
816
|
json.put("channel", channel);
|
|
816
817
|
} catch (JSONException e) {
|
|
817
818
|
Log.e(TAG, "Error setChannel JSONException", e);
|
|
818
|
-
final
|
|
819
|
+
final Map<String, Object> retError = new HashMap<>();
|
|
819
820
|
retError.put("message", "Cannot get info: " + e);
|
|
820
821
|
retError.put("error", "json_error");
|
|
821
822
|
callback.callback(retError);
|
|
@@ -829,7 +830,7 @@ public class CapacitorUpdater {
|
|
|
829
830
|
String channelUrl = this.channelUrl;
|
|
830
831
|
if (channelUrl == null || channelUrl.isEmpty()) {
|
|
831
832
|
Log.e(TAG, "Channel URL is not set");
|
|
832
|
-
final
|
|
833
|
+
final Map<String, Object> retError = new HashMap<>();
|
|
833
834
|
retError.put("message", "Channel URL is not set");
|
|
834
835
|
retError.put("error", "missing_config");
|
|
835
836
|
callback.callback(retError);
|
|
@@ -840,7 +841,7 @@ public class CapacitorUpdater {
|
|
|
840
841
|
json = this.createInfoObject();
|
|
841
842
|
} catch (JSONException e) {
|
|
842
843
|
Log.e(TAG, "Error getChannel JSONException", e);
|
|
843
|
-
final
|
|
844
|
+
final Map<String, Object> retError = new HashMap<>();
|
|
844
845
|
retError.put("message", "Cannot get info: " + e);
|
|
845
846
|
retError.put("error", "json_error");
|
|
846
847
|
callback.callback(retError);
|
|
@@ -858,7 +859,7 @@ public class CapacitorUpdater {
|
|
|
858
859
|
new okhttp3.Callback() {
|
|
859
860
|
@Override
|
|
860
861
|
public void onFailure(@NonNull Call call, @NonNull IOException e) {
|
|
861
|
-
|
|
862
|
+
Map<String, Object> retError = new HashMap<>();
|
|
862
863
|
retError.put("message", "Request failed: " + e.getMessage());
|
|
863
864
|
retError.put("error", "network_error");
|
|
864
865
|
callback.callback(retError);
|
|
@@ -871,7 +872,7 @@ public class CapacitorUpdater {
|
|
|
871
872
|
assert responseBody != null;
|
|
872
873
|
String data = responseBody.string();
|
|
873
874
|
if (data.contains("channel_not_found") && !defaultChannel.isEmpty()) {
|
|
874
|
-
|
|
875
|
+
Map<String, Object> ret = new HashMap<>();
|
|
875
876
|
ret.put("channel", defaultChannel);
|
|
876
877
|
ret.put("status", "default");
|
|
877
878
|
Log.i(TAG, "Channel get to \"" + ret);
|
|
@@ -881,7 +882,7 @@ public class CapacitorUpdater {
|
|
|
881
882
|
}
|
|
882
883
|
|
|
883
884
|
if (!response.isSuccessful()) {
|
|
884
|
-
|
|
885
|
+
Map<String, Object> retError = new HashMap<>();
|
|
885
886
|
retError.put("message", "Server error: " + response.code());
|
|
886
887
|
retError.put("error", "response_error");
|
|
887
888
|
callback.callback(retError);
|
|
@@ -891,7 +892,7 @@ public class CapacitorUpdater {
|
|
|
891
892
|
assert responseBody != null;
|
|
892
893
|
String responseData = responseBody.string();
|
|
893
894
|
JSONObject jsonResponse = new JSONObject(responseData);
|
|
894
|
-
|
|
895
|
+
Map<String, Object> ret = new HashMap<>();
|
|
895
896
|
|
|
896
897
|
Iterator<String> keys = jsonResponse.keys();
|
|
897
898
|
while (keys.hasNext()) {
|
|
@@ -903,7 +904,7 @@ public class CapacitorUpdater {
|
|
|
903
904
|
Log.i(TAG, "Channel get to \"" + ret);
|
|
904
905
|
callback.callback(ret);
|
|
905
906
|
} catch (JSONException e) {
|
|
906
|
-
|
|
907
|
+
Map<String, Object> retError = new HashMap<>();
|
|
907
908
|
retError.put("message", "JSON parse error: " + e.getMessage());
|
|
908
909
|
retError.put("error", "parse_error");
|
|
909
910
|
callback.callback(retError);
|
|
@@ -1039,7 +1040,7 @@ public class CapacitorUpdater {
|
|
|
1039
1040
|
}
|
|
1040
1041
|
|
|
1041
1042
|
public String getCurrentBundlePath() {
|
|
1042
|
-
String path = this.prefs.getString(
|
|
1043
|
+
String path = this.prefs.getString(this.CAP_SERVER_PATH, "public");
|
|
1043
1044
|
if (path.trim().isEmpty()) {
|
|
1044
1045
|
return "public";
|
|
1045
1046
|
}
|
|
@@ -36,6 +36,7 @@ import java.util.Arrays;
|
|
|
36
36
|
import java.util.Date;
|
|
37
37
|
import java.util.Iterator;
|
|
38
38
|
import java.util.List;
|
|
39
|
+
import java.util.Map;
|
|
39
40
|
import java.util.Objects;
|
|
40
41
|
import java.util.Timer;
|
|
41
42
|
import java.util.TimerTask;
|
|
@@ -58,7 +59,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
58
59
|
private static final String statsUrlDefault = "https://plugin.capgo.app/stats";
|
|
59
60
|
private static final String channelUrlDefault = "https://plugin.capgo.app/channel_self";
|
|
60
61
|
|
|
61
|
-
private final String PLUGIN_VERSION = "7.2.
|
|
62
|
+
private final String PLUGIN_VERSION = "7.2.20";
|
|
62
63
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
63
64
|
|
|
64
65
|
private SharedPreferences.Editor editor;
|
|
@@ -89,6 +90,14 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
89
90
|
|
|
90
91
|
private DelayUpdateUtils delayUpdateUtils;
|
|
91
92
|
|
|
93
|
+
private JSObject mapToJSObject(Map<String, Object> map) {
|
|
94
|
+
JSObject jsObject = new JSObject();
|
|
95
|
+
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
|
96
|
+
jsObject.put(entry.getKey(), entry.getValue());
|
|
97
|
+
}
|
|
98
|
+
return jsObject;
|
|
99
|
+
}
|
|
100
|
+
|
|
92
101
|
public Thread startNewThread(final Runnable function, Number waitTime) {
|
|
93
102
|
Thread bgTask = new Thread(() -> {
|
|
94
103
|
try {
|
|
@@ -128,13 +137,14 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
128
137
|
}
|
|
129
138
|
|
|
130
139
|
@Override
|
|
131
|
-
public void notifyListeners(final String id, final
|
|
132
|
-
CapacitorUpdaterPlugin.this.notifyListeners(id, res);
|
|
140
|
+
public void notifyListeners(final String id, final Map<String, Object> res) {
|
|
141
|
+
CapacitorUpdaterPlugin.this.notifyListeners(id, CapacitorUpdaterPlugin.this.mapToJSObject(res));
|
|
133
142
|
}
|
|
134
143
|
};
|
|
135
144
|
final PackageInfo pInfo = this.getContext().getPackageManager().getPackageInfo(this.getContext().getPackageName(), 0);
|
|
136
145
|
this.implementation.activity = this.getActivity();
|
|
137
146
|
this.implementation.versionBuild = this.getConfig().getString("version", pInfo.versionName);
|
|
147
|
+
this.implementation.CAP_SERVER_PATH = WebView.CAP_SERVER_PATH;
|
|
138
148
|
this.implementation.PLUGIN_VERSION = this.PLUGIN_VERSION;
|
|
139
149
|
this.implementation.versionCode = Integer.toString(pInfo.versionCode);
|
|
140
150
|
this.implementation.client = new OkHttpClient.Builder()
|
|
@@ -235,7 +245,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
235
245
|
private void sendReadyToJs(final BundleInfo current, final String msg) {
|
|
236
246
|
Log.i(CapacitorUpdater.TAG, "sendReadyToJs");
|
|
237
247
|
final JSObject ret = new JSObject();
|
|
238
|
-
ret.put("bundle", current.
|
|
248
|
+
ret.put("bundle", mapToJSObject(current.toJSONMap()));
|
|
239
249
|
ret.put("status", msg);
|
|
240
250
|
startNewThread(() -> {
|
|
241
251
|
Log.i(CapacitorUpdater.TAG, "semaphoreReady sendReadyToJs");
|
|
@@ -286,7 +296,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
286
296
|
final JSObject ret = new JSObject();
|
|
287
297
|
ret.put("percent", percent);
|
|
288
298
|
final BundleInfo bundleInfo = this.implementation.getBundleInfo(id);
|
|
289
|
-
ret.put("bundle", bundleInfo.
|
|
299
|
+
ret.put("bundle", mapToJSObject(bundleInfo.toJSONMap()));
|
|
290
300
|
this.notifyListeners("download", ret);
|
|
291
301
|
|
|
292
302
|
if (percent == 100) {
|
|
@@ -412,14 +422,15 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
412
422
|
Log.i(CapacitorUpdater.TAG, "unsetChannel triggerAutoUpdate: " + triggerAutoUpdate);
|
|
413
423
|
startNewThread(() ->
|
|
414
424
|
CapacitorUpdaterPlugin.this.implementation.unsetChannel(res -> {
|
|
415
|
-
|
|
416
|
-
|
|
425
|
+
JSObject jsRes = mapToJSObject(res);
|
|
426
|
+
if (jsRes.has("error")) {
|
|
427
|
+
call.reject(jsRes.getString("error"));
|
|
417
428
|
} else {
|
|
418
429
|
if (CapacitorUpdaterPlugin.this._isAutoUpdateEnabled() && Boolean.TRUE.equals(triggerAutoUpdate)) {
|
|
419
430
|
Log.i(CapacitorUpdater.TAG, "Calling autoupdater after channel change!");
|
|
420
431
|
backgroundDownload();
|
|
421
432
|
}
|
|
422
|
-
call.resolve(
|
|
433
|
+
call.resolve(jsRes);
|
|
423
434
|
}
|
|
424
435
|
})
|
|
425
436
|
);
|
|
@@ -443,14 +454,15 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
443
454
|
Log.i(CapacitorUpdater.TAG, "setChannel " + channel + " triggerAutoUpdate: " + triggerAutoUpdate);
|
|
444
455
|
startNewThread(() ->
|
|
445
456
|
CapacitorUpdaterPlugin.this.implementation.setChannel(channel, res -> {
|
|
446
|
-
|
|
447
|
-
|
|
457
|
+
JSObject jsRes = mapToJSObject(res);
|
|
458
|
+
if (jsRes.has("error")) {
|
|
459
|
+
call.reject(jsRes.getString("error"));
|
|
448
460
|
} else {
|
|
449
461
|
if (CapacitorUpdaterPlugin.this._isAutoUpdateEnabled() && Boolean.TRUE.equals(triggerAutoUpdate)) {
|
|
450
462
|
Log.i(CapacitorUpdater.TAG, "Calling autoupdater after channel change!");
|
|
451
463
|
backgroundDownload();
|
|
452
464
|
}
|
|
453
|
-
call.resolve(
|
|
465
|
+
call.resolve(jsRes);
|
|
454
466
|
}
|
|
455
467
|
})
|
|
456
468
|
);
|
|
@@ -466,10 +478,11 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
466
478
|
Log.i(CapacitorUpdater.TAG, "getChannel");
|
|
467
479
|
startNewThread(() ->
|
|
468
480
|
CapacitorUpdaterPlugin.this.implementation.getChannel(res -> {
|
|
469
|
-
|
|
470
|
-
|
|
481
|
+
JSObject jsRes = mapToJSObject(res);
|
|
482
|
+
if (jsRes.has("error")) {
|
|
483
|
+
call.reject(jsRes.getString("error"));
|
|
471
484
|
} else {
|
|
472
|
-
call.resolve(
|
|
485
|
+
call.resolve(jsRes);
|
|
473
486
|
}
|
|
474
487
|
})
|
|
475
488
|
);
|
|
@@ -503,7 +516,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
503
516
|
if (downloaded.isErrorStatus()) {
|
|
504
517
|
throw new RuntimeException("Download failed: " + downloaded.getStatus());
|
|
505
518
|
} else {
|
|
506
|
-
call.resolve(downloaded.
|
|
519
|
+
call.resolve(mapToJSObject(downloaded.toJSONMap()));
|
|
507
520
|
}
|
|
508
521
|
} catch (final Exception e) {
|
|
509
522
|
Log.e(CapacitorUpdater.TAG, "Failed to download from: " + url, e);
|
|
@@ -625,7 +638,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
625
638
|
Log.e(CapacitorUpdater.TAG, "Set next id failed. Bundle " + id + " does not exist.");
|
|
626
639
|
call.reject("Set next id failed. Bundle " + id + " does not exist.");
|
|
627
640
|
} else {
|
|
628
|
-
call.resolve(this.implementation.getBundleInfo(id).
|
|
641
|
+
call.resolve(mapToJSObject(this.implementation.getBundleInfo(id).toJSONMap()));
|
|
629
642
|
}
|
|
630
643
|
} catch (final Exception e) {
|
|
631
644
|
Log.e(CapacitorUpdater.TAG, "Could not set next id " + id, e);
|
|
@@ -686,7 +699,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
686
699
|
final JSObject ret = new JSObject();
|
|
687
700
|
final JSArray values = new JSArray();
|
|
688
701
|
for (final BundleInfo bundle : res) {
|
|
689
|
-
values.put(bundle.
|
|
702
|
+
values.put(mapToJSObject(bundle.toJSONMap()));
|
|
690
703
|
}
|
|
691
704
|
ret.put("bundles", values);
|
|
692
705
|
call.resolve(ret);
|
|
@@ -701,28 +714,16 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
701
714
|
final String channel = call.getString("channel");
|
|
702
715
|
startNewThread(() ->
|
|
703
716
|
CapacitorUpdaterPlugin.this.implementation.getLatest(CapacitorUpdaterPlugin.this.updateUrl, channel, res -> {
|
|
704
|
-
|
|
705
|
-
|
|
717
|
+
JSObject jsRes = mapToJSObject(res);
|
|
718
|
+
if (jsRes.has("error")) {
|
|
719
|
+
call.reject(jsRes.getString("error"));
|
|
706
720
|
return;
|
|
707
|
-
} else if (
|
|
708
|
-
call.reject(
|
|
721
|
+
} else if (jsRes.has("message")) {
|
|
722
|
+
call.reject(jsRes.getString("message"));
|
|
709
723
|
return;
|
|
710
724
|
} else {
|
|
711
|
-
call.resolve(
|
|
712
|
-
}
|
|
713
|
-
final JSObject ret = new JSObject();
|
|
714
|
-
Iterator<String> keys = res.keys();
|
|
715
|
-
while (keys.hasNext()) {
|
|
716
|
-
String key = keys.next();
|
|
717
|
-
if (res.has(key)) {
|
|
718
|
-
try {
|
|
719
|
-
ret.put(key, res.get(key));
|
|
720
|
-
} catch (JSONException e) {
|
|
721
|
-
e.printStackTrace();
|
|
722
|
-
}
|
|
723
|
-
}
|
|
725
|
+
call.resolve(jsRes);
|
|
724
726
|
}
|
|
725
|
-
call.resolve(ret);
|
|
726
727
|
})
|
|
727
728
|
);
|
|
728
729
|
}
|
|
@@ -761,7 +762,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
761
762
|
try {
|
|
762
763
|
final JSObject ret = new JSObject();
|
|
763
764
|
final BundleInfo bundle = this.implementation.getCurrentBundle();
|
|
764
|
-
ret.put("bundle", bundle.
|
|
765
|
+
ret.put("bundle", mapToJSObject(bundle.toJSONMap()));
|
|
765
766
|
ret.put("native", this.currentVersionNative);
|
|
766
767
|
call.resolve(ret);
|
|
767
768
|
} catch (final Exception e) {
|
|
@@ -779,7 +780,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
779
780
|
return;
|
|
780
781
|
}
|
|
781
782
|
|
|
782
|
-
call.resolve(bundle.
|
|
783
|
+
call.resolve(mapToJSObject(bundle.toJSONMap()));
|
|
783
784
|
} catch (final Exception e) {
|
|
784
785
|
Log.e(CapacitorUpdater.TAG, "Could not get next bundle", e);
|
|
785
786
|
call.reject("Could not get next bundle", e);
|
|
@@ -797,10 +798,11 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
797
798
|
public void run() {
|
|
798
799
|
try {
|
|
799
800
|
CapacitorUpdaterPlugin.this.implementation.getLatest(CapacitorUpdaterPlugin.this.updateUrl, null, res -> {
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
801
|
+
JSObject jsRes = mapToJSObject(res);
|
|
802
|
+
if (jsRes.has("error")) {
|
|
803
|
+
Log.e(CapacitorUpdater.TAG, Objects.requireNonNull(jsRes.getString("error")));
|
|
804
|
+
} else if (jsRes.has("version")) {
|
|
805
|
+
String newVersion = jsRes.getString("version");
|
|
804
806
|
String currentVersion = String.valueOf(CapacitorUpdaterPlugin.this.implementation.getCurrentBundle());
|
|
805
807
|
if (!Objects.equals(newVersion, currentVersion)) {
|
|
806
808
|
Log.i(CapacitorUpdater.TAG, "New version found: " + newVersion);
|
|
@@ -828,7 +830,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
828
830
|
this.semaphoreDown();
|
|
829
831
|
Log.i(CapacitorUpdater.TAG, "semaphoreReady countDown done");
|
|
830
832
|
final JSObject ret = new JSObject();
|
|
831
|
-
ret.put("bundle", bundle.
|
|
833
|
+
ret.put("bundle", mapToJSObject(bundle.toJSONMap()));
|
|
832
834
|
call.resolve(ret);
|
|
833
835
|
} catch (final Exception e) {
|
|
834
836
|
Log.e(CapacitorUpdater.TAG, "Failed to notify app ready state. [Error calling 'notifyAppReady()']", e);
|
|
@@ -950,7 +952,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
950
952
|
this.notifyListeners("downloadFailed", ret);
|
|
951
953
|
}
|
|
952
954
|
final JSObject ret = new JSObject();
|
|
953
|
-
ret.put("bundle", current.
|
|
955
|
+
ret.put("bundle", mapToJSObject(current.toJSONMap()));
|
|
954
956
|
this.notifyListeners("noNeedUpdate", ret);
|
|
955
957
|
this.sendReadyToJs(current, msg);
|
|
956
958
|
this.backgroundDownloadTask = null;
|
|
@@ -964,17 +966,18 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
964
966
|
return startNewThread(() -> {
|
|
965
967
|
Log.i(CapacitorUpdater.TAG, "Check for update via: " + CapacitorUpdaterPlugin.this.updateUrl);
|
|
966
968
|
CapacitorUpdaterPlugin.this.implementation.getLatest(CapacitorUpdaterPlugin.this.updateUrl, null, res -> {
|
|
969
|
+
JSObject jsRes = mapToJSObject(res);
|
|
967
970
|
final BundleInfo current = CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
|
|
968
971
|
try {
|
|
969
|
-
if (
|
|
970
|
-
Log.i(CapacitorUpdater.TAG, "API message: " +
|
|
971
|
-
if (
|
|
972
|
+
if (jsRes.has("message")) {
|
|
973
|
+
Log.i(CapacitorUpdater.TAG, "API message: " + jsRes.get("message"));
|
|
974
|
+
if (jsRes.has("major") && jsRes.getBoolean("major") && jsRes.has("version")) {
|
|
972
975
|
final JSObject majorAvailable = new JSObject();
|
|
973
|
-
majorAvailable.put("version",
|
|
976
|
+
majorAvailable.put("version", jsRes.getString("version"));
|
|
974
977
|
CapacitorUpdaterPlugin.this.notifyListeners("majorAvailable", majorAvailable);
|
|
975
978
|
}
|
|
976
979
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
977
|
-
|
|
980
|
+
jsRes.getString("message"),
|
|
978
981
|
current.getVersionName(),
|
|
979
982
|
current,
|
|
980
983
|
true
|
|
@@ -982,7 +985,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
982
985
|
return;
|
|
983
986
|
}
|
|
984
987
|
|
|
985
|
-
final String latestVersionName =
|
|
988
|
+
final String latestVersionName = jsRes.getString("version");
|
|
986
989
|
|
|
987
990
|
if ("builtin".equals(latestVersionName)) {
|
|
988
991
|
Log.i(CapacitorUpdater.TAG, "Latest version is builtin");
|
|
@@ -1008,7 +1011,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1008
1011
|
return;
|
|
1009
1012
|
}
|
|
1010
1013
|
|
|
1011
|
-
if (!
|
|
1014
|
+
if (!jsRes.has("url") || !CapacitorUpdaterPlugin.this.isValidURL(jsRes.getString("url"))) {
|
|
1012
1015
|
Log.e(CapacitorUpdater.TAG, "Error no url or wrong format");
|
|
1013
1016
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1014
1017
|
"Error no url or wrong format",
|
|
@@ -1025,7 +1028,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1025
1028
|
final BundleInfo latest = CapacitorUpdaterPlugin.this.implementation.getBundleInfoByName(latestVersionName);
|
|
1026
1029
|
if (latest != null) {
|
|
1027
1030
|
final JSObject ret = new JSObject();
|
|
1028
|
-
ret.put("bundle", latest.
|
|
1031
|
+
ret.put("bundle", mapToJSObject(latest.toJSONMap()));
|
|
1029
1032
|
if (latest.isErrorStatus()) {
|
|
1030
1033
|
Log.e(CapacitorUpdater.TAG, "Latest bundle already exists, and is in error state. Aborting update.");
|
|
1031
1034
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
@@ -1103,13 +1106,13 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1103
1106
|
messageUpdate
|
|
1104
1107
|
);
|
|
1105
1108
|
|
|
1106
|
-
final String url =
|
|
1107
|
-
final String sessionKey =
|
|
1108
|
-
final String checksum =
|
|
1109
|
+
final String url = jsRes.getString("url");
|
|
1110
|
+
final String sessionKey = jsRes.has("sessionKey") ? jsRes.getString("sessionKey") : "";
|
|
1111
|
+
final String checksum = jsRes.has("checksum") ? jsRes.getString("checksum") : "";
|
|
1109
1112
|
|
|
1110
|
-
if (
|
|
1113
|
+
if (jsRes.has("manifest")) {
|
|
1111
1114
|
// Handle manifest-based download
|
|
1112
|
-
JSONArray manifest =
|
|
1115
|
+
JSONArray manifest = jsRes.getJSONArray("manifest");
|
|
1113
1116
|
CapacitorUpdaterPlugin.this.implementation.downloadBackground(
|
|
1114
1117
|
url,
|
|
1115
1118
|
latestVersionName,
|
|
@@ -1196,7 +1199,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1196
1199
|
Log.e(CapacitorUpdater.TAG, "notifyAppReady was not called, roll back current bundle: " + current.getId());
|
|
1197
1200
|
Log.i(CapacitorUpdater.TAG, "Did you forget to call 'notifyAppReady()' in your Capacitor App code?");
|
|
1198
1201
|
final JSObject ret = new JSObject();
|
|
1199
|
-
ret.put("bundle", current.
|
|
1202
|
+
ret.put("bundle", mapToJSObject(current.toJSONMap()));
|
|
1200
1203
|
this.notifyListeners("updateFailed", ret);
|
|
1201
1204
|
this.implementation.sendStats("update_fail", current.getVersionName());
|
|
1202
1205
|
this.implementation.setError(current);
|
|
@@ -45,7 +45,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
45
45
|
CAPPluginMethod(name: "getNextBundle", returnType: CAPPluginReturnPromise)
|
|
46
46
|
]
|
|
47
47
|
public var implementation = CapacitorUpdater()
|
|
48
|
-
private let PLUGIN_VERSION: String = "7.2.
|
|
48
|
+
private let PLUGIN_VERSION: String = "7.2.20"
|
|
49
49
|
static let updateUrlDefault = "https://plugin.capgo.app/updates"
|
|
50
50
|
static let statsUrlDefault = "https://plugin.capgo.app/stats"
|
|
51
51
|
static let channelUrlDefault = "https://plugin.capgo.app/channel_self"
|