Skip to content

Commit 17cd9f6

Browse files
committed
[Update Version] - Pull requests
1 parent 47d2648 commit 17cd9f6

File tree

1 file changed

+87
-24
lines changed

1 file changed

+87
-24
lines changed

sw.js

Lines changed: 87 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const version = '2.7.1';
2-
const hash = '0be8e';
1+
const version = '2.8.0';
2+
const hash = '214c4';
33
const cacheName = `pwa-tunime-${hash}-v${version}`;
44
const appShellFilesToCache = [
55
// Директория: /images/genres
@@ -28,15 +28,22 @@ const appShellFilesToCache = [
2828
"/images/icons/logo-x384-o.png",
2929
"/images/icons/logo-x512-b.png",
3030
"/images/icons/logo-x512-o.png",
31+
// Директория: /images/seasons
32+
"/images/seasons/autum.webp",
33+
"/images/seasons/spring.webp",
34+
"/images/seasons/summer.webp",
35+
"/images/seasons/winter.webp",
3136
// Директория: /images
3237
"/images/anime-not.png",
3338
"/images/ava.jpeg",
3439
"/images/black-bg-player.png",
3540
"/images/collections.png",
41+
"/images/endlist.png",
3642
"/images/error-trailers.png",
3743
"/images/icon-web.png",
3844
"/images/login-icon.png",
3945
"/images/logo-login.png",
46+
"/images/noanime.png",
4047
"/images/player-icon.png",
4148
"/images/popup.png",
4249
"/images/preview-image.png",
@@ -48,11 +55,13 @@ const appShellFilesToCache = [
4855
"/javascript/library/hls.js",
4956
"/javascript/library/jqery.min.js",
5057
"/javascript/library/jsyaml.js",
58+
"/javascript/library/md5.wasm.min.js",
5159
"/javascript/library/rxjs.umd.min.js",
5260
"/javascript/library/swiper-bundle.min.js",
5361
// Директория: /javascript/modules
5462
"/javascript/modules/ActionVerify.js",
5563
"/javascript/modules/AnimeCard.js",
64+
"/javascript/modules/api.jikan.js",
5665
"/javascript/modules/Collection.js",
5766
"/javascript/modules/EventTools.js",
5867
"/javascript/modules/functions.js",
@@ -64,6 +73,7 @@ const appShellFilesToCache = [
6473
"/javascript/modules/ShikiUSR.js",
6574
"/javascript/modules/TDatabase.js",
6675
"/javascript/modules/TDownload.js",
76+
"/javascript/modules/tun.cache.js",
6777
"/javascript/modules/TunimeApi.js",
6878
"/javascript/modules/Windows.js",
6979
// Директория: /javascript/pages/downloads
@@ -103,11 +113,17 @@ const appShellFilesToCache = [
103113
"/javascript/pages/player/mod_stream.js",
104114
"/javascript/pages/player/mod_ui.js",
105115
// Директория: /javascript/pages/search
116+
"/javascript/pages/search/mod_card.js",
117+
"/javascript/pages/search/mod_genres.js",
106118
"/javascript/pages/search/mod_history.js",
107-
"/javascript/pages/search/mod_list.js",
108119
"/javascript/pages/search/mod_popular.js",
109120
"/javascript/pages/search/mod_search.js",
110-
"/javascript/pages/search/mod_searchState.js",
121+
"/javascript/pages/search/mod_seasons.js",
122+
"/javascript/pages/search/mod_studios.js",
123+
"/javascript/pages/search/mod_voicelist.js",
124+
"/javascript/pages/search/mod_w_filter.js",
125+
"/javascript/pages/search/mod_w_genres.js",
126+
"/javascript/pages/search/mod_w_season.js",
111127
// Директория: /javascript/pages/settings
112128
"/javascript/pages/settings/mod_cleardb.js",
113129
"/javascript/pages/settings/mod_select.js",
@@ -124,14 +140,14 @@ const appShellFilesToCache = [
124140
"/javascript/pages/user/mod_stats.js",
125141
"/javascript/pages/user/mod_w_anime.js",
126142
// Директория: /javascript/pages/watch
143+
"/javascript/pages/watch/mod.chronology.js",
144+
"/javascript/pages/watch/mod.resource.js",
127145
"/javascript/pages/watch/mod_collection.js",
128146
"/javascript/pages/watch/mod_dbanime.js",
129147
"/javascript/pages/watch/mod_download.js",
130-
"/javascript/pages/watch/mod_franchise.js",
131148
"/javascript/pages/watch/mod_history.js",
132149
"/javascript/pages/watch/mod_player.js",
133150
"/javascript/pages/watch/mod_private.js",
134-
"/javascript/pages/watch/mod_resource.js",
135151
"/javascript/pages/watch/mod_scrolling.js",
136152
"/javascript/pages/watch/mod_transition.js",
137153
"/javascript/pages/watch/mod_translation.js",
@@ -153,8 +169,10 @@ const appShellFilesToCache = [
153169
"/javascript/services/dispatcher.js",
154170
"/javascript/services/installing.js",
155171
"/javascript/services/update.js",
172+
// Директория: /javascript/utils
173+
"/javascript/utils/auth.login.js",
174+
"/javascript/utils/auth.logout.js",
156175
// Директория: /javascript
157-
"/javascript/kodik.js",
158176
"/javascript/menu.js",
159177
"/javascript/parametrs.js",
160178
"/javascript/server.js",
@@ -197,11 +215,50 @@ const servers = [
197215
"https://tunime-hujg.onrender.com"
198216
];
199217

200-
self.addEventListener('install', async event => {
201-
event.waitUntil(caches.open(cacheName).then((cache) => {
202-
console.log('[SW]: Caching App Shell');
203-
return cache.addAll(appShellFilesToCache);
204-
}).catch((err) => { console.log('Не удалось установить файл', err) }));
218+
self.addEventListener('install', event => {
219+
const broadcast = new BroadcastChannel('tun.update');
220+
broadcast.postMessage({
221+
type: 'NEW_VERSION', payload: {
222+
version,
223+
hash,
224+
cacheName
225+
}
226+
});
227+
event.waitUntil(
228+
caches.open(cacheName).then(async (cache) => {
229+
console.log('[SW]: Caching App Shell');
230+
231+
const total = appShellFilesToCache.length;
232+
let processed = 0;
233+
234+
for (let i = 0; i < total; i++) {
235+
const file = appShellFilesToCache[i];
236+
let success = true;
237+
try {
238+
await cache.add(file);
239+
} catch (err) {
240+
success = false;
241+
}
242+
243+
processed++;
244+
const percent = ((processed / total) * 100).toFixed(2);
245+
246+
broadcast.postMessage({
247+
type: 'CACHE_PROGRESS', payload: {
248+
total,
249+
processed,
250+
percent,
251+
file,
252+
success
253+
}
254+
});
255+
}
256+
257+
console.log('[SW]: Caching complete.');
258+
}).catch((err) => {
259+
console.error('[SW]: Failed to open cache', err);
260+
})
261+
);
205262

206263
setTimeout(() => {
207264
self.skipWaiting();
@@ -252,17 +309,23 @@ self.addEventListener('fetch', event => {
252309
});
253310

254311
self.addEventListener('message', async event => {
312+
const call = {
313+
215: async (client) => {
314+
client.postMessage(JSON.stringify({ id: 215, val: version }));
315+
},
316+
221: async (client) => {
317+
await self.skipWaiting();
318+
client.postMessage(JSON.stringify({ id: 221, val: 'ok' }));
319+
},
320+
216: async (client) => {
321+
client.postMessage(JSON.stringify({ id: 216, val: hash }));
322+
},
323+
220: async (client) => {
324+
client.postMessage(JSON.stringify({ id: 220, val: { ver: version, hash: hash } }));
325+
}
326+
};
327+
255328
const client = event.source;
256-
if (event.data.id === 215) {
257-
client.postMessage(JSON.stringify({ id: 215, val: version }));
258-
} else if (event.data.id === 221) {
259-
await self.skipWaiting();
260-
client.postMessage(JSON.stringify({ id: 221, val: 'ok' }));
261-
} else if (event.data.id === 216) {
262-
const client = event.source;
263-
client.postMessage(JSON.stringify({ id: 216, val: hash }));
264-
} else if (event.data.id === 220) {
265-
const client = event.source;
266-
client.postMessage(JSON.stringify({ id: 220, val: { ver: version, hash: hash } }));
267-
}
329+
const id = event.data.id;
330+
if (call[id]) return call[id](client);
268331
});

0 commit comments

Comments
 (0)