@capgo/capacitor-updater 8.52.1 → 8.53.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. package/README.md +198 -66
  2. package/android/build.gradle +2 -1
  3. package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +409 -148
  4. package/android/src/main/java/ee/forgr/capacitor_updater/CapgoUpdater.java +521 -197
  5. package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipher.java +2 -1
  6. package/android/src/main/java/ee/forgr/capacitor_updater/DelayUpdateUtils.java +226 -105
  7. package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +30 -10
  8. package/android/src/main/java/ee/forgr/capacitor_updater/HeadlessUpdateWorker.java +318 -0
  9. package/android/src/main/java/ee/forgr/capacitor_updater/NativeUpdatePrompt.java +303 -0
  10. package/android/src/main/java/ee/forgr/capacitor_updater/ShakeMenu.java +4 -4
  11. package/android/src/main/java/ee/forgr/capacitor_updater/Version.java +1 -1
  12. package/dist/docs.json +378 -27
  13. package/dist/esm/definitions.d.ts +206 -7
  14. package/dist/esm/definitions.js.map +1 -1
  15. package/dist/plugin.cjs.js.map +1 -1
  16. package/dist/plugin.js.map +1 -1
  17. package/ios/Sources/CapacitorUpdaterPlugin/AES.swift +104 -52
  18. package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +292 -94
  19. package/ios/Sources/CapacitorUpdaterPlugin/CapgoUpdater.swift +156 -10
  20. package/ios/Sources/CapacitorUpdaterPlugin/CryptoCipher.swift +2 -1
  21. package/ios/Sources/CapacitorUpdaterPlugin/DelayUpdateUtils.swift +202 -90
  22. package/ios/Sources/CapacitorUpdaterPlugin/NativeUpdatePrompt.swift +183 -0
  23. package/ios/Sources/CapacitorUpdaterPlugin/ShakeMenu.swift +5 -2
  24. package/package.json +7 -3
@@ -110,6 +110,11 @@ declare module '@capacitor/cli' {
110
110
  * WebView renderer exits, unclean WebView restarts, app launch readiness timing,
111
111
  * and WebView load milestones when available.
112
112
  *
113
+ * Failed background update checks that never start a download (network errors, timeouts,
114
+ * non-2xx responses, unreadable payloads) are reported as `update_check_error` with
115
+ * `metadata.error` and optional `metadata.status_code`, not as `download_fail`.
116
+ * Self-hosted Capgo backends must allow the `update_check_error` stats action.
117
+ *
113
118
  * @default https://plugin.capgo.app/stats
114
119
  * @example https://example.com/api/stats
115
120
  */
@@ -425,6 +430,82 @@ declare module '@capacitor/cli' {
425
430
  * @since 8.43.0
426
431
  */
427
432
  allowShakeChannelSelector?: boolean;
433
+ /**
434
+ * When enabled, show a native dialog prompting the user to install a newer native app from the App Store or Play Store.
435
+ * The prompt appears when a live update is blocked because the device native app is too old, including backend
436
+ * `disable_auto_update_*` responses, `store_update_required`, and `breakingAvailable` / `majorAvailable` flows.
437
+ *
438
+ * Only available for Android and iOS. No-op on web.
439
+ *
440
+ * @default false
441
+ * @since 8.53.0
442
+ */
443
+ nativeUpdatePrompt?: boolean;
444
+ /**
445
+ * Optional title for the native store update dialog shown when {@link PluginsConfig.CapacitorUpdater.nativeUpdatePrompt} is enabled.
446
+ *
447
+ * Only available for Android and iOS.
448
+ *
449
+ * @default "Update available"
450
+ * @since 8.53.0
451
+ */
452
+ nativeUpdatePromptTitle?: string;
453
+ /**
454
+ * Optional message body for the native store update dialog shown when {@link PluginsConfig.CapacitorUpdater.nativeUpdatePrompt} is enabled.
455
+ *
456
+ * Only available for Android and iOS.
457
+ *
458
+ * @default A short message explaining that a newer native app is available in the store.
459
+ * @since 8.53.0
460
+ */
461
+ nativeUpdatePromptMessage?: string;
462
+ /**
463
+ * Optional label for the primary action button that opens the store or starts an in-app update on Android.
464
+ *
465
+ * Only available for Android and iOS.
466
+ *
467
+ * @default "Update"
468
+ * @since 8.53.0
469
+ */
470
+ nativeUpdatePromptUpdateButton?: string;
471
+ /**
472
+ * Optional label for the dismiss action on the native store update dialog.
473
+ *
474
+ * Only available for Android and iOS.
475
+ *
476
+ * @default "Not now"
477
+ * @since 8.53.0
478
+ */
479
+ nativeUpdatePromptLaterButton?: string;
480
+ /**
481
+ * Optional ISO 3166-1 alpha-2 country filter. When set, the prompt is shown only when the device region matches
482
+ * one of the comma-separated country codes (for example `"US"` or `"US,CA"`).
483
+ *
484
+ * Only available for Android and iOS.
485
+ *
486
+ * @default undefined (show in all regions)
487
+ * @since 8.53.0
488
+ */
489
+ nativeUpdatePromptCountry?: string;
490
+ /**
491
+ * When {@link PluginsConfig.CapacitorUpdater.nativeUpdatePrompt} is enabled, also show the dialog when {@link CapacitorUpdaterPlugin.getAppUpdateInfo}
492
+ * reports that a store update is available.
493
+ *
494
+ * Only available for Android and iOS.
495
+ *
496
+ * @default false
497
+ * @since 8.53.0
498
+ */
499
+ nativeUpdatePromptOnStoreCheck?: boolean;
500
+ /**
501
+ * Minimum hours between native update prompts for the same native app version. Also limited to once per app session.
502
+ *
503
+ * Only available for Android and iOS.
504
+ *
505
+ * @default 24
506
+ * @since 8.53.0
507
+ */
508
+ nativeUpdatePromptCooldownHours?: number;
428
509
  };
429
510
  }
430
511
  }
@@ -804,23 +885,25 @@ export interface CapacitorUpdaterPlugin {
804
885
  * Configure conditions that must be met before a pending update is applied.
805
886
  *
806
887
  * After calling {@link next} to queue an update, use this method to control when it gets applied.
807
- * The update will only be installed after ALL specified conditions are satisfied.
888
+ * By default, the update is installed only after **all** specified conditions are satisfied (`conditionMode: 'and'`).
889
+ * Set `conditionMode` to `'or'` to apply the update as soon as **any** condition is met.
808
890
  *
809
891
  * Available condition types:
810
- * - `background`: Wait for the app to be backgrounded. Optionally specify duration in milliseconds.
811
- * - `kill`: Wait for the app to be killed and relaunched (**Note:** Current behavior triggers update immediately on kill, not on next background. This will be fixed in v8.)
892
+ * - `background`: Wait until the app has spent more than the configured time in the background (see value formats below).
893
+ * - `kill`: The condition clears on the next launch and can also clear during Android activity destruction; activity destruction does not prove that the app process ended. Automatic installation waits for the next background, because it runs from appMovedToBackground. Calling {@link reload} can apply the pending bundle immediately.
812
894
  * - `date`: Wait until a specific date/time (ISO 8601 format)
813
895
  * - `nativeVersion`: Wait until the native app is updated to a specific version
814
896
  *
815
897
  * Condition value formats:
816
- * - `background`: Number in milliseconds (e.g., `"300000"` for 5 minutes), or omit for immediate
898
+ * - `background`: Time in milliseconds in background must exceed this value before the condition can clear on return to foreground (e.g., `"300000"` for more than 5 minutes; exactly `300000` ms does not clear). Omit `value` or use `"0"` to clear after one background-and-return cycle; the update installs on the following background.
817
899
  * - `kill`: No value needed
818
900
  * - `date`: ISO 8601 date string (e.g., `"2025-12-31T23:59:59Z"`)
819
901
  * - `nativeVersion`: Version string (e.g., `"2.0.0"`)
820
902
  *
821
903
  * @example
822
- * // Update after user kills app OR after 5 minutes in background
904
+ * // Update after kill condition clears on launch AND background time exceeds 5 minutes
823
905
  * await CapacitorUpdater.setMultiDelay({
906
+ * conditionMode: 'or',
824
907
  * delayConditions: [
825
908
  * { kind: 'kill' },
826
909
  * { kind: 'background', value: '300000' }
@@ -834,7 +917,7 @@ export interface CapacitorUpdaterPlugin {
834
917
  * });
835
918
  *
836
919
  * @example
837
- * // Default behavior: update on next background
920
+ * // One background-and-return clears the condition; update installs on the next background
838
921
  * await CapacitorUpdater.setMultiDelay({
839
922
  * delayConditions: [{ kind: 'background' }]
840
923
  * });
@@ -1198,6 +1281,7 @@ export interface CapacitorUpdaterPlugin {
1198
1281
  * Remove all event listeners registered for this plugin.
1199
1282
  *
1200
1283
  * This unregisters all listeners added via {@link addListener} for all event types:
1284
+ * - `updaterEvent`
1201
1285
  * - `download`
1202
1286
  * - `noNeedUpdate`
1203
1287
  * - `updateCheckResult`
@@ -1216,16 +1300,44 @@ export interface CapacitorUpdaterPlugin {
1216
1300
  * @since 1.0.0
1217
1301
  */
1218
1302
  removeAllListeners(): Promise<void>;
1303
+ /**
1304
+ * Listen for every updater event with a single listener.
1305
+ *
1306
+ * Each call receives `{ type, data }`: `type` is the event name (`download`, `updateAvailable`,
1307
+ * `downloadFailed`, `appReady`, ...) and `data` is the payload the matching legacy listener receives.
1308
+ * When the native layer retains an event until a listener attaches (for example `set` and `appReady`),
1309
+ * `updaterEvent` gets the same retention.
1310
+ *
1311
+ * The per-event listeners below are deprecated and will be removed in v9.
1312
+ *
1313
+ * ```typescript
1314
+ * CapacitorUpdater.addListener('updaterEvent', (event) => {
1315
+ * switch (event.type) {
1316
+ * case 'download':
1317
+ * console.log('progress', event.data.percent);
1318
+ * break;
1319
+ * case 'downloadFailed':
1320
+ * console.warn('download failed', event.data.version);
1321
+ * break;
1322
+ * }
1323
+ * });
1324
+ * ```
1325
+ *
1326
+ * @since 8.53.0
1327
+ */
1328
+ addListener(eventName: 'updaterEvent', listenerFunc: (event: UpdaterEvent) => void): Promise<PluginListenerHandle>;
1219
1329
  /**
1220
1330
  * Listen for bundle download event in the App. Fires once a download has started, during downloading and when finished.
1221
1331
  * This will return you all download percent during the download
1222
1332
  *
1333
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1223
1334
  * @since 2.0.11
1224
1335
  */
1225
1336
  addListener(eventName: 'download', listenerFunc: (state: DownloadEvent) => void): Promise<PluginListenerHandle>;
1226
1337
  /**
1227
1338
  * Listen for no need to update event, useful when you want force check every time the app is launched
1228
1339
  *
1340
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1229
1341
  * @since 4.0.0
1230
1342
  */
1231
1343
  addListener(eventName: 'noNeedUpdate', listenerFunc: (state: NoNeedEvent) => void): Promise<PluginListenerHandle>;
@@ -1235,20 +1347,24 @@ export interface CapacitorUpdaterPlugin {
1235
1347
  *
1236
1348
  * This event is emitted alongside legacy events. For `up_to_date` and `blocked`, it is emitted before
1237
1349
  * `noNeedUpdate` and does not emit `downloadFailed`. For `failed`, it is emitted before the legacy
1238
- * `downloadFailed` event and keeps the existing failure stats behavior.
1350
+ * `downloadFailed` event; native code also sends an `update_check_error` stat (with error metadata)
1351
+ * instead of `download_fail`, because no bundle download was attempted.
1239
1352
  *
1353
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1240
1354
  * @since 8.45.11
1241
1355
  */
1242
1356
  addListener(eventName: 'updateCheckResult', listenerFunc: (state: UpdateCheckResultEvent) => void): Promise<PluginListenerHandle>;
1243
1357
  /**
1244
1358
  * Listen for available update event, useful when you want to force check every time the app is launched
1245
1359
  *
1360
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1246
1361
  * @since 4.0.0
1247
1362
  */
1248
1363
  addListener(eventName: 'updateAvailable', listenerFunc: (state: UpdateAvailableEvent) => void): Promise<PluginListenerHandle>;
1249
1364
  /**
1250
1365
  * Listen for downloadComplete events.
1251
1366
  *
1367
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1252
1368
  * @since 4.0.0
1253
1369
  */
1254
1370
  addListener(eventName: 'downloadComplete', listenerFunc: (state: DownloadCompleteEvent) => void): Promise<PluginListenerHandle>;
@@ -1256,6 +1372,7 @@ export interface CapacitorUpdaterPlugin {
1256
1372
  * Listen for breaking update events when the backend flags an update as incompatible with the current app.
1257
1373
  * Emits the same payload as the legacy `majorAvailable` listener.
1258
1374
  *
1375
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1259
1376
  * @since 7.22.0
1260
1377
  */
1261
1378
  addListener(eventName: 'breakingAvailable', listenerFunc: (state: BreakingAvailableEvent) => void): Promise<PluginListenerHandle>;
@@ -1269,6 +1386,7 @@ export interface CapacitorUpdaterPlugin {
1269
1386
  /**
1270
1387
  * Listen for update fail event in the App, let you know when update has fail to install at next app start
1271
1388
  *
1389
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1272
1390
  * @since 2.3.0
1273
1391
  */
1274
1392
  addListener(eventName: 'updateFailed', listenerFunc: (state: UpdateFailedEvent) => void): Promise<PluginListenerHandle>;
@@ -1277,24 +1395,28 @@ export interface CapacitorUpdaterPlugin {
1277
1395
  * This event is retained natively until JavaScript consumes it, so if the app reloads before your
1278
1396
  * listener is attached, the last pending `set` event is delivered once the listener subscribes.
1279
1397
  *
1398
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1280
1399
  * @since 8.43.12
1281
1400
  */
1282
1401
  addListener(eventName: 'set', listenerFunc: (state: SetEvent) => void): Promise<PluginListenerHandle>;
1283
1402
  /**
1284
1403
  * Listen for set next event in the App, let you know when a bundle is queued as the next bundle to install.
1285
1404
  *
1405
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1286
1406
  * @since 6.14.0
1287
1407
  */
1288
1408
  addListener(eventName: 'setNext', listenerFunc: (state: SetNextEvent) => void): Promise<PluginListenerHandle>;
1289
1409
  /**
1290
1410
  * Listen for download fail event in the App, let you know when a bundle download has failed
1291
1411
  *
1412
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1292
1413
  * @since 4.0.0
1293
1414
  */
1294
1415
  addListener(eventName: 'downloadFailed', listenerFunc: (state: DownloadFailedEvent) => void): Promise<PluginListenerHandle>;
1295
1416
  /**
1296
1417
  * Listen for reload event in the App, let you know when reload has happened
1297
1418
  *
1419
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1298
1420
  * @since 4.3.0
1299
1421
  */
1300
1422
  addListener(eventName: 'appReloaded', listenerFunc: () => void): Promise<PluginListenerHandle>;
@@ -1303,6 +1425,7 @@ export interface CapacitorUpdaterPlugin {
1303
1425
  * This event is retained natively until JavaScript consumes it, so it can still be delivered after
1304
1426
  * a reload even if the listener is attached later in app startup.
1305
1427
  *
1428
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1306
1429
  * @since 5.1.0
1307
1430
  */
1308
1431
  addListener(eventName: 'appReady', listenerFunc: (state: AppReadyEvent) => void): Promise<PluginListenerHandle>;
@@ -1314,6 +1437,7 @@ export interface CapacitorUpdaterPlugin {
1314
1437
  * - Implementing custom error handling for channel restrictions
1315
1438
  * - Logging unauthorized channel access attempts
1316
1439
  *
1440
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1317
1441
  * @since 7.34.0
1318
1442
  */
1319
1443
  addListener(eventName: 'channelPrivate', listenerFunc: (state: ChannelPrivateEvent) => void): Promise<PluginListenerHandle>;
@@ -1337,6 +1461,7 @@ export interface CapacitorUpdaterPlugin {
1337
1461
  * When status is `DOWNLOADED`, you should prompt the user and call
1338
1462
  * {@link completeFlexibleUpdate} to finish the installation.
1339
1463
  *
1464
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1340
1465
  * @since 8.0.0
1341
1466
  */
1342
1467
  addListener(eventName: 'onFlexibleUpdateStateChange', listenerFunc: (state: FlexibleUpdateState) => void): Promise<PluginListenerHandle>;
@@ -1844,6 +1969,64 @@ export interface ChannelPrivateEvent {
1844
1969
  channel: string;
1845
1970
  message: string;
1846
1971
  }
1972
+ /**
1973
+ * Payload of the single `updaterEvent` listener: every plugin event as `{ type, data }`.
1974
+ * `type` is the legacy event name and `data` is the same payload the legacy listener receives,
1975
+ * so you can switch on `type` and get a typed `data`.
1976
+ *
1977
+ * The deprecated `majorAvailable` alias is not forwarded: use `breakingAvailable`.
1978
+ *
1979
+ * @since 8.53.0
1980
+ */
1981
+ export type UpdaterEvent = {
1982
+ type: 'download';
1983
+ data: DownloadEvent;
1984
+ } | {
1985
+ type: 'noNeedUpdate';
1986
+ data: NoNeedEvent;
1987
+ } | {
1988
+ type: 'updateCheckResult';
1989
+ data: UpdateCheckResultEvent;
1990
+ } | {
1991
+ type: 'updateAvailable';
1992
+ data: UpdateAvailableEvent;
1993
+ } | {
1994
+ type: 'downloadComplete';
1995
+ data: DownloadCompleteEvent;
1996
+ } | {
1997
+ type: 'downloadFailed';
1998
+ data: DownloadFailedEvent;
1999
+ } | {
2000
+ type: 'breakingAvailable';
2001
+ data: BreakingAvailableEvent;
2002
+ } | {
2003
+ type: 'updateFailed';
2004
+ data: UpdateFailedEvent;
2005
+ } | {
2006
+ type: 'set';
2007
+ data: SetEvent;
2008
+ } | {
2009
+ type: 'setNext';
2010
+ data: SetNextEvent;
2011
+ } | {
2012
+ type: 'appReloaded';
2013
+ data: Record<string, never>;
2014
+ } | {
2015
+ type: 'appReady';
2016
+ data: AppReadyEvent;
2017
+ } | {
2018
+ type: 'channelPrivate';
2019
+ data: ChannelPrivateEvent;
2020
+ } | {
2021
+ type: 'onFlexibleUpdateStateChange';
2022
+ data: FlexibleUpdateState;
2023
+ };
2024
+ /**
2025
+ * Every event name that can appear in {@link UpdaterEvent}.
2026
+ *
2027
+ * @since 8.53.0
2028
+ */
2029
+ export type UpdaterEventType = UpdaterEvent['type'];
1847
2030
  export interface ManifestEntry {
1848
2031
  file_name: string | null;
1849
2032
  file_hash: string | null;
@@ -2353,8 +2536,24 @@ export interface CurrentBundleResult {
2353
2536
  bundle: BundleInfo;
2354
2537
  native: string;
2355
2538
  }
2539
+ /**
2540
+ * How multiple delay conditions are combined when more than one is set.
2541
+ *
2542
+ * - `and`: every condition must be satisfied before the pending update is applied (default, backward compatible).
2543
+ * - `or`: the pending update is applied as soon as any condition is satisfied.
2544
+ *
2545
+ * @since 8.50.0
2546
+ */
2547
+ export type DelayConditionMode = 'and' | 'or';
2356
2548
  export interface MultiDelayConditions {
2357
2549
  delayConditions: DelayCondition[];
2550
+ /**
2551
+ * How to combine multiple delay conditions.
2552
+ *
2553
+ * @default 'and'
2554
+ * @since 8.50.0
2555
+ */
2556
+ conditionMode?: DelayConditionMode;
2358
2557
  }
2359
2558
  export interface BuiltinVersion {
2360
2559
  version: string;