@simplysm/capacitor-plugin-auto-update 14.0.46 → 14.0.48

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 +182 -0
  2. package/package.json +7 -7
package/README.md ADDED
@@ -0,0 +1,182 @@
1
+ # @simplysm/capacitor-plugin-auto-update
2
+
3
+ 심플리즘 패키지 - Capacitor 자동 업데이트 플러그인. 서버 버전 비교 후 APK 다운로드·설치를 처리하며, 외부 저장소(USB 등)에서도 업데이트할 수 있다.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @simplysm/capacitor-plugin-auto-update
9
+ ```
10
+
11
+ 피어 의존성으로 `@capacitor/core ^7`이 필요하다. Android 네이티브 플러그인이 포함되어 있으므로 `npx cap sync` 후 사용한다.
12
+
13
+ ## API Overview
14
+
15
+ ### APK 설치
16
+
17
+ | API | Type | Description |
18
+ |-----|------|-------------|
19
+ | `VersionInfo` | interface | 앱 버전 정보 (versionName, versionCode) |
20
+ | `ApkInstallerPlugin` | interface | Capacitor 네이티브 플러그인 인터페이스 (직접 사용하지 않음) |
21
+ | `ApkInstaller` | abstract class | APK 설치 플러그인 정적 파사드 — 권한 확인/요청, 설치, 버전 조회 |
22
+
23
+ ### 자동 업데이트
24
+
25
+ | API | Type | Description |
26
+ |-----|------|-------------|
27
+ | `AutoUpdate` | abstract class | 자동 업데이트 오케스트레이터 — 서버 또는 외부 저장소에서 최신 APK를 확인하고 설치 |
28
+
29
+ ---
30
+
31
+ ## `VersionInfo`
32
+
33
+ 앱 버전 정보를 나타내는 인터페이스.
34
+
35
+ ```typescript
36
+ export interface VersionInfo {
37
+ versionName: string;
38
+ versionCode: string;
39
+ }
40
+ ```
41
+
42
+ | Field | Type | Description |
43
+ |-------|------|-------------|
44
+ | `versionName` | `string` | 앱 버전 이름. semver 형식 (예: `"1.2.3"`). `AutoUpdate`의 버전 비교에 사용된다. |
45
+ | `versionCode` | `string` | 앱 버전 코드. 정수를 문자열로 표현 (예: `"42"`). |
46
+
47
+ ## `ApkInstallerPlugin`
48
+
49
+ Capacitor 네이티브 플러그인 인터페이스. 직접 사용하지 않고 `ApkInstaller` 파사드를 통해 접근한다. 타입 참조 목적으로만 export된다.
50
+
51
+ ```typescript
52
+ export interface ApkInstallerPlugin {
53
+ install(options: { uri: string }): Promise<void>;
54
+ checkPermissions(): Promise<{ granted: boolean; manifest: boolean }>;
55
+ requestPermissions(): Promise<void>;
56
+ getVersionInfo(): Promise<VersionInfo>;
57
+ }
58
+ ```
59
+
60
+ | Method | Return | Description |
61
+ |--------|--------|-------------|
62
+ | `install(options: { uri: string })` | `Promise<void>` | `content://` URI(FileProvider URI)로 APK 설치 인텐트 실행 |
63
+ | `checkPermissions()` | `Promise<{ granted: boolean; manifest: boolean }>` | 설치 권한 승인 여부(`granted`)와 AndroidManifest 선언 여부(`manifest`) 동시 확인 |
64
+ | `requestPermissions()` | `Promise<void>` | `REQUEST_INSTALL_PACKAGES` 권한 요청 — 시스템 설정 화면으로 이동 |
65
+ | `getVersionInfo()` | `Promise<VersionInfo>` | PackageManager에서 현재 앱 버전 정보 조회 |
66
+
67
+ ## `ApkInstaller`
68
+
69
+ APK 설치 플러그인 정적 파사드 클래스. Android에서는 네이티브 플러그인을 실행하고, 브라우저 환경에서는 `ApkInstallerWeb`으로 폴백한다. 브라우저 폴백: `install()`은 `alert()` 표시 후 반환, `checkPermissions()`는 항상 `{ granted: true, manifest: true }` 반환, `requestPermissions()`는 무동작, `getVersionInfo()`는 `env("__VER__") ?? "0.0.0"`을 `versionName`으로 반환.
70
+
71
+ ```typescript
72
+ export abstract class ApkInstaller {
73
+ static async checkPermissions(): Promise<{ granted: boolean; manifest: boolean }>;
74
+ static async requestPermissions(): Promise<void>;
75
+ static async install(apkUri: string): Promise<void>;
76
+ static async getVersionInfo(): Promise<VersionInfo>;
77
+ }
78
+ ```
79
+
80
+ | Method | Parameters | Return | Description |
81
+ |--------|-----------|--------|-------------|
82
+ | `checkPermissions` | 없음 | `Promise<{ granted: boolean; manifest: boolean }>` | 설치 권한 승인 여부와 AndroidManifest 선언 여부 확인. `manifest: false`이면 APK를 재설치해야 한다. |
83
+ | `requestPermissions` | 없음 | `Promise<void>` | `REQUEST_INSTALL_PACKAGES` 권한 요청. 시스템 설정 화면으로 이동하므로 이후 `checkPermissions`로 결과를 폴링해야 한다. |
84
+ | `install` | `apkUri: string` | `Promise<void>` | `content://` URI(FileProvider URI)로 APK 설치. `FileSystem.getUri(filePath)`로 URI를 얻는다. |
85
+ | `getVersionInfo` | 없음 | `Promise<VersionInfo>` | 현재 설치된 앱의 버전 정보 조회. 브라우저 환경에서는 `env("__VER__") ?? "0.0.0"`을 `versionName`으로 반환한다. |
86
+
87
+ ## `AutoUpdate`
88
+
89
+ 자동 업데이트 오케스트레이터. 서버 또는 외부 저장소에서 최신 APK를 확인하고 설치한다. 모든 메서드가 `static`이며 인스턴스화하지 않는다. Android 환경 전용이며, 비-Android에서 호출하면 에러를 표시하고 앱을 무한 대기 상태로 전환한다.
90
+
91
+ ```typescript
92
+ export abstract class AutoUpdate {
93
+ static async run(opt: {
94
+ log: (messageHtml: string) => void;
95
+ serviceClient: ServiceClient;
96
+ }): Promise<void>;
97
+
98
+ static async runByExternalStorage(opt: {
99
+ log: (messageHtml: string) => void;
100
+ dirPath: string;
101
+ }): Promise<void>;
102
+ }
103
+ ```
104
+
105
+ | Method | Parameters | Description |
106
+ |--------|-----------|-------------|
107
+ | `run` | `opt.log: (messageHtml: string) => void`, `opt.serviceClient: ServiceClient` | `AutoUpdateService.getLastVersion("android")`로 서버에서 최신 버전 정보를 조회한 뒤, 현재 버전보다 높으면 APK를 다운로드하여 설치한다. 업데이트 후 `_freezeApp()`으로 앱을 무한 대기 상태로 전환한다. |
108
+ | `runByExternalStorage` | `opt.log: (messageHtml: string) => void`, `opt.dirPath: string` | 외부 저장소의 `opt.dirPath` 디렉토리에서 `{semver}.apk` 패턴 파일 중 최신 버전을 찾아 설치한다. 현재 버전보다 높은 경우에만 업데이트한다. |
109
+
110
+ **`opt.log` 콜백**: HTML 문자열을 받아 사용자에게 진행 상황을 표시한다. 버튼(`<button>`) 등 인터랙티브 HTML이 포함될 수 있다. 에러 발생 시에도 `log`로 에러 메시지를 표시한 뒤 `_freezeApp()`으로 전환한다.
111
+
112
+ **권한 처리**: 두 메서드 모두 내부적으로 `_checkPermission()`을 호출한다. `manifest: false`이면 재설치 에러를 throw하고, `granted: false`이면 권한 요청 후 최대 300초간 폴링한다.
113
+
114
+ **버전 비교**: `semver` 라이브러리를 사용한다. `versionName`이 유효한 semver 형식이 아니면 업데이트 확인을 건너뛴다.
115
+
116
+ ## Usage Examples
117
+
118
+ ### 서버 기반 자동 업데이트
119
+
120
+ 앱 부트스트랩 시 `AutoUpdate.run()`을 호출한다. `AutoUpdateService`는 `@simplysm/service-common`의 서비스 인터페이스다.
121
+
122
+ ```typescript
123
+ import { AutoUpdate } from "@simplysm/capacitor-plugin-auto-update";
124
+ import type { ServiceClient } from "@simplysm/service-client";
125
+
126
+ async function checkForUpdate(serviceClient: ServiceClient) {
127
+ const statusEl = document.getElementById("status")!;
128
+
129
+ await AutoUpdate.run({
130
+ log: (messageHtml) => {
131
+ statusEl.innerHTML = messageHtml;
132
+ },
133
+ serviceClient,
134
+ });
135
+
136
+ // 업데이트가 없거나 업데이트가 완료되면(무한 대기 전환 전) 이 줄에 도달한다.
137
+ statusEl.innerHTML = "";
138
+ }
139
+ ```
140
+
141
+ ### 외부 저장소(USB) 기반 업데이트
142
+
143
+ `opt.dirPath`는 외부 저장소 루트 기준 상대 경로다. 해당 경로에 `1.2.3.apk` 형식 파일이 있어야 한다.
144
+
145
+ ```typescript
146
+ import { AutoUpdate } from "@simplysm/capacitor-plugin-auto-update";
147
+
148
+ await AutoUpdate.runByExternalStorage({
149
+ log: (messageHtml) => {
150
+ document.getElementById("status")!.innerHTML = messageHtml;
151
+ },
152
+ dirPath: "updates/my-app",
153
+ });
154
+ ```
155
+
156
+ ### APK 설치 직접 제어
157
+
158
+ `AutoUpdate`를 사용하지 않고 `ApkInstaller`를 직접 제어하는 경우:
159
+
160
+ ```typescript
161
+ import { ApkInstaller } from "@simplysm/capacitor-plugin-auto-update";
162
+ import { FileSystem } from "@simplysm/capacitor-plugin-file-system";
163
+
164
+ // 권한 확인
165
+ const { granted, manifest } = await ApkInstaller.checkPermissions();
166
+ if (!manifest) {
167
+ // AndroidManifest.xml에 REQUEST_INSTALL_PACKAGES 미선언 → APK 재설치 필요
168
+ throw new Error("앱을 재설치해야 합니다.");
169
+ }
170
+ if (!granted) {
171
+ await ApkInstaller.requestPermissions();
172
+ }
173
+
174
+ // 현재 버전 확인
175
+ const versionInfo = await ApkInstaller.getVersionInfo();
176
+ // versionInfo.versionName → "1.2.3"
177
+ // versionInfo.versionCode → "42"
178
+
179
+ // APK 설치 (filePath는 FileSystem으로 저장한 경로)
180
+ const apkUri = await FileSystem.getUri("/path/to/latest.apk");
181
+ await ApkInstaller.install(apkUri);
182
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplysm/capacitor-plugin-auto-update",
3
- "version": "14.0.46",
3
+ "version": "14.0.48",
4
4
  "description": "심플리즘 패키지 - Capacitor 자동 업데이트 플러그인",
5
5
  "author": "심플리즘",
6
6
  "license": "Apache-2.0",
@@ -19,14 +19,14 @@
19
19
  ],
20
20
  "dependencies": {
21
21
  "semver": "^7.7.4",
22
- "@simplysm/capacitor-plugin-file-system": "14.0.46",
23
- "@simplysm/core-browser": "14.0.46",
24
- "@simplysm/core-common": "14.0.46",
25
- "@simplysm/service-client": "14.0.46",
26
- "@simplysm/service-common": "14.0.46"
22
+ "@simplysm/capacitor-plugin-file-system": "14.0.48",
23
+ "@simplysm/core-browser": "14.0.48",
24
+ "@simplysm/service-client": "14.0.48",
25
+ "@simplysm/core-common": "14.0.48",
26
+ "@simplysm/service-common": "14.0.48"
27
27
  },
28
28
  "devDependencies": {
29
- "@capacitor/core": "^7.6.1",
29
+ "@capacitor/core": "^7.6.2",
30
30
  "@types/semver": "^7.7.1"
31
31
  },
32
32
  "peerDependencies": {