@capgo/capacitor-updater 4.0.0-alpha.40 → 4.0.0-alpha.43
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 +33 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdater.java +3 -2
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +39 -4
- package/dist/docs.json +101 -0
- package/dist/esm/definitions.d.ts +15 -0
- package/ios/Plugin/CapacitorUpdater.swift +4 -4
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +22 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -130,6 +130,7 @@ Capacitor Updator works by unzipping a compiled app bundle to the native device
|
|
|
130
130
|
* [`cancelDelay()`](#canceldelay)
|
|
131
131
|
* [`getLatest(...)`](#getlatest)
|
|
132
132
|
* [`addListener('download', ...)`](#addlistenerdownload)
|
|
133
|
+
* [`addListener('noNeedUpdate', ...)`](#addlistenernoneedupdate)
|
|
133
134
|
* [`addListener('downloadComplete', ...)`](#addlistenerdownloadcomplete)
|
|
134
135
|
* [`addListener('majorAvailable', ...)`](#addlistenermajoravailable)
|
|
135
136
|
* [`addListener('updateFailed', ...)`](#addlistenerupdatefailed)
|
|
@@ -345,6 +346,26 @@ Listen for download event in the App, let you know when the download is started,
|
|
|
345
346
|
--------------------
|
|
346
347
|
|
|
347
348
|
|
|
349
|
+
### addListener('noNeedUpdate', ...)
|
|
350
|
+
|
|
351
|
+
```typescript
|
|
352
|
+
addListener(eventName: 'noNeedUpdate', listenerFunc: NoNeedListener) => Promise<PluginListenerHandle> & PluginListenerHandle
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
Listen for no need to update event, usefull when you want force check every time the app is launched
|
|
356
|
+
|
|
357
|
+
| Param | Type |
|
|
358
|
+
| ------------------ | --------------------------------------------------------- |
|
|
359
|
+
| **`eventName`** | <code>'noNeedUpdate'</code> |
|
|
360
|
+
| **`listenerFunc`** | <code><a href="#noneedlistener">NoNeedListener</a></code> |
|
|
361
|
+
|
|
362
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>> & <a href="#pluginlistenerhandle">PluginListenerHandle</a></code>
|
|
363
|
+
|
|
364
|
+
**Since:** 4.0.0
|
|
365
|
+
|
|
366
|
+
--------------------
|
|
367
|
+
|
|
368
|
+
|
|
348
369
|
### addListener('downloadComplete', ...)
|
|
349
370
|
|
|
350
371
|
```typescript
|
|
@@ -529,6 +550,13 @@ removeAllListeners() => Promise<void>
|
|
|
529
550
|
| **`bundle`** | <code><a href="#bundleinfo">BundleInfo</a></code> | | |
|
|
530
551
|
|
|
531
552
|
|
|
553
|
+
#### noNeedEvent
|
|
554
|
+
|
|
555
|
+
| Prop | Type | Description | Since |
|
|
556
|
+
| ------------ | ------------------------------------------------- | ---------------------------------------------- | ----- |
|
|
557
|
+
| **`bundle`** | <code><a href="#bundleinfo">BundleInfo</a></code> | Current status of download, between 0 and 100. | 4.0.0 |
|
|
558
|
+
|
|
559
|
+
|
|
532
560
|
#### DownloadCompleteEvent
|
|
533
561
|
|
|
534
562
|
| Prop | Type | Description | Since |
|
|
@@ -575,6 +603,11 @@ removeAllListeners() => Promise<void>
|
|
|
575
603
|
<code>(state: <a href="#downloadevent">DownloadEvent</a>): void</code>
|
|
576
604
|
|
|
577
605
|
|
|
606
|
+
#### NoNeedListener
|
|
607
|
+
|
|
608
|
+
<code>(state: <a href="#noneedevent">noNeedEvent</a>): void</code>
|
|
609
|
+
|
|
610
|
+
|
|
578
611
|
#### DownloadCompleteListener
|
|
579
612
|
|
|
580
613
|
<code>(state: <a href="#downloadcompleteevent">DownloadCompleteEvent</a>): void</code>
|
|
@@ -47,7 +47,7 @@ public class CapacitorUpdater {
|
|
|
47
47
|
private static final String bundleDirectory = "versions";
|
|
48
48
|
|
|
49
49
|
public static final String TAG = "Capacitor-updater";
|
|
50
|
-
public static final String pluginVersion = "4.0.0-alpha.
|
|
50
|
+
public static final String pluginVersion = "4.0.0-alpha.43";
|
|
51
51
|
|
|
52
52
|
public SharedPreferences.Editor editor;
|
|
53
53
|
public SharedPreferences prefs;
|
|
@@ -367,6 +367,7 @@ public class CapacitorUpdater {
|
|
|
367
367
|
json.put("version_name", version);
|
|
368
368
|
json.put("plugin_version", pluginVersion);
|
|
369
369
|
|
|
370
|
+
Log.e(CapacitorUpdater.TAG, "Auto-update parameters: " + json.toString());
|
|
370
371
|
// Building a request
|
|
371
372
|
JsonObjectRequest request = new JsonObjectRequest(
|
|
372
373
|
Request.Method.POST,
|
|
@@ -432,7 +433,7 @@ public class CapacitorUpdater {
|
|
|
432
433
|
|
|
433
434
|
public BundleInfo getBundleInfo(final String id) {
|
|
434
435
|
String trueId = BundleInfo.VERSION_UNKNOWN;
|
|
435
|
-
if(id
|
|
436
|
+
if(id != null) {
|
|
436
437
|
trueId = id;
|
|
437
438
|
}
|
|
438
439
|
Log.d(TAG, "Getting info for bundle [" + trueId + "]");
|
|
@@ -28,6 +28,8 @@ import io.github.g00fy2.versioncompare.Version;
|
|
|
28
28
|
import org.json.JSONException;
|
|
29
29
|
|
|
30
30
|
import java.io.IOException;
|
|
31
|
+
import java.net.MalformedURLException;
|
|
32
|
+
import java.net.URL;
|
|
31
33
|
import java.text.SimpleDateFormat;
|
|
32
34
|
import java.util.Date;
|
|
33
35
|
import java.util.Iterator;
|
|
@@ -521,7 +523,15 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
521
523
|
}
|
|
522
524
|
}
|
|
523
525
|
|
|
524
|
-
|
|
526
|
+
private boolean isValidURL(String urlStr) {
|
|
527
|
+
try {
|
|
528
|
+
URL url = new URL(urlStr);
|
|
529
|
+
return true;
|
|
530
|
+
}
|
|
531
|
+
catch (MalformedURLException e) {
|
|
532
|
+
return false;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
525
535
|
|
|
526
536
|
@Override // appMovedToForeground
|
|
527
537
|
public void onActivityStarted(@NonNull final Activity activity) {
|
|
@@ -532,17 +542,27 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
532
542
|
|
|
533
543
|
Log.i(CapacitorUpdater.TAG, "Check for update via: " + CapacitorUpdaterPlugin.this.updateUrl);
|
|
534
544
|
CapacitorUpdaterPlugin.this.implementation.getLatest(CapacitorUpdaterPlugin.this.updateUrl, (res) -> {
|
|
545
|
+
final BundleInfo current = CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
|
|
535
546
|
try {
|
|
536
547
|
if (res.has("message")) {
|
|
537
|
-
Log.i(CapacitorUpdater.TAG, "message
|
|
548
|
+
Log.i(CapacitorUpdater.TAG, "message " + res.get("message"));
|
|
538
549
|
if (res.has("major") && res.getBoolean("major") && res.has("version")) {
|
|
539
550
|
final JSObject majorAvailable = new JSObject();
|
|
540
551
|
majorAvailable.put("version", (String) res.get("version"));
|
|
541
552
|
CapacitorUpdaterPlugin.this.notifyListeners("majorAvailable", majorAvailable);
|
|
542
553
|
}
|
|
554
|
+
final JSObject retNoNeed = new JSObject();
|
|
555
|
+
retNoNeed.put("bundle", current.toJSON());
|
|
556
|
+
CapacitorUpdaterPlugin.this.notifyListeners("noNeedUpdate", retNoNeed);
|
|
543
557
|
return;
|
|
544
558
|
}
|
|
545
|
-
|
|
559
|
+
|
|
560
|
+
if (!res.has("url") || CapacitorUpdaterPlugin.this.isValidURL((String)res.get("url"))) {
|
|
561
|
+
Log.e(CapacitorUpdater.TAG, "Error no url or wrong format");
|
|
562
|
+
final JSObject retNoNeed = new JSObject();
|
|
563
|
+
retNoNeed.put("bundle", current.toJSON());
|
|
564
|
+
CapacitorUpdaterPlugin.this.notifyListeners("noNeedUpdate", retNoNeed);
|
|
565
|
+
}
|
|
546
566
|
final String latestVersionName = (String) res.get("version");
|
|
547
567
|
|
|
548
568
|
if (latestVersionName != null && !"".equals(latestVersionName) && !current.getVersionName().equals(latestVersionName)) {
|
|
@@ -551,11 +571,17 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
551
571
|
if(latest != null) {
|
|
552
572
|
if(latest.isErrorStatus()) {
|
|
553
573
|
Log.e(CapacitorUpdater.TAG, "Latest bundle already exists, and is in error state. Aborting update.");
|
|
574
|
+
final JSObject retNoNeed = new JSObject();
|
|
575
|
+
retNoNeed.put("bundle", current.toJSON());
|
|
576
|
+
CapacitorUpdaterPlugin.this.notifyListeners("noNeedUpdate", retNoNeed);
|
|
554
577
|
return;
|
|
555
578
|
}
|
|
556
579
|
if(latest.isDownloaded()){
|
|
557
580
|
Log.e(CapacitorUpdater.TAG, "Latest bundle already exists and download is NOT required. Update will occur next time app moves to background.");
|
|
558
581
|
CapacitorUpdaterPlugin.this.implementation.setNextBundle(latest.getId());
|
|
582
|
+
final JSObject ret = new JSObject();
|
|
583
|
+
ret.put("bundle", latest.toJSON());
|
|
584
|
+
CapacitorUpdaterPlugin.this.notifyListeners("updateAvailable", ret);
|
|
559
585
|
return;
|
|
560
586
|
}
|
|
561
587
|
}
|
|
@@ -578,14 +604,23 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
578
604
|
final JSObject ret = new JSObject();
|
|
579
605
|
ret.put("version", latestVersionName);
|
|
580
606
|
CapacitorUpdaterPlugin.this.notifyListeners("downloadFailed", ret);
|
|
607
|
+
final JSObject retNoNeed = new JSObject();
|
|
608
|
+
retNoNeed.put("bundle", current.toJSON());
|
|
609
|
+
CapacitorUpdaterPlugin.this.notifyListeners("noNeedUpdate", retNoNeed);
|
|
581
610
|
}
|
|
582
611
|
}
|
|
583
612
|
}).start();
|
|
584
613
|
} else {
|
|
585
|
-
Log.i(CapacitorUpdater.TAG, "No need to update, " + current + " is the latest bundle.");
|
|
614
|
+
Log.i(CapacitorUpdater.TAG, "No need to update, " + current.getId() + " is the latest bundle.");
|
|
615
|
+
final JSObject retNoNeed = new JSObject();
|
|
616
|
+
retNoNeed.put("bundle", current.toJSON());
|
|
617
|
+
CapacitorUpdaterPlugin.this.notifyListeners("noNeedUpdate", retNoNeed);
|
|
586
618
|
}
|
|
587
619
|
} catch (final JSONException e) {
|
|
588
620
|
Log.e(CapacitorUpdater.TAG, "error parsing JSON", e);
|
|
621
|
+
final JSObject retNoNeed = new JSObject();
|
|
622
|
+
retNoNeed.put("bundle", current.toJSON());
|
|
623
|
+
CapacitorUpdaterPlugin.this.notifyListeners("noNeedUpdate", retNoNeed);
|
|
589
624
|
}
|
|
590
625
|
});
|
|
591
626
|
}
|
package/dist/docs.json
CHANGED
|
@@ -362,6 +362,35 @@
|
|
|
362
362
|
],
|
|
363
363
|
"slug": "addlistenerdownload"
|
|
364
364
|
},
|
|
365
|
+
{
|
|
366
|
+
"name": "addListener",
|
|
367
|
+
"signature": "(eventName: 'noNeedUpdate', listenerFunc: NoNeedListener) => Promise<PluginListenerHandle> & PluginListenerHandle",
|
|
368
|
+
"parameters": [
|
|
369
|
+
{
|
|
370
|
+
"name": "eventName",
|
|
371
|
+
"docs": "",
|
|
372
|
+
"type": "'noNeedUpdate'"
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
"name": "listenerFunc",
|
|
376
|
+
"docs": "",
|
|
377
|
+
"type": "NoNeedListener"
|
|
378
|
+
}
|
|
379
|
+
],
|
|
380
|
+
"returns": "Promise<PluginListenerHandle> & PluginListenerHandle",
|
|
381
|
+
"tags": [
|
|
382
|
+
{
|
|
383
|
+
"name": "since",
|
|
384
|
+
"text": "4.0.0"
|
|
385
|
+
}
|
|
386
|
+
],
|
|
387
|
+
"docs": "Listen for no need to update event, usefull when you want force check every time the app is launched",
|
|
388
|
+
"complexTypes": [
|
|
389
|
+
"PluginListenerHandle",
|
|
390
|
+
"NoNeedListener"
|
|
391
|
+
],
|
|
392
|
+
"slug": "addlistenernoneedupdate"
|
|
393
|
+
},
|
|
365
394
|
{
|
|
366
395
|
"name": "addListener",
|
|
367
396
|
"signature": "(eventName: 'downloadComplete', listenerFunc: DownloadCompleteListener) => Promise<PluginListenerHandle> & PluginListenerHandle",
|
|
@@ -573,6 +602,7 @@
|
|
|
573
602
|
"importObject": [
|
|
574
603
|
"PluginListenerHandle",
|
|
575
604
|
"\"@capacitor/cli\"",
|
|
605
|
+
"noNeedEvent",
|
|
576
606
|
"DownloadEvent",
|
|
577
607
|
"MajorAvailableEvent",
|
|
578
608
|
"DownloadFailedEvent",
|
|
@@ -583,6 +613,7 @@
|
|
|
583
613
|
"BundleStatus",
|
|
584
614
|
"DelayUntilNext",
|
|
585
615
|
"DownloadChangeListener",
|
|
616
|
+
"NoNeedListener",
|
|
586
617
|
"DownloadFailedListener",
|
|
587
618
|
"DownloadCompleteListener",
|
|
588
619
|
"MajorAvailableListener",
|
|
@@ -638,6 +669,7 @@
|
|
|
638
669
|
"importObject": [
|
|
639
670
|
"PluginListenerHandle",
|
|
640
671
|
"\"@capacitor/cli\"",
|
|
672
|
+
"noNeedEvent",
|
|
641
673
|
"DownloadEvent",
|
|
642
674
|
"MajorAvailableEvent",
|
|
643
675
|
"DownloadFailedEvent",
|
|
@@ -647,6 +679,7 @@
|
|
|
647
679
|
"BundleStatus",
|
|
648
680
|
"DelayUntilNext",
|
|
649
681
|
"DownloadChangeListener",
|
|
682
|
+
"NoNeedListener",
|
|
650
683
|
"DownloadFailedListener",
|
|
651
684
|
"DownloadCompleteListener",
|
|
652
685
|
"MajorAvailableListener",
|
|
@@ -705,6 +738,7 @@
|
|
|
705
738
|
"importObject": [
|
|
706
739
|
"PluginListenerHandle",
|
|
707
740
|
"\"@capacitor/cli\"",
|
|
741
|
+
"noNeedEvent",
|
|
708
742
|
"DownloadEvent",
|
|
709
743
|
"MajorAvailableEvent",
|
|
710
744
|
"DownloadFailedEvent",
|
|
@@ -714,6 +748,7 @@
|
|
|
714
748
|
"BundleStatus",
|
|
715
749
|
"DelayUntilNext",
|
|
716
750
|
"DownloadChangeListener",
|
|
751
|
+
"NoNeedListener",
|
|
717
752
|
"DownloadFailedListener",
|
|
718
753
|
"DownloadCompleteListener",
|
|
719
754
|
"MajorAvailableListener",
|
|
@@ -781,6 +816,50 @@
|
|
|
781
816
|
"importObject": [
|
|
782
817
|
"PluginListenerHandle",
|
|
783
818
|
"\"@capacitor/cli\"",
|
|
819
|
+
"noNeedEvent",
|
|
820
|
+
"MajorAvailableEvent",
|
|
821
|
+
"DownloadFailedEvent",
|
|
822
|
+
"DownloadCompleteEvent",
|
|
823
|
+
"UpdateFailedEvent",
|
|
824
|
+
"latestVersion",
|
|
825
|
+
"BundleInfo",
|
|
826
|
+
"BundleStatus",
|
|
827
|
+
"DelayUntilNext",
|
|
828
|
+
"DownloadChangeListener",
|
|
829
|
+
"NoNeedListener",
|
|
830
|
+
"DownloadFailedListener",
|
|
831
|
+
"DownloadCompleteListener",
|
|
832
|
+
"MajorAvailableListener",
|
|
833
|
+
"UpdateFailedListener",
|
|
834
|
+
"CapacitorUpdaterPlugin"
|
|
835
|
+
]
|
|
836
|
+
},
|
|
837
|
+
{
|
|
838
|
+
"name": "noNeedEvent",
|
|
839
|
+
"slug": "noneedevent",
|
|
840
|
+
"docs": "",
|
|
841
|
+
"tags": [],
|
|
842
|
+
"methods": [],
|
|
843
|
+
"properties": [
|
|
844
|
+
{
|
|
845
|
+
"name": "bundle",
|
|
846
|
+
"tags": [
|
|
847
|
+
{
|
|
848
|
+
"text": "4.0.0",
|
|
849
|
+
"name": "since"
|
|
850
|
+
}
|
|
851
|
+
],
|
|
852
|
+
"docs": "Current status of download, between 0 and 100.",
|
|
853
|
+
"complexTypes": [
|
|
854
|
+
"BundleInfo"
|
|
855
|
+
],
|
|
856
|
+
"type": "BundleInfo"
|
|
857
|
+
}
|
|
858
|
+
],
|
|
859
|
+
"importObject": [
|
|
860
|
+
"PluginListenerHandle",
|
|
861
|
+
"\"@capacitor/cli\"",
|
|
862
|
+
"DownloadEvent",
|
|
784
863
|
"MajorAvailableEvent",
|
|
785
864
|
"DownloadFailedEvent",
|
|
786
865
|
"DownloadCompleteEvent",
|
|
@@ -790,6 +869,7 @@
|
|
|
790
869
|
"BundleStatus",
|
|
791
870
|
"DelayUntilNext",
|
|
792
871
|
"DownloadChangeListener",
|
|
872
|
+
"NoNeedListener",
|
|
793
873
|
"DownloadFailedListener",
|
|
794
874
|
"DownloadCompleteListener",
|
|
795
875
|
"MajorAvailableListener",
|
|
@@ -822,6 +902,7 @@
|
|
|
822
902
|
"importObject": [
|
|
823
903
|
"PluginListenerHandle",
|
|
824
904
|
"\"@capacitor/cli\"",
|
|
905
|
+
"noNeedEvent",
|
|
825
906
|
"DownloadEvent",
|
|
826
907
|
"MajorAvailableEvent",
|
|
827
908
|
"DownloadFailedEvent",
|
|
@@ -831,6 +912,7 @@
|
|
|
831
912
|
"BundleStatus",
|
|
832
913
|
"DelayUntilNext",
|
|
833
914
|
"DownloadChangeListener",
|
|
915
|
+
"NoNeedListener",
|
|
834
916
|
"DownloadFailedListener",
|
|
835
917
|
"DownloadCompleteListener",
|
|
836
918
|
"MajorAvailableListener",
|
|
@@ -861,6 +943,7 @@
|
|
|
861
943
|
"importObject": [
|
|
862
944
|
"PluginListenerHandle",
|
|
863
945
|
"\"@capacitor/cli\"",
|
|
946
|
+
"noNeedEvent",
|
|
864
947
|
"DownloadEvent",
|
|
865
948
|
"DownloadFailedEvent",
|
|
866
949
|
"DownloadCompleteEvent",
|
|
@@ -870,6 +953,7 @@
|
|
|
870
953
|
"BundleStatus",
|
|
871
954
|
"DelayUntilNext",
|
|
872
955
|
"DownloadChangeListener",
|
|
956
|
+
"NoNeedListener",
|
|
873
957
|
"DownloadFailedListener",
|
|
874
958
|
"DownloadCompleteListener",
|
|
875
959
|
"MajorAvailableListener",
|
|
@@ -902,6 +986,7 @@
|
|
|
902
986
|
"importObject": [
|
|
903
987
|
"PluginListenerHandle",
|
|
904
988
|
"\"@capacitor/cli\"",
|
|
989
|
+
"noNeedEvent",
|
|
905
990
|
"DownloadEvent",
|
|
906
991
|
"MajorAvailableEvent",
|
|
907
992
|
"DownloadFailedEvent",
|
|
@@ -911,6 +996,7 @@
|
|
|
911
996
|
"BundleStatus",
|
|
912
997
|
"DelayUntilNext",
|
|
913
998
|
"DownloadChangeListener",
|
|
999
|
+
"NoNeedListener",
|
|
914
1000
|
"DownloadFailedListener",
|
|
915
1001
|
"DownloadCompleteListener",
|
|
916
1002
|
"MajorAvailableListener",
|
|
@@ -941,6 +1027,7 @@
|
|
|
941
1027
|
"importObject": [
|
|
942
1028
|
"PluginListenerHandle",
|
|
943
1029
|
"\"@capacitor/cli\"",
|
|
1030
|
+
"noNeedEvent",
|
|
944
1031
|
"DownloadEvent",
|
|
945
1032
|
"MajorAvailableEvent",
|
|
946
1033
|
"DownloadCompleteEvent",
|
|
@@ -950,6 +1037,7 @@
|
|
|
950
1037
|
"BundleStatus",
|
|
951
1038
|
"DelayUntilNext",
|
|
952
1039
|
"DownloadChangeListener",
|
|
1040
|
+
"NoNeedListener",
|
|
953
1041
|
"DownloadFailedListener",
|
|
954
1042
|
"DownloadCompleteListener",
|
|
955
1043
|
"MajorAvailableListener",
|
|
@@ -1019,6 +1107,19 @@
|
|
|
1019
1107
|
}
|
|
1020
1108
|
]
|
|
1021
1109
|
},
|
|
1110
|
+
{
|
|
1111
|
+
"name": "NoNeedListener",
|
|
1112
|
+
"slug": "noneedlistener",
|
|
1113
|
+
"docs": "",
|
|
1114
|
+
"types": [
|
|
1115
|
+
{
|
|
1116
|
+
"text": "(state: noNeedEvent): void",
|
|
1117
|
+
"complexTypes": [
|
|
1118
|
+
"noNeedEvent"
|
|
1119
|
+
]
|
|
1120
|
+
}
|
|
1121
|
+
]
|
|
1122
|
+
},
|
|
1022
1123
|
{
|
|
1023
1124
|
"name": "DownloadCompleteListener",
|
|
1024
1125
|
"slug": "downloadcompletelistener",
|
|
@@ -71,6 +71,14 @@ declare module '@capacitor/cli' {
|
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
+
export interface noNeedEvent {
|
|
75
|
+
/**
|
|
76
|
+
* Current status of download, between 0 and 100.
|
|
77
|
+
*
|
|
78
|
+
* @since 4.0.0
|
|
79
|
+
*/
|
|
80
|
+
bundle: BundleInfo;
|
|
81
|
+
}
|
|
74
82
|
export interface DownloadEvent {
|
|
75
83
|
/**
|
|
76
84
|
* Current status of download, between 0 and 100.
|
|
@@ -134,6 +142,7 @@ export interface BundleInfo {
|
|
|
134
142
|
export declare type BundleStatus = 'success' | 'error' | 'pending' | 'downloading';
|
|
135
143
|
export declare type DelayUntilNext = 'background' | 'kill' | 'nativeVersion' | 'date';
|
|
136
144
|
export declare type DownloadChangeListener = (state: DownloadEvent) => void;
|
|
145
|
+
export declare type NoNeedListener = (state: noNeedEvent) => void;
|
|
137
146
|
export declare type DownloadFailedListener = (state: DownloadFailedEvent) => void;
|
|
138
147
|
export declare type DownloadCompleteListener = (state: DownloadCompleteEvent) => void;
|
|
139
148
|
export declare type MajorAvailableListener = (state: MajorAvailableEvent) => void;
|
|
@@ -261,6 +270,12 @@ export interface CapacitorUpdaterPlugin {
|
|
|
261
270
|
* @since 2.0.11
|
|
262
271
|
*/
|
|
263
272
|
addListener(eventName: 'download', listenerFunc: DownloadChangeListener): Promise<PluginListenerHandle> & PluginListenerHandle;
|
|
273
|
+
/**
|
|
274
|
+
* Listen for no need to update event, usefull when you want force check every time the app is launched
|
|
275
|
+
*
|
|
276
|
+
* @since 4.0.0
|
|
277
|
+
*/
|
|
278
|
+
addListener(eventName: 'noNeedUpdate', listenerFunc: NoNeedListener): Promise<PluginListenerHandle> & PluginListenerHandle;
|
|
264
279
|
/**
|
|
265
280
|
* Listen for download event in the App, let you know when the download is started, loading and finished
|
|
266
281
|
*
|
|
@@ -149,7 +149,7 @@ extension CustomError: LocalizedError {
|
|
|
149
149
|
|
|
150
150
|
public let TAG = "✨ Capacitor-updater:";
|
|
151
151
|
public let CAP_SERVER_PATH = "serverBasePath"
|
|
152
|
-
public let pluginVersion = "4.0.0-alpha.
|
|
152
|
+
public let pluginVersion = "4.0.0-alpha.43"
|
|
153
153
|
public var statsUrl = ""
|
|
154
154
|
public var appId = ""
|
|
155
155
|
public var deviceID = UIDevice.current.identifierForVendor?.uuidString ?? ""
|
|
@@ -229,7 +229,7 @@ extension CustomError: LocalizedError {
|
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
public func getLatest(url: URL) -> AppVersion
|
|
232
|
+
public func getLatest(url: URL) -> AppVersion {
|
|
233
233
|
let semaphore = DispatchSemaphore(value: 0)
|
|
234
234
|
let latest = AppVersion()
|
|
235
235
|
let parameters: [String: String] = [
|
|
@@ -242,6 +242,7 @@ extension CustomError: LocalizedError {
|
|
|
242
242
|
"plugin_version": self.pluginVersion,
|
|
243
243
|
"version_name": self.getCurrentBundle().getVersionName()
|
|
244
244
|
]
|
|
245
|
+
print("\(self.TAG) Auto-update parameters: \(parameters)")
|
|
245
246
|
let request = AF.request(url, method: .post,parameters: parameters, encoder: JSONParameterEncoder.default)
|
|
246
247
|
|
|
247
248
|
request.validate().responseDecodable(of: AppVersionDec.self) { response in
|
|
@@ -258,7 +259,6 @@ extension CustomError: LocalizedError {
|
|
|
258
259
|
}
|
|
259
260
|
if let message = response.value?.message {
|
|
260
261
|
latest.message = message
|
|
261
|
-
print("\(self.TAG) Auto-update message: \(message)")
|
|
262
262
|
}
|
|
263
263
|
case let .failure(error):
|
|
264
264
|
print("\(self.TAG) Error getting Latest", error )
|
|
@@ -266,7 +266,7 @@ extension CustomError: LocalizedError {
|
|
|
266
266
|
semaphore.signal()
|
|
267
267
|
}
|
|
268
268
|
semaphore.wait()
|
|
269
|
-
return latest
|
|
269
|
+
return latest
|
|
270
270
|
}
|
|
271
271
|
|
|
272
272
|
private func setCurrentBundle(bundle: String) {
|
|
@@ -193,7 +193,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
193
193
|
|
|
194
194
|
@objc func getLatest(_ call: CAPPluginCall) {
|
|
195
195
|
let res = self.implementation.getLatest(url: URL(string: self.updateUrl)!)
|
|
196
|
-
call.resolve(
|
|
196
|
+
call.resolve(res.toDict())
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
@objc func _reset(toLastSuccessful: Bool) -> Bool {
|
|
@@ -364,46 +364,51 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
364
364
|
print("\(self.implementation.TAG) Check for update via \(self.updateUrl)")
|
|
365
365
|
let url = URL(string: self.updateUrl)!
|
|
366
366
|
let res = self.implementation.getLatest(url: url)
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
if (res?.major == true) {
|
|
374
|
-
self.notifyListeners("majorAvailable", data: ["version": res?.version ?? "0.0.0"])
|
|
367
|
+
let current = self.implementation.getCurrentBundle()
|
|
368
|
+
|
|
369
|
+
if ((res.message) != nil) {
|
|
370
|
+
print("\(self.implementation.TAG) message \(res.message ?? "")")
|
|
371
|
+
if (res.major == true) {
|
|
372
|
+
self.notifyListeners("majorAvailable", data: ["version": res.version])
|
|
375
373
|
}
|
|
374
|
+
self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
|
|
376
375
|
return
|
|
377
376
|
}
|
|
378
|
-
guard let downloadUrl = URL(string: res
|
|
377
|
+
guard let downloadUrl = URL(string: res.url) else {
|
|
379
378
|
print("\(self.implementation.TAG) Error no url or wrong format")
|
|
379
|
+
self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
|
|
380
380
|
return
|
|
381
381
|
}
|
|
382
|
-
let
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
let latest = self.implementation.getBundleInfoByVersionName(version: latestVersionName!)
|
|
382
|
+
let latestVersionName = res.version
|
|
383
|
+
if (latestVersionName != "" && current.getVersionName() != latestVersionName) {
|
|
384
|
+
let latest = self.implementation.getBundleInfoByVersionName(version: latestVersionName)
|
|
386
385
|
if (latest != nil) {
|
|
387
386
|
if(latest!.isErrorStatus()) {
|
|
388
387
|
print("\(self.implementation.TAG) Latest version already exists, and is in error state. Aborting update.")
|
|
388
|
+
self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
|
|
389
389
|
return
|
|
390
390
|
}
|
|
391
391
|
if(latest!.isDownloaded()){
|
|
392
392
|
print("\(self.implementation.TAG) Latest version already exists and download is NOT required. Update will occur next time app moves to background.")
|
|
393
393
|
let _ = self.implementation.setNextBundle(next: latest!.getId())
|
|
394
|
+
self.notifyListeners("updateAvailable", data: ["bundle": current.toJSON()])
|
|
394
395
|
return
|
|
395
396
|
}
|
|
396
397
|
}
|
|
397
398
|
|
|
398
399
|
do {
|
|
399
|
-
print("\(self.implementation.TAG) New bundle: \(latestVersionName
|
|
400
|
-
let next = try self.implementation.download(url: downloadUrl, version: latestVersionName
|
|
400
|
+
print("\(self.implementation.TAG) New bundle: \(latestVersionName) found. Current is: \(current.getVersionName()). Update will occur next time app moves to background.")
|
|
401
|
+
let next = try self.implementation.download(url: downloadUrl, version: latestVersionName)
|
|
401
402
|
self.notifyListeners("updateAvailable", data: ["bundle": next.toJSON()])
|
|
402
403
|
let _ = self.implementation.setNextBundle(next: next.getId())
|
|
403
404
|
} catch {
|
|
404
405
|
print("\(self.implementation.TAG) Error downloading file", error.localizedDescription)
|
|
405
|
-
self.notifyListeners("downloadFailed", data: ["version": latestVersionName
|
|
406
|
+
self.notifyListeners("downloadFailed", data: ["version": latestVersionName])
|
|
407
|
+
self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
|
|
406
408
|
}
|
|
409
|
+
} else {
|
|
410
|
+
print("\(self.implementation.TAG) No need to update, \(current.getId()) is the latest bundle.")
|
|
411
|
+
self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
|
|
407
412
|
}
|
|
408
413
|
}
|
|
409
414
|
}
|