@simplysm/capacitor-plugin-auto-update 13.0.72 → 13.0.74
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.
- package/README.md +139 -12
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -2,27 +2,154 @@
|
|
|
2
2
|
|
|
3
3
|
Simplysm Package - Capacitor Auto Update Plugin
|
|
4
4
|
|
|
5
|
+
Provides Android APK auto-update capabilities for Capacitor apps. Includes APK installation via native Android intent and automated update flows from either a remote server or external storage.
|
|
6
|
+
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
9
|
+
```bash
|
|
7
10
|
pnpm add @simplysm/capacitor-plugin-auto-update
|
|
11
|
+
```
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## Source Index
|
|
13
|
+
## Main Modules
|
|
12
14
|
|
|
13
15
|
### APK Installer
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
#### `ApkInstaller`
|
|
18
|
+
|
|
19
|
+
Abstract class with static methods that wrap the native `ApkInstaller` Capacitor plugin.
|
|
20
|
+
|
|
21
|
+
- Android: executes APK install intent and manages `REQUEST_INSTALL_PACKAGES` permission.
|
|
22
|
+
- Browser (web fallback): shows an alert message and returns normally.
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { ApkInstaller } from "@simplysm/capacitor-plugin-auto-update";
|
|
26
|
+
|
|
27
|
+
// Check whether REQUEST_INSTALL_PACKAGES is declared in the manifest
|
|
28
|
+
const declared = await ApkInstaller.hasPermissionManifest();
|
|
29
|
+
|
|
30
|
+
// Check whether REQUEST_INSTALL_PACKAGES is currently granted
|
|
31
|
+
const granted = await ApkInstaller.hasPermission();
|
|
32
|
+
|
|
33
|
+
// Navigate the user to the settings page to grant the permission
|
|
34
|
+
await ApkInstaller.requestPermission();
|
|
35
|
+
|
|
36
|
+
// Install an APK given a content:// FileProvider URI
|
|
37
|
+
await ApkInstaller.install("content://com.example/files/latest.apk");
|
|
38
|
+
|
|
39
|
+
// Get the running app's version information
|
|
40
|
+
const info = await ApkInstaller.getVersionInfo();
|
|
41
|
+
// info.versionName → e.g. "1.2.3"
|
|
42
|
+
// info.versionCode → e.g. "10203"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Static methods**
|
|
46
|
+
|
|
47
|
+
| Method | Signature | Description |
|
|
48
|
+
|---|---|---|
|
|
49
|
+
| `hasPermissionManifest` | `() => Promise<boolean>` | Returns `true` if `REQUEST_INSTALL_PACKAGES` is declared in the manifest. |
|
|
50
|
+
| `hasPermission` | `() => Promise<boolean>` | Returns `true` if `REQUEST_INSTALL_PACKAGES` is currently granted. |
|
|
51
|
+
| `requestPermission` | `() => Promise<void>` | Opens the system settings screen for the user to grant the permission. |
|
|
52
|
+
| `install` | `(apkUri: string) => Promise<void>` | Fires the install intent for the given `content://` URI. |
|
|
53
|
+
| `getVersionInfo` | `() => Promise<IVersionInfo>` | Returns the running app's `versionName` and `versionCode`. |
|
|
54
|
+
|
|
55
|
+
---
|
|
19
56
|
|
|
20
57
|
### Auto Update
|
|
21
58
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
59
|
+
#### `AutoUpdate`
|
|
60
|
+
|
|
61
|
+
Abstract class with static methods that orchestrate the full auto-update flow.
|
|
62
|
+
|
|
63
|
+
**`AutoUpdate.run`**
|
|
64
|
+
|
|
65
|
+
Downloads the latest APK from a remote server using a `ServiceClient` connection and installs it.
|
|
66
|
+
|
|
67
|
+
1. Queries the server for the latest version via `AutoUpdateService.getLastVersion("android")`.
|
|
68
|
+
2. Checks and requests install permission if needed.
|
|
69
|
+
3. Compares the server version against the installed version using semver.
|
|
70
|
+
4. Downloads the APK to app cache storage and triggers installation.
|
|
71
|
+
5. Freezes the app (waits indefinitely) after install to prevent further execution.
|
|
72
|
+
6. On any error the log callback is called with an HTML error message and the app is frozen.
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { AutoUpdate } from "@simplysm/capacitor-plugin-auto-update";
|
|
76
|
+
import type { ServiceClient } from "@simplysm/service-client";
|
|
77
|
+
|
|
78
|
+
declare const serviceClient: ServiceClient;
|
|
79
|
+
|
|
80
|
+
await AutoUpdate.run({
|
|
81
|
+
log: (messageHtml) => {
|
|
82
|
+
document.getElementById("status")!.innerHTML = messageHtml;
|
|
83
|
+
},
|
|
84
|
+
serviceClient,
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**Options**
|
|
89
|
+
|
|
90
|
+
| Property | Type | Description |
|
|
91
|
+
|---|---|---|
|
|
92
|
+
| `log` | `(messageHtml: string) => void` | Callback that receives HTML status messages to display to the user. |
|
|
93
|
+
| `serviceClient` | `ServiceClient` | Connected service client used to reach `AutoUpdateService` on the server. |
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
**`AutoUpdate.runByExternalStorage`**
|
|
98
|
+
|
|
99
|
+
Finds the newest APK file stored in a directory on the device's external storage and installs it.
|
|
100
|
+
|
|
101
|
+
1. Checks and requests install permission if needed.
|
|
102
|
+
2. Reads the specified directory on external storage, selecting `.apk` files whose basenames are valid semver strings.
|
|
103
|
+
3. Picks the highest version using `semver.maxSatisfying`.
|
|
104
|
+
4. Compares it against the installed version; skips if already up-to-date.
|
|
105
|
+
5. Triggers installation and freezes the app.
|
|
106
|
+
6. On any error the log callback is called with an HTML error message and the app is frozen.
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
import { AutoUpdate } from "@simplysm/capacitor-plugin-auto-update";
|
|
110
|
+
|
|
111
|
+
await AutoUpdate.runByExternalStorage({
|
|
112
|
+
log: (messageHtml) => {
|
|
113
|
+
document.getElementById("status")!.innerHTML = messageHtml;
|
|
114
|
+
},
|
|
115
|
+
dirPath: "MyApp/updates",
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**Options**
|
|
120
|
+
|
|
121
|
+
| Property | Type | Description |
|
|
122
|
+
|---|---|---|
|
|
123
|
+
| `log` | `(messageHtml: string) => void` | Callback that receives HTML status messages to display to the user. |
|
|
124
|
+
| `dirPath` | `string` | Path relative to the external storage root where APK files are located. |
|
|
125
|
+
|
|
126
|
+
## Types
|
|
127
|
+
|
|
128
|
+
### `IVersionInfo`
|
|
129
|
+
|
|
130
|
+
Version information returned by `ApkInstaller.getVersionInfo()`.
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
import type { IVersionInfo } from "@simplysm/capacitor-plugin-auto-update";
|
|
134
|
+
|
|
135
|
+
interface IVersionInfo {
|
|
136
|
+
versionName: string; // Human-readable version string, e.g. "1.2.3"
|
|
137
|
+
versionCode: string; // Integer build number as a string, e.g. "10203"
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### `IApkInstallerPlugin`
|
|
142
|
+
|
|
143
|
+
Low-level interface implemented by the native Capacitor plugin. Use `ApkInstaller` (the abstract class) instead of this interface directly.
|
|
25
144
|
|
|
26
|
-
|
|
145
|
+
```ts
|
|
146
|
+
import type { IApkInstallerPlugin } from "@simplysm/capacitor-plugin-auto-update";
|
|
27
147
|
|
|
28
|
-
|
|
148
|
+
interface IApkInstallerPlugin {
|
|
149
|
+
install(options: { uri: string }): Promise<void>;
|
|
150
|
+
hasPermission(): Promise<{ granted: boolean }>;
|
|
151
|
+
requestPermission(): Promise<void>;
|
|
152
|
+
hasPermissionManifest(): Promise<{ declared: boolean }>;
|
|
153
|
+
getVersionInfo(): Promise<IVersionInfo>;
|
|
154
|
+
}
|
|
155
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplysm/capacitor-plugin-auto-update",
|
|
3
|
-
"version": "13.0.
|
|
3
|
+
"version": "13.0.74",
|
|
4
4
|
"description": "Simplysm Package - Capacitor Auto Update Plugin",
|
|
5
5
|
"author": "simplysm",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"semver": "^7.7.4",
|
|
22
|
-
"@simplysm/
|
|
23
|
-
"@simplysm/
|
|
24
|
-
"@simplysm/core-browser": "13.0.
|
|
25
|
-
"@simplysm/service-
|
|
26
|
-
"@simplysm/service-
|
|
22
|
+
"@simplysm/core-common": "13.0.74",
|
|
23
|
+
"@simplysm/capacitor-plugin-file-system": "13.0.74",
|
|
24
|
+
"@simplysm/core-browser": "13.0.74",
|
|
25
|
+
"@simplysm/service-common": "13.0.74",
|
|
26
|
+
"@simplysm/service-client": "13.0.74"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@capacitor/core": "^7.5.0",
|