@capgo/capacitor-updater 7.3.3 → 7.5.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.
@@ -0,0 +1,169 @@
1
+ /*
2
+ * This Source Code Form is subject to the terms of the Mozilla Public
3
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
+ */
6
+
7
+ package ee.forgr.capacitor_updater;
8
+
9
+ import android.app.Activity;
10
+ import android.app.AlertDialog;
11
+ import android.content.DialogInterface;
12
+ import android.hardware.SensorManager;
13
+ import com.getcapacitor.Bridge;
14
+ import com.getcapacitor.BridgeActivity;
15
+
16
+ public class ShakeMenu implements ShakeDetector.Listener {
17
+
18
+ private CapacitorUpdaterPlugin plugin;
19
+ private BridgeActivity activity;
20
+ private ShakeDetector shakeDetector;
21
+ private boolean isShowing = false;
22
+ private Logger logger;
23
+
24
+ public ShakeMenu(CapacitorUpdaterPlugin plugin, BridgeActivity activity, Logger logger) {
25
+ this.plugin = plugin;
26
+ this.activity = activity;
27
+ this.logger = logger;
28
+
29
+ SensorManager sensorManager = (SensorManager) activity.getSystemService(Activity.SENSOR_SERVICE);
30
+ this.shakeDetector = new ShakeDetector(this);
31
+ this.shakeDetector.start(sensorManager);
32
+ }
33
+
34
+ public void stop() {
35
+ if (shakeDetector != null) {
36
+ shakeDetector.stop();
37
+ }
38
+ }
39
+
40
+ @Override
41
+ public void onShakeDetected() {
42
+ logger.info("Shake detected");
43
+
44
+ // Check if shake menu is enabled
45
+ if (!plugin.shakeMenuEnabled) {
46
+ logger.info("Shake menu is disabled");
47
+ return;
48
+ }
49
+
50
+ // Prevent multiple dialogs
51
+ if (isShowing) {
52
+ logger.info("Dialog already showing");
53
+ return;
54
+ }
55
+
56
+ isShowing = true;
57
+ showShakeMenu();
58
+ }
59
+
60
+ private void showShakeMenu() {
61
+ activity.runOnUiThread(() -> {
62
+ try {
63
+ String appName = activity.getPackageManager().getApplicationLabel(activity.getApplicationInfo()).toString();
64
+ String title = "Preview " + appName + " Menu";
65
+ String message = "What would you like to do?";
66
+ String okButtonTitle = "Go Home";
67
+ String reloadButtonTitle = "Reload app";
68
+ String cancelButtonTitle = "Close menu";
69
+
70
+ CapgoUpdater updater = plugin.implementation;
71
+ Bridge bridge = activity.getBridge();
72
+
73
+ AlertDialog.Builder builder = new AlertDialog.Builder(activity);
74
+ builder.setTitle(title);
75
+ builder.setMessage(message);
76
+
77
+ // Go Home button
78
+ builder.setPositiveButton(
79
+ okButtonTitle,
80
+ new DialogInterface.OnClickListener() {
81
+ public void onClick(DialogInterface dialog, int id) {
82
+ try {
83
+ BundleInfo current = updater.getCurrentBundle();
84
+ logger.info("Current bundle: " + current.toString());
85
+
86
+ BundleInfo next = updater.getNextBundle();
87
+ logger.info("Next bundle: " + (next != null ? next.toString() : "null"));
88
+
89
+ if (next != null && !next.isBuiltin()) {
90
+ logger.info("Setting bundle to: " + next.toString());
91
+ updater.set(next);
92
+ String path = updater.getCurrentBundlePath();
93
+ logger.info("Setting server path: " + path);
94
+ if (updater.isUsingBuiltin()) {
95
+ bridge.setServerAssetPath(path);
96
+ } else {
97
+ bridge.setServerBasePath(path);
98
+ }
99
+ } else {
100
+ logger.info("Resetting to builtin");
101
+ updater.reset();
102
+ String path = updater.getCurrentBundlePath();
103
+ bridge.setServerAssetPath(path);
104
+ }
105
+
106
+ // Try to delete the current bundle
107
+ try {
108
+ updater.delete(current.getId());
109
+ } catch (Exception err) {
110
+ logger.warn("Cannot delete version " + current.getId() + ": " + err.getMessage());
111
+ }
112
+
113
+ logger.info("Reload app done");
114
+ } catch (Exception e) {
115
+ logger.error("Error in Go Home action: " + e.getMessage());
116
+ } finally {
117
+ dialog.dismiss();
118
+ isShowing = false;
119
+ }
120
+ }
121
+ }
122
+ );
123
+
124
+ // Reload button
125
+ builder.setNeutralButton(
126
+ reloadButtonTitle,
127
+ new DialogInterface.OnClickListener() {
128
+ public void onClick(DialogInterface dialog, int id) {
129
+ try {
130
+ logger.info("Reloading webview");
131
+ String pathHot = updater.getCurrentBundlePath();
132
+ bridge.setServerBasePath(pathHot);
133
+ activity.runOnUiThread(() -> {
134
+ if (bridge.getWebView() != null) {
135
+ bridge.getWebView().reload();
136
+ }
137
+ });
138
+ } catch (Exception e) {
139
+ logger.error("Error in Reload action: " + e.getMessage());
140
+ } finally {
141
+ dialog.dismiss();
142
+ isShowing = false;
143
+ }
144
+ }
145
+ }
146
+ );
147
+
148
+ // Cancel button
149
+ builder.setNegativeButton(
150
+ cancelButtonTitle,
151
+ new DialogInterface.OnClickListener() {
152
+ public void onClick(DialogInterface dialog, int id) {
153
+ logger.info("Shake menu cancelled");
154
+ dialog.dismiss();
155
+ isShowing = false;
156
+ }
157
+ }
158
+ );
159
+
160
+ AlertDialog dialog = builder.create();
161
+ dialog.setOnDismissListener(dialogInterface -> isShowing = false);
162
+ dialog.show();
163
+ } catch (Exception e) {
164
+ logger.error("Error showing shake menu: " + e.getMessage());
165
+ isShowing = false;
166
+ }
167
+ });
168
+ }
169
+ }
package/dist/docs.json CHANGED
@@ -547,6 +547,31 @@
547
547
  ],
548
548
  "slug": "getchannel"
549
549
  },
550
+ {
551
+ "name": "listChannels",
552
+ "signature": "() => Promise<ListChannelsResult>",
553
+ "parameters": [],
554
+ "returns": "Promise<ListChannelsResult>",
555
+ "tags": [
556
+ {
557
+ "name": "returns",
558
+ "text": "A Promise that resolves with the available channels"
559
+ },
560
+ {
561
+ "name": "throws",
562
+ "text": "{Error}"
563
+ },
564
+ {
565
+ "name": "since",
566
+ "text": "7.5.0"
567
+ }
568
+ ],
569
+ "docs": "List all channels available for this device that allow self-assignment",
570
+ "complexTypes": [
571
+ "ListChannelsResult"
572
+ ],
573
+ "slug": "listchannels"
574
+ },
550
575
  {
551
576
  "name": "setCustomId",
552
577
  "signature": "(options: SetCustomIdOptions) => Promise<void>",
@@ -986,6 +1011,65 @@
986
1011
  "BundleInfo"
987
1012
  ],
988
1013
  "slug": "getnextbundle"
1014
+ },
1015
+ {
1016
+ "name": "setShakeMenu",
1017
+ "signature": "(options: SetShakeMenuOptions) => Promise<void>",
1018
+ "parameters": [
1019
+ {
1020
+ "name": "options",
1021
+ "docs": "Contains enabled boolean to enable or disable shake menu",
1022
+ "type": "SetShakeMenuOptions"
1023
+ }
1024
+ ],
1025
+ "returns": "Promise<void>",
1026
+ "tags": [
1027
+ {
1028
+ "name": "param",
1029
+ "text": "options Contains enabled boolean to enable or disable shake menu"
1030
+ },
1031
+ {
1032
+ "name": "returns"
1033
+ },
1034
+ {
1035
+ "name": "throws",
1036
+ "text": "{Error}"
1037
+ },
1038
+ {
1039
+ "name": "since",
1040
+ "text": "7.5.0"
1041
+ }
1042
+ ],
1043
+ "docs": "Enable or disable the shake menu for debugging/testing purposes",
1044
+ "complexTypes": [
1045
+ "SetShakeMenuOptions"
1046
+ ],
1047
+ "slug": "setshakemenu"
1048
+ },
1049
+ {
1050
+ "name": "isShakeMenuEnabled",
1051
+ "signature": "() => Promise<ShakeMenuEnabled>",
1052
+ "parameters": [],
1053
+ "returns": "Promise<ShakeMenuEnabled>",
1054
+ "tags": [
1055
+ {
1056
+ "name": "returns",
1057
+ "text": "The current state of shake menu"
1058
+ },
1059
+ {
1060
+ "name": "throws",
1061
+ "text": "{Error}"
1062
+ },
1063
+ {
1064
+ "name": "since",
1065
+ "text": "7.5.0"
1066
+ }
1067
+ ],
1068
+ "docs": "Get the current state of the shake menu",
1069
+ "complexTypes": [
1070
+ "ShakeMenuEnabled"
1071
+ ],
1072
+ "slug": "isshakemenuenabled"
989
1073
  }
990
1074
  ],
991
1075
  "properties": []
@@ -1155,6 +1239,54 @@
1155
1239
  "docs": "The checksum for the update, it should be in sha256 and encrypted with private key if the bundle is encrypted",
1156
1240
  "complexTypes": [],
1157
1241
  "type": "string | undefined"
1242
+ },
1243
+ {
1244
+ "name": "manifest",
1245
+ "tags": [
1246
+ {
1247
+ "text": "6.1.0",
1248
+ "name": "since"
1249
+ },
1250
+ {
1251
+ "text": "undefined",
1252
+ "name": "default"
1253
+ }
1254
+ ],
1255
+ "docs": "The manifest for multi-file downloads",
1256
+ "complexTypes": [
1257
+ "ManifestEntry"
1258
+ ],
1259
+ "type": "ManifestEntry[] | undefined"
1260
+ }
1261
+ ]
1262
+ },
1263
+ {
1264
+ "name": "ManifestEntry",
1265
+ "slug": "manifestentry",
1266
+ "docs": "",
1267
+ "tags": [],
1268
+ "methods": [],
1269
+ "properties": [
1270
+ {
1271
+ "name": "file_name",
1272
+ "tags": [],
1273
+ "docs": "",
1274
+ "complexTypes": [],
1275
+ "type": "string | null"
1276
+ },
1277
+ {
1278
+ "name": "file_hash",
1279
+ "tags": [],
1280
+ "docs": "",
1281
+ "complexTypes": [],
1282
+ "type": "string | null"
1283
+ },
1284
+ {
1285
+ "name": "download_url",
1286
+ "tags": [],
1287
+ "docs": "",
1288
+ "complexTypes": [],
1289
+ "type": "string | null"
1158
1290
  }
1159
1291
  ]
1160
1292
  },
@@ -1399,36 +1531,6 @@
1399
1531
  }
1400
1532
  ]
1401
1533
  },
1402
- {
1403
- "name": "ManifestEntry",
1404
- "slug": "manifestentry",
1405
- "docs": "",
1406
- "tags": [],
1407
- "methods": [],
1408
- "properties": [
1409
- {
1410
- "name": "file_name",
1411
- "tags": [],
1412
- "docs": "",
1413
- "complexTypes": [],
1414
- "type": "string | null"
1415
- },
1416
- {
1417
- "name": "file_hash",
1418
- "tags": [],
1419
- "docs": "",
1420
- "complexTypes": [],
1421
- "type": "string | null"
1422
- },
1423
- {
1424
- "name": "download_url",
1425
- "tags": [],
1426
- "docs": "",
1427
- "complexTypes": [],
1428
- "type": "string | null"
1429
- }
1430
- ]
1431
- },
1432
1534
  {
1433
1535
  "name": "GetLatestOptions",
1434
1536
  "slug": "getlatestoptions",
@@ -1577,6 +1679,86 @@
1577
1679
  }
1578
1680
  ]
1579
1681
  },
1682
+ {
1683
+ "name": "ListChannelsResult",
1684
+ "slug": "listchannelsresult",
1685
+ "docs": "",
1686
+ "tags": [],
1687
+ "methods": [],
1688
+ "properties": [
1689
+ {
1690
+ "name": "channels",
1691
+ "tags": [
1692
+ {
1693
+ "text": "7.5.0",
1694
+ "name": "since"
1695
+ }
1696
+ ],
1697
+ "docs": "List of available channels",
1698
+ "complexTypes": [
1699
+ "ChannelInfo"
1700
+ ],
1701
+ "type": "ChannelInfo[]"
1702
+ }
1703
+ ]
1704
+ },
1705
+ {
1706
+ "name": "ChannelInfo",
1707
+ "slug": "channelinfo",
1708
+ "docs": "",
1709
+ "tags": [],
1710
+ "methods": [],
1711
+ "properties": [
1712
+ {
1713
+ "name": "id",
1714
+ "tags": [
1715
+ {
1716
+ "text": "7.5.0",
1717
+ "name": "since"
1718
+ }
1719
+ ],
1720
+ "docs": "The channel ID",
1721
+ "complexTypes": [],
1722
+ "type": "string"
1723
+ },
1724
+ {
1725
+ "name": "name",
1726
+ "tags": [
1727
+ {
1728
+ "text": "7.5.0",
1729
+ "name": "since"
1730
+ }
1731
+ ],
1732
+ "docs": "The channel name",
1733
+ "complexTypes": [],
1734
+ "type": "string"
1735
+ },
1736
+ {
1737
+ "name": "public",
1738
+ "tags": [
1739
+ {
1740
+ "text": "7.5.0",
1741
+ "name": "since"
1742
+ }
1743
+ ],
1744
+ "docs": "Whether this is a public channel",
1745
+ "complexTypes": [],
1746
+ "type": "boolean"
1747
+ },
1748
+ {
1749
+ "name": "allow_self_set",
1750
+ "tags": [
1751
+ {
1752
+ "text": "7.5.0",
1753
+ "name": "since"
1754
+ }
1755
+ ],
1756
+ "docs": "Whether devices can self-assign to this channel",
1757
+ "complexTypes": [],
1758
+ "type": "boolean"
1759
+ }
1760
+ ]
1761
+ },
1580
1762
  {
1581
1763
  "name": "SetCustomIdOptions",
1582
1764
  "slug": "setcustomidoptions",
@@ -1882,6 +2064,38 @@
1882
2064
  "type": "boolean"
1883
2065
  }
1884
2066
  ]
2067
+ },
2068
+ {
2069
+ "name": "SetShakeMenuOptions",
2070
+ "slug": "setshakemenuoptions",
2071
+ "docs": "",
2072
+ "tags": [],
2073
+ "methods": [],
2074
+ "properties": [
2075
+ {
2076
+ "name": "enabled",
2077
+ "tags": [],
2078
+ "docs": "",
2079
+ "complexTypes": [],
2080
+ "type": "boolean"
2081
+ }
2082
+ ]
2083
+ },
2084
+ {
2085
+ "name": "ShakeMenuEnabled",
2086
+ "slug": "shakemenuenabled",
2087
+ "docs": "",
2088
+ "tags": [],
2089
+ "methods": [],
2090
+ "properties": [
2091
+ {
2092
+ "name": "enabled",
2093
+ "tags": [],
2094
+ "docs": "",
2095
+ "complexTypes": [],
2096
+ "type": "boolean"
2097
+ }
2098
+ ]
1885
2099
  }
1886
2100
  ],
1887
2101
  "enums": [],
@@ -2333,6 +2547,22 @@
2333
2547
  "docs": "Disable the JavaScript logging of the plugin. if true, the plugin will not log to the JavaScript console. only the native log will be done",
2334
2548
  "complexTypes": [],
2335
2549
  "type": "boolean | undefined"
2550
+ },
2551
+ {
2552
+ "name": "shakeMenu",
2553
+ "tags": [
2554
+ {
2555
+ "text": "false",
2556
+ "name": "default"
2557
+ },
2558
+ {
2559
+ "text": "7.5.0",
2560
+ "name": "since"
2561
+ }
2562
+ ],
2563
+ "docs": "Enable shake gesture to show update menu for debugging/testing purposes",
2564
+ "complexTypes": [],
2565
+ "type": "boolean | undefined"
2336
2566
  }
2337
2567
  ],
2338
2568
  "docs": "CapacitorUpdater can be configured with these options:"
@@ -218,6 +218,13 @@ declare module '@capacitor/cli' {
218
218
  * @since 7.3.0
219
219
  */
220
220
  disableJSLogging?: boolean;
221
+ /**
222
+ * Enable shake gesture to show update menu for debugging/testing purposes
223
+ *
224
+ * @default false
225
+ * @since 7.5.0
226
+ */
227
+ shakeMenu?: boolean;
221
228
  };
222
229
  }
223
230
  }
@@ -391,6 +398,14 @@ export interface CapacitorUpdaterPlugin {
391
398
  * @since 4.8.0
392
399
  */
393
400
  getChannel(): Promise<GetChannelRes>;
401
+ /**
402
+ * List all channels available for this device that allow self-assignment
403
+ *
404
+ * @returns {Promise<ListChannelsResult>} A Promise that resolves with the available channels
405
+ * @throws {Error}
406
+ * @since 7.5.0
407
+ */
408
+ listChannels(): Promise<ListChannelsResult>;
394
409
  /**
395
410
  * Set a custom ID for this device
396
411
  *
@@ -505,6 +520,23 @@ export interface CapacitorUpdaterPlugin {
505
520
  * @since 6.8.0
506
521
  */
507
522
  getNextBundle(): Promise<BundleInfo | null>;
523
+ /**
524
+ * Enable or disable the shake menu for debugging/testing purposes
525
+ *
526
+ * @param options Contains enabled boolean to enable or disable shake menu
527
+ * @returns {Promise<void>}
528
+ * @throws {Error}
529
+ * @since 7.5.0
530
+ */
531
+ setShakeMenu(options: SetShakeMenuOptions): Promise<void>;
532
+ /**
533
+ * Get the current state of the shake menu
534
+ *
535
+ * @returns {Promise<ShakeMenuEnabled>} The current state of shake menu
536
+ * @throws {Error}
537
+ * @since 7.5.0
538
+ */
539
+ isShakeMenuEnabled(): Promise<ShakeMenuEnabled>;
508
540
  }
509
541
  /**
510
542
  * pending: The bundle is pending to be **SET** as the next bundle.
@@ -552,6 +584,40 @@ export interface GetChannelRes {
552
584
  status?: string;
553
585
  allowSet?: boolean;
554
586
  }
587
+ export interface ChannelInfo {
588
+ /**
589
+ * The channel ID
590
+ *
591
+ * @since 7.5.0
592
+ */
593
+ id: string;
594
+ /**
595
+ * The channel name
596
+ *
597
+ * @since 7.5.0
598
+ */
599
+ name: string;
600
+ /**
601
+ * Whether this is a public channel
602
+ *
603
+ * @since 7.5.0
604
+ */
605
+ public: boolean;
606
+ /**
607
+ * Whether devices can self-assign to this channel
608
+ *
609
+ * @since 7.5.0
610
+ */
611
+ allow_self_set: boolean;
612
+ }
613
+ export interface ListChannelsResult {
614
+ /**
615
+ * List of available channels
616
+ *
617
+ * @since 7.5.0
618
+ */
619
+ channels: ChannelInfo[];
620
+ }
555
621
  export interface DownloadEvent {
556
622
  /**
557
623
  * Current status of download, between 0 and 100.
@@ -700,6 +766,12 @@ export interface DownloadOptions {
700
766
  * @default undefined
701
767
  */
702
768
  checksum?: string;
769
+ /**
770
+ * The manifest for multi-file downloads
771
+ * @since 6.1.0
772
+ * @default undefined
773
+ */
774
+ manifest?: ManifestEntry[];
703
775
  }
704
776
  export interface BundleId {
705
777
  id: string;
@@ -740,3 +812,9 @@ export interface AutoUpdateEnabled {
740
812
  export interface AutoUpdateAvailable {
741
813
  available: boolean;
742
814
  }
815
+ export interface SetShakeMenuOptions {
816
+ enabled: boolean;
817
+ }
818
+ export interface ShakeMenuEnabled {
819
+ enabled: boolean;
820
+ }