@capgo/capacitor-updater 3.0.8 → 3.1.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.
@@ -47,7 +47,7 @@ public class CapacitorUpdater {
47
47
  public String statsUrl = "";
48
48
  public String appId = "";
49
49
  public String deviceID = "";
50
- private String pluginVersion = "3.0.8";
50
+ private String pluginVersion = "3.1.0";
51
51
 
52
52
 
53
53
  private FilenameFilter filter = new FilenameFilter() {
@@ -59,6 +59,7 @@ public class CapacitorUpdater {
59
59
  };
60
60
  private final CapacitorUpdaterPlugin plugin;
61
61
  private String versionBuild = "";
62
+ private String versionCode = "";
62
63
  private String TAG = "Capacitor-updater";
63
64
  private Context context;
64
65
  private String basePathHot = "versions";
@@ -86,6 +87,7 @@ public class CapacitorUpdater {
86
87
  this.deviceID = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
87
88
  PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
88
89
  this.versionBuild = pInfo.versionName;
90
+ this.versionCode = Integer.toString(pInfo.versionCode);
89
91
  }
90
92
  public CapacitorUpdater (Context context, CapacitorUpdaterPlugin plugin) throws PackageManager.NameNotFoundException {
91
93
  this.context = context;
@@ -95,6 +97,7 @@ public class CapacitorUpdater {
95
97
  this.deviceID = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
96
98
  PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
97
99
  this.versionBuild = pInfo.versionName;
100
+ this.versionCode = Integer.toString(pInfo.versionCode);
98
101
  }
99
102
 
100
103
  private Boolean unzip(String source, String dest) {
@@ -114,7 +117,7 @@ public class CapacitorUpdater {
114
117
  int buffLength = 8192;
115
118
  byte[] buffer = new byte[buffLength];
116
119
  long totalLength = zipFile.length();
117
- long readedLength = buffLength;
120
+ long readLength = buffLength;
118
121
  int percent = 0;
119
122
  this.plugin.notifyDownload(75);
120
123
  while ((ze = zis.getNextEntry()) != null) {
@@ -131,19 +134,19 @@ public class CapacitorUpdater {
131
134
  dir.getAbsolutePath());
132
135
  if (ze.isDirectory())
133
136
  continue;
134
- FileOutputStream fout = new FileOutputStream(file);
137
+ FileOutputStream fileOut = new FileOutputStream(file);
135
138
  try {
136
139
  while ((count = zis.read(buffer)) != -1)
137
- fout.write(buffer, 0, count);
140
+ fileOut.write(buffer, 0, count);
138
141
  } finally {
139
- fout.close();
142
+ fileOut.close();
140
143
  }
141
- int newPercent = (int)((readedLength * 100) / totalLength);
144
+ int newPercent = (int)((readLength * 100) / totalLength);
142
145
  if (totalLength > 1 && newPercent != percent) {
143
146
  percent = newPercent;
144
147
  this.plugin.notifyDownload(calcTotalPercent((int)percent, 75, 90));
145
148
  }
146
- readedLength += ze.getCompressedSize();
149
+ readLength += ze.getCompressedSize();
147
150
  }
148
151
  } catch (Exception e) {
149
152
  Log.i(TAG, "unzip error", e);
@@ -194,17 +197,17 @@ public class CapacitorUpdater {
194
197
  downFile.getParentFile().mkdirs();
195
198
  downFile.createNewFile();
196
199
  FileOutputStream fos = new FileOutputStream(downFile);
197
- int readedLength = buffLength;
200
+ int readLength = buffLength;
198
201
  int percent = 0;
199
202
  this.plugin.notifyDownload(10);
200
203
  while ((length = dis.read(buffer))>0) {
201
204
  fos.write(buffer, 0, length);
202
- int newPercent = (int)((readedLength * 100) / totalLength);
205
+ int newPercent = (int)((readLength * 100) / totalLength);
203
206
  if (totalLength > 1 && newPercent != percent) {
204
207
  percent = newPercent;
205
208
  this.plugin.notifyDownload(calcTotalPercent(percent, 10, 70));
206
209
  }
207
- readedLength += length;
210
+ readLength += length;
208
211
  }
209
212
  } catch (Exception e) {
210
213
  Log.e(TAG, "downloadFile error", e);
@@ -297,6 +300,7 @@ public class CapacitorUpdater {
297
300
  String deviceID = this.deviceID;
298
301
  String appId = this.appId;
299
302
  String versionBuild = this.versionBuild;
303
+ String versionCode = this.versionCode;
300
304
  String pluginVersion = this.pluginVersion;
301
305
  String versionName = getVersionName().equals("") ? "builtin" : getVersionName();
302
306
  StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
@@ -323,6 +327,7 @@ public class CapacitorUpdater {
323
327
  params.put("cap_device_id", deviceID);
324
328
  params.put("cap_app_id", appId);
325
329
  params.put("cap_version_build", versionBuild);
330
+ params.put("cap_version_code", versionCode);
326
331
  params.put("cap_version_name", versionName);
327
332
  params.put("cap_plugin_version", pluginVersion);
328
333
  return params;
@@ -361,6 +366,7 @@ public class CapacitorUpdater {
361
366
  json.put("version_name", version);
362
367
  json.put("device_id", this.deviceID);
363
368
  json.put("version_build", this.versionBuild);
369
+ json.put("version_code", this.versionCode);
364
370
  json.put("plugin_version", this.pluginVersion);
365
371
  json.put("app_id", this.appId);
366
372
  jsonString = json.toString();
@@ -82,7 +82,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
82
82
  editor.putString("LatestVersionNative", currentVersionNative.toString());
83
83
  editor.commit();
84
84
  } catch (Exception ex) {
85
- Log.e("CapacitorUpdater", "Cannot get the current version" + ex.getMessage());
85
+ Log.e("CapacitorUpdater", "Cannot get the current version " + ex.getMessage());
86
86
  }
87
87
  }
88
88
  if (!autoUpdate || this.autoUpdateUrl.equals("")) return;
@@ -183,7 +183,10 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
183
183
  }
184
184
  implementation.reset();
185
185
  String pathHot = implementation.getLastPathHot();
186
- this.bridge.setServerAssetPath(pathHot);
186
+ if (this.bridge.getLocalServer() != null) {
187
+ // if the server is not ready yet, hot reload is not needed
188
+ this.bridge.setServerAssetPath(pathHot);
189
+ }
187
190
  return true;
188
191
  }
189
192
 
@@ -37,8 +37,9 @@ extension Bundle {
37
37
  public var appId = ""
38
38
  public var deviceID = UIDevice.current.identifierForVendor?.uuidString ?? ""
39
39
  public var notifyDownload: (Int) -> Void = { _ in }
40
- public var pluginVersion = "3.0.8"
40
+ public var pluginVersion = "3.1.0"
41
41
  private var versionBuild = Bundle.main.releaseVersionNumber ?? ""
42
+ private var versionCode = Bundle.main.buildVersionNumber ?? ""
42
43
  private var lastPathHot = ""
43
44
  private var lastPathPersist = ""
44
45
  private let basePathHot = "versions"
@@ -112,6 +113,7 @@ extension Bundle {
112
113
  "cap_device_id": self.deviceID,
113
114
  "cap_app_id": self.appId,
114
115
  "cap_version_build": self.versionBuild,
116
+ "cap_version_code": self.versionCode,
115
117
  "cap_plugin_version": self.pluginVersion,
116
118
  "cap_version_name": UserDefaults.standard.string(forKey: "versionName") ?? "builtin"
117
119
  ]
@@ -253,6 +255,7 @@ extension Bundle {
253
255
  "device_id": self.deviceID,
254
256
  "version_name": version,
255
257
  "version_build": self.versionBuild,
258
+ "version_code": self.versionCode,
256
259
  "plugin_version": self.pluginVersion,
257
260
  "app_id": self.appId
258
261
  ]
@@ -32,6 +32,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
32
32
  implementation.appId = config?["appId"] as! String
33
33
  }
34
34
  implementation.statsUrl = getConfigValue("statsUrl") as? String ?? CapacitorUpdaterPlugin.statsUrlDefault
35
+ resetWhenUpdate = getConfigValue("resetWhenUpdate") as? Bool ?? true
35
36
  if (resetWhenUpdate) {
36
37
  var LatestVersionNative: Version = "0.0.0"
37
38
  do {
@@ -51,7 +52,6 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
51
52
  UserDefaults.standard.set( Bundle.main.buildVersionNumber, forKey: "LatestVersionNative")
52
53
  }
53
54
  if (!autoUpdate || autoUpdateUrl == "") { return }
54
- resetWhenUpdate = getConfigValue("resetWhenUpdate") as? Bool ?? true
55
55
  let nc = NotificationCenter.default
56
56
  nc.addObserver(self, selector: #selector(appMovedToBackground), name: UIApplication.didEnterBackgroundNotification, object: nil)
57
57
  nc.addObserver(self, selector: #selector(appMovedToForeground), name: UIApplication.willEnterForegroundNotification, object: nil)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "3.0.8",
3
+ "version": "3.1.0",
4
4
  "license": "AGPL-3.0-only",
5
5
  "description": "OTA update for capacitor apps",
6
6
  "main": "dist/plugin.cjs.js",