@simplysm/capacitor-plugin-auto-update 12.16.31 → 12.16.36
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 +93 -107
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @simplysm/capacitor-plugin-auto-update
|
|
2
2
|
|
|
3
|
-
Capacitor
|
|
3
|
+
Capacitor Auto Update Plugin -- APK installation and OTA update for Android/Browser. Manages `REQUEST_INSTALL_PACKAGES` permission, installs APK files via intent, retrieves app version info, and provides a full OTA update flow via `SdServiceClient` or external storage.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,150 +8,136 @@ Capacitor 7 plugin for auto-updating Android apps via APK installation. Provides
|
|
|
8
8
|
npm install @simplysm/capacitor-plugin-auto-update
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
## API Overview
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
| API | Type | Description |
|
|
14
|
+
|-----|------|-------------|
|
|
15
|
+
| `ApkInstaller` | Abstract class | Static methods for APK installation permission management, APK install, and version info retrieval |
|
|
16
|
+
| `AutoUpdate` | Abstract class | Static methods for OTA auto-update flows (server-based and external-storage-based) |
|
|
17
|
+
| `IApkInstallerPlugin` | Interface | Low-level Capacitor plugin interface for APK installation |
|
|
18
|
+
| `IVersionInfo` | Interface | App version information structure |
|
|
15
19
|
|
|
16
|
-
|
|
20
|
+
## API Reference
|
|
17
21
|
|
|
18
|
-
|
|
22
|
+
### `IVersionInfo`
|
|
19
23
|
|
|
20
|
-
|
|
21
|
-
import kr.co.simplysm.capacitor.apkinstaller.ApkInstallerPlugin;
|
|
22
|
-
|
|
23
|
-
public class MainActivity extends BridgeActivity {
|
|
24
|
-
@Override
|
|
25
|
-
protected void onCreate(Bundle savedInstanceState) {
|
|
26
|
-
registerPlugin(ApkInstallerPlugin.class);
|
|
27
|
-
super.onCreate(savedInstanceState);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
The plugin declares `REQUEST_INSTALL_PACKAGES` permission in its `AndroidManifest.xml`.
|
|
33
|
-
|
|
34
|
-
## API
|
|
35
|
-
|
|
36
|
-
### `AutoUpdate`
|
|
37
|
-
|
|
38
|
-
Abstract utility class that orchestrates the full update flow: version check, download, permission handling, and APK installation.
|
|
39
|
-
|
|
40
|
-
#### `AutoUpdate.runAsync(opt)`
|
|
41
|
-
|
|
42
|
-
Performs a server-based auto-update. Connects to the server via `SdServiceClient`, compares the current app version (`process.env["SD_VERSION"]`) against the server's latest version, downloads the APK if outdated, and triggers installation.
|
|
24
|
+
App version information returned by `ApkInstaller.getVersionInfo()`.
|
|
43
25
|
|
|
44
26
|
```typescript
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
serviceClient: sdServiceClient,
|
|
50
|
-
});
|
|
27
|
+
export interface IVersionInfo {
|
|
28
|
+
versionName: string;
|
|
29
|
+
versionCode: string;
|
|
30
|
+
}
|
|
51
31
|
```
|
|
52
32
|
|
|
53
|
-
|
|
|
54
|
-
|
|
55
|
-
| `
|
|
56
|
-
| `
|
|
33
|
+
| Field | Type | Description |
|
|
34
|
+
|-------|------|-------------|
|
|
35
|
+
| `versionName` | `string` | Human-readable version name (e.g. `"1.2.3"`) |
|
|
36
|
+
| `versionCode` | `string` | Numeric version code used by Android |
|
|
57
37
|
|
|
58
|
-
|
|
38
|
+
### `IApkInstallerPlugin`
|
|
59
39
|
|
|
60
|
-
|
|
40
|
+
Low-level Capacitor plugin interface. Use `ApkInstaller` instead for a simplified API.
|
|
61
41
|
|
|
62
42
|
```typescript
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
43
|
+
export interface IApkInstallerPlugin {
|
|
44
|
+
install(options: { uri: string }): Promise<void>;
|
|
45
|
+
hasPermission(): Promise<{ granted: boolean }>;
|
|
46
|
+
requestPermission(): Promise<void>;
|
|
47
|
+
hasPermissionManifest(): Promise<{ declared: boolean }>;
|
|
48
|
+
getVersionInfo(): Promise<IVersionInfo>;
|
|
49
|
+
}
|
|
69
50
|
```
|
|
70
51
|
|
|
71
|
-
|
|
|
72
|
-
|
|
73
|
-
| `
|
|
74
|
-
| `
|
|
52
|
+
| Method | Parameters | Returns | Description |
|
|
53
|
+
|--------|------------|---------|-------------|
|
|
54
|
+
| `install` | `options: { uri: string }` | `Promise<void>` | Install an APK from a content:// URI |
|
|
55
|
+
| `hasPermission` | -- | `Promise<{ granted: boolean }>` | Check if install permission is granted |
|
|
56
|
+
| `requestPermission` | -- | `Promise<void>` | Request install permission (opens settings) |
|
|
57
|
+
| `hasPermissionManifest` | -- | `Promise<{ declared: boolean }>` | Check if permission is declared in manifest |
|
|
58
|
+
| `getVersionInfo` | -- | `Promise<IVersionInfo>` | Get current app version info |
|
|
75
59
|
|
|
76
60
|
### `ApkInstaller`
|
|
77
61
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
#### `ApkInstaller.hasPermissionManifest()`
|
|
62
|
+
Abstract class with static methods for APK installation and permission management.
|
|
81
63
|
|
|
82
|
-
|
|
64
|
+
- **Android**: Executes APK install intents, manages `REQUEST_INSTALL_PACKAGES` permission
|
|
65
|
+
- **Browser**: Shows alert and returns normally
|
|
83
66
|
|
|
84
67
|
```typescript
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
```typescript
|
|
93
|
-
const granted: boolean = await ApkInstaller.hasPermission();
|
|
68
|
+
export abstract class ApkInstaller {
|
|
69
|
+
static async hasPermissionManifest(): Promise<boolean>;
|
|
70
|
+
static async hasPermission(): Promise<boolean>;
|
|
71
|
+
static async requestPermission(): Promise<void>;
|
|
72
|
+
static async install(apkUri: string): Promise<void>;
|
|
73
|
+
static async getVersionInfo(): Promise<IVersionInfo>;
|
|
74
|
+
}
|
|
94
75
|
```
|
|
95
76
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
77
|
+
| Method | Parameters | Returns | Description |
|
|
78
|
+
|--------|------------|---------|-------------|
|
|
79
|
+
| `hasPermissionManifest` | -- | `Promise<boolean>` | Check if `REQUEST_INSTALL_PACKAGES` is declared in the AndroidManifest |
|
|
80
|
+
| `hasPermission` | -- | `Promise<boolean>` | Check if install packages permission is currently granted |
|
|
81
|
+
| `requestPermission` | -- | `Promise<void>` | Request install permission (navigates to settings screen) |
|
|
82
|
+
| `install` | `apkUri: string` | `Promise<void>` | Install an APK from a `content://` URI (FileProvider URI) |
|
|
83
|
+
| `getVersionInfo` | -- | `Promise<IVersionInfo>` | Retrieve the current app version name and code |
|
|
103
84
|
|
|
104
|
-
|
|
85
|
+
### `AutoUpdate`
|
|
105
86
|
|
|
106
|
-
|
|
87
|
+
Abstract class providing a complete OTA auto-update flow. Supports two modes: server-based update via `SdServiceClient` and external-storage-based update from APK files on the device.
|
|
107
88
|
|
|
108
89
|
```typescript
|
|
109
|
-
|
|
90
|
+
export abstract class AutoUpdate {
|
|
91
|
+
static async runAsync(opt: {
|
|
92
|
+
log: (messageHtml: string) => void;
|
|
93
|
+
serviceClient: SdServiceClient;
|
|
94
|
+
}): Promise<void>;
|
|
95
|
+
|
|
96
|
+
static async runByExternalStorageAsync(opt: {
|
|
97
|
+
log: (messageHtml: string) => void;
|
|
98
|
+
dirPath: string;
|
|
99
|
+
}): Promise<void>;
|
|
100
|
+
}
|
|
110
101
|
```
|
|
111
102
|
|
|
112
|
-
|
|
|
113
|
-
|
|
114
|
-
| `
|
|
103
|
+
| Method | Parameters | Returns | Description |
|
|
104
|
+
|--------|------------|---------|-------------|
|
|
105
|
+
| `runAsync` | `opt: { log, serviceClient }` | `Promise<void>` | Run OTA update: check server version via `SdServiceClient`, download APK, and install |
|
|
106
|
+
| `runByExternalStorageAsync` | `opt: { log, dirPath }` | `Promise<void>` | Run update from external storage: scan `dirPath` for APK files, find latest version via semver, and install |
|
|
115
107
|
|
|
116
|
-
|
|
108
|
+
## Usage Examples
|
|
117
109
|
|
|
118
|
-
|
|
110
|
+
### Check permission and install an APK
|
|
119
111
|
|
|
120
112
|
```typescript
|
|
121
|
-
|
|
122
|
-
// info.versionName - e.g., "1.2.3"
|
|
123
|
-
// info.versionCode - e.g., "10"
|
|
124
|
-
```
|
|
113
|
+
import { ApkInstaller } from "@simplysm/capacitor-plugin-auto-update";
|
|
125
114
|
|
|
126
|
-
|
|
115
|
+
// Check if install permission is granted
|
|
116
|
+
const hasPermission = await ApkInstaller.hasPermission();
|
|
117
|
+
if (!hasPermission) {
|
|
118
|
+
await ApkInstaller.requestPermission();
|
|
119
|
+
}
|
|
127
120
|
|
|
128
|
-
|
|
121
|
+
// Install APK from a content:// URI
|
|
122
|
+
await ApkInstaller.install("content://com.example.fileprovider/apk/update.apk");
|
|
129
123
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
versionCode: string;
|
|
134
|
-
}
|
|
124
|
+
// Get current app version
|
|
125
|
+
const versionInfo = await ApkInstaller.getVersionInfo();
|
|
126
|
+
console.log(versionInfo.versionName, versionInfo.versionCode);
|
|
135
127
|
```
|
|
136
128
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
Low-level Capacitor plugin interface. Use `ApkInstaller` static methods instead of calling this directly.
|
|
129
|
+
### Run OTA auto-update from server
|
|
140
130
|
|
|
141
131
|
```typescript
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
hasPermission(): Promise<{ granted: boolean }>;
|
|
145
|
-
requestPermission(): Promise<void>;
|
|
146
|
-
hasPermissionManifest(): Promise<{ declared: boolean }>;
|
|
147
|
-
getVersionInfo(): Promise<IVersionInfo>;
|
|
148
|
-
}
|
|
149
|
-
```
|
|
132
|
+
import { AutoUpdate } from "@simplysm/capacitor-plugin-auto-update";
|
|
133
|
+
import { SdServiceClient } from "@simplysm/sd-service-client";
|
|
150
134
|
|
|
151
|
-
|
|
135
|
+
const serviceClient = new SdServiceClient("https://my-server.com");
|
|
152
136
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
137
|
+
await AutoUpdate.runAsync({
|
|
138
|
+
log: (messageHtml) => {
|
|
139
|
+
document.getElementById("status")!.innerHTML = messageHtml;
|
|
140
|
+
},
|
|
141
|
+
serviceClient,
|
|
142
|
+
});
|
|
143
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplysm/capacitor-plugin-auto-update",
|
|
3
|
-
"version": "12.16.
|
|
3
|
+
"version": "12.16.36",
|
|
4
4
|
"description": "심플리즘 패키지 - Capacitor Plugin Auto Update",
|
|
5
5
|
"author": "김석래",
|
|
6
6
|
"repository": {
|
|
@@ -18,18 +18,18 @@
|
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@simplysm/sd-core-common": "12.16.
|
|
22
|
-
"@simplysm/sd-service-client": "12.16.
|
|
23
|
-
"@simplysm/sd-service-common": "12.16.
|
|
21
|
+
"@simplysm/sd-core-common": "12.16.36",
|
|
22
|
+
"@simplysm/sd-service-client": "12.16.36",
|
|
23
|
+
"@simplysm/sd-service-common": "12.16.36",
|
|
24
24
|
"semver": "^7.7.4"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@capacitor/core": "^7.
|
|
28
|
-
"@simplysm/capacitor-plugin-file-system": "12.16.
|
|
27
|
+
"@capacitor/core": "^7.6.0",
|
|
28
|
+
"@simplysm/capacitor-plugin-file-system": "12.16.36",
|
|
29
29
|
"@types/semver": "^7.7.1"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"@capacitor/core": "^7.0.0",
|
|
33
|
-
"@simplysm/capacitor-plugin-file-system": "12.16.
|
|
33
|
+
"@simplysm/capacitor-plugin-file-system": "12.16.36"
|
|
34
34
|
}
|
|
35
35
|
}
|