@capgo/capacitor-updater 3.0.3

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 ADDED
@@ -0,0 +1,456 @@
1
+ # capacitor-updater
2
+
3
+ Update capacitor app withtout store review.
4
+
5
+ You have 3 ways possible :
6
+ - use [capgo.app](https://capgo.app) a full featured auto update system in 5 min Setup, to manage version, update, revert and see stats.
7
+ - use your own server update with auto update system
8
+ - use manual methods to zip, upload, download, from JS to do it when you want.
9
+
10
+
11
+ ## Community
12
+ Join the [discord](https://discord.gg/VnYRvBfgA6) to get help.
13
+
14
+ ## Documentation
15
+ I maintain a more user friendly and complete [documentation](https://github.com/Cap-go/capacitor-updater/wiki) in GitHub wiki.
16
+
17
+ ## install plugin
18
+
19
+ ```bash
20
+ npm install capacitor-updater
21
+ npx cap sync
22
+ ```
23
+
24
+ ## Auto update setup
25
+
26
+ Create account in [capgo.app](https://capgo.app) and get your [API key](https://capgo.app/app/apikeys)
27
+ - Download the CLI `npm i -g capgo`
28
+ - Add app from CLI `capgo add -a API_KEY`
29
+ - Upload app `capgo upload -a API_KEY`
30
+ - Upload app `capgo set -a API_KEY -s public`
31
+ - Edit your `capacitor.config.json` like below, set `autoUpdate` to true.
32
+ ```json
33
+ // capacitor.config.json
34
+ {
35
+ "appId": "**.***.**",
36
+ "appName": "Name",
37
+ "plugins": {
38
+ "CapacitorUpdater": {
39
+ "autoUpdate": true,
40
+ }
41
+ }
42
+ }
43
+ ```
44
+ - Add to your main code
45
+ ```javascript
46
+ import { CapacitorUpdater } from 'capacitor-updater'
47
+ CapacitorUpdater.notifyAppReady()
48
+ // To let auto update know you app boot well.
49
+ ```
50
+
51
+ - Do `npm run build && npx cap copy` to copy the build to capacitor.
52
+ - Run the app and see app auto update after each backgrounding.
53
+ - If update fail it will roolback to previous version.
54
+
55
+ See more there in the [Auto update](
56
+ https://doc.capgo.app/Auto-update-2cf9edda70484d7fa57111ab9c435d08) documentation.
57
+
58
+
59
+ ## Manual setup
60
+
61
+ Download app update from url when user enter the app
62
+ install it when user background the app.
63
+
64
+ In your main code :
65
+
66
+ ```javascript
67
+ import { CapacitorUpdater } from 'capacitor-updater'
68
+ import { SplashScreen } from '@capacitor/splash-screen'
69
+ import { App } from '@capacitor/app'
70
+
71
+ let version = ""
72
+ App.addListener('appStateChange', async(state) => {
73
+ if (state.isActive) {
74
+ // Do the download during user active app time to prevent failed download
75
+ version = await CapacitorUpdater.download({
76
+ url: 'https://github.com/Cap-go/demo-app/releases/download/0.0.4/dist.zip',
77
+ })
78
+ }
79
+ if (!state.isActive && version !== "") {
80
+ // Do the switch when user leave app
81
+ SplashScreen.show()
82
+ try {
83
+ await CapacitorUpdater.set(version)
84
+ } catch () {
85
+ SplashScreen.hide() // in case the set fail, otherwise the new app will have to hide it
86
+ }
87
+ }
88
+ })
89
+
90
+ // or do it when click on button
91
+ const updateNow = async () => {
92
+ const version = await CapacitorUpdater.download({
93
+ url: 'https://github.com/Cap-go/demo-app/releases/download/0.0.4/dist.zip',
94
+ })
95
+ // show the splashscreen to let the update happen
96
+ SplashScreen.show()
97
+ await CapacitorUpdater.set(version)
98
+ SplashScreen.hide() // in case the set fail, otherwise the new app will have to hide it
99
+ }
100
+ ```
101
+
102
+ *Be extra carufull for your update* if you send a broken update, the app will crash until the user reinstalls it.
103
+
104
+ If you need more secure way to update your app, you can use Auto update system.
105
+
106
+ You can list the version and manage it with the command below.
107
+
108
+ ### Packaging `dist.zip`
109
+
110
+ Whatever you choose to name the file you download from your release/update server URL, the zip file should contain the full contents of your production Capacitor build output folder, usually `{project directory}/dist/` or `{project directory}/www/`. This is where `index.html` will be located, and it should also contain all bundled JavaScript, CSS, and web resources necessary for your app to run.
111
+
112
+ Do not password encrypt this file, or it will fail to unpack.
113
+
114
+ ## API
115
+
116
+ <docgen-index>
117
+
118
+ * [`download(...)`](#download)
119
+ * [`set(...)`](#set)
120
+ * [`getId()`](#getid)
121
+ * [`delete(...)`](#delete)
122
+ * [`list()`](#list)
123
+ * [`reset(...)`](#reset)
124
+ * [`current()`](#current)
125
+ * [`reload()`](#reload)
126
+ * [`versionName()`](#versionname)
127
+ * [`notifyAppReady()`](#notifyappready)
128
+ * [`delayUpdate()`](#delayupdate)
129
+ * [`cancelDelay()`](#canceldelay)
130
+ * [`addListener('download', ...)`](#addlistenerdownload)
131
+ * [`addListener('majorAvailable', ...)`](#addlistenermajoravailable)
132
+ * [`addListener('updateAvailable', ...)`](#addlistenerupdateavailable)
133
+ * [`addListener(string, ...)`](#addlistenerstring)
134
+ * [`removeAllListeners()`](#removealllisteners)
135
+ * [Interfaces](#interfaces)
136
+ * [Type Aliases](#type-aliases)
137
+
138
+ </docgen-index>
139
+
140
+ <docgen-api>
141
+ <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
142
+
143
+ ### download(...)
144
+
145
+ ```typescript
146
+ download(options: { url: string; }) => Promise<{ version: string; }>
147
+ ```
148
+
149
+ Download a new version from the provided URL, it should be a zip file, with files inside or with a unique folder inside with all your files
150
+
151
+ | Param | Type |
152
+ | ------------- | ----------------------------- |
153
+ | **`options`** | <code>{ url: string; }</code> |
154
+
155
+ **Returns:** <code>Promise&lt;{ version: string; }&gt;</code>
156
+
157
+ --------------------
158
+
159
+
160
+ ### set(...)
161
+
162
+ ```typescript
163
+ set(options: { version: string; versionName?: string; }) => Promise<void>
164
+ ```
165
+
166
+ Set version as current version, set will return an error if there are is no index.html file inside the version folder. `versionName` is optional and it's a custom value that will be saved for you
167
+
168
+ | Param | Type |
169
+ | ------------- | ------------------------------------------------------- |
170
+ | **`options`** | <code>{ version: string; versionName?: string; }</code> |
171
+
172
+ --------------------
173
+
174
+
175
+ ### getId()
176
+
177
+ ```typescript
178
+ getId() => Promise<{ id: string; }>
179
+ ```
180
+
181
+ Get unique ID used to identify device into auto update server
182
+
183
+ **Returns:** <code>Promise&lt;{ id: string; }&gt;</code>
184
+
185
+ --------------------
186
+
187
+
188
+ ### delete(...)
189
+
190
+ ```typescript
191
+ delete(options: { version: string; }) => Promise<void>
192
+ ```
193
+
194
+ Delete version in storage
195
+
196
+ | Param | Type |
197
+ | ------------- | --------------------------------- |
198
+ | **`options`** | <code>{ version: string; }</code> |
199
+
200
+ --------------------
201
+
202
+
203
+ ### list()
204
+
205
+ ```typescript
206
+ list() => Promise<{ versions: string[]; }>
207
+ ```
208
+
209
+ Get all available versions
210
+
211
+ **Returns:** <code>Promise&lt;{ versions: string[]; }&gt;</code>
212
+
213
+ --------------------
214
+
215
+
216
+ ### reset(...)
217
+
218
+ ```typescript
219
+ reset(options?: { toAutoUpdate?: boolean | undefined; } | undefined) => Promise<void>
220
+ ```
221
+
222
+ Set the `builtin` version (the one sent to Apple store / Google play store ) as current version
223
+
224
+ | Param | Type |
225
+ | ------------- | ---------------------------------------- |
226
+ | **`options`** | <code>{ toAutoUpdate?: boolean; }</code> |
227
+
228
+ --------------------
229
+
230
+
231
+ ### current()
232
+
233
+ ```typescript
234
+ current() => Promise<{ current: string; currentNative: string; }>
235
+ ```
236
+
237
+ Get the current version, if none are set it returns `builtin`, currentNative is the original version install on the device
238
+
239
+ **Returns:** <code>Promise&lt;{ current: string; currentNative: string; }&gt;</code>
240
+
241
+ --------------------
242
+
243
+
244
+ ### reload()
245
+
246
+ ```typescript
247
+ reload() => Promise<void>
248
+ ```
249
+
250
+ Reload the view
251
+
252
+ --------------------
253
+
254
+
255
+ ### versionName()
256
+
257
+ ```typescript
258
+ versionName() => Promise<{ versionName: string; }>
259
+ ```
260
+
261
+ Get the version name, if it was set during the set phase
262
+
263
+ **Returns:** <code>Promise&lt;{ versionName: string; }&gt;</code>
264
+
265
+ --------------------
266
+
267
+
268
+ ### notifyAppReady()
269
+
270
+ ```typescript
271
+ notifyAppReady() => Promise<void>
272
+ ```
273
+
274
+ Notify native plugin that the update is working, only in auto-update
275
+
276
+ --------------------
277
+
278
+
279
+ ### delayUpdate()
280
+
281
+ ```typescript
282
+ delayUpdate() => Promise<void>
283
+ ```
284
+
285
+ Skip updates in the next time the app goes into the background, only in auto-update
286
+
287
+ --------------------
288
+
289
+
290
+ ### cancelDelay()
291
+
292
+ ```typescript
293
+ cancelDelay() => Promise<void>
294
+ ```
295
+
296
+ allow update in the next time the app goes into the background, only in auto-update
297
+
298
+ --------------------
299
+
300
+
301
+ ### addListener('download', ...)
302
+
303
+ ```typescript
304
+ addListener(eventName: 'download', listenerFunc: DownloadChangeListener) => Promise<PluginListenerHandle> & PluginListenerHandle
305
+ ```
306
+
307
+ Listen for download event in the App, let you know when the download is started, loading and finished
308
+
309
+ | Param | Type |
310
+ | ------------------ | ------------------------------------------------------------------------- |
311
+ | **`eventName`** | <code>'download'</code> |
312
+ | **`listenerFunc`** | <code><a href="#downloadchangelistener">DownloadChangeListener</a></code> |
313
+
314
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt; & <a href="#pluginlistenerhandle">PluginListenerHandle</a></code>
315
+
316
+ **Since:** 2.0.11
317
+
318
+ --------------------
319
+
320
+
321
+ ### addListener('majorAvailable', ...)
322
+
323
+ ```typescript
324
+ addListener(eventName: 'majorAvailable', listenerFunc: MajorAvailableListener) => Promise<PluginListenerHandle> & PluginListenerHandle
325
+ ```
326
+
327
+ Listen for Major update event in the App, let you know when major update is blocked by setting disableAutoUpdateBreaking
328
+
329
+ | Param | Type |
330
+ | ------------------ | ------------------------------------------------------------------------- |
331
+ | **`eventName`** | <code>'majorAvailable'</code> |
332
+ | **`listenerFunc`** | <code><a href="#majoravailablelistener">MajorAvailableListener</a></code> |
333
+
334
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt; & <a href="#pluginlistenerhandle">PluginListenerHandle</a></code>
335
+
336
+ **Since:** 2.3.0
337
+
338
+ --------------------
339
+
340
+
341
+ ### addListener('updateAvailable', ...)
342
+
343
+ ```typescript
344
+ addListener(eventName: 'updateAvailable', listenerFunc: UpdateAvailableListener) => Promise<PluginListenerHandle> & PluginListenerHandle
345
+ ```
346
+
347
+ Listen for update event in the App, let you know when update is ready to install at next app start
348
+
349
+ | Param | Type |
350
+ | ------------------ | --------------------------------------------------------------------------- |
351
+ | **`eventName`** | <code>'updateAvailable'</code> |
352
+ | **`listenerFunc`** | <code><a href="#updateavailablelistener">UpdateAvailableListener</a></code> |
353
+
354
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt; & <a href="#pluginlistenerhandle">PluginListenerHandle</a></code>
355
+
356
+ **Since:** 2.3.0
357
+
358
+ --------------------
359
+
360
+
361
+ ### addListener(string, ...)
362
+
363
+ ```typescript
364
+ addListener(eventName: string, listenerFunc: (...args: any[]) => any) => Promise<PluginListenerHandle>
365
+ ```
366
+
367
+ | Param | Type |
368
+ | ------------------ | --------------------------------------- |
369
+ | **`eventName`** | <code>string</code> |
370
+ | **`listenerFunc`** | <code>(...args: any[]) =&gt; any</code> |
371
+
372
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
373
+
374
+ --------------------
375
+
376
+
377
+ ### removeAllListeners()
378
+
379
+ ```typescript
380
+ removeAllListeners() => Promise<void>
381
+ ```
382
+
383
+ --------------------
384
+
385
+
386
+ ### Interfaces
387
+
388
+
389
+ #### PluginListenerHandle
390
+
391
+ | Prop | Type |
392
+ | ------------ | ----------------------------------------- |
393
+ | **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |
394
+
395
+
396
+ #### DownloadEvent
397
+
398
+ | Prop | Type | Description | Since |
399
+ | ------------- | ------------------- | ---------------------------------------------- | ------ |
400
+ | **`percent`** | <code>number</code> | Current status of download, between 0 and 100. | 2.0.11 |
401
+
402
+
403
+ #### MajorAvailableEvent
404
+
405
+ | Prop | Type | Description | Since |
406
+ | ------------- | ------------------- | ------------------------------------------- | ----- |
407
+ | **`version`** | <code>string</code> | Emit when a new major version is available. | 2.3.0 |
408
+
409
+
410
+ #### UpdateAvailableEvent
411
+
412
+ | Prop | Type | Description | Since |
413
+ | ------------- | ------------------- | ------------------------------------ | ----- |
414
+ | **`version`** | <code>string</code> | Emit when a new update is available. | 3.0.0 |
415
+
416
+
417
+ ### Type Aliases
418
+
419
+
420
+ #### DownloadChangeListener
421
+
422
+ <code>(state: <a href="#downloadevent">DownloadEvent</a>): void</code>
423
+
424
+
425
+ #### MajorAvailableListener
426
+
427
+ <code>(state: <a href="#majoravailableevent">MajorAvailableEvent</a>): void</code>
428
+
429
+
430
+ #### UpdateAvailableListener
431
+
432
+ <code>(state: <a href="#updateavailableevent">UpdateAvailableEvent</a>): void</code>
433
+
434
+ </docgen-api>
435
+
436
+ ### Listen to download events
437
+
438
+ ```javascript
439
+ import { CapacitorUpdater } from 'capacitor-updater';
440
+
441
+ CapacitorUpdater.addListener('download', (info: any) => {
442
+ console.log('download was fired', info.percent);
443
+ });
444
+ ```
445
+
446
+ On iOS, Apple don't allow you to show a message when the app is updated, so you can't show a progress bar.
447
+
448
+ ### Inspiration
449
+
450
+ - [cordova-plugin-ionic](https://github.com/ionic-team/cordova-plugin-ionic)
451
+ - [capacitor-codepush](https://github.dev/mapiacompany/capacitor-codepush)
452
+
453
+
454
+ ### Contributors
455
+
456
+ [jamesyoung1337](https://github.com/jamesyoung1337) Thanks a lot for your guidance and support, it was impossible to make this plugin work without you.
@@ -0,0 +1,60 @@
1
+ ext {
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.1'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.2.0'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.2'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.3.0'
6
+ }
7
+
8
+ buildscript {
9
+ repositories {
10
+ google()
11
+ jcenter()
12
+ }
13
+ dependencies {
14
+ classpath 'com.android.tools.build:gradle:4.2.1'
15
+ }
16
+ }
17
+
18
+ apply plugin: 'com.android.library'
19
+
20
+ android {
21
+ compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 30
22
+ defaultConfig {
23
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 21
24
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 30
25
+ versionCode 1
26
+ versionName "1.0"
27
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
28
+ }
29
+ buildTypes {
30
+ release {
31
+ minifyEnabled false
32
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
33
+ }
34
+ }
35
+ lintOptions {
36
+ abortOnError false
37
+ }
38
+ compileOptions {
39
+ sourceCompatibility JavaVersion.VERSION_1_8
40
+ targetCompatibility JavaVersion.VERSION_1_8
41
+ }
42
+ }
43
+
44
+ repositories {
45
+ google()
46
+ jcenter()
47
+ mavenCentral()
48
+ }
49
+
50
+
51
+ dependencies {
52
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
53
+ implementation project(':capacitor-android')
54
+ implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
55
+ implementation 'com.android.volley:volley:1.2.1'
56
+ implementation 'io.github.g00fy2:versioncompare:1.5.0'
57
+ testImplementation "junit:junit:$junitVersion"
58
+ androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
59
+ androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
60
+ }
@@ -0,0 +1,3 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="ee.forgr.capacitor_updater">
3
+ </manifest>