@simplysm/capacitor-plugin-auto-update 12.16.31 → 12.16.35

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.
Files changed (2) hide show
  1. package/README.md +93 -107
  2. package/package.json +7 -7
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @simplysm/capacitor-plugin-auto-update
2
2
 
3
- Capacitor 7 plugin for auto-updating Android apps via APK installation. Provides two update strategies: server-based updates through `SdServiceClient` and external storage-based updates from a local directory.
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
- ### Peer Dependencies
11
+ ## API Overview
12
12
 
13
- - `@capacitor/core` ^7.0.0
14
- - `@simplysm/capacitor-plugin-file-system`
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
- ### Android Setup
20
+ ## API Reference
17
21
 
18
- Register the plugin in your `MainActivity`:
22
+ ### `IVersionInfo`
19
23
 
20
- ```java
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
- await AutoUpdate.runAsync({
46
- log: (messageHtml: string) => {
47
- // Display progress/status HTML to the user
48
- },
49
- serviceClient: sdServiceClient,
50
- });
27
+ export interface IVersionInfo {
28
+ versionName: string;
29
+ versionCode: string;
30
+ }
51
31
  ```
52
32
 
53
- | Parameter | Type | Description |
54
- |---|---|---|
55
- | `opt.log` | `(messageHtml: string) => void` | Callback to display status messages (may contain HTML) |
56
- | `opt.serviceClient` | `SdServiceClient` | Connected service client instance. The server must implement `ISdAutoUpdateService`. |
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
- #### `AutoUpdate.runByExternalStorageAsync(opt)`
38
+ ### `IApkInstallerPlugin`
59
39
 
60
- Performs an update from APK files stored in external storage. Scans the specified directory for APK files named by semver version (e.g., `1.2.3.apk`), selects the highest version, and installs it if newer than the current version.
40
+ Low-level Capacitor plugin interface. Use `ApkInstaller` instead for a simplified API.
61
41
 
62
42
  ```typescript
63
- await AutoUpdate.runByExternalStorageAsync({
64
- log: (messageHtml: string) => {
65
- // Display progress/status HTML to the user
66
- },
67
- dirPath: "MyApp/updates",
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
- | Parameter | Type | Description |
72
- |---|---|---|
73
- | `opt.log` | `(messageHtml: string) => void` | Callback to display status messages (may contain HTML) |
74
- | `opt.dirPath` | `string` | Relative path within external storage containing versioned APK files |
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
- Low-level static API wrapping the native Capacitor plugin for APK installation and permission management. On web, all methods resolve with no-op behavior.
79
-
80
- #### `ApkInstaller.hasPermissionManifest()`
62
+ Abstract class with static methods for APK installation and permission management.
81
63
 
82
- Checks whether `REQUEST_INSTALL_PACKAGES` is declared in the app's `AndroidManifest.xml`.
64
+ - **Android**: Executes APK install intents, manages `REQUEST_INSTALL_PACKAGES` permission
65
+ - **Browser**: Shows alert and returns normally
83
66
 
84
67
  ```typescript
85
- const declared: boolean = await ApkInstaller.hasPermissionManifest();
86
- ```
87
-
88
- #### `ApkInstaller.hasPermission()`
89
-
90
- Checks whether the app currently has permission to install unknown apps (Android 8.0+). Returns `true` on older versions.
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
- #### `ApkInstaller.requestPermission()`
97
-
98
- Opens the system settings screen for managing unknown app install sources (Android 8.0+).
99
-
100
- ```typescript
101
- await ApkInstaller.requestPermission();
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
- #### `ApkInstaller.install(apkUri)`
85
+ ### `AutoUpdate`
105
86
 
106
- Triggers APK installation via `ACTION_VIEW` intent.
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
- await ApkInstaller.install(apkUri);
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
- | Parameter | Type | Description |
113
- |---|---|---|
114
- | `apkUri` | `string` | `content://` URI of the APK file (FileProvider URI) |
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
- #### `ApkInstaller.getVersionInfo()`
108
+ ## Usage Examples
117
109
 
118
- Returns the current app's version name and version code.
110
+ ### Check permission and install an APK
119
111
 
120
112
  ```typescript
121
- const info: IVersionInfo = await ApkInstaller.getVersionInfo();
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
- ### Interfaces
115
+ // Check if install permission is granted
116
+ const hasPermission = await ApkInstaller.hasPermission();
117
+ if (!hasPermission) {
118
+ await ApkInstaller.requestPermission();
119
+ }
127
120
 
128
- #### `IVersionInfo`
121
+ // Install APK from a content:// URI
122
+ await ApkInstaller.install("content://com.example.fileprovider/apk/update.apk");
129
123
 
130
- ```typescript
131
- interface IVersionInfo {
132
- versionName: string;
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
- #### `IApkInstallerPlugin`
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
- interface IApkInstallerPlugin {
143
- install(options: { uri: string }): Promise<void>;
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
- ## Platform Support
135
+ const serviceClient = new SdServiceClient("https://my-server.com");
152
136
 
153
- | Platform | Behavior |
154
- |---|---|
155
- | Android | Full APK installation with permission management |
156
- | Web | No-op stubs (permission checks return `true`, install shows an alert) |
157
- | iOS | Not supported |
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.31",
3
+ "version": "12.16.35",
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.31",
22
- "@simplysm/sd-service-client": "12.16.31",
23
- "@simplysm/sd-service-common": "12.16.31",
21
+ "@simplysm/sd-core-common": "12.16.35",
22
+ "@simplysm/sd-service-client": "12.16.35",
23
+ "@simplysm/sd-service-common": "12.16.35",
24
24
  "semver": "^7.7.4"
25
25
  },
26
26
  "devDependencies": {
27
- "@capacitor/core": "^7.5.0",
28
- "@simplysm/capacitor-plugin-file-system": "12.16.31",
27
+ "@capacitor/core": "^7.6.0",
28
+ "@simplysm/capacitor-plugin-file-system": "12.16.35",
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.31"
33
+ "@simplysm/capacitor-plugin-file-system": "12.16.35"
34
34
  }
35
35
  }