Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nghyd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Cassiopée
nghyd
Commits
37600fab
Commit
37600fab
authored
2 years ago
by
François Grand
Browse files
Options
Downloads
Patches
Plain Diff
refactor: service worker: display confirmation dialog when application update is ready
refs
#604
parent
2b5c5af4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!225
Release v4.17.0
,
!206
Resolve "PWA: l'application ne se met pas à jour"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/app/services/service-worker-update.service.ts
+19
-6
19 additions, 6 deletions
src/app/services/service-worker-update.service.ts
with
19 additions
and
6 deletions
src/app/services/service-worker-update.service.ts
+
19
−
6
View file @
37600fab
import
{
Injectable
}
from
"
@angular/core
"
;
import
{
SwUpdate
,
VersionEvent
}
from
'
@angular/service-worker
'
;
import
{
SwUpdate
}
from
'
@angular/service-worker
'
;
import
{
I18nService
}
from
"
./internationalisation.service
"
;
import
{
NotificationsService
}
from
"
./notifications.service
"
;
import
{
UserConfirmationService
}
from
"
./user-confirmation.service
"
;
@
Injectable
()
export
class
ServiceWorkerUpdateService
{
constructor
(
private
swUpdate
:
SwUpdate
,
private
notificationService
:
NotificationsService
,
private
i18nService
:
I18nService
private
i18nService
:
I18nService
,
private
userConfirmationService
:
UserConfirmationService
)
{
swUpdate
.
versionUpdates
.
subscribe
(
evt
=>
{
switch
(
evt
.
type
)
{
case
'
VERSION_DETECTED
'
:
let
ver
=
(
evt
as
any
).
version
?.
appData
?.
version
??
"
<NA>
"
;
console
.
log
(
"
S
wUpdate
VERSION_DETECTED
"
,
ver
);
console
.
log
(
"
S
erviceWorkerUpdateService:
VERSION_DETECTED
"
,
ver
);
notificationService
.
notify
(
i18nService
.
localizeText
(
"
INFO_SERVICE_WORKER_VERSION_DETECTED
"
,
{
"
ver
"
:
ver
}),
10000
);
break
;
case
'
VERSION_READY
'
:
const
currVer
=
(
evt
as
any
).
currentVersion
?.
appData
?.
version
??
"
<NA>
"
;
const
newVer
=
(
evt
as
any
).
latestVersion
?.
appData
?.
version
??
"
<NA>
"
;
console
.
log
(
"
S
wUpdate
VERSION_READY
"
,
currVer
,
newVer
);
console
.
log
(
"
S
erviceWorkerUpdateService:
VERSION_READY
"
,
currVer
,
"
->
"
,
newVer
);
notificationService
.
notify
(
i18nService
.
localizeText
(
"
INFO_SERVICE_WORKER_VERSION_READY
"
,
{
"
ver
"
:
newVer
}),
10000
);
// PLANTE si on stocke le message dans une variable !!!!
...
...
@@ -29,17 +31,28 @@ export class ServiceWorkerUpdateService {
// notificationService.notify(msg, 10000);
// -> ReferenceError: can't access lexical declaration 'xxx' before initialization
// avec xxx qui varie d'une fois à l'autre !!!
userConfirmationService
.
askUserConfirmation
(
"
Confirmation
"
,
i18nService
.
localizeText
(
"
INFO_SERVICE_WORKER_VERSION_READY
"
,
{
"
ver
"
:
newVer
})).
then
(
data
=>
{
if
(
data
[
"
confirm
"
])
{
console
.
log
(
"
ServiceWorkerUpdateService: application update confirmed
"
);
window
.
location
.
reload
();
}
else
{
console
.
log
(
"
ServiceWorkerUpdateService: application update canceled
"
);
}
});
break
;
case
'
VERSION_INSTALLATION_FAILED
'
:
ver
=
(
evt
as
any
).
version
?.
appData
?.
version
??
"
NA
"
;
console
.
log
(
"
S
wUpdate
VERSION_INSTALLATION_FAILED
"
,
ver
);
console
.
log
(
"
S
erviceWorkerUpdateService:
VERSION_INSTALLATION_FAILED
"
,
ver
);
notificationService
.
notify
(
i18nService
.
localizeText
(
"
ERROR_SERVICE_WORKER_INSTALL_FAILED
"
,
{
"
ver
"
:
ver
}),
10000
);
break
;
}
});
swUpdate
.
unrecoverable
.
subscribe
(
event
=>
{
console
.
log
(
"
SwUpdate.unrecoverable
"
,
event
.
reason
,
event
.
type
);
console
.
log
(
"
SwUpdate.unrecoverable
reason
"
,
event
.
reason
,
"
type
"
,
event
.
type
);
notificationService
.
notify
(
"
SwUpdate: unrecoverable state. Reason=
"
+
event
.
reason
+
"
, type=
"
+
event
.
type
,
10000
);
});
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment