Skip to content

Commit

Permalink
refactor(live-update)!: disable automatic rollbacks
Browse files Browse the repository at this point in the history
Close #258
  • Loading branch information
robingenz committed Jan 21, 2025
1 parent 0dc1492 commit 48f35a3
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/fast-peas-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@capawesome/capacitor-live-update': major
---

refactor: disable automatic rollbacks by default
5 changes: 5 additions & 0 deletions packages/live-update/BREAKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
29 changes: 16 additions & 13 deletions packages/live-update/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,17 @@ We recommend to declare [`CA92.1`](https://developer.apple.com/documentation/bun
<docgen-config>
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->

| Prop | Type | Description | Default | Since |
| ----------------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------ | ----- |
| **`appId`** | <code>string</code> | 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`** | <code>boolean</code> | Whether or not to automatically delete unused bundles. When enabled, the plugin will automatically delete unused bundles after calling `ready()`. | <code>false</code> | 5.0.0 |
| **`defaultChannel`** | <code>string</code> | The default channel of the app. | | 6.3.0 |
| **`enabled`** | <code>boolean</code> | Whether or not the plugin is enabled. | <code>true</code> | 5.0.0 |
| **`httpTimeout`** | <code>number</code> | The timeout in milliseconds for HTTP requests. | <code>60000</code> | 6.4.0 |
| **`publicKey`** | <code>string</code> | 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`** | <code>number</code> | The timeout in milliseconds to wait for the app to be ready before resetting to the default bundle. | <code>10000</code> | 5.0.0 |
| **`resetOnUpdate`** | <code>boolean</code> | Whether or not the app should be reset to the default bundle during an update. | <code>true</code> | 5.0.0 |
| Prop | Type | Description | Default | Since |
| ----------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------- | ----- |
| **`appId`** | <code>string</code> | 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`** | <code>boolean</code> | Whether or not to automatically delete unused bundles. When enabled, the plugin will automatically delete unused bundles after calling `ready()`. | <code>false</code> | 5.0.0 |
| **`defaultChannel`** | <code>string</code> | The default channel of the app. | | 6.3.0 |
| **`enabled`** | <code>boolean</code> | Whether or not the plugin is enabled. | <code>true</code> | 5.0.0 |
| **`httpTimeout`** | <code>number</code> | The timeout in milliseconds for HTTP requests. | <code>60000</code> | 6.4.0 |
| **`publicKey`** | <code>string</code> | 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`** | <code>number</code> | 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. | <code>0</code> | 5.0.0 |
| **`resetOnUpdate`** | <code>boolean</code> | Whether or not the app should be reset to the default bundle during an update. | <code>true</code> | 5.0.0 |
| **`serverDomain`** | <code>string</code> | The API domain of the [Capawesome Cloud](https://cloud.capawesome.io) server. | <code>'api.cloud.capawesome.io'</code> | 7.0.0 |

### Examples

Expand All @@ -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
}
}
}
Expand All @@ -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,
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -858,6 +861,9 @@ private void setPreviousBundleId(@Nullable String bundleId) {
}

private void startRollbackTimer() {
if (config.getReadyTimeout() <= 0) {
return;
}
stopRollbackTimer();
rollbackHandler.postDelayed(() -> rollback(), config.getReadyTimeout());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
6 changes: 6 additions & 0 deletions packages/live-update/ios/Plugin/LiveUpdate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -675,6 +678,9 @@ import CommonCrypto
}

private func startRollbackTimer() {
guard config.readyTimeout > 0 else {
return
}
stopRollbackTimer()
rollbackDispatchWorkItem = DispatchWorkItem { [weak self] in
self?.rollback()
Expand Down
2 changes: 1 addition & 1 deletion packages/live-update/ios/Plugin/LiveUpdateConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
13 changes: 11 additions & 2 deletions packages/live-update/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/**
Expand Down

0 comments on commit 48f35a3

Please sign in to comment.