@rdlabo/ionic-angular-kit 21.5.21 → 21.5.23
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.
|
@@ -1,32 +1,28 @@
|
|
|
1
|
-
import * as i0 from '@angular/core';
|
|
2
|
-
import { inject, ApplicationRef, Injectable, makeEnvironmentProviders, provideEnvironmentInitializer } from '@angular/core';
|
|
3
1
|
import { DOCUMENT } from '@angular/common';
|
|
2
|
+
import * as i0 from '@angular/core';
|
|
3
|
+
import { inject, Injectable, makeEnvironmentProviders, provideAppInitializer } from '@angular/core';
|
|
4
4
|
import { SwUpdate } from '@angular/service-worker';
|
|
5
|
-
import { filter, first } from 'rxjs';
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
const UPDATE_CHECK_TIMEOUT_MS = 10_000;
|
|
7
|
+
/** Checks for a complete Angular service-worker update before users can interact with the application. */
|
|
8
8
|
class KitAppUpdateService {
|
|
9
|
-
#applicationRef = inject(ApplicationRef);
|
|
10
9
|
#document = inject(DOCUMENT);
|
|
11
10
|
#updates = inject(SwUpdate);
|
|
12
|
-
#
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
#initialization = null;
|
|
12
|
+
/** Runs one startup update check and reloads directly into a downloaded version when one is available. */
|
|
13
|
+
initialize() {
|
|
14
|
+
this.#initialization ??= this.#initialize();
|
|
15
|
+
return this.#initialization;
|
|
16
|
+
}
|
|
17
|
+
async #initialize() {
|
|
18
|
+
if (!this.#updates.isEnabled || !this.#document.defaultView?.navigator.serviceWorker?.controller) {
|
|
16
19
|
return;
|
|
17
20
|
}
|
|
18
|
-
this.#started = true;
|
|
19
|
-
this.#applicationRef.isStable
|
|
20
|
-
.pipe(filter((stable) => stable), first())
|
|
21
|
-
.subscribe(() => void this.#activateUpdate());
|
|
22
|
-
}
|
|
23
|
-
async #activateUpdate() {
|
|
24
21
|
try {
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
const available = await withTimeout(this.#updates.checkForUpdate(), UPDATE_CHECK_TIMEOUT_MS);
|
|
23
|
+
if (available) {
|
|
24
|
+
this.#document.location?.reload();
|
|
27
25
|
}
|
|
28
|
-
await this.#updates.activateUpdate();
|
|
29
|
-
this.#document.location?.reload();
|
|
30
26
|
}
|
|
31
27
|
catch (error) {
|
|
32
28
|
console.error('Angular service-worker update check failed', error);
|
|
@@ -39,12 +35,31 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImpo
|
|
|
39
35
|
type: Injectable,
|
|
40
36
|
args: [{ providedIn: 'root' }]
|
|
41
37
|
}] });
|
|
42
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* Provides a startup check that reloads into the latest complete web application version.
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* The check finishes before application bootstrap so a delayed update cannot discard user input. It times out rather
|
|
43
|
+
* than preventing offline startup. API deployments must remain backward compatible while a newly adopted updater is
|
|
44
|
+
* rolling out because code already running in older application versions cannot gain this behavior retroactively.
|
|
45
|
+
*/
|
|
43
46
|
function provideKitAppUpdate() {
|
|
44
47
|
return makeEnvironmentProviders([
|
|
45
|
-
|
|
48
|
+
provideAppInitializer(() => inject(KitAppUpdateService).initialize()),
|
|
46
49
|
]);
|
|
47
50
|
}
|
|
51
|
+
function withTimeout(promise, timeoutMs) {
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
const timeout = window.setTimeout(() => resolve(undefined), timeoutMs);
|
|
54
|
+
void promise.then((value) => {
|
|
55
|
+
window.clearTimeout(timeout);
|
|
56
|
+
resolve(value);
|
|
57
|
+
}, (error) => {
|
|
58
|
+
window.clearTimeout(timeout);
|
|
59
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
48
63
|
|
|
49
64
|
/** Automatic startup updates for Angular service-worker web applications. */
|
|
50
65
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rdlabo-ionic-angular-kit-app-update.mjs","sources":["../../../projects/kit/app-update/src/lib/kit-app-update.provider.ts","../../../projects/kit/app-update/src/public-api.ts","../../../projects/kit/app-update/src/rdlabo-ionic-angular-kit-app-update.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"rdlabo-ionic-angular-kit-app-update.mjs","sources":["../../../projects/kit/app-update/src/lib/kit-app-update.provider.ts","../../../projects/kit/app-update/src/public-api.ts","../../../projects/kit/app-update/src/rdlabo-ionic-angular-kit-app-update.ts"],"sourcesContent":["import { DOCUMENT } from '@angular/common';\nimport type { EnvironmentProviders } from '@angular/core';\nimport { Injectable, inject, makeEnvironmentProviders, provideAppInitializer } from '@angular/core';\nimport { SwUpdate } from '@angular/service-worker';\n\nconst UPDATE_CHECK_TIMEOUT_MS = 10_000;\n\n/** Checks for a complete Angular service-worker update before users can interact with the application. */\n@Injectable({ providedIn: 'root' })\nexport class KitAppUpdateService {\n readonly #document = inject(DOCUMENT);\n readonly #updates = inject(SwUpdate);\n #initialization: Promise<void> | null = null;\n\n /** Runs one startup update check and reloads directly into a downloaded version when one is available. */\n initialize(): Promise<void> {\n this.#initialization ??= this.#initialize();\n return this.#initialization;\n }\n\n async #initialize(): Promise<void> {\n if (!this.#updates.isEnabled || !this.#document.defaultView?.navigator.serviceWorker?.controller) {\n return;\n }\n try {\n const available = await withTimeout(this.#updates.checkForUpdate(), UPDATE_CHECK_TIMEOUT_MS);\n if (available) {\n this.#document.location?.reload();\n }\n } catch (error) {\n console.error('Angular service-worker update check failed', error);\n }\n }\n}\n\n/**\n * Provides a startup check that reloads into the latest complete web application version.\n *\n * @remarks\n * The check finishes before application bootstrap so a delayed update cannot discard user input. It times out rather\n * than preventing offline startup. API deployments must remain backward compatible while a newly adopted updater is\n * rolling out because code already running in older application versions cannot gain this behavior retroactively.\n */\nexport function provideKitAppUpdate(): EnvironmentProviders {\n return makeEnvironmentProviders([\n provideAppInitializer(() => inject(KitAppUpdateService).initialize()),\n ]);\n}\n\nfunction withTimeout<T>(promise: Promise<T>, timeoutMs: number): Promise<T | undefined> {\n return new Promise((resolve, reject) => {\n const timeout = window.setTimeout(() => resolve(undefined), timeoutMs);\n void promise.then(\n (value) => {\n window.clearTimeout(timeout);\n resolve(value);\n },\n (error: unknown) => {\n window.clearTimeout(timeout);\n reject(error instanceof Error ? error : new Error(String(error)));\n },\n );\n });\n}\n","/** Automatic startup updates for Angular service-worker web applications. */\nexport * from './lib/kit-app-update.provider';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;AAKA,MAAM,uBAAuB,GAAG,MAAM;AAEtC;MAEa,mBAAmB,CAAA;AACrB,IAAA,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC;AAC5B,IAAA,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;IACpC,eAAe,GAAyB,IAAI;;IAG5C,UAAU,GAAA;AACR,QAAA,IAAI,CAAC,eAAe,KAAK,IAAI,CAAC,WAAW,EAAE;QAC3C,OAAO,IAAI,CAAC,eAAe;IAC7B;AAEA,IAAA,MAAM,WAAW,GAAA;QACf,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,SAAS,CAAC,aAAa,EAAE,UAAU,EAAE;YAChG;QACF;AACA,QAAA,IAAI;AACF,YAAA,MAAM,SAAS,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,EAAE,uBAAuB,CAAC;YAC5F,IAAI,SAAS,EAAE;AACb,gBAAA,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE;YACnC;QACF;QAAE,OAAO,KAAK,EAAE;AACd,YAAA,OAAO,CAAC,KAAK,CAAC,4CAA4C,EAAE,KAAK,CAAC;QACpE;IACF;+GAvBW,mBAAmB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA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entProviders } from '@angular/core';
|
|
3
3
|
|
|
4
|
-
/** Checks for
|
|
4
|
+
/** Checks for a complete Angular service-worker update before users can interact with the application. */
|
|
5
5
|
declare class KitAppUpdateService {
|
|
6
6
|
#private;
|
|
7
|
-
/**
|
|
8
|
-
|
|
7
|
+
/** Runs one startup update check and reloads directly into a downloaded version when one is available. */
|
|
8
|
+
initialize(): Promise<void>;
|
|
9
9
|
static ɵfac: i0.ɵɵFactoryDeclaration<KitAppUpdateService, never>;
|
|
10
10
|
static ɵprov: i0.ɵɵInjectableDeclaration<KitAppUpdateService>;
|
|
11
11
|
}
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Provides a startup check that reloads into the latest complete web application version.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* The check finishes before application bootstrap so a delayed update cannot discard user input. It times out rather
|
|
17
|
+
* than preventing offline startup. API deployments must remain backward compatible while a newly adopted updater is
|
|
18
|
+
* rolling out because code already running in older application versions cannot gain this behavior retroactively.
|
|
19
|
+
*/
|
|
13
20
|
declare function provideKitAppUpdate(): EnvironmentProviders;
|
|
14
21
|
|
|
15
22
|
export { KitAppUpdateService, provideKitAppUpdate };
|