Skip to content

Commit

Permalink
feat: listener for app reloaded
Browse files Browse the repository at this point in the history
  • Loading branch information
luca-peruzzo committed Sep 14, 2022
1 parent fb42865 commit 5783f53
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ Capacitor Updator works by unzipping a compiled app bundle to the native device
* [`addListener('majorAvailable', ...)`](#addlistenermajoravailable)
* [`addListener('updateFailed', ...)`](#addlistenerupdatefailed)
* [`addListener('downloadFailed', ...)`](#addlistenerdownloadfailed)
* [`addListener('appReloaded', ...)`](#addlistenerappreloaded)
* [`getDeviceId()`](#getdeviceid)
* [`getPluginVersion()`](#getpluginversion)
* [`isAutoUpdateEnabled()`](#isautoupdateenabled)
Expand Down Expand Up @@ -486,6 +487,26 @@ Listen for download fail event in the App, let you know when download has fail f
--------------------


### addListener('appReloaded', ...)

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

Listen for download fail event in the App, let you know when download has fail finished

| Param | Type |
| ------------------ | ------------------------------------------------------------------- |
| **`eventName`** | <code>'appReloaded'</code> |
| **`listenerFunc`** | <code><a href="#appreloadedlistener">AppReloadedListener</a></code> |

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

**Since:** 4.3.0

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


### getDeviceId()

```typescript
Expand Down Expand Up @@ -687,6 +708,11 @@ removeAllListeners() => Promise<void>

<code>(state: <a href="#downloadfailedevent">DownloadFailedEvent</a>): void</code>


#### AppReloadedListener

<code>(state: void): void</code>

</docgen-api>

### Listen to download events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ private boolean _reload() {
this.bridge.setServerBasePath(path);
}
this.checkAppReady();
this.notifyListeners("appReloaded", new JSObject());
return true;
}

Expand Down
1 change: 1 addition & 0 deletions ios/Plugin/CapacitorUpdaterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
if let vc = bridge.viewController as? CAPBridgeViewController {
vc.setServerBasePath(path: destHot.path)
self.checkAppReady()
self.notifyListeners("appReloaded", data: [:])
return true
}
return false
Expand Down
11 changes: 11 additions & 0 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export type DownloadFailedListener = (state: DownloadFailedEvent) => void;
export type DownloadCompleteListener = (state: DownloadCompleteEvent) => void;
export type MajorAvailableListener = (state: MajorAvailableEvent) => void;
export type UpdateFailedListener = (state: UpdateFailedEvent) => void;
export type AppReloadedListener = (state: void) => void;

export interface CapacitorUpdaterPlugin {
/**
Expand Down Expand Up @@ -381,6 +382,16 @@ export interface CapacitorUpdaterPlugin {
listenerFunc: DownloadFailedListener
): Promise<PluginListenerHandle> & PluginListenerHandle;

/**
* Listen for download fail event in the App, let you know when download has fail finished

This comment has been minimized.

Copy link
@arendjantetteroo

arendjantetteroo Sep 19, 2022

Comment is incorrect

*
* @since 4.3.0
*/
addListener(
eventName: 'appReloaded',
listenerFunc: AppReloadedListener
): Promise<PluginListenerHandle> & PluginListenerHandle;

/**
* Get unique ID used to identify device (sent to auto update server)
*
Expand Down

0 comments on commit 5783f53

Please sign in to comment.