防止Angular PWA自动更新

问题描述 投票:0回答:1

Angular-PWA可能是我最近启动项目的不错选择。但必须禁用其中一个很好的功能!

该应用程序将具有敏感数据,并且必须在很长一段时间内保持稳定(直到用户明确选择更新)。所以它不能自动更新。

The official documentation of Angular's Service-worker对此策略没有任何想法。

有什么想法吗?

angular progressive-web-apps auto-update angular-service-worker
1个回答
0
投票

Angular的服务工作者试图检查更新共有3个地方。首先是明确的请求(OK),另外两个(check-updates-on-navigationinit post-load (update))是自动化的,必须禁用。见下面的补丁(对于@angular/service-worker v7.1.0):

--- "node_modules/@angular/service-worker/ngsw-worker.js"   1985-10-26 11:45:00.000000000 +0330
+++ "node_modules/@angular/service-worker/ngsw-worker.js"   2019-02-13 23:28:10.828903500 +0330
@@ -1990 +1990 @@
-                    const action = (() => __awaiter$5(this, void 0, void 0, function* () { yield this.checkForUpdate(); }))();
+                    const action = (() => __awaiter$5(this, void 0, void 0, function* () { console.log('WILL_UPDATE_ON_EXPLICIT_MESSAGE'); yield this.checkForUpdate(); }))();
@@ -2101 +2101 @@
-                        yield this.checkForUpdate();
+                        console.log('DISCARDED: check-updates-on-navigation'); //yield this.checkForUpdate();
@@ -2171 +2171 @@
-                        yield this.checkForUpdate();
+                        console.log('DISCARDED: init post-load (update)'); //yield this.checkForUpdate();

但我不会用这种危险的方式。

© www.soinside.com 2019 - 2024. All rights reserved.