@capgo/capacitor-updater 3.0.9 → 3.2.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.
@@ -5,6 +5,7 @@ import android.content.Context;
5
5
  import android.content.SharedPreferences;
6
6
  import android.content.pm.PackageInfo;
7
7
  import android.content.pm.PackageManager;
8
+ import android.os.Build;
8
9
  import android.util.Log;
9
10
 
10
11
  import com.android.volley.AuthFailureError;
@@ -47,7 +48,7 @@ public class CapacitorUpdater {
47
48
  public String statsUrl = "";
48
49
  public String appId = "";
49
50
  public String deviceID = "";
50
- private String pluginVersion = "3.0.9";
51
+ private String pluginVersion = "3.2.0";
51
52
 
52
53
 
53
54
  private FilenameFilter filter = new FilenameFilter() {
@@ -59,6 +60,8 @@ public class CapacitorUpdater {
59
60
  };
60
61
  private final CapacitorUpdaterPlugin plugin;
61
62
  private String versionBuild = "";
63
+ private String versionCode = "";
64
+ private String versionOs = "";
62
65
  private String TAG = "Capacitor-updater";
63
66
  private Context context;
64
67
  private String basePathHot = "versions";
@@ -83,18 +86,22 @@ public class CapacitorUpdater {
83
86
  this.plugin = new CapacitorUpdaterPlugin();
84
87
  this.prefs = context.getSharedPreferences("CapWebViewSettings", Activity.MODE_PRIVATE);
85
88
  this.editor = prefs.edit();
89
+ this.versionOs = Build.VERSION.RELEASE;
86
90
  this.deviceID = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
87
91
  PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
88
92
  this.versionBuild = pInfo.versionName;
93
+ this.versionCode = Integer.toString(pInfo.versionCode);
89
94
  }
90
95
  public CapacitorUpdater (Context context, CapacitorUpdaterPlugin plugin) throws PackageManager.NameNotFoundException {
91
96
  this.context = context;
92
97
  this.plugin = plugin;
93
98
  this.prefs = context.getSharedPreferences("CapWebViewSettings", Activity.MODE_PRIVATE);
94
99
  this.editor = prefs.edit();
100
+ this.versionOs = Build.VERSION.RELEASE;
95
101
  this.deviceID = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
96
102
  PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
97
103
  this.versionBuild = pInfo.versionName;
104
+ this.versionCode = Integer.toString(pInfo.versionCode);
98
105
  }
99
106
 
100
107
  private Boolean unzip(String source, String dest) {
@@ -114,7 +121,7 @@ public class CapacitorUpdater {
114
121
  int buffLength = 8192;
115
122
  byte[] buffer = new byte[buffLength];
116
123
  long totalLength = zipFile.length();
117
- long readedLength = buffLength;
124
+ long readLength = buffLength;
118
125
  int percent = 0;
119
126
  this.plugin.notifyDownload(75);
120
127
  while ((ze = zis.getNextEntry()) != null) {
@@ -131,19 +138,19 @@ public class CapacitorUpdater {
131
138
  dir.getAbsolutePath());
132
139
  if (ze.isDirectory())
133
140
  continue;
134
- FileOutputStream fout = new FileOutputStream(file);
141
+ FileOutputStream fileOut = new FileOutputStream(file);
135
142
  try {
136
143
  while ((count = zis.read(buffer)) != -1)
137
- fout.write(buffer, 0, count);
144
+ fileOut.write(buffer, 0, count);
138
145
  } finally {
139
- fout.close();
146
+ fileOut.close();
140
147
  }
141
- int newPercent = (int)((readedLength * 100) / totalLength);
148
+ int newPercent = (int)((readLength * 100) / totalLength);
142
149
  if (totalLength > 1 && newPercent != percent) {
143
150
  percent = newPercent;
144
151
  this.plugin.notifyDownload(calcTotalPercent((int)percent, 75, 90));
145
152
  }
146
- readedLength += ze.getCompressedSize();
153
+ readLength += ze.getCompressedSize();
147
154
  }
148
155
  } catch (Exception e) {
149
156
  Log.i(TAG, "unzip error", e);
@@ -194,17 +201,17 @@ public class CapacitorUpdater {
194
201
  downFile.getParentFile().mkdirs();
195
202
  downFile.createNewFile();
196
203
  FileOutputStream fos = new FileOutputStream(downFile);
197
- int readedLength = buffLength;
204
+ int readLength = buffLength;
198
205
  int percent = 0;
199
206
  this.plugin.notifyDownload(10);
200
207
  while ((length = dis.read(buffer))>0) {
201
208
  fos.write(buffer, 0, length);
202
- int newPercent = (int)((readedLength * 100) / totalLength);
209
+ int newPercent = (int)((readLength * 100) / totalLength);
203
210
  if (totalLength > 1 && newPercent != percent) {
204
211
  percent = newPercent;
205
212
  this.plugin.notifyDownload(calcTotalPercent(percent, 10, 70));
206
213
  }
207
- readedLength += length;
214
+ readLength += length;
208
215
  }
209
216
  } catch (Exception e) {
210
217
  Log.e(TAG, "downloadFile error", e);
@@ -297,35 +304,39 @@ public class CapacitorUpdater {
297
304
  String deviceID = this.deviceID;
298
305
  String appId = this.appId;
299
306
  String versionBuild = this.versionBuild;
307
+ String versionCode = this.versionCode;
308
+ String versionOs = this.versionOs;
300
309
  String pluginVersion = this.pluginVersion;
301
310
  String versionName = getVersionName().equals("") ? "builtin" : getVersionName();
302
311
  StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
303
- new Response.Listener<String>() {
304
- @Override
305
- public void onResponse(String response) {
306
- try {
307
- JSONObject jsonObject = new JSONObject(response);
308
- callback.callback(jsonObject);
309
- } catch (JSONException e) {
310
- e.printStackTrace();
311
- }
312
- }
313
- }, new Response.ErrorListener() {
312
+ new Response.Listener<String>() {
313
+ @Override
314
+ public void onResponse(String response) {
315
+ try {
316
+ JSONObject jsonObject = new JSONObject(response);
317
+ callback.callback(jsonObject);
318
+ } catch (JSONException e) {
319
+ e.printStackTrace();
320
+ }
321
+ }
322
+ }, new Response.ErrorListener() {
314
323
  @Override
315
324
  public void onErrorResponse(VolleyError error) {
316
325
  Log.e(TAG, "Error getting Latest" + error);
317
326
  }
318
- }) {
327
+ }) {
319
328
  @Override
320
329
  public Map<String, String> getHeaders() throws AuthFailureError {
321
- Map<String, String> params = new HashMap<String, String>();
322
- params.put("cap_platform", "android");
323
- params.put("cap_device_id", deviceID);
324
- params.put("cap_app_id", appId);
325
- params.put("cap_version_build", versionBuild);
326
- params.put("cap_version_name", versionName);
327
- params.put("cap_plugin_version", pluginVersion);
328
- return params;
330
+ Map<String, String> params = new HashMap<String, String>();
331
+ params.put("cap_platform", "android");
332
+ params.put("cap_device_id", deviceID);
333
+ params.put("cap_app_id", appId);
334
+ params.put("cap_version_build", versionBuild);
335
+ params.put("cap_version_code", versionCode);
336
+ params.put("cap_version_os", versionOs);
337
+ params.put("cap_version_name", versionName);
338
+ params.put("cap_plugin_version", pluginVersion);
339
+ return params;
329
340
  }
330
341
  };
331
342
  RequestQueue requestQueue = Volley.newRequestQueue(this.context);
@@ -340,7 +351,7 @@ public class CapacitorUpdater {
340
351
  return prefs.getString("versionName", "");
341
352
  }
342
353
 
343
- public void reset() {
354
+ public void reset() {
344
355
  String version = prefs.getString("versionName", "");
345
356
  this.sendStats("reset", version);
346
357
  editor.putString("lastPathHot", "public");
@@ -361,6 +372,8 @@ public class CapacitorUpdater {
361
372
  json.put("version_name", version);
362
373
  json.put("device_id", this.deviceID);
363
374
  json.put("version_build", this.versionBuild);
375
+ json.put("version_code", this.versionCode);
376
+ json.put("version_os", this.versionOs);
364
377
  json.put("plugin_version", this.pluginVersion);
365
378
  json.put("app_id", this.appId);
366
379
  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
 
@@ -22,6 +22,11 @@ public class AppVersion: NSObject {
22
22
  var message: String?
23
23
  var major: Bool?
24
24
  }
25
+ extension OperatingSystemVersion {
26
+ func getFullVersion(separator: String = ".") -> String {
27
+ return "\(majorVersion)\(separator)\(minorVersion)\(separator)\(patchVersion)"
28
+ }
29
+ }
25
30
  extension Bundle {
26
31
  var releaseVersionNumber: String? {
27
32
  return infoDictionary?["CFBundleShortVersionString"] as? String
@@ -37,8 +42,10 @@ extension Bundle {
37
42
  public var appId = ""
38
43
  public var deviceID = UIDevice.current.identifierForVendor?.uuidString ?? ""
39
44
  public var notifyDownload: (Int) -> Void = { _ in }
40
- public var pluginVersion = "3.0.9"
45
+ public var pluginVersion = "3.2.0"
41
46
  private var versionBuild = Bundle.main.releaseVersionNumber ?? ""
47
+ private var versionCode = Bundle.main.buildVersionNumber ?? ""
48
+ private var versionOs = ProcessInfo().operatingSystemVersion.getFullVersion()
42
49
  private var lastPathHot = ""
43
50
  private var lastPathPersist = ""
44
51
  private let basePathHot = "versions"
@@ -112,6 +119,8 @@ extension Bundle {
112
119
  "cap_device_id": self.deviceID,
113
120
  "cap_app_id": self.appId,
114
121
  "cap_version_build": self.versionBuild,
122
+ "cap_version_code": self.versionCode,
123
+ "cap_version_os": self.versionOs,
115
124
  "cap_plugin_version": self.pluginVersion,
116
125
  "cap_version_name": UserDefaults.standard.string(forKey: "versionName") ?? "builtin"
117
126
  ]
@@ -253,6 +262,8 @@ extension Bundle {
253
262
  "device_id": self.deviceID,
254
263
  "version_name": version,
255
264
  "version_build": self.versionBuild,
265
+ "version_code": self.versionCode,
266
+ "version_os": self.versionOs,
256
267
  "plugin_version": self.pluginVersion,
257
268
  "app_id": self.appId
258
269
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "3.0.9",
3
+ "version": "3.2.0",
4
4
  "license": "AGPL-3.0-only",
5
5
  "description": "OTA update for capacitor apps",
6
6
  "main": "dist/plugin.cjs.js",