-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathservice_worker.js
187 lines (151 loc) · 4.71 KB
/
service_worker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
//
// Service worker for abctools offline use resource caching
//
//
//
//
//
// Updated 3 February 2025 at 0600
//
//
//
//
//
const cacheName = 'abctoolscache-2296';
const contentToCache = [
'abctools.html',
'abctools-quick-editor.html',
'userguide.html',
'tunesources.html',
'tunesources.css',
'credits.html',
'tipjars.html',
'general_midi_extended_v7.pdf',
'abc_standard_v2.1.pdf',
'ABCquickRefv0_6.pdf',
'app.css',
'app-min.js',
'jquery-1.11.1.min.js',
'jszip.min.js',
'xml2abc-min.js',
'abcjs-chord-intervals.js',
'abcjs-basic-eskin-min.js',
'jspdf.min.js',
'pdf-lib-min.js',
'html2image.js',
'qrcode.js',
'lz-string.min.js',
'daypilot-modal.min-3.10.1.js',
'lame.min.js',
'unmute.min.js',
'tab-injectors-min.js',
'visualscript-sdk.js',
'smartdraw-export-min.js',
'acoustic_grand_piano-mp3.js',
'percussion-mp3.js',
'online-check.js',
'database.js',
'download-reverb.js',
'bww2abc.js',
'manage_database.js',
'website_generator.js',
'pdf-website-import.js',
'context-menu.js',
'api-keys.js',
'img/zoomin.png',
'img/zoomout.png',
'img/helpbutton.png',
'img/playbutton.png',
'img/pdfbutton.png',
'img/michael.jpg',
'img/settings.png',
'img/abc-android-icon-144x144.png',
'img/abc-android-icon-192x192.png',
'img/abc-android-icon-36x36.png',
'img/abc-android-icon-48x48.png',
'img/abc-android-icon-72x72.png',
'img/abc-android-icon-96x96.png',
'img/abc-apple-icon-114x114.png',
'img/abc-apple-icon-120x120.png',
'img/abc-apple-icon-144x144.png',
'img/abc-apple-icon-152x152.png',
'img/abc-apple-icon-180x180.png',
'img/abc-apple-icon-57x57.png',
'img/abc-apple-icon-60x60.png',
'img/abc-apple-icon-72x72.png',
'img/abc-apple-icon-76x76.png',
'img/abc-apple-icon-precomposed.png',
'img/abc-apple-icon.png',
'img/abc-favicon-16x16.png',
'img/abc-favicon-32x32.png',
'img/abc-favicon-96x96.png',
'img/abc-favicon.ico',
'img/abc-icon-512x512.png',
'img/abc-icon-user-guide-basic.png',
'img/abc-icon.png',
'img/abc-ms-icon-144x144.png',
'img/abc-ms-icon-150x150.png',
'img/abc-ms-icon-310x310.png',
'img/abc-ms-icon-70x70.png',
'img/abc-manifest.json',
'img/abc-manifest-qe.json'
];
// Installing Service Worker
self.addEventListener('install', (e) => {
console.log('[Service Worker] Install');
// Make this the current service worker
self.skipWaiting();
e.waitUntil((async () => {
const cache = await caches.open(cacheName);
console.log('[Service Worker] Caching all: app shell and content');
await cache.addAll(contentToCache);
console.log('[Service Worker] Cache addAll complete!');
})());
});
self.addEventListener('activate', event => {
console.log("[Service Worker] Activate event");
clients.claim().then(() => {
//claim means that the html file will use this new service worker.
console.log(
'[Service Worker] - The service worker has now claimed all pages so they use the new service worker.'
);
});
event.waitUntil(
caches.keys().then((keys) => {
return Promise.all(
keys.filter((key) => key != cacheName).map((key) => {if ((key.indexOf("abctoolscache") != -1) || (key.indexOf("cache-20") != -1)){caches.delete(key)}})
);
})
);
});
// Fetching content using Service Worker
self.addEventListener('fetch', (e) => {
//console.log(`[Service Worker] fetching: ${e.request.url}`);
// Cache http and https only, skip unsupported chrome-extension:// and file://...
if (!(
e.request.url.startsWith('http:') || e.request.url.startsWith('https:')
)) {
return;
}
e.respondWith((async () => {
const r = await caches.match(e.request,{ignoreSearch: true, ignoreVary:true});
if (r){
//console.log(`[Service Worker] Returning cached resource: ${e.request.url}`);
return r;
}
try{
//console.log(`[Service Worker] Fetching resource: ${e.request.url}`);
const response = await fetch(e.request);
//Don't cache any resources
// if ((e.request.url.indexOf("service_worker") == -1) && (e.request.url.indexOf("soundfonts") == -1)){
// const cache = await caches.open(cacheName);
// console.log(`[Service Worker] Caching new resource: ${e.request.url}`);
// cache.put(e.request, response.clone());
// }
return response;
}
catch (error){
//console.log("[Service Worker] fetch error: "+error);
}
})());
});