@capgo/capacitor-updater 5.0.18 → 5.0.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/README.md CHANGED
@@ -27,7 +27,7 @@ You have 3 ways possible :
27
27
  Join the [discord](https://discord.gg/VnYRvBfgA6) to get help.
28
28
 
29
29
  ## Documentation
30
- I maintain a more user friendly and complete [documentation here](https://docs.capgo.app/).
30
+ I maintain a more user friendly and complete [documentation here](https://capgo.app/docs/).
31
31
 
32
32
  ## Installation
33
33
 
@@ -42,7 +42,7 @@ Create your account in [capgo.app](https://capgo.app) and get your [API key](htt
42
42
  - Login to CLI `npx @capgo/cli@latest init API_KEY`
43
43
  And follow the steps by step to setup your app.
44
44
 
45
- See more there in the [Auto update documentation](https://docs.capgo.app/plugin/auto-update).
45
+ See more there in the [Auto update documentation](https://capgo.app/docs/plugin/auto-update).
46
46
 
47
47
 
48
48
  ## Manual setup
@@ -158,10 +158,12 @@ public class CapacitorUpdater {
158
158
  private File unzip(final String id, final File zipFile, final String dest)
159
159
  throws IOException {
160
160
  final File targetDirectory = new File(this.documentsDir, dest);
161
- final ZipInputStream zis = new ZipInputStream(
162
- new BufferedInputStream(new FileInputStream(zipFile))
163
- );
164
- try {
161
+ try (
162
+ final BufferedInputStream bis = new BufferedInputStream(
163
+ new FileInputStream(zipFile)
164
+ );
165
+ final ZipInputStream zis = new ZipInputStream(bis)
166
+ ) {
165
167
  int count;
166
168
  final int bufferSize = 8192;
167
169
  final byte[] buffer = new byte[bufferSize];
@@ -220,12 +222,6 @@ public class CapacitorUpdater {
220
222
  lengthRead += entry.getCompressedSize();
221
223
  }
222
224
  return targetDirectory;
223
- } finally {
224
- try {
225
- zis.close();
226
- } catch (final IOException e) {
227
- Log.e(TAG, "Failed to close zip input stream", e);
228
- }
229
225
  }
230
226
  }
231
227
 
@@ -419,13 +415,10 @@ public class CapacitorUpdater {
419
415
  ) throws IOException {
420
416
  final URL u = new URL(url);
421
417
  final URLConnection connection = u.openConnection();
422
- final InputStream is = u.openStream();
423
- final DataInputStream dis = new DataInputStream(is);
424
418
 
425
419
  final File target = new File(this.documentsDir, dest);
426
420
  target.getParentFile().mkdirs();
427
421
  target.createNewFile();
428
- final FileOutputStream fos = new FileOutputStream(target);
429
422
 
430
423
  final long totalLength = connection.getContentLength();
431
424
  final int bufferSize = 1024;
@@ -435,14 +428,20 @@ public class CapacitorUpdater {
435
428
  int bytesRead = bufferSize;
436
429
  int percent = 0;
437
430
  this.notifyDownload(id, 10);
438
- while ((length = dis.read(buffer)) > 0) {
439
- fos.write(buffer, 0, length);
440
- final int newPercent = (int) ((bytesRead / (float) totalLength) * 100);
441
- if (totalLength > 1 && newPercent != percent) {
442
- percent = newPercent;
443
- this.notifyDownload(id, this.calcTotalPercent(percent, 10, 70));
431
+ try (
432
+ final InputStream is = u.openStream();
433
+ final DataInputStream dis = new DataInputStream(is);
434
+ final FileOutputStream fos = new FileOutputStream(target)
435
+ ) {
436
+ while ((length = dis.read(buffer)) > 0) {
437
+ fos.write(buffer, 0, length);
438
+ final int newPercent = (int) ((bytesRead / (float) totalLength) * 100);
439
+ if (totalLength > 1 && newPercent != percent) {
440
+ percent = newPercent;
441
+ this.notifyDownload(id, this.calcTotalPercent(percent, 10, 70));
442
+ }
443
+ bytesRead += length;
444
444
  }
445
- bytesRead += length;
446
445
  }
447
446
  return target;
448
447
  }
@@ -506,17 +505,24 @@ public class CapacitorUpdater {
506
505
  byte[] decryptedSessionKey = CryptoCipher.decryptRSA(sessionKey, pKey);
507
506
  SecretKey sKey = CryptoCipher.byteToSessionKey(decryptedSessionKey);
508
507
  byte[] content = new byte[(int) file.length()];
509
- BufferedInputStream bis = new BufferedInputStream(
510
- new FileInputStream(file)
511
- );
512
- DataInputStream dis = new DataInputStream(bis);
513
- dis.readFully(content);
514
- dis.close();
515
- byte[] decrypted = CryptoCipher.decryptAES(content, sKey, iv);
516
- // write the decrypted string to the file
517
- FileOutputStream fos = new FileOutputStream(file.getAbsolutePath());
518
- fos.write(decrypted);
519
- fos.close();
508
+
509
+ try (
510
+ final FileInputStream fis = new FileInputStream(file);
511
+ final BufferedInputStream bis = new BufferedInputStream(fis);
512
+ final DataInputStream dis = new DataInputStream(bis)
513
+ ) {
514
+ dis.readFully(content);
515
+ dis.close();
516
+ byte[] decrypted = CryptoCipher.decryptAES(content, sKey, iv);
517
+ // write the decrypted string to the file
518
+ try (
519
+ final FileOutputStream fos = new FileOutputStream(
520
+ file.getAbsolutePath()
521
+ )
522
+ ) {
523
+ fos.write(decrypted);
524
+ }
525
+ }
520
526
  } catch (GeneralSecurityException e) {
521
527
  Log.i(TAG, "decryptFile fail");
522
528
  this.sendStats("decrypt_fail", version);
@@ -55,7 +55,7 @@ public class CapacitorUpdaterPlugin
55
55
  private static final String channelUrlDefault =
56
56
  "https://api.capgo.app/channel_self";
57
57
 
58
- private final String PLUGIN_VERSION = "5.0.18";
58
+ private final String PLUGIN_VERSION = "5.0.20";
59
59
  private static final String DELAY_CONDITION_PREFERENCES = "";
60
60
 
61
61
  private SharedPreferences.Editor editor;
@@ -55,32 +55,35 @@ public class DownloadService extends IntentService {
55
55
  try {
56
56
  final URL u = new URL(url);
57
57
  final URLConnection connection = u.openConnection();
58
- final InputStream is = u.openStream();
59
- final DataInputStream dis = new DataInputStream(is);
60
58
 
61
- final File target = new File(documentsDir, dest);
62
- target.getParentFile().mkdirs();
63
- target.createNewFile();
64
- final FileOutputStream fos = new FileOutputStream(target);
59
+ try (
60
+ final InputStream is = u.openStream();
61
+ final DataInputStream dis = new DataInputStream(is)
62
+ ) {
63
+ final File target = new File(documentsDir, dest);
64
+ target.getParentFile().mkdirs();
65
+ target.createNewFile();
66
+ try (final FileOutputStream fos = new FileOutputStream(target)) {
67
+ final long totalLength = connection.getContentLength();
68
+ final int bufferSize = 1024;
69
+ final byte[] buffer = new byte[bufferSize];
70
+ int length;
65
71
 
66
- final long totalLength = connection.getContentLength();
67
- final int bufferSize = 1024;
68
- final byte[] buffer = new byte[bufferSize];
69
- int length;
70
-
71
- int bytesRead = bufferSize;
72
- int percent = 0;
73
- this.notifyDownload(id, 10);
74
- while ((length = dis.read(buffer)) > 0) {
75
- fos.write(buffer, 0, length);
76
- final int newPercent = (int) ((bytesRead * 100) / totalLength);
77
- if (totalLength > 1 && newPercent != percent) {
78
- percent = newPercent;
79
- this.notifyDownload(id, this.calcTotalPercent(percent, 10, 70));
72
+ int bytesRead = bufferSize;
73
+ int percent = 0;
74
+ this.notifyDownload(id, 10);
75
+ while ((length = dis.read(buffer)) > 0) {
76
+ fos.write(buffer, 0, length);
77
+ final int newPercent = (int) ((bytesRead * 100) / totalLength);
78
+ if (totalLength > 1 && newPercent != percent) {
79
+ percent = newPercent;
80
+ this.notifyDownload(id, this.calcTotalPercent(percent, 10, 70));
81
+ }
82
+ bytesRead += length;
83
+ }
84
+ publishResults(dest, id, version, checksum, sessionKey, "");
80
85
  }
81
- bytesRead += length;
82
86
  }
83
- publishResults(dest, id, version, checksum, sessionKey, "");
84
87
  } catch (Exception e) {
85
88
  e.printStackTrace();
86
89
  publishResults(
@@ -15,7 +15,7 @@ import Version
15
15
  @objc(CapacitorUpdaterPlugin)
16
16
  public class CapacitorUpdaterPlugin: CAPPlugin {
17
17
  private var implementation = CapacitorUpdater()
18
- private let PLUGIN_VERSION: String = "5.0.18"
18
+ private let PLUGIN_VERSION: String = "5.0.20"
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.0.18",
3
+ "version": "5.0.20",
4
4
  "packageManager": "pnpm@8.6.12",
5
5
  "license": "MPL-2.0",
6
6
  "description": "Live update for capacitor apps",