@simplysm/capacitor-plugin-auto-update 13.0.81 → 13.0.83
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 +187 -0
- package/package.json +7 -8
package/README.md
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# @simplysm/capacitor-plugin-auto-update
|
|
2
|
+
|
|
3
|
+
Capacitor plugin for automatic APK updates on Android. Provides APK installation with permission management and two update strategies: server-based (via `ServiceClient`) and external-storage-based.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @simplysm/capacitor-plugin-auto-update
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Android Configuration
|
|
12
|
+
|
|
13
|
+
Add the `REQUEST_INSTALL_PACKAGES` permission to your `AndroidManifest.xml`:
|
|
14
|
+
|
|
15
|
+
```xml
|
|
16
|
+
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Register the plugin in your `MainActivity.java`:
|
|
20
|
+
|
|
21
|
+
```java
|
|
22
|
+
import kr.co.simplysm.capacitor.apkinstaller.ApkInstallerPlugin;
|
|
23
|
+
|
|
24
|
+
public class MainActivity extends BridgeActivity {
|
|
25
|
+
@Override
|
|
26
|
+
protected void init(Bundle savedInstanceState) {
|
|
27
|
+
super.init(savedInstanceState);
|
|
28
|
+
registerPlugin(ApkInstallerPlugin.class);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## API
|
|
34
|
+
|
|
35
|
+
### `ApkInstaller`
|
|
36
|
+
|
|
37
|
+
Abstract utility class for low-level APK installation and permission management.
|
|
38
|
+
|
|
39
|
+
- **Android**: Executes APK install intent, manages `REQUEST_INSTALL_PACKAGES` permission.
|
|
40
|
+
- **Browser**: Shows an alert message and resolves normally (web fallback).
|
|
41
|
+
|
|
42
|
+
#### `ApkInstaller.checkPermissions()`
|
|
43
|
+
|
|
44
|
+
Check whether install permission is granted and declared in the manifest.
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
const result = await ApkInstaller.checkPermissions();
|
|
48
|
+
// result.granted — true if the app can install packages
|
|
49
|
+
// result.manifest — true if REQUEST_INSTALL_PACKAGES is declared in AndroidManifest.xml
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Returns:** `Promise<{ granted: boolean; manifest: boolean }>`
|
|
53
|
+
|
|
54
|
+
#### `ApkInstaller.requestPermissions()`
|
|
55
|
+
|
|
56
|
+
Navigate the user to the system settings page to grant the `REQUEST_INSTALL_PACKAGES` permission (Android 8.0+).
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
await ApkInstaller.requestPermissions();
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**Returns:** `Promise<void>`
|
|
63
|
+
|
|
64
|
+
#### `ApkInstaller.install(apkUri)`
|
|
65
|
+
|
|
66
|
+
Install an APK file from the given `content://` URI (FileProvider URI).
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
await ApkInstaller.install("content://com.example.provider/files/latest.apk");
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
| Parameter | Type | Description |
|
|
73
|
+
|-----------|------|-------------|
|
|
74
|
+
| `apkUri` | `string` | A `content://` URI pointing to the APK file |
|
|
75
|
+
|
|
76
|
+
**Returns:** `Promise<void>`
|
|
77
|
+
|
|
78
|
+
#### `ApkInstaller.getVersionInfo()`
|
|
79
|
+
|
|
80
|
+
Get the current app version information.
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
const info = await ApkInstaller.getVersionInfo();
|
|
84
|
+
// info.versionName — e.g. "1.2.3"
|
|
85
|
+
// info.versionCode — e.g. "10"
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**Returns:** `Promise<VersionInfo>`
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
### `AutoUpdate`
|
|
93
|
+
|
|
94
|
+
Abstract utility class that orchestrates the full update flow: version check, download, permission handling, and APK installation. Provides two update strategies.
|
|
95
|
+
|
|
96
|
+
#### `AutoUpdate.run(opt)`
|
|
97
|
+
|
|
98
|
+
Server-based update strategy. Connects to the server via `ServiceClient`, compares versions using semver, downloads the APK, and triggers installation.
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import { AutoUpdate } from "@simplysm/capacitor-plugin-auto-update";
|
|
102
|
+
|
|
103
|
+
await AutoUpdate.run({
|
|
104
|
+
log: (messageHtml) => {
|
|
105
|
+
// Display progress/status messages (may contain HTML)
|
|
106
|
+
document.getElementById("status")!.innerHTML = messageHtml;
|
|
107
|
+
},
|
|
108
|
+
serviceClient: myServiceClient,
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
| Parameter | Type | Description |
|
|
113
|
+
|-----------|------|-------------|
|
|
114
|
+
| `opt.log` | `(messageHtml: string) => void` | Callback for progress/status messages (may include HTML) |
|
|
115
|
+
| `opt.serviceClient` | `ServiceClient` | Service client instance connected to a server that implements `AutoUpdateService` |
|
|
116
|
+
|
|
117
|
+
**Returns:** `Promise<void>`
|
|
118
|
+
|
|
119
|
+
**Flow:**
|
|
120
|
+
1. Queries `AutoUpdateService.getLastVersion("android")` for latest version info.
|
|
121
|
+
2. Checks and requests install permissions if needed.
|
|
122
|
+
3. Compares server version with current app version using semver.
|
|
123
|
+
4. Downloads the APK with progress reporting.
|
|
124
|
+
5. Triggers APK installation and freezes the app until restart.
|
|
125
|
+
|
|
126
|
+
#### `AutoUpdate.runByExternalStorage(opt)`
|
|
127
|
+
|
|
128
|
+
External-storage-based update strategy. Scans a directory on external storage for APK files named by semver version (e.g., `1.2.3.apk`), finds the latest, and triggers installation if newer than the current version.
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
import { AutoUpdate } from "@simplysm/capacitor-plugin-auto-update";
|
|
132
|
+
|
|
133
|
+
await AutoUpdate.runByExternalStorage({
|
|
134
|
+
log: (messageHtml) => {
|
|
135
|
+
document.getElementById("status")!.innerHTML = messageHtml;
|
|
136
|
+
},
|
|
137
|
+
dirPath: "updates/my-app",
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
| Parameter | Type | Description |
|
|
142
|
+
|-----------|------|-------------|
|
|
143
|
+
| `opt.log` | `(messageHtml: string) => void` | Callback for progress/status messages (may include HTML) |
|
|
144
|
+
| `opt.dirPath` | `string` | Relative path within external storage containing versioned APK files |
|
|
145
|
+
|
|
146
|
+
**Returns:** `Promise<void>`
|
|
147
|
+
|
|
148
|
+
**Flow:**
|
|
149
|
+
1. Checks and requests install permissions if needed.
|
|
150
|
+
2. Reads the external storage directory for `.apk` files with semver-formatted names.
|
|
151
|
+
3. Finds the highest version using semver comparison.
|
|
152
|
+
4. Compares with the current app version.
|
|
153
|
+
5. Triggers APK installation and freezes the app until restart.
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
### `VersionInfo`
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
interface VersionInfo {
|
|
161
|
+
versionName: string; // Semantic version string, e.g. "1.2.3"
|
|
162
|
+
versionCode: string; // Android numeric version code, e.g. "10"
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### `ApkInstallerPlugin`
|
|
167
|
+
|
|
168
|
+
Low-level Capacitor plugin interface. Use the `ApkInstaller` static class instead of calling this directly.
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
interface ApkInstallerPlugin {
|
|
172
|
+
install(options: { uri: string }): Promise<void>;
|
|
173
|
+
checkPermissions(): Promise<{ granted: boolean; manifest: boolean }>;
|
|
174
|
+
requestPermissions(): Promise<void>;
|
|
175
|
+
getVersionInfo(): Promise<VersionInfo>;
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Dependencies
|
|
180
|
+
|
|
181
|
+
- `@simplysm/capacitor-plugin-file-system` -- File system access for reading/writing APK files
|
|
182
|
+
- `@simplysm/core-browser` -- `fetchUrlBytes` for downloading APK files with progress
|
|
183
|
+
- `@simplysm/core-common` -- Utility functions (`html`, `wait`, `path`)
|
|
184
|
+
- `@simplysm/service-client` -- Server communication for the server-based update strategy
|
|
185
|
+
- `@simplysm/service-common` -- `AutoUpdateService` type definition
|
|
186
|
+
- `semver` -- Semantic version comparison
|
|
187
|
+
- `@capacitor/core` -- Capacitor plugin system (peer dependency)
|
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.83",
|
|
4
4
|
"description": "Simplysm Package - Capacitor Auto Update Plugin",
|
|
5
5
|
"author": "simplysm",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,16 +15,15 @@
|
|
|
15
15
|
"files": [
|
|
16
16
|
"dist",
|
|
17
17
|
"src",
|
|
18
|
-
"android"
|
|
19
|
-
"docs"
|
|
18
|
+
"android"
|
|
20
19
|
],
|
|
21
20
|
"dependencies": {
|
|
22
21
|
"semver": "^7.7.4",
|
|
23
|
-
"@simplysm/capacitor-plugin-file-system": "13.0.
|
|
24
|
-
"@simplysm/core-browser": "13.0.
|
|
25
|
-
"@simplysm/
|
|
26
|
-
"@simplysm/
|
|
27
|
-
"@simplysm/service-
|
|
22
|
+
"@simplysm/capacitor-plugin-file-system": "13.0.83",
|
|
23
|
+
"@simplysm/core-browser": "13.0.83",
|
|
24
|
+
"@simplysm/service-client": "13.0.83",
|
|
25
|
+
"@simplysm/core-common": "13.0.83",
|
|
26
|
+
"@simplysm/service-common": "13.0.83"
|
|
28
27
|
},
|
|
29
28
|
"devDependencies": {
|
|
30
29
|
"@capacitor/core": "^7.6.0",
|