Skip to content

Commit

Permalink
feat: add majorAvailable event
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Mar 31, 2022
1 parent 1a81009 commit 48ceca0
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 1 deletion.
110 changes: 109 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ Do not password encrypt this file, or it will fail to unpack.
* [`notifyAppReady()`](#notifyappready)
* [`delayUpdate()`](#delayupdate)
* [`cancelDelay()`](#canceldelay)
* [`addListener('download', ...)`](#addlistenerdownload)
* [`addListener('majorAvailable', ...)`](#addlistenermajoravailable)
* [`addListener(string, ...)`](#addlistenerstring)
* [`removeAllListeners()`](#removealllisteners)
* [Interfaces](#interfaces)
* [Type Aliases](#type-aliases)

</docgen-index>

Expand Down Expand Up @@ -195,7 +201,7 @@ Get all available versions
### reset(...)

```typescript
reset(options: { toAutoUpdate?: boolean; }) => Promise<void>
reset(options?: { toAutoUpdate?: boolean | undefined; } | undefined) => Promise<void>
```

Set the `builtin` version (the one sent to Apple store / Google play store ) as current version
Expand Down Expand Up @@ -276,6 +282,108 @@ allow update in the next time the app goes into the background, only in auto-upd

--------------------


### addListener('download', ...)

```typescript
addListener(eventName: 'download', listenerFunc: DownloadChangeListener) => Promise<PluginListenerHandle> & PluginListenerHandle
```

Listen for download event in the App, let you know when the download is started, loading and finished

| Param | Type |
| ------------------ | ------------------------------------------------------------------------- |
| **`eventName`** | <code>'download'</code> |
| **`listenerFunc`** | <code><a href="#downloadchangelistener">DownloadChangeListener</a></code> |

**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt; & <a href="#pluginlistenerhandle">PluginListenerHandle</a></code>

**Since:** 2.0.11

--------------------


### addListener('majorAvailable', ...)

```typescript
addListener(eventName: 'majorAvailable', listenerFunc: MajorAvailableListener) => Promise<PluginListenerHandle> & PluginListenerHandle
```

Listen for Major update event in the App, let you know when major update is blocked by setting disableAutoUpdateBreaking

| Param | Type |
| ------------------ | ------------------------------------------------------------------------- |
| **`eventName`** | <code>'majorAvailable'</code> |
| **`listenerFunc`** | <code><a href="#majoravailablelistener">MajorAvailableListener</a></code> |

**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt; & <a href="#pluginlistenerhandle">PluginListenerHandle</a></code>

**Since:** 2.3.0

--------------------


### addListener(string, ...)

```typescript
addListener(eventName: string, listenerFunc: (...args: any[]) => any) => Promise<PluginListenerHandle>
```

| Param | Type |
| ------------------ | --------------------------------------- |
| **`eventName`** | <code>string</code> |
| **`listenerFunc`** | <code>(...args: any[]) =&gt; any</code> |

**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>

--------------------


### removeAllListeners()

```typescript
removeAllListeners() => Promise<void>
```

--------------------


### Interfaces


#### PluginListenerHandle

| Prop | Type |
| ------------ | ----------------------------------------- |
| **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |


#### DownloadEvent

| Prop | Type | Description | Since |
| ------------- | ------------------- | ---------------------------------------------- | ------ |
| **`percent`** | <code>number</code> | Current status of download, between 0 and 100. | 2.0.11 |


#### MajorAvailableEvent

| Prop | Type | Description | Since |
| ------------- | ------------------- | ---------------------------------------------- | ----- |
| **`version`** | <code>string</code> | Current status of download, between 0 and 100. | 2.3.0 |


### Type Aliases


#### DownloadChangeListener

<code>(state: <a href="#downloadevent">DownloadEvent</a>): void</code>


#### MajorAvailableListener

<code>(state: <a href="#majoravailableevent">MajorAvailableEvent</a>): void</code>

</docgen-api>

### Listen to download events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ public void run() {
}
else if (disableAutoUpdateToMajor && new Version(newVersion).getMajor() > new Version(currentVersion).getMajor()) {
Log.i(TAG, "Cannot download Major, " + newVersion + " is Breaking change from " + currentVersion);
notifyListeners("majorAvailable", newVersion);
}
else if (!newVersion.equals("") && !newVersion.equals(currentVersion) && !newVersion.equals(failingVersion)) {
new Thread(new Runnable(){
Expand Down
1 change: 1 addition & 0 deletions ios/Plugin/CapacitorUpdaterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
}
else if (self.disableAutoUpdateToMajor && newVersion.major > currentVersionNative.major) {
print("✨ Capacitor-updater: Cannot download Major, \(newVersion) is Breaking change from \(currentVersion)")
self.notifyListeners("majorAvailable", data: ["version": newVersion])
}
else if (newVersion != "0.0.0" && newVersion != currentVersionForCompare && newVersion != failingVersion) {
let dlOp = self.implementation.download(url: downloadUrl)
Expand Down
19 changes: 19 additions & 0 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@ export interface DownloadEvent {
*/
percent: number;
}
export interface MajorAvailableEvent {
/**
* Current status of download, between 0 and 100.
*
* @since 2.3.0
*/
version: string;
}

export type DownloadChangeListener = (state: DownloadEvent) => void;
export type MajorAvailableListener = (state: MajorAvailableEvent) => void;
export interface CapacitorUpdaterPlugin {
/**
* Download a new version from the provided URL, it should be a zip file, with files inside or with a unique folder inside with all your files
Expand Down Expand Up @@ -80,4 +89,14 @@ export interface CapacitorUpdaterPlugin {
eventName: 'download',
listenerFunc: DownloadChangeListener,
): Promise<PluginListenerHandle> & PluginListenerHandle;

/**
* Listen for Major update event in the App, let you know when major update is blocked by setting disableAutoUpdateBreaking
*
* @since 2.3.0
*/
addListener(
eventName: 'majorAvailable',
listenerFunc: MajorAvailableListener,
): Promise<PluginListenerHandle> & PluginListenerHandle;
}

0 comments on commit 48ceca0

Please sign in to comment.