diff --git a/.changeset/fast-peas-smile.md b/.changeset/fast-peas-smile.md new file mode 100644 index 0000000..1e484bd --- /dev/null +++ b/.changeset/fast-peas-smile.md @@ -0,0 +1,5 @@ +--- +'@capawesome/capacitor-live-update': major +--- + +refactor: disable automatic rollbacks by default diff --git a/packages/live-update/BREAKING.md b/packages/live-update/BREAKING.md index 08d6133..2f3df5d 100644 --- a/packages/live-update/BREAKING.md +++ b/packages/live-update/BREAKING.md @@ -23,3 +23,8 @@ The `checksum` property has been removed from the `DownloadBundleOptions` interf ### `location` configuration option The `location` configuration option has been replaced by the `serverDomain` configuration option. + +### `readyTimeout` configuration option + +The default value of the `readyTimeout` configuration option has been changed from `10000` to `0` to disable the timeout by default. +However, it is strongly **recommended** to configure this option so that the plugin can roll back to the default bundle in case of problems. diff --git a/packages/live-update/README.md b/packages/live-update/README.md index aa7bec1..70867f3 100644 --- a/packages/live-update/README.md +++ b/packages/live-update/README.md @@ -66,16 +66,17 @@ We recommend to declare [`CA92.1`](https://developer.apple.com/documentation/bun -| Prop | Type | Description | Default | Since | -| ----------------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------ | ----- | -| **`appId`** | string | The app ID is used to identify the app when using [Capawesome Cloud](https://capawesome.io/cloud). This is **NOT** the same as the app identifier (e.g. `com.example.app`). This is a unique identifier generated by Capawesome Cloud (e.g. `6e351b4f-69a7-415e-a057-4567df7ffe94`). | | 5.0.0 | -| **`autoDeleteBundles`** | boolean | Whether or not to automatically delete unused bundles. When enabled, the plugin will automatically delete unused bundles after calling `ready()`. | false | 5.0.0 | -| **`defaultChannel`** | string | The default channel of the app. | | 6.3.0 | -| **`enabled`** | boolean | Whether or not the plugin is enabled. | true | 5.0.0 | -| **`httpTimeout`** | number | The timeout in milliseconds for HTTP requests. | 60000 | 6.4.0 | -| **`publicKey`** | string | The public key to verify the integrity of the bundle. The public key must be a PEM-encoded RSA public key. | | 6.1.0 | -| **`readyTimeout`** | number | The timeout in milliseconds to wait for the app to be ready before resetting to the default bundle. | 10000 | 5.0.0 | -| **`resetOnUpdate`** | boolean | Whether or not the app should be reset to the default bundle during an update. | true | 5.0.0 | +| Prop | Type | Description | Default | Since | +| ----------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------- | ----- | +| **`appId`** | string | The app ID is used to identify the app when using [Capawesome Cloud](https://capawesome.io/cloud). This is **NOT** the same as the app identifier (e.g. `com.example.app`). This is a unique identifier generated by Capawesome Cloud (e.g. `6e351b4f-69a7-415e-a057-4567df7ffe94`). | | 5.0.0 | +| **`autoDeleteBundles`** | boolean | Whether or not to automatically delete unused bundles. When enabled, the plugin will automatically delete unused bundles after calling `ready()`. | false | 5.0.0 | +| **`defaultChannel`** | string | The default channel of the app. | | 6.3.0 | +| **`enabled`** | boolean | Whether or not the plugin is enabled. | true | 5.0.0 | +| **`httpTimeout`** | number | The timeout in milliseconds for HTTP requests. | 60000 | 6.4.0 | +| **`publicKey`** | string | The public key to verify the integrity of the bundle. The public key must be a PEM-encoded RSA public key. | | 6.1.0 | +| **`readyTimeout`** | number | The timeout in milliseconds to wait for the app to be ready before resetting to the default bundle. It is strongly **recommended** to configure this option so that the plugin can roll back to the default bundle in case of problems. If configured, the plugin will wait for the app to call the `ready()` method before resetting to the default bundle. Set to `0` to disable the timeout. | 0 | 5.0.0 | +| **`resetOnUpdate`** | boolean | Whether or not the app should be reset to the default bundle during an update. | true | 5.0.0 | +| **`serverDomain`** | string | The API domain of the [Capawesome Cloud](https://cloud.capawesome.io) server. | 'api.cloud.capawesome.io' | 7.0.0 | ### Examples @@ -91,8 +92,9 @@ In `capacitor.config.json`: "enabled": undefined, "httpTimeout": undefined, "publicKey": '-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDDodf1SD0OOn6hIlDuKBza0Ed0OqtwyVJwiyjmE9BJaZ7y8ZUfcF+SKmd0l2cDPM45XIg2tAFux5n29uoKyHwSt+6tCi5CJA5Z1/1eZruRRqABLonV77KS3HUtvOgqRLDnKSV89dYZkM++NwmzOPgIF422mvc+VukcVOBfc8/AHQIDAQAB-----END PUBLIC KEY-----', - "readyTimeout": undefined, - "resetOnUpdate": undefined + "readyTimeout": 10000, + "resetOnUpdate": undefined, + "serverDomain": undefined } } } @@ -114,8 +116,9 @@ const config: CapacitorConfig = { enabled: undefined, httpTimeout: undefined, publicKey: '-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDDodf1SD0OOn6hIlDuKBza0Ed0OqtwyVJwiyjmE9BJaZ7y8ZUfcF+SKmd0l2cDPM45XIg2tAFux5n29uoKyHwSt+6tCi5CJA5Z1/1eZruRRqABLonV77KS3HUtvOgqRLDnKSV89dYZkM++NwmzOPgIF422mvc+VukcVOBfc8/AHQIDAQAB-----END PUBLIC KEY-----', - readyTimeout: undefined, + readyTimeout: 10000, resetOnUpdate: undefined, + serverDomain: undefined, }, }, }; diff --git a/packages/live-update/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdate.java b/packages/live-update/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdate.java index aeeccf6..babafde 100644 --- a/packages/live-update/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdate.java +++ b/packages/live-update/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdate.java @@ -200,6 +200,9 @@ public void getVersionName(@NonNull NonEmptyCallback callback) throws PackageMan public void ready(@NonNull NonEmptyCallback callback) { Logger.debug(LiveUpdatePlugin.TAG, "App is ready."); + if (config.getReadyTimeout() <= 0) { + Logger.warn(LiveUpdatePlugin.TAG, "Ready timeout is set to 0. Automatic rollback is disabled."); + } // Stop the rollback timer stopRollbackTimer(); // Delete unused bundles @@ -858,6 +861,9 @@ private void setPreviousBundleId(@Nullable String bundleId) { } private void startRollbackTimer() { + if (config.getReadyTimeout() <= 0) { + return; + } stopRollbackTimer(); rollbackHandler.postDelayed(() -> rollback(), config.getReadyTimeout()); } diff --git a/packages/live-update/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdateConfig.java b/packages/live-update/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdateConfig.java index af17945..44c93b1 100644 --- a/packages/live-update/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdateConfig.java +++ b/packages/live-update/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdateConfig.java @@ -19,7 +19,7 @@ public class LiveUpdateConfig { @Nullable private String publicKey = null; - private int readyTimeout = 10000; + private int readyTimeout = 0; private boolean resetOnUpdate = true; private String serverDomain = "api.cloud.capawesome.io"; diff --git a/packages/live-update/ios/Plugin/LiveUpdate.swift b/packages/live-update/ios/Plugin/LiveUpdate.swift index 504d8d4..3efd4cb 100644 --- a/packages/live-update/ios/Plugin/LiveUpdate.swift +++ b/packages/live-update/ios/Plugin/LiveUpdate.swift @@ -134,6 +134,9 @@ import CommonCrypto @objc public func ready(completion: @escaping (Result?, Error?) -> Void) { CAPLog.print("[", LiveUpdatePlugin.tag, "] ", "App is ready.") + if config.readyTimeout <= 0 { + CAPLog.print("[", LiveUpdatePlugin.tag, "] ", "Ready timeout is set to 0. Automatic rollback is disabled.") + } // Stop the rollback timer stopRollbackTimer() // Delete unused bundles @@ -675,6 +678,9 @@ import CommonCrypto } private func startRollbackTimer() { + guard config.readyTimeout > 0 else { + return + } stopRollbackTimer() rollbackDispatchWorkItem = DispatchWorkItem { [weak self] in self?.rollback() diff --git a/packages/live-update/ios/Plugin/LiveUpdateConfig.swift b/packages/live-update/ios/Plugin/LiveUpdateConfig.swift index ec58f9f..359815b 100644 --- a/packages/live-update/ios/Plugin/LiveUpdateConfig.swift +++ b/packages/live-update/ios/Plugin/LiveUpdateConfig.swift @@ -5,7 +5,7 @@ public struct LiveUpdateConfig { var enabled = true var httpTimeout = 60000 var publicKey: String? - var readyTimeout = 10000 + var readyTimeout = 0 var resetOnUpdate = true var serverDomain = "api.cloud.capawesome.io" } diff --git a/packages/live-update/src/definitions.ts b/packages/live-update/src/definitions.ts index 06d3302..c159493 100644 --- a/packages/live-update/src/definitions.ts +++ b/packages/live-update/src/definitions.ts @@ -53,10 +53,19 @@ declare module '@capacitor/cli' { */ publicKey?: string; /** - * The timeout in milliseconds to wait for the app to be ready before resetting to the default bundle. + * The timeout in milliseconds to wait for the app to be ready + * before resetting to the default bundle. + * + * It is strongly **recommended** to configure this option so that + * the plugin can roll back to the default bundle in case of problems. + * If configured, the plugin will wait for the app to call the `ready()` + * method before resetting to the default bundle. + * + * Set to `0` to disable the timeout. * * @since 5.0.0 - * @default 10000 + * @default 0 + * @example 10000 */ readyTimeout?: number; /**