@capgo/capacitor-updater 5.7.7 → 5.7.9

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.
@@ -0,0 +1,7 @@
1
+ package ee.forgr.capacitor_updater;
2
+
3
+ import com.getcapacitor.JSObject;
4
+
5
+ public interface Callback {
6
+ void callback(JSObject jsoObject);
7
+ }
@@ -23,7 +23,6 @@ import com.android.volley.DefaultRetryPolicy;
23
23
  import com.android.volley.NetworkResponse;
24
24
  import com.android.volley.Request;
25
25
  import com.android.volley.RequestQueue;
26
- import com.android.volley.Response;
27
26
  import com.android.volley.VolleyError;
28
27
  import com.android.volley.toolbox.HttpHeaderParser;
29
28
  import com.android.volley.toolbox.JsonObjectRequest;
@@ -56,10 +55,6 @@ import javax.crypto.SecretKey;
56
55
  import org.json.JSONException;
57
56
  import org.json.JSONObject;
58
57
 
59
- interface Callback {
60
- void callback(JSObject jsoObject);
61
- }
62
-
63
58
  public class CapacitorUpdater {
64
59
 
65
60
  private static final String AB =
@@ -95,16 +90,13 @@ public class CapacitorUpdater {
95
90
  public String deviceID = "";
96
91
  public int timeout = 20000;
97
92
 
98
- private final FilenameFilter filter = new FilenameFilter() {
99
- @Override
100
- public boolean accept(final File f, final String name) {
101
- // ignore directories generated by mac os x
102
- return (
103
- !name.startsWith("__MACOSX") &&
104
- !name.startsWith(".") &&
105
- !name.startsWith(".DS_Store")
106
- );
107
- }
93
+ private final FilenameFilter filter = (f, name) -> {
94
+ // ignore directories generated by mac os x
95
+ return (
96
+ !name.startsWith("__MACOSX") &&
97
+ !name.startsWith(".") &&
98
+ !name.startsWith(".DS_Store")
99
+ );
108
100
  };
109
101
 
110
102
  private boolean isProd() {
@@ -143,23 +135,15 @@ public class CapacitorUpdater {
143
135
  return (percent * (max - min)) / 100 + min;
144
136
  }
145
137
 
146
- void notifyDownload(final String id, final int percent) {
147
- return;
148
- }
138
+ void notifyDownload(final String id, final int percent) {}
149
139
 
150
- void directUpdateFinish(final BundleInfo latest) {
151
- return;
152
- }
140
+ void directUpdateFinish(final BundleInfo latest) {}
153
141
 
154
- void notifyListeners(final String id, final JSObject res) {
155
- return;
156
- }
142
+ void notifyListeners(final String id, final JSObject res) {}
157
143
 
158
- private String randomString(final int len) {
159
- final StringBuilder sb = new StringBuilder(len);
160
- for (int i = 0; i < len; i++) sb.append(
161
- AB.charAt(rnd.nextInt(AB.length()))
162
- );
144
+ private String randomString() {
145
+ final StringBuilder sb = new StringBuilder(10);
146
+ for (int i = 0; i < 10; i++) sb.append(AB.charAt(rnd.nextInt(AB.length())));
163
147
  return sb.toString();
164
148
  }
165
149
 
@@ -205,8 +189,8 @@ public class CapacitorUpdater {
205
189
  );
206
190
  }
207
191
 
192
+ assert dir != null;
208
193
  if (!dir.isDirectory() && !dir.mkdirs()) {
209
- final JSObject ret = new JSObject();
210
194
  this.sendStats("directory_path_fail");
211
195
  throw new FileNotFoundException(
212
196
  "Failed to ensure directory: " + dir.getAbsolutePath()
@@ -248,7 +232,7 @@ public class CapacitorUpdater {
248
232
  );
249
233
  }
250
234
  final File destinationFile = new File(this.documentsDir, dest);
251
- destinationFile.getParentFile().mkdirs();
235
+ Objects.requireNonNull(destinationFile.getParentFile()).mkdirs();
252
236
  final String[] entries = sourceFile.list(this.filter);
253
237
  if (entries == null || entries.length == 0) {
254
238
  throw new IOException(
@@ -283,7 +267,7 @@ public class CapacitorUpdater {
283
267
  this.activity.unregisterReceiver(receiver);
284
268
  }
285
269
 
286
- private BroadcastReceiver receiver = new BroadcastReceiver() {
270
+ private final BroadcastReceiver receiver = new BroadcastReceiver() {
287
271
  @Override
288
272
  public void onReceive(Context context, Intent intent) {
289
273
  String action = intent.getAction();
@@ -358,7 +342,7 @@ public class CapacitorUpdater {
358
342
  final String checksum;
359
343
  checksum = this.getChecksum(downloaded);
360
344
  this.notifyDownload(id, 71);
361
- final File unzipped = this.unzip(id, downloaded, this.randomString(10));
345
+ final File unzipped = this.unzip(id, downloaded, this.randomString());
362
346
  downloaded.delete();
363
347
  this.notifyDownload(id, 91);
364
348
  final String idName = bundleDirectory + "/" + id;
@@ -439,7 +423,7 @@ public class CapacitorUpdater {
439
423
  this.activity.startService(intent);
440
424
  }
441
425
 
442
- private File downloadFile(
426
+ private void downloadFile(
443
427
  final String id,
444
428
  final String url,
445
429
  final String dest
@@ -478,7 +462,6 @@ public class CapacitorUpdater {
478
462
  this.sendStats("low_mem_fail");
479
463
  throw new IOException("OutOfMemoryError while downloading file");
480
464
  }
481
- return target;
482
465
  }
483
466
 
484
467
  private void deleteDirectory(final File file) throws IOException {
@@ -575,7 +558,7 @@ public class CapacitorUpdater {
575
558
  final String sessionKey,
576
559
  final String checksum
577
560
  ) {
578
- final String id = this.randomString(10);
561
+ final String id = this.randomString();
579
562
  this.saveBundleInfo(
580
563
  id,
581
564
  new BundleInfo(
@@ -594,7 +577,7 @@ public class CapacitorUpdater {
594
577
  version,
595
578
  sessionKey,
596
579
  checksum,
597
- this.randomString(10)
580
+ this.randomString()
598
581
  );
599
582
  }
600
583
 
@@ -604,7 +587,7 @@ public class CapacitorUpdater {
604
587
  final String sessionKey,
605
588
  final String checksum
606
589
  ) throws IOException {
607
- final String id = this.randomString(10);
590
+ final String id = this.randomString();
608
591
  this.saveBundleInfo(
609
592
  id,
610
593
  new BundleInfo(
@@ -616,10 +599,9 @@ public class CapacitorUpdater {
616
599
  )
617
600
  );
618
601
  this.notifyDownload(id, 0);
619
- final String idName = bundleDirectory + "/" + id;
620
602
  this.notifyDownload(id, 5);
621
- final String dest = this.randomString(10);
622
- final File downloaded = this.downloadFile(id, url, dest);
603
+ final String dest = this.randomString();
604
+ this.downloadFile(id, url, dest);
623
605
  final Boolean finished =
624
606
  this.finishDownload(id, dest, version, sessionKey, checksum, false);
625
607
  final BundleStatus status = finished
@@ -684,15 +666,12 @@ public class CapacitorUpdater {
684
666
  private boolean bundleExists(final String id) {
685
667
  final File bundle = this.getBundleDirectory(id);
686
668
  final BundleInfo bundleInfo = this.getBundleInfo(id);
687
- if (
669
+ return (
688
670
  bundle.isDirectory() &&
689
671
  bundle.exists() &&
690
672
  new File(bundle.getPath(), "/index.html").exists() &&
691
673
  !bundleInfo.isDeleted()
692
- ) {
693
- return true;
694
- }
695
- return false;
674
+ );
696
675
  }
697
676
 
698
677
  public Boolean set(final BundleInfo bundle) {
@@ -804,10 +783,10 @@ public class CapacitorUpdater {
804
783
  );
805
784
  retError.put("message", message + ": " + json);
806
785
  } catch (UnsupportedEncodingException e) {
807
- retError.put("message", message + ": " + e.toString());
786
+ retError.put("message", message + ": " + e);
808
787
  }
809
788
  } else {
810
- retError.put("message", message + ": " + error.toString());
789
+ retError.put("message", message + ": " + error);
811
790
  }
812
791
  Log.e(TAG, message + ": " + retError);
813
792
  return retError;
@@ -821,7 +800,7 @@ public class CapacitorUpdater {
821
800
  Log.e(TAG, "Error getLatest JSONException", e);
822
801
  e.printStackTrace();
823
802
  final JSObject retError = new JSObject();
824
- retError.put("message", "Cannot get info: " + e.toString());
803
+ retError.put("message", "Cannot get info: " + e);
825
804
  retError.put("error", "json_error");
826
805
  callback.callback(retError);
827
806
  return;
@@ -833,40 +812,33 @@ public class CapacitorUpdater {
833
812
  Request.Method.POST,
834
813
  updateUrl,
835
814
  json,
836
- new Response.Listener<JSONObject>() {
837
- @Override
838
- public void onResponse(JSONObject res) {
839
- final JSObject ret = new JSObject();
840
- Iterator<String> keys = res.keys();
841
- while (keys.hasNext()) {
842
- String key = keys.next();
843
- if (res.has(key)) {
844
- try {
845
- if ("session_key".equals(key)) {
846
- ret.put("sessionKey", res.get(key));
847
- } else {
848
- ret.put(key, res.get(key));
849
- }
850
- } catch (JSONException e) {
851
- e.printStackTrace();
852
- final JSObject retError = new JSObject();
853
- retError.put("message", "Cannot set info: " + e.toString());
854
- retError.put("error", "response_error");
855
- callback.callback(retError);
815
+ res -> {
816
+ final JSObject ret = new JSObject();
817
+ Iterator<String> keys = res.keys();
818
+ while (keys.hasNext()) {
819
+ String key = keys.next();
820
+ if (res.has(key)) {
821
+ try {
822
+ if ("session_key".equals(key)) {
823
+ ret.put("sessionKey", res.get(key));
824
+ } else {
825
+ ret.put(key, res.get(key));
856
826
  }
827
+ } catch (JSONException e) {
828
+ e.printStackTrace();
829
+ final JSObject retError = new JSObject();
830
+ retError.put("message", "Cannot set info: " + e);
831
+ retError.put("error", "response_error");
832
+ callback.callback(retError);
857
833
  }
858
834
  }
859
- callback.callback(ret);
860
835
  }
836
+ callback.callback(ret);
861
837
  },
862
- new Response.ErrorListener() {
863
- @Override
864
- public void onErrorResponse(VolleyError error) {
865
- callback.callback(
866
- CapacitorUpdater.this.createError("Error get latest", error)
867
- );
868
- }
869
- }
838
+ error ->
839
+ callback.callback(
840
+ CapacitorUpdater.this.createError("Error get latest", error)
841
+ )
870
842
  );
871
843
  this.requestQueue.add(setRetryPolicy(request));
872
844
  }
@@ -881,14 +853,14 @@ public class CapacitorUpdater {
881
853
  callback.callback(retError);
882
854
  return;
883
855
  }
884
- JSONObject json = null;
856
+ JSONObject json;
885
857
  try {
886
858
  json = this.createInfoObject();
887
859
  } catch (JSONException e) {
888
860
  Log.e(TAG, "Error unsetChannel JSONException", e);
889
861
  e.printStackTrace();
890
862
  final JSObject retError = new JSObject();
891
- retError.put("message", "Cannot get info: " + e.toString());
863
+ retError.put("message", "Cannot get info: " + e);
892
864
  retError.put("error", "json_error");
893
865
  callback.callback(retError);
894
866
  return;
@@ -898,40 +870,30 @@ public class CapacitorUpdater {
898
870
  Request.Method.DELETE,
899
871
  channelUrl,
900
872
  json,
901
- new Response.Listener<JSONObject>() {
902
- @Override
903
- public void onResponse(JSONObject res) {
904
- final JSObject ret = new JSObject();
905
- Iterator<String> keys = res.keys();
906
- while (keys.hasNext()) {
907
- String key = keys.next();
908
- if (res.has(key)) {
909
- try {
910
- ret.put(key, res.get(key));
911
- } catch (JSONException e) {
912
- e.printStackTrace();
913
- final JSObject retError = new JSObject();
914
- retError.put(
915
- "message",
916
- "Cannot unset channel: " + e.toString()
917
- );
918
- retError.put("error", "response_error");
919
- callback.callback(ret);
920
- }
873
+ res -> {
874
+ final JSObject ret = new JSObject();
875
+ Iterator<String> keys = res.keys();
876
+ while (keys.hasNext()) {
877
+ String key = keys.next();
878
+ if (res.has(key)) {
879
+ try {
880
+ ret.put(key, res.get(key));
881
+ } catch (JSONException e) {
882
+ e.printStackTrace();
883
+ final JSObject retError = new JSObject();
884
+ retError.put("message", "Cannot unset channel: " + e);
885
+ retError.put("error", "response_error");
886
+ callback.callback(ret);
921
887
  }
922
888
  }
923
- Log.i(TAG, "Channel unset");
924
- callback.callback(ret);
925
889
  }
890
+ Log.i(TAG, "Channel unset");
891
+ callback.callback(ret);
926
892
  },
927
- new Response.ErrorListener() {
928
- @Override
929
- public void onErrorResponse(VolleyError error) {
930
- callback.callback(
931
- CapacitorUpdater.this.createError("Error unset channel", error)
932
- );
933
- }
934
- }
893
+ error ->
894
+ callback.callback(
895
+ CapacitorUpdater.this.createError("Error unset channel", error)
896
+ )
935
897
  );
936
898
  this.requestQueue.add(setRetryPolicy(request));
937
899
  }
@@ -946,7 +908,7 @@ public class CapacitorUpdater {
946
908
  callback.callback(retError);
947
909
  return;
948
910
  }
949
- JSONObject json = null;
911
+ JSONObject json;
950
912
  try {
951
913
  json = this.createInfoObject();
952
914
  json.put("channel", channel);
@@ -954,7 +916,7 @@ public class CapacitorUpdater {
954
916
  Log.e(TAG, "Error setChannel JSONException", e);
955
917
  e.printStackTrace();
956
918
  final JSObject retError = new JSObject();
957
- retError.put("message", "Cannot get info: " + e.toString());
919
+ retError.put("message", "Cannot get info: " + e);
958
920
  retError.put("error", "json_error");
959
921
  callback.callback(retError);
960
922
  return;
@@ -964,37 +926,30 @@ public class CapacitorUpdater {
964
926
  Request.Method.POST,
965
927
  channelUrl,
966
928
  json,
967
- new Response.Listener<JSONObject>() {
968
- @Override
969
- public void onResponse(JSONObject res) {
970
- final JSObject ret = new JSObject();
971
- Iterator<String> keys = res.keys();
972
- while (keys.hasNext()) {
973
- String key = keys.next();
974
- if (res.has(key)) {
975
- try {
976
- ret.put(key, res.get(key));
977
- } catch (JSONException e) {
978
- e.printStackTrace();
979
- final JSObject retError = new JSObject();
980
- retError.put("message", "Cannot set channel: " + e.toString());
981
- retError.put("error", "response_error");
982
- callback.callback(ret);
983
- }
929
+ res -> {
930
+ final JSObject ret = new JSObject();
931
+ Iterator<String> keys = res.keys();
932
+ while (keys.hasNext()) {
933
+ String key = keys.next();
934
+ if (res.has(key)) {
935
+ try {
936
+ ret.put(key, res.get(key));
937
+ } catch (JSONException e) {
938
+ e.printStackTrace();
939
+ final JSObject retError = new JSObject();
940
+ retError.put("message", "Cannot set channel: " + e);
941
+ retError.put("error", "response_error");
942
+ callback.callback(ret);
984
943
  }
985
944
  }
986
- Log.i(TAG, "Channel set to \"" + channel);
987
- callback.callback(ret);
988
945
  }
946
+ Log.i(TAG, "Channel set to \"" + channel);
947
+ callback.callback(ret);
989
948
  },
990
- new Response.ErrorListener() {
991
- @Override
992
- public void onErrorResponse(VolleyError error) {
993
- callback.callback(
994
- CapacitorUpdater.this.createError("Error set channel", error)
995
- );
996
- }
997
- }
949
+ error ->
950
+ callback.callback(
951
+ CapacitorUpdater.this.createError("Error set channel", error)
952
+ )
998
953
  );
999
954
  this.requestQueue.add(setRetryPolicy(request));
1000
955
  }
@@ -1009,14 +964,14 @@ public class CapacitorUpdater {
1009
964
  callback.callback(retError);
1010
965
  return;
1011
966
  }
1012
- JSONObject json = null;
967
+ JSONObject json;
1013
968
  try {
1014
969
  json = this.createInfoObject();
1015
970
  } catch (JSONException e) {
1016
971
  Log.e(TAG, "Error getChannel JSONException", e);
1017
972
  e.printStackTrace();
1018
973
  final JSObject retError = new JSObject();
1019
- retError.put("message", "Cannot get info: " + e.toString());
974
+ retError.put("message", "Cannot get info: " + e);
1020
975
  retError.put("error", "json_error");
1021
976
  callback.callback(retError);
1022
977
  return;
@@ -1026,33 +981,26 @@ public class CapacitorUpdater {
1026
981
  Request.Method.PUT,
1027
982
  channelUrl,
1028
983
  json,
1029
- new Response.Listener<JSONObject>() {
1030
- @Override
1031
- public void onResponse(JSONObject res) {
1032
- final JSObject ret = new JSObject();
1033
- Iterator<String> keys = res.keys();
1034
- while (keys.hasNext()) {
1035
- String key = keys.next();
1036
- if (res.has(key)) {
1037
- try {
1038
- ret.put(key, res.get(key));
1039
- } catch (JSONException e) {
1040
- e.printStackTrace();
1041
- }
984
+ res -> {
985
+ final JSObject ret = new JSObject();
986
+ Iterator<String> keys = res.keys();
987
+ while (keys.hasNext()) {
988
+ String key = keys.next();
989
+ if (res.has(key)) {
990
+ try {
991
+ ret.put(key, res.get(key));
992
+ } catch (JSONException e) {
993
+ e.printStackTrace();
1042
994
  }
1043
995
  }
1044
- Log.i(TAG, "Channel get to \"" + ret);
1045
- callback.callback(ret);
1046
996
  }
997
+ Log.i(TAG, "Channel get to \"" + ret);
998
+ callback.callback(ret);
1047
999
  },
1048
- new Response.ErrorListener() {
1049
- @Override
1050
- public void onErrorResponse(VolleyError error) {
1051
- callback.callback(
1052
- CapacitorUpdater.this.createError("Error get channel", error)
1053
- );
1054
- }
1055
- }
1000
+ error ->
1001
+ callback.callback(
1002
+ CapacitorUpdater.this.createError("Error get channel", error)
1003
+ )
1056
1004
  );
1057
1005
  this.requestQueue.add(setRetryPolicy(request));
1058
1006
  }
@@ -1066,7 +1014,7 @@ public class CapacitorUpdater {
1066
1014
  if (statsUrl == null || statsUrl.isEmpty()) {
1067
1015
  return;
1068
1016
  }
1069
- JSONObject json = null;
1017
+ JSONObject json;
1070
1018
  try {
1071
1019
  json = this.createInfoObject();
1072
1020
  json.put("action", action);
@@ -1080,21 +1028,9 @@ public class CapacitorUpdater {
1080
1028
  Request.Method.POST,
1081
1029
  statsUrl,
1082
1030
  json,
1083
- new Response.Listener<JSONObject>() {
1084
- @Override
1085
- public void onResponse(JSONObject response) {
1086
- Log.i(
1087
- TAG,
1088
- "Stats send for \"" + action + "\", version " + versionName
1089
- );
1090
- }
1091
- },
1092
- new Response.ErrorListener() {
1093
- @Override
1094
- public void onErrorResponse(VolleyError error) {
1095
- CapacitorUpdater.this.createError("Error send stats", error);
1096
- }
1097
- }
1031
+ response ->
1032
+ Log.i(TAG, "Stats send for \"" + action + "\", version " + versionName),
1033
+ error -> CapacitorUpdater.this.createError("Error send stats", error)
1098
1034
  );
1099
1035
  this.requestQueue.add(setRetryPolicy(request));
1100
1036
  }
@@ -1156,14 +1092,6 @@ public class CapacitorUpdater {
1156
1092
  this.editor.commit();
1157
1093
  }
1158
1094
 
1159
- public void setVersionName(final String id, final String name) {
1160
- if (id != null) {
1161
- Log.d(TAG, "Setting name for bundle [" + id + "] to " + name);
1162
- BundleInfo info = this.getBundleInfo(id);
1163
- this.saveBundleInfo(id, info.setVersionName(name));
1164
- }
1165
- }
1166
-
1167
1095
  private void setBundleStatus(final String id, final BundleStatus status) {
1168
1096
  if (id != null && status != null) {
1169
1097
  BundleInfo info = this.getBundleInfo(id);
@@ -55,7 +55,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
55
55
  private static final String channelUrlDefault =
56
56
  "https://api.capgo.app/channel_self";
57
57
 
58
- private final String PLUGIN_VERSION = "5.7.7";
58
+ private final String PLUGIN_VERSION = "5.7.9";
59
59
  private static final String DELAY_CONDITION_PREFERENCES = "";
60
60
 
61
61
  private SharedPreferences.Editor editor;
@@ -950,12 +950,6 @@ extension CustomError: LocalizedError {
950
950
  UserDefaults.standard.synchronize()
951
951
  }
952
952
 
953
- public func setVersionName(id: String, version: String) {
954
- print("\(self.TAG) Setting version for folder [\(id)] to \(version)")
955
- let info = self.getBundleInfo(id: id)
956
- self.saveBundleInfo(id: id, bundle: info.setVersionName(version: version))
957
- }
958
-
959
953
  private func setBundleStatus(id: String, status: BundleStatus) {
960
954
  print("\(self.TAG) Setting status for bundle [\(id)] to \(status)")
961
955
  let info = self.getBundleInfo(id: id)
@@ -15,7 +15,7 @@ import Version
15
15
  @objc(CapacitorUpdaterPlugin)
16
16
  public class CapacitorUpdaterPlugin: CAPPlugin {
17
17
  public var implementation = CapacitorUpdater()
18
- private let PLUGIN_VERSION: String = "5.7.7"
18
+ private let PLUGIN_VERSION: String = "5.7.9"
19
19
  static let updateUrlDefault = "https://api.capgo.app/updates"
20
20
  static let statsUrlDefault = "https://api.capgo.app/stats"
21
21
  static let channelUrlDefault = "https://api.capgo.app/channel_self"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "5.7.7",
3
+ "version": "5.7.9",
4
4
  "packageManager": "pnpm@8.15.4",
5
5
  "license": "MPL-2.0",
6
6
  "description": "Live update for capacitor apps",