@capgo/capacitor-updater 3.2.0 → 3.2.1

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 CHANGED
@@ -53,7 +53,7 @@ Create account in [capgo.app](https://capgo.app) and get your [API key](https://
53
53
  - If update fail it will roolback to previous version.
54
54
 
55
55
  See more there in the [Auto update](
56
- https://doc.capgo.app/Auto-update-2cf9edda70484d7fa57111ab9c435d08) documentation.
56
+ https://github.com/Cap-go/capacitor-updater/wiki) documentation.
57
57
 
58
58
 
59
59
  ## Manual setup
@@ -48,87 +48,84 @@ public class CapacitorUpdater {
48
48
  public String statsUrl = "";
49
49
  public String appId = "";
50
50
  public String deviceID = "";
51
- private String pluginVersion = "3.2.0";
51
+ private final String pluginVersion = "3.2.1";
52
52
 
53
53
 
54
- private FilenameFilter filter = new FilenameFilter() {
54
+ private final FilenameFilter filter = new FilenameFilter() {
55
55
  @Override
56
- public boolean accept(File f, String name) {
56
+ public boolean accept(final File f, final String name) {
57
57
  // ignore directories generated by mac os x
58
58
  return !name.startsWith("__MACOSX") && !name.startsWith(".") && !name.startsWith(".DS_Store");
59
59
  }
60
60
  };
61
- private final CapacitorUpdaterPlugin plugin;
61
+ private final Context context;
62
+ private final CapacitorUpdaterEvents events;
63
+
62
64
  private String versionBuild = "";
63
65
  private String versionCode = "";
64
66
  private String versionOs = "";
65
- private String TAG = "Capacitor-updater";
66
- private Context context;
67
- private String basePathHot = "versions";
68
- private SharedPreferences prefs;
69
- private SharedPreferences.Editor editor;
67
+ private final String TAG = "Capacitor-updater";
68
+ private final String basePathHot = "versions";
69
+ private final SharedPreferences prefs;
70
+ private final SharedPreferences.Editor editor;
70
71
 
71
72
  static final String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
72
73
  static SecureRandom rnd = new SecureRandom();
73
74
 
74
- private int calcTotalPercent(int percent, int min, int max) {
75
+ private int calcTotalPercent(final int percent, final int min, final int max) {
75
76
  return (percent * (max - min)) / 100 + min;
76
77
  }
77
78
 
78
- private String randomString(int len){
79
- StringBuilder sb = new StringBuilder(len);
79
+ private String randomString(final int len){
80
+ final StringBuilder sb = new StringBuilder(len);
80
81
  for(int i = 0; i < len; i++)
81
82
  sb.append(AB.charAt(rnd.nextInt(AB.length())));
82
83
  return sb.toString();
83
84
  }
84
- public CapacitorUpdater (Context context) throws PackageManager.NameNotFoundException {
85
- this.context = context;
86
- this.plugin = new CapacitorUpdaterPlugin();
87
- this.prefs = context.getSharedPreferences("CapWebViewSettings", Activity.MODE_PRIVATE);
88
- this.editor = prefs.edit();
89
- this.versionOs = Build.VERSION.RELEASE;
90
- this.deviceID = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
91
- PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
92
- this.versionBuild = pInfo.versionName;
93
- this.versionCode = Integer.toString(pInfo.versionCode);
85
+
86
+ public CapacitorUpdater(final Context context) throws PackageManager.NameNotFoundException {
87
+ this(context, new CapacitorUpdaterEvents() {});
94
88
  }
95
- public CapacitorUpdater (Context context, CapacitorUpdaterPlugin plugin) throws PackageManager.NameNotFoundException {
89
+
90
+ public CapacitorUpdater (final Context context, final CapacitorUpdaterEvents events) throws PackageManager.NameNotFoundException {
96
91
  this.context = context;
97
- this.plugin = plugin;
98
- this.prefs = context.getSharedPreferences("CapWebViewSettings", Activity.MODE_PRIVATE);
99
- this.editor = prefs.edit();
92
+ this.events = events;
93
+
94
+ this.prefs = this.context.getSharedPreferences("CapWebViewSettings", Activity.MODE_PRIVATE);
95
+ this.editor = this.prefs.edit();
100
96
  this.versionOs = Build.VERSION.RELEASE;
101
97
  this.deviceID = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
102
- PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
98
+
99
+ final PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
103
100
  this.versionBuild = pInfo.versionName;
104
101
  this.versionCode = Integer.toString(pInfo.versionCode);
105
102
  }
106
103
 
107
- private Boolean unzip(String source, String dest) {
108
- File zipFile = new File(this.context.getFilesDir() + "/" + source);
109
- File targetDirectory = new File(this.context.getFilesDir() + "/" + dest);
104
+ private Boolean unzip(final String source, final String dest) {
105
+ final File zipFile = new File(this.context.getFilesDir() + "/" + source);
106
+ final File targetDirectory = new File(this.context.getFilesDir() + "/" + dest);
110
107
  ZipInputStream zis = null;
111
108
  try {
112
109
  zis = new ZipInputStream(
113
110
  new BufferedInputStream(new FileInputStream(zipFile)));
114
- } catch (FileNotFoundException e) {
111
+ } catch (final FileNotFoundException e) {
115
112
  e.printStackTrace();
116
113
  return false;
117
114
  }
118
115
  try {
119
116
  ZipEntry ze;
120
117
  int count;
121
- int buffLength = 8192;
122
- byte[] buffer = new byte[buffLength];
123
- long totalLength = zipFile.length();
118
+ final int buffLength = 8192;
119
+ final byte[] buffer = new byte[buffLength];
120
+ final long totalLength = zipFile.length();
124
121
  long readLength = buffLength;
125
122
  int percent = 0;
126
- this.plugin.notifyDownload(75);
123
+ this.events.notifyDownload(75);
127
124
  while ((ze = zis.getNextEntry()) != null) {
128
- File file = new File(targetDirectory, ze.getName());
129
- String canonicalPath = file.getCanonicalPath();
130
- String canonicalDir = (new File(String.valueOf(targetDirectory))).getCanonicalPath();
131
- File dir = ze.isDirectory() ? file : file.getParentFile();
125
+ final File file = new File(targetDirectory, ze.getName());
126
+ final String canonicalPath = file.getCanonicalPath();
127
+ final String canonicalDir = (new File(String.valueOf(targetDirectory))).getCanonicalPath();
128
+ final File dir = ze.isDirectory() ? file : file.getParentFile();
132
129
  if (!canonicalPath.startsWith(canonicalDir)) {
133
130
  throw new FileNotFoundException("SecurityException, Failed to ensure directory is the start path : " +
134
131
  canonicalDir + " of " + canonicalPath);
@@ -138,27 +135,27 @@ public class CapacitorUpdater {
138
135
  dir.getAbsolutePath());
139
136
  if (ze.isDirectory())
140
137
  continue;
141
- FileOutputStream fileOut = new FileOutputStream(file);
138
+ final FileOutputStream fileOut = new FileOutputStream(file);
142
139
  try {
143
140
  while ((count = zis.read(buffer)) != -1)
144
141
  fileOut.write(buffer, 0, count);
145
142
  } finally {
146
143
  fileOut.close();
147
144
  }
148
- int newPercent = (int)((readLength * 100) / totalLength);
145
+ final int newPercent = (int)((readLength * 100) / totalLength);
149
146
  if (totalLength > 1 && newPercent != percent) {
150
147
  percent = newPercent;
151
- this.plugin.notifyDownload(calcTotalPercent((int)percent, 75, 90));
148
+ this.events.notifyDownload(this.calcTotalPercent(percent, 75, 90));
152
149
  }
153
150
  readLength += ze.getCompressedSize();
154
151
  }
155
- } catch (Exception e) {
156
- Log.i(TAG, "unzip error", e);
152
+ } catch (final Exception e) {
153
+ Log.i(this.TAG, "unzip error", e);
157
154
  return false;
158
155
  } finally {
159
156
  try {
160
157
  zis.close();
161
- } catch (IOException e) {
158
+ } catch (final IOException e) {
162
159
  e.printStackTrace();
163
160
  return false;
164
161
  }
@@ -166,19 +163,19 @@ public class CapacitorUpdater {
166
163
  }
167
164
  }
168
165
 
169
- private Boolean flattenAssets(String source, String dest) {
170
- File current = new File(this.context.getFilesDir() + "/" + source);
166
+ private Boolean flattenAssets(final String source, final String dest) {
167
+ final File current = new File(this.context.getFilesDir() + "/" + source);
171
168
  if (!current.exists()) {
172
169
  return false;
173
170
  }
174
- File fDest = new File(this.context.getFilesDir() + "/" + dest);
171
+ final File fDest = new File(this.context.getFilesDir() + "/" + dest);
175
172
  fDest.getParentFile().mkdirs();
176
- String[] pathsName = current.list(filter);
173
+ final String[] pathsName = current.list(this.filter);
177
174
  if (pathsName == null || pathsName.length == 0) {
178
175
  return false;
179
176
  }
180
177
  if (pathsName.length == 1 && !pathsName[0].equals("index.html")) {
181
- File newFlat = new File(current.getPath() + "/" + pathsName[0]);
178
+ final File newFlat = new File(current.getPath() + "/" + pathsName[0]);
182
179
  newFlat.renameTo(fDest);
183
180
  } else {
184
181
  current.renameTo(fDest);
@@ -187,45 +184,45 @@ public class CapacitorUpdater {
187
184
  return true;
188
185
  }
189
186
 
190
- private Boolean downloadFile(String url, String dest) throws JSONException {
187
+ private Boolean downloadFile(final String url, final String dest) throws JSONException {
191
188
  try {
192
- URL u = new URL(url);
193
- URLConnection uc = u.openConnection();
194
- InputStream is = u.openStream();
195
- DataInputStream dis = new DataInputStream(is);
196
- long totalLength = uc.getContentLength();
197
- int buffLength = 1024;
198
- byte[] buffer = new byte[buffLength];
189
+ final URL u = new URL(url);
190
+ final URLConnection uc = u.openConnection();
191
+ final InputStream is = u.openStream();
192
+ final DataInputStream dis = new DataInputStream(is);
193
+ final long totalLength = uc.getContentLength();
194
+ final int buffLength = 1024;
195
+ final byte[] buffer = new byte[buffLength];
199
196
  int length;
200
- File downFile = new File(this.context.getFilesDir() + "/" + dest);
197
+ final File downFile = new File(this.context.getFilesDir() + "/" + dest);
201
198
  downFile.getParentFile().mkdirs();
202
199
  downFile.createNewFile();
203
- FileOutputStream fos = new FileOutputStream(downFile);
200
+ final FileOutputStream fos = new FileOutputStream(downFile);
204
201
  int readLength = buffLength;
205
202
  int percent = 0;
206
- this.plugin.notifyDownload(10);
203
+ this.events.notifyDownload(10);
207
204
  while ((length = dis.read(buffer))>0) {
208
205
  fos.write(buffer, 0, length);
209
- int newPercent = (int)((readLength * 100) / totalLength);
206
+ final int newPercent = (int)((readLength * 100) / totalLength);
210
207
  if (totalLength > 1 && newPercent != percent) {
211
208
  percent = newPercent;
212
- this.plugin.notifyDownload(calcTotalPercent(percent, 10, 70));
209
+ this.events.notifyDownload(this.calcTotalPercent(percent, 10, 70));
213
210
  }
214
211
  readLength += length;
215
212
  }
216
- } catch (Exception e) {
217
- Log.e(TAG, "downloadFile error", e);
213
+ } catch (final Exception e) {
214
+ Log.e(this.TAG, "downloadFile error", e);
218
215
  return false;
219
216
  }
220
217
  return true;
221
218
  }
222
219
 
223
- private void deleteDirectory(File file) throws IOException {
220
+ private void deleteDirectory(final File file) throws IOException {
224
221
  if (file.isDirectory()) {
225
- File[] entries = file.listFiles();
222
+ final File[] entries = file.listFiles();
226
223
  if (entries != null) {
227
- for (File entry : entries) {
228
- deleteDirectory(entry);
224
+ for (final File entry : entries) {
225
+ this.deleteDirectory(entry);
229
226
  }
230
227
  }
231
228
  }
@@ -234,100 +231,100 @@ public class CapacitorUpdater {
234
231
  }
235
232
  }
236
233
 
237
- public String download(String url) {
234
+ public String download(final String url) {
238
235
  try {
239
- this.plugin.notifyDownload(0);
240
- String folderNameZip = this.randomString(10);
241
- File fileZip = new File(this.context.getFilesDir() + "/" + folderNameZip);
242
- String folderNameUnZip = this.randomString(10);
243
- String version = this.randomString(10);
244
- String folderName = basePathHot + "/" + version;
245
- this.plugin.notifyDownload(5);
246
- Boolean downloaded = this.downloadFile(url, folderNameZip);
236
+ this.events.notifyDownload(0);
237
+ final String folderNameZip = this.randomString(10);
238
+ final File fileZip = new File(this.context.getFilesDir() + "/" + folderNameZip);
239
+ final String folderNameUnZip = this.randomString(10);
240
+ final String version = this.randomString(10);
241
+ final String folderName = this.basePathHot + "/" + version;
242
+ this.events.notifyDownload(5);
243
+ final Boolean downloaded = this.downloadFile(url, folderNameZip);
247
244
  if(!downloaded) return "";
248
- this.plugin.notifyDownload(71);
249
- Boolean unzipped = this.unzip(folderNameZip, folderNameUnZip);
245
+ this.events.notifyDownload(71);
246
+ final Boolean unzipped = this.unzip(folderNameZip, folderNameUnZip);
250
247
  if(!unzipped) return "";
251
248
  fileZip.delete();
252
- this.plugin.notifyDownload(91);
253
- Boolean flatt = this.flattenAssets(folderNameUnZip, folderName);
249
+ this.events.notifyDownload(91);
250
+ final Boolean flatt = this.flattenAssets(folderNameUnZip, folderName);
254
251
  if(!flatt) return "";
255
- this.plugin.notifyDownload(100);
252
+ this.events.notifyDownload(100);
256
253
  return version;
257
- } catch (Exception e) {
258
- Log.e(TAG, "updateApp error", e);
254
+ } catch (final Exception e) {
255
+ Log.e(this.TAG, "updateApp error", e);
259
256
  return "";
260
257
  }
261
258
  }
262
259
 
263
260
  public ArrayList<String> list() {
264
- ArrayList<String> res = new ArrayList<String>();
265
- File destHot = new File(this.context.getFilesDir() + "/" + basePathHot);
266
- Log.i(TAG, "list File : " + destHot.getPath());
261
+ final ArrayList<String> res = new ArrayList<String>();
262
+ final File destHot = new File(this.context.getFilesDir() + "/" + this.basePathHot);
263
+ Log.i(this.TAG, "list File : " + destHot.getPath());
267
264
  if (destHot.exists()) {
268
- for (File i : destHot.listFiles()) {
265
+ for (final File i : destHot.listFiles()) {
269
266
  res.add(i.getName());
270
267
  }
271
268
  } else {
272
- Log.i(TAG, "No version available" + destHot);
269
+ Log.i(this.TAG, "No version available" + destHot);
273
270
  }
274
271
  return res;
275
272
  }
276
273
 
277
- public Boolean delete(String version, String versionName) throws IOException {
278
- File destHot = new File(this.context.getFilesDir() + "/" + basePathHot + "/" + version);
274
+ public Boolean delete(final String version, final String versionName) throws IOException {
275
+ final File destHot = new File(this.context.getFilesDir() + "/" + this.basePathHot + "/" + version);
279
276
  if (destHot.exists()) {
280
- deleteDirectory(destHot);
277
+ this.deleteDirectory(destHot);
281
278
  return true;
282
279
  }
283
- Log.i(TAG, "Directory not removed: " + destHot.getPath());
280
+ Log.i(this.TAG, "Directory not removed: " + destHot.getPath());
284
281
  this.sendStats("delete", versionName);
285
282
  return false;
286
283
  }
287
284
 
288
- public Boolean set(String version, String versionName) {
289
- File destHot = new File(this.context.getFilesDir() + "/" + basePathHot + "/" + version);
290
- File destIndex = new File(destHot.getPath() + "/index.html");
285
+ public Boolean set(final String version, final String versionName) {
286
+ final File destHot = new File(this.context.getFilesDir() + "/" + this.basePathHot + "/" + version);
287
+ final File destIndex = new File(destHot.getPath() + "/index.html");
291
288
  if (destHot.exists() && destIndex.exists()) {
292
- editor.putString("lastPathHot", destHot.getPath());
293
- editor.putString("serverBasePath", destHot.getPath());
294
- editor.putString("versionName", versionName);
295
- editor.commit();
296
- sendStats("set", versionName);
289
+ this.editor.putString("lastPathHot", destHot.getPath());
290
+ this.editor.putString("serverBasePath", destHot.getPath());
291
+ this.editor.putString("versionName", versionName);
292
+ this.editor.commit();
293
+ this.sendStats("set", versionName);
297
294
  return true;
298
295
  }
299
- sendStats("set_fail", versionName);
296
+ this.sendStats("set_fail", versionName);
300
297
  return false;
301
298
  }
302
299
 
303
- public void getLatest(String url, Callback callback) {
304
- String deviceID = this.deviceID;
305
- String appId = this.appId;
306
- String versionBuild = this.versionBuild;
307
- String versionCode = this.versionCode;
308
- String versionOs = this.versionOs;
309
- String pluginVersion = this.pluginVersion;
310
- String versionName = getVersionName().equals("") ? "builtin" : getVersionName();
311
- StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
300
+ public void getLatest(final String url, final Callback callback) {
301
+ final String deviceID = this.deviceID;
302
+ final String appId = this.appId;
303
+ final String versionBuild = this.versionBuild;
304
+ final String versionCode = this.versionCode;
305
+ final String versionOs = this.versionOs;
306
+ final String pluginVersion = this.pluginVersion;
307
+ final String versionName = this.getVersionName().equals("") ? "builtin" : this.getVersionName();
308
+ final StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
312
309
  new Response.Listener<String>() {
313
310
  @Override
314
- public void onResponse(String response) {
311
+ public void onResponse(final String response) {
315
312
  try {
316
- JSONObject jsonObject = new JSONObject(response);
313
+ final JSONObject jsonObject = new JSONObject(response);
317
314
  callback.callback(jsonObject);
318
- } catch (JSONException e) {
315
+ } catch (final JSONException e) {
319
316
  e.printStackTrace();
320
317
  }
321
318
  }
322
319
  }, new Response.ErrorListener() {
323
320
  @Override
324
- public void onErrorResponse(VolleyError error) {
325
- Log.e(TAG, "Error getting Latest" + error);
321
+ public void onErrorResponse(final VolleyError error) {
322
+ Log.e(CapacitorUpdater.this.TAG, "Error getting Latest" + error);
326
323
  }
327
324
  }) {
328
325
  @Override
329
326
  public Map<String, String> getHeaders() throws AuthFailureError {
330
- Map<String, String> params = new HashMap<String, String>();
327
+ final Map<String, String> params = new HashMap<String, String>();
331
328
  params.put("cap_platform", "android");
332
329
  params.put("cap_device_id", deviceID);
333
330
  params.put("cap_app_id", appId);
@@ -339,34 +336,34 @@ public class CapacitorUpdater {
339
336
  return params;
340
337
  }
341
338
  };
342
- RequestQueue requestQueue = Volley.newRequestQueue(this.context);
339
+ final RequestQueue requestQueue = Volley.newRequestQueue(this.context);
343
340
  requestQueue.add(stringRequest);
344
341
  }
345
342
 
346
343
  public String getLastPathHot() {
347
- return prefs.getString("lastPathHot", "public");
344
+ return this.prefs.getString("lastPathHot", "public");
348
345
  }
349
346
 
350
347
  public String getVersionName() {
351
- return prefs.getString("versionName", "");
348
+ return this.prefs.getString("versionName", "");
352
349
  }
353
350
 
354
351
  public void reset() {
355
- String version = prefs.getString("versionName", "");
352
+ final String version = this.prefs.getString("versionName", "");
356
353
  this.sendStats("reset", version);
357
- editor.putString("lastPathHot", "public");
358
- editor.putString("serverBasePath", "public");
359
- editor.putString("versionName", "");
360
- editor.commit();
354
+ this.editor.putString("lastPathHot", "public");
355
+ this.editor.putString("serverBasePath", "public");
356
+ this.editor.putString("versionName", "");
357
+ this.editor.commit();
361
358
  }
362
359
 
363
- public void sendStats(String action, String version) {
364
- if (statsUrl == "") { return; }
365
- URL url;
366
- JSONObject json = new JSONObject();
367
- String jsonString;
360
+ public void sendStats(final String action, final String version) {
361
+ if (this.statsUrl == "") { return; }
362
+ final URL url;
363
+ final JSONObject json = new JSONObject();
364
+ final String jsonString;
368
365
  try {
369
- url = new URL(statsUrl);
366
+ url = new URL(this.statsUrl);
370
367
  json.put("platform", "android");
371
368
  json.put("action", action);
372
369
  json.put("version_name", version);
@@ -377,8 +374,8 @@ public class CapacitorUpdater {
377
374
  json.put("plugin_version", this.pluginVersion);
378
375
  json.put("app_id", this.appId);
379
376
  jsonString = json.toString();
380
- } catch (Exception ex) {
381
- Log.e(TAG, "Error get stats", ex);
377
+ } catch (final Exception ex) {
378
+ Log.e(this.TAG, "Error get stats", ex);
382
379
  return;
383
380
  }
384
381
  new Thread(new Runnable(){
@@ -393,17 +390,17 @@ public class CapacitorUpdater {
393
390
  con.setRequestProperty("Content-Length", Integer.toString(jsonString.getBytes().length));
394
391
  con.setDoOutput(true);
395
392
  con.setConnectTimeout(500);
396
- DataOutputStream wr = new DataOutputStream (con.getOutputStream());
393
+ final DataOutputStream wr = new DataOutputStream (con.getOutputStream());
397
394
  wr.writeBytes(jsonString);
398
395
  wr.close();
399
- int responseCode = con.getResponseCode();
396
+ final int responseCode = con.getResponseCode();
400
397
  if (responseCode != 200) {
401
- Log.e(TAG, "Stats error responseCode: " + responseCode);
398
+ Log.e(CapacitorUpdater.this.TAG, "Stats error responseCode: " + responseCode);
402
399
  } else {
403
- Log.i(TAG, "Stats send for \"" + action + "\", version " + version);
400
+ Log.i(CapacitorUpdater.this.TAG, "Stats send for \"" + action + "\", version " + version);
404
401
  }
405
- } catch (Exception ex) {
406
- Log.e(TAG, "Error post stats", ex);
402
+ } catch (final Exception ex) {
403
+ Log.e(CapacitorUpdater.this.TAG, "Error post stats", ex);
407
404
  } finally {
408
405
  if (con != null) {
409
406
  con.disconnect();
@@ -0,0 +1,11 @@
1
+ package ee.forgr.capacitor_updater;
2
+
3
+ public interface CapacitorUpdaterEvents {
4
+ /**
5
+ * Notify listeners of download progress.
6
+ * @param percent Current percentage as an integer (e.g.: N out of 100)
7
+ */
8
+ default void notifyDownload(final int percent) {
9
+ return;
10
+ }
11
+ }
@@ -29,7 +29,7 @@ import java.util.ArrayList;
29
29
 
30
30
  @CapacitorPlugin(name = "CapacitorUpdater")
31
31
  public class CapacitorUpdaterPlugin extends Plugin implements Application.ActivityLifecycleCallbacks {
32
- private String TAG = "Capacitor-updater";
32
+ private final String TAG = "Capacitor-updater";
33
33
  private CapacitorUpdater implementation;
34
34
  private SharedPreferences prefs;
35
35
  private SharedPreferences.Editor editor;
@@ -45,74 +45,79 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
45
45
  public void load() {
46
46
  super.load();
47
47
  this.prefs = this.getContext().getSharedPreferences("CapWebViewSettings", Activity.MODE_PRIVATE);
48
- this.editor = prefs.edit();
48
+ this.editor = this.prefs.edit();
49
49
  try {
50
- implementation = new CapacitorUpdater(this.getContext(), this);
51
- PackageInfo pInfo = this.getContext().getPackageManager().getPackageInfo(this.getContext().getPackageName(), 0);
52
- currentVersionNative = new Version(pInfo.versionName);
53
- } catch (PackageManager.NameNotFoundException e) {
50
+ this.implementation = new CapacitorUpdater(this.getContext(), new CapacitorUpdaterEvents() {
51
+ @Override
52
+ public void notifyDownload(final int percent) {
53
+ CapacitorUpdaterPlugin.this.notifyDownload(percent);
54
+ }
55
+ });
56
+ final PackageInfo pInfo = this.getContext().getPackageManager().getPackageInfo(this.getContext().getPackageName(), 0);
57
+ this.currentVersionNative = new Version(pInfo.versionName);
58
+ } catch (final PackageManager.NameNotFoundException e) {
54
59
  e.printStackTrace();
55
60
  return;
56
- } catch (Exception ex) {
57
- Log.e(TAG, "Error get currentVersionNative", ex);
61
+ } catch (final Exception ex) {
62
+ Log.e(this.TAG, "Error get currentVersionNative", ex);
58
63
  return;
59
64
  }
60
- CapConfig config = CapConfig.loadDefault(getActivity());
61
- implementation.appId = config.getString("appId", "");
62
- implementation.statsUrl = getConfig().getString("statsUrl", statsUrlDefault);
63
- this.autoUpdateUrl = getConfig().getString("autoUpdateUrl", autoUpdateUrlDefault);
64
- this.autoUpdate = getConfig().getBoolean("autoUpdate", false);
65
- resetWhenUpdate = getConfig().getBoolean("resetWhenUpdate", true);
66
- if (resetWhenUpdate) {
67
- Version LatestVersionNative = new Version(prefs.getString("LatestVersionNative", ""));
65
+ final CapConfig config = CapConfig.loadDefault(this.getActivity());
66
+ this.implementation.appId = config.getString("appId", "");
67
+ this.implementation.statsUrl = this.getConfig().getString("statsUrl", statsUrlDefault);
68
+ this.autoUpdateUrl = this.getConfig().getString("autoUpdateUrl", autoUpdateUrlDefault);
69
+ this.autoUpdate = this.getConfig().getBoolean("autoUpdate", false);
70
+ this.resetWhenUpdate = this.getConfig().getBoolean("resetWhenUpdate", true);
71
+ if (this.resetWhenUpdate) {
72
+ final Version LatestVersionNative = new Version(this.prefs.getString("LatestVersionNative", ""));
68
73
  try {
69
- if (!LatestVersionNative.equals("") && currentVersionNative.getMajor() > LatestVersionNative.getMajor()) {
74
+ if (!LatestVersionNative.equals("") && this.currentVersionNative.getMajor() > LatestVersionNative.getMajor()) {
70
75
  this._reset(false);
71
- editor.putString("LatestVersionAutoUpdate", "");
72
- editor.putString("LatestVersionNameAutoUpdate", "");
73
- ArrayList<String> res = implementation.list();
76
+ this.editor.putString("LatestVersionAutoUpdate", "");
77
+ this.editor.putString("LatestVersionNameAutoUpdate", "");
78
+ final ArrayList<String> res = this.implementation.list();
74
79
  for (int i = 0; i < res.size(); i++) {
75
80
  try {
76
- implementation.delete(res.get(i), "");
77
- } catch (IOException e) {
81
+ this.implementation.delete(res.get(i), "");
82
+ } catch (final IOException e) {
78
83
  e.printStackTrace();
79
84
  }
80
85
  }
81
86
  }
82
- editor.putString("LatestVersionNative", currentVersionNative.toString());
83
- editor.commit();
84
- } catch (Exception ex) {
87
+ this.editor.putString("LatestVersionNative", this.currentVersionNative.toString());
88
+ this.editor.commit();
89
+ } catch (final Exception ex) {
85
90
  Log.e("CapacitorUpdater", "Cannot get the current version " + ex.getMessage());
86
91
  }
87
92
  }
88
- if (!autoUpdate || this.autoUpdateUrl.equals("")) return;
89
- Application application = (Application) this.getContext().getApplicationContext();
93
+ if (!this.autoUpdate || this.autoUpdateUrl.equals("")) return;
94
+ final Application application = (Application) this.getContext().getApplicationContext();
90
95
  application.registerActivityLifecycleCallbacks(this);
91
- onActivityStarted(getActivity());
96
+ this.onActivityStarted(this.getActivity());
92
97
  }
93
98
 
94
- public void notifyDownload(int percent) {
95
- JSObject ret = new JSObject();
99
+ public void notifyDownload(final int percent) {
100
+ final JSObject ret = new JSObject();
96
101
  ret.put("percent", percent);
97
- notifyListeners("download", ret);
102
+ this.notifyListeners("download", ret);
98
103
  }
99
104
 
100
105
  @PluginMethod
101
- public void getId(PluginCall call) {
102
- JSObject ret = new JSObject();
103
- ret.put("id", implementation.deviceID);
106
+ public void getId(final PluginCall call) {
107
+ final JSObject ret = new JSObject();
108
+ ret.put("id", this.implementation.deviceID);
104
109
  call.resolve(ret);
105
110
  }
106
111
 
107
112
  @PluginMethod
108
- public void download(PluginCall call) {
113
+ public void download(final PluginCall call) {
109
114
  new Thread(new Runnable(){
110
115
  @Override
111
116
  public void run() {
112
- String url = call.getString("url");
113
- String res = implementation.download(url);
117
+ final String url = call.getString("url");
118
+ final String res = CapacitorUpdaterPlugin.this.implementation.download(url);
114
119
  if (!res.equals("")) {
115
- JSObject ret = new JSObject();
120
+ final JSObject ret = new JSObject();
116
121
  ret.put("version", res);
117
122
  call.resolve(ret);
118
123
  } else {
@@ -123,13 +128,13 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
123
128
  }
124
129
 
125
130
  private boolean _reload() {
126
- String pathHot = implementation.getLastPathHot();
131
+ final String pathHot = this.implementation.getLastPathHot();
127
132
  this.bridge.setServerBasePath(pathHot);
128
133
  return true;
129
134
  }
130
135
 
131
136
  @PluginMethod
132
- public void reload(PluginCall call) {
137
+ public void reload(final PluginCall call) {
133
138
  if (this._reload()) {
134
139
  call.resolve();
135
140
  } else {
@@ -138,10 +143,10 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
138
143
  }
139
144
 
140
145
  @PluginMethod
141
- public void set(PluginCall call) {
142
- String version = call.getString("version");
143
- String versionName = call.getString("versionName", version);
144
- Boolean res = implementation.set(version, versionName);
146
+ public void set(final PluginCall call) {
147
+ final String version = call.getString("version");
148
+ final String versionName = call.getString("versionName", version);
149
+ final Boolean res = this.implementation.set(version, versionName);
145
150
 
146
151
  if (!res) {
147
152
  call.reject("Update failed, version " + version + " doesn't exist");
@@ -151,38 +156,38 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
151
156
  }
152
157
 
153
158
  @PluginMethod
154
- public void delete(PluginCall call) {
155
- String version = call.getString("version");
159
+ public void delete(final PluginCall call) {
160
+ final String version = call.getString("version");
156
161
  try {
157
- Boolean res = implementation.delete(version, "");
162
+ final Boolean res = this.implementation.delete(version, "");
158
163
  if (res) {
159
164
  call.resolve();
160
165
  } else {
161
166
  call.reject("Delete failed, version " + version + " doesn't exist");
162
167
  }
163
- } catch(IOException ex) {
168
+ } catch(final IOException ex) {
164
169
  Log.e("CapacitorUpdater", "An unexpected error occurred during deletion of folder. Message: " + ex.getMessage());
165
170
  call.reject("An unexpected error occurred during deletion of folder.");
166
171
  }
167
172
  }
168
173
 
169
174
  @PluginMethod
170
- public void list(PluginCall call) {
171
- ArrayList<String> res = implementation.list();
172
- JSObject ret = new JSObject();
175
+ public void list(final PluginCall call) {
176
+ final ArrayList<String> res = this.implementation.list();
177
+ final JSObject ret = new JSObject();
173
178
  ret.put("versions", new JSArray(res));
174
179
  call.resolve(ret);
175
180
  }
176
181
 
177
- private boolean _reset(Boolean toAutoUpdate) {
178
- String version = prefs.getString("LatestVersionAutoUpdate", "");
179
- String versionName = prefs.getString("LatestVersionNameAutoUpdate", "");
182
+ private boolean _reset(final Boolean toAutoUpdate) {
183
+ final String version = this.prefs.getString("LatestVersionAutoUpdate", "");
184
+ final String versionName = this.prefs.getString("LatestVersionNameAutoUpdate", "");
180
185
  if (toAutoUpdate && !version.equals("") && !versionName.equals("")) {
181
- Boolean res = implementation.set(version, versionName);
186
+ final Boolean res = this.implementation.set(version, versionName);
182
187
  return res && this._reload();
183
188
  }
184
- implementation.reset();
185
- String pathHot = implementation.getLastPathHot();
189
+ this.implementation.reset();
190
+ final String pathHot = this.implementation.getLastPathHot();
186
191
  if (this.bridge.getLocalServer() != null) {
187
192
  // if the server is not ready yet, hot reload is not needed
188
193
  this.bridge.setServerAssetPath(pathHot);
@@ -191,8 +196,8 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
191
196
  }
192
197
 
193
198
  @PluginMethod
194
- public void reset(PluginCall call) {
195
- Boolean toAutoUpdate = call.getBoolean("toAutoUpdate");
199
+ public void reset(final PluginCall call) {
200
+ final Boolean toAutoUpdate = call.getBoolean("toAutoUpdate", false);
196
201
  if (this._reset(toAutoUpdate)) {
197
202
  call.resolve();
198
203
  return;
@@ -201,101 +206,101 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
201
206
  }
202
207
 
203
208
  @PluginMethod
204
- public void versionName(PluginCall call) {
205
- String name = implementation.getVersionName();
206
- JSObject ret = new JSObject();
209
+ public void versionName(final PluginCall call) {
210
+ final String name = this.implementation.getVersionName();
211
+ final JSObject ret = new JSObject();
207
212
  ret.put("versionName", name);
208
213
  call.resolve(ret);
209
214
  }
210
215
 
211
216
  @PluginMethod
212
- public void current(PluginCall call) {
213
- String pathHot = implementation.getLastPathHot();
214
- JSObject ret = new JSObject();
215
- String current = pathHot.length() >= 10 ? pathHot.substring(pathHot.length() - 10) : "builtin";
217
+ public void current(final PluginCall call) {
218
+ final String pathHot = this.implementation.getLastPathHot();
219
+ final JSObject ret = new JSObject();
220
+ final String current = pathHot.length() >= 10 ? pathHot.substring(pathHot.length() - 10) : "builtin";
216
221
  ret.put("current", current);
217
- ret.put("currentNative", currentVersionNative);
222
+ ret.put("currentNative", this.currentVersionNative);
218
223
  call.resolve(ret);
219
224
  }
220
225
 
221
226
  @PluginMethod
222
- public void notifyAppReady(PluginCall call) {
223
- editor.putBoolean("notifyAppReady", true);
224
- editor.commit();
227
+ public void notifyAppReady(final PluginCall call) {
228
+ this.editor.putBoolean("notifyAppReady", true);
229
+ this.editor.commit();
225
230
  call.resolve();
226
231
  }
227
232
 
228
233
  @PluginMethod
229
- public void delayUpdate(PluginCall call) {
230
- editor.putBoolean("delayUpdate", true);
231
- editor.commit();
234
+ public void delayUpdate(final PluginCall call) {
235
+ this.editor.putBoolean("delayUpdate", true);
236
+ this.editor.commit();
232
237
  call.resolve();
233
238
  }
234
239
 
235
240
  @PluginMethod
236
- public void cancelDelay(PluginCall call) {
237
- editor.putBoolean("delayUpdate", false);
238
- editor.commit();
241
+ public void cancelDelay(final PluginCall call) {
242
+ this.editor.putBoolean("delayUpdate", false);
243
+ this.editor.commit();
239
244
  call.resolve();
240
245
  }
241
246
 
242
247
  @Override
243
- public void onActivityStarted(@NonNull Activity activity) {
248
+ public void onActivityStarted(@NonNull final Activity activity) {
244
249
  // disableRevert disableBreaking
245
250
  String currentVersionNative = "";
246
251
  try {
247
- PackageInfo pInfo = this.getContext().getPackageManager().getPackageInfo(this.getContext().getPackageName(), 0);
252
+ final PackageInfo pInfo = this.getContext().getPackageManager().getPackageInfo(this.getContext().getPackageName(), 0);
248
253
  currentVersionNative = pInfo.versionName;
249
- } catch (Exception ex) {
250
- Log.e(TAG, "Error get stats", ex);
254
+ } catch (final Exception ex) {
255
+ Log.e(this.TAG, "Error get stats", ex);
251
256
  return;
252
257
  }
253
- Log.i(TAG, "Check for update in the server");
254
- if (autoUpdateUrl.equals("")) return;
255
- String finalCurrentVersionNative = currentVersionNative;
258
+ Log.i(this.TAG, "Check for update in the server");
259
+ if (this.autoUpdateUrl.equals("")) return;
260
+ final String finalCurrentVersionNative = currentVersionNative;
256
261
  new Thread(new Runnable(){
257
262
  @Override
258
263
  public void run() {
259
- implementation.getLatest(autoUpdateUrl, (res) -> {
264
+ CapacitorUpdaterPlugin.this.implementation.getLatest(CapacitorUpdaterPlugin.this.autoUpdateUrl, (res) -> {
260
265
  try {
261
266
  if (res.has("message")) {
262
- Log.i(TAG, "Capacitor-updater: " + res.get("message"));
267
+ Log.i(CapacitorUpdaterPlugin.this.TAG, "Capacitor-updater: " + res.get("message"));
263
268
  if (res.has("major") && res.getBoolean("major") && res.has("version")) {
264
- JSObject ret = new JSObject();
269
+ final JSObject ret = new JSObject();
265
270
  ret.put("newVersion", (String) res.get("version"));
266
- notifyListeners("majorAvailable", ret);
271
+ CapacitorUpdaterPlugin.this.notifyListeners("majorAvailable", ret);
267
272
  }
268
273
  return;
269
274
  }
270
- String currentVersion = implementation.getVersionName();
271
- String newVersion = (String) res.get("version");
272
- JSObject ret = new JSObject();
275
+ final String currentVersion = CapacitorUpdaterPlugin.this.implementation.getVersionName();
276
+ final String newVersion = (String) res.get("version");
277
+ final JSObject ret = new JSObject();
273
278
  ret.put("newVersion", newVersion);
274
- String failingVersion = prefs.getString("failingVersion", "");
279
+ final String failingVersion = CapacitorUpdaterPlugin.this.prefs.getString("failingVersion", "");
275
280
  if (!newVersion.equals("") && !newVersion.equals(failingVersion)) {
276
281
  new Thread(new Runnable(){
277
282
  @Override
278
283
  public void run() {
279
284
  try {
280
- String dl = implementation.download((String) res.get("url"));
285
+ final String dl = CapacitorUpdaterPlugin.this.implementation.download((String) res.get("url"));
281
286
  if (dl.equals("")) {
282
- Log.i(TAG, "Download version: " + newVersion + " failed");
287
+ Log.i(CapacitorUpdaterPlugin.this.TAG, "Download version: " + newVersion + " failed");
283
288
  return;
284
289
  }
285
- Log.i(TAG, "New version: " + newVersion + " found. Current is " + (currentVersion.equals("") ? "builtin" : currentVersion) + ", next backgrounding will trigger update");
286
- editor.putString("nextVersion", dl);
287
- editor.putString("nextVersionName", (String) res.get("version"));
288
- editor.commit();
289
- notifyListeners("updateAvailable", ret);
290
- } catch (JSONException e) {
290
+ Log.i(CapacitorUpdaterPlugin.this.TAG, "New version: " + newVersion + " found. Current is " + (currentVersion.equals("") ? "builtin" : currentVersion) + ", next backgrounding will trigger update");
291
+ CapacitorUpdaterPlugin.this.editor.putString("nextVersion", dl);
292
+ CapacitorUpdaterPlugin.this.editor.putString("nextVersionName", (String) res.get("version"));
293
+ CapacitorUpdaterPlugin.this.editor.commit();
294
+ CapacitorUpdaterPlugin.this.notifyListeners("updateAvailable", ret);
295
+ } catch (final JSONException e) {
291
296
  e.printStackTrace();
292
297
  }
293
298
  }
294
299
  }).start();
295
300
  } else {
296
- Log.i(TAG, "No need to update, " + currentVersion + " is the latest");
301
+ Log.i(CapacitorUpdaterPlugin.this.TAG, "No need to update, " + currentVersion + " is the latest");
297
302
  }
298
- } catch (JSONException e) {
303
+ } catch (final JSONException e) {
299
304
  e.printStackTrace();
300
305
  }
301
306
  });
@@ -304,106 +309,106 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
304
309
  }
305
310
 
306
311
  @Override
307
- public void onActivityStopped(@NonNull Activity activity) {
308
- String pathHot = implementation.getLastPathHot();
309
- Log.i(TAG, "Check for waiting update");
310
- String nextVersion = prefs.getString("nextVersion", "");
311
- Boolean delayUpdate = prefs.getBoolean("delayUpdate", false);
312
- editor.putBoolean("delayUpdate", false);
313
- editor.commit();
312
+ public void onActivityStopped(@NonNull final Activity activity) {
313
+ final String pathHot = this.implementation.getLastPathHot();
314
+ Log.i(this.TAG, "Check for waiting update");
315
+ final String nextVersion = this.prefs.getString("nextVersion", "");
316
+ final Boolean delayUpdate = this.prefs.getBoolean("delayUpdate", false);
317
+ this.editor.putBoolean("delayUpdate", false);
318
+ this.editor.commit();
314
319
  if (delayUpdate) {
315
- Log.i(TAG, "Update delayed to next backgrounding");
320
+ Log.i(this.TAG, "Update delayed to next backgrounding");
316
321
  return;
317
322
  }
318
- String nextVersionName = prefs.getString("nextVersionName", "");
319
- String pastVersion = prefs.getString("pastVersion", "");
320
- String pastVersionName = prefs.getString("pastVersionName", "");
321
- Boolean notifyAppReady = prefs.getBoolean("notifyAppReady", false);
322
- String tmpCurVersion = implementation.getLastPathHot();
323
- String curVersion = tmpCurVersion.substring(tmpCurVersion.lastIndexOf('/') +1);
324
- String curVersionName = implementation.getVersionName();
323
+ final String nextVersionName = this.prefs.getString("nextVersionName", "");
324
+ final String pastVersion = this.prefs.getString("pastVersion", "");
325
+ final String pastVersionName = this.prefs.getString("pastVersionName", "");
326
+ final Boolean notifyAppReady = this.prefs.getBoolean("notifyAppReady", false);
327
+ final String tmpCurVersion = this.implementation.getLastPathHot();
328
+ final String curVersion = tmpCurVersion.substring(tmpCurVersion.lastIndexOf('/') +1);
329
+ final String curVersionName = this.implementation.getVersionName();
325
330
  if (!nextVersion.equals("") && !nextVersionName.equals("")) {
326
- Boolean res = implementation.set(nextVersion, nextVersionName);
331
+ final Boolean res = this.implementation.set(nextVersion, nextVersionName);
327
332
  if (res && this._reload()) {
328
- Log.i(TAG, "Auto update to version: " + nextVersionName);
329
- editor.putString("LatestVersionAutoUpdate", nextVersion);
330
- editor.putString("LatestVersionNameAutoUpdate", nextVersionName);
331
- editor.putString("nextVersion", "");
332
- editor.putString("nextVersionName", "");
333
- editor.putString("pastVersion", curVersion);
334
- editor.putString("pastVersionName", curVersionName);
335
- editor.putBoolean("notifyAppReady", false);
336
- editor.commit();
333
+ Log.i(this.TAG, "Auto update to version: " + nextVersionName);
334
+ this.editor.putString("LatestVersionAutoUpdate", nextVersion);
335
+ this.editor.putString("LatestVersionNameAutoUpdate", nextVersionName);
336
+ this.editor.putString("nextVersion", "");
337
+ this.editor.putString("nextVersionName", "");
338
+ this.editor.putString("pastVersion", curVersion);
339
+ this.editor.putString("pastVersionName", curVersionName);
340
+ this.editor.putBoolean("notifyAppReady", false);
341
+ this.editor.commit();
337
342
  } else {
338
- Log.i(TAG, "Auto update to version: " + nextVersionName + "Failed");
343
+ Log.i(this.TAG, "Auto update to version: " + nextVersionName + "Failed");
339
344
  }
340
345
  } else if (!notifyAppReady && !pathHot.equals("public")) {
341
- Log.i(TAG, "notifyAppReady never trigger");
342
- Log.i(TAG, "Version: " + curVersionName + ", is considered broken");
343
- Log.i(TAG, "Will downgraded to version: " + (pastVersionName.equals("") ? "builtin" : pastVersionName) + " for next start");
344
- Log.i(TAG, "Don't forget to trigger 'notifyAppReady()' in js code to validate a version.");
346
+ Log.i(this.TAG, "notifyAppReady never trigger");
347
+ Log.i(this.TAG, "Version: " + curVersionName + ", is considered broken");
348
+ Log.i(this.TAG, "Will downgraded to version: " + (pastVersionName.equals("") ? "builtin" : pastVersionName) + " for next start");
349
+ Log.i(this.TAG, "Don't forget to trigger 'notifyAppReady()' in js code to validate a version.");
345
350
  if (!pastVersion.equals("") && !pastVersionName.equals("")) {
346
- Boolean res = implementation.set(pastVersion, pastVersionName);
351
+ final Boolean res = this.implementation.set(pastVersion, pastVersionName);
347
352
  if (res && this._reload()) {
348
- Log.i(TAG, "Revert to version: " + (pastVersionName.equals("") ? "builtin" : pastVersionName));
349
- editor.putString("LatestVersionAutoUpdate", pastVersion);
350
- editor.putString("LatestVersionNameAutoUpdate", pastVersionName);
351
- editor.putString("pastVersion", "");
352
- editor.putString("pastVersionName", "");
353
- editor.commit();
353
+ Log.i(this.TAG, "Revert to version: " + (pastVersionName.equals("") ? "builtin" : pastVersionName));
354
+ this.editor.putString("LatestVersionAutoUpdate", pastVersion);
355
+ this.editor.putString("LatestVersionNameAutoUpdate", pastVersionName);
356
+ this.editor.putString("pastVersion", "");
357
+ this.editor.putString("pastVersionName", "");
358
+ this.editor.commit();
354
359
  } else {
355
- Log.i(TAG, "Revert to version: " + (pastVersionName.equals("") ? "builtin" : pastVersionName) + "Failed");
360
+ Log.i(this.TAG, "Revert to version: " + (pastVersionName.equals("") ? "builtin" : pastVersionName) + "Failed");
356
361
  }
357
362
  } else {
358
363
  if (this._reset(false)) {
359
- editor.putString("LatestVersionAutoUpdate", "");
360
- editor.putString("LatestVersionNameAutoUpdate", "");
361
- Log.i(TAG, "Auto reset done");
364
+ this.editor.putString("LatestVersionAutoUpdate", "");
365
+ this.editor.putString("LatestVersionNameAutoUpdate", "");
366
+ Log.i(this.TAG, "Auto reset done");
362
367
  }
363
368
  }
364
- editor.putString("failingVersion", curVersionName);
365
- editor.commit();
369
+ this.editor.putString("failingVersion", curVersionName);
370
+ this.editor.commit();
366
371
  try {
367
- Boolean res = implementation.delete(curVersion, curVersionName);
372
+ final Boolean res = this.implementation.delete(curVersion, curVersionName);
368
373
  if (res) {
369
- Log.i(TAG, "Delete failing version: " + curVersionName);
374
+ Log.i(this.TAG, "Delete failing version: " + curVersionName);
370
375
  }
371
- } catch (IOException e) {
376
+ } catch (final IOException e) {
372
377
  e.printStackTrace();
373
378
  }
374
379
  } else if (!pastVersion.equals("")) {
375
- Log.i(TAG, "Validated version: " + curVersionName);
380
+ Log.i(this.TAG, "Validated version: " + curVersionName);
376
381
  try {
377
- Boolean res = implementation.delete(pastVersion, pastVersionName);
382
+ final Boolean res = this.implementation.delete(pastVersion, pastVersionName);
378
383
  if (res) {
379
- Log.i(TAG, "Delete past version: " + pastVersionName);
384
+ Log.i(this.TAG, "Delete past version: " + pastVersionName);
380
385
  }
381
- } catch (IOException e) {
386
+ } catch (final IOException e) {
382
387
  e.printStackTrace();
383
388
  }
384
- editor.putString("pastVersion", "");
385
- editor.putString("pastVersionName", "");
386
- editor.commit();
389
+ this.editor.putString("pastVersion", "");
390
+ this.editor.putString("pastVersionName", "");
391
+ this.editor.commit();
387
392
  }
388
393
  }
389
394
 
390
395
  // not use but necessary here to remove warnings
391
396
  @Override
392
- public void onActivityResumed(@NonNull Activity activity) {
397
+ public void onActivityResumed(@NonNull final Activity activity) {
393
398
  }
394
399
 
395
400
  @Override
396
- public void onActivityPaused(@NonNull Activity activity) {
401
+ public void onActivityPaused(@NonNull final Activity activity) {
397
402
  }
398
403
  @Override
399
- public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
404
+ public void onActivityCreated(@NonNull final Activity activity, @Nullable final Bundle savedInstanceState) {
400
405
  }
401
406
 
402
407
  @Override
403
- public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {
408
+ public void onActivitySaveInstanceState(@NonNull final Activity activity, @NonNull final Bundle outState) {
404
409
  }
405
410
 
406
411
  @Override
407
- public void onActivityDestroyed(@NonNull Activity activity) {
412
+ public void onActivityDestroyed(@NonNull final Activity activity) {
408
413
  }
409
414
  }
@@ -42,7 +42,7 @@ extension Bundle {
42
42
  public var appId = ""
43
43
  public var deviceID = UIDevice.current.identifierForVendor?.uuidString ?? ""
44
44
  public var notifyDownload: (Int) -> Void = { _ in }
45
- public var pluginVersion = "3.2.0"
45
+ public var pluginVersion = "3.2.1"
46
46
  private var versionBuild = Bundle.main.releaseVersionNumber ?? ""
47
47
  private var versionCode = Bundle.main.buildVersionNumber ?? ""
48
48
  private var versionOs = ProcessInfo().operatingSystemVersion.getFullVersion()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "3.2.0",
3
+ "version": "3.2.1",
4
4
  "license": "AGPL-3.0-only",
5
5
  "description": "OTA update for capacitor apps",
6
6
  "main": "dist/plugin.cjs.js",