Compare commits
2 Commits
release-20
...
release-20
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d88084fb9a | ||
|
|
f8639f2967 |
@@ -105,29 +105,39 @@ pub fn provide_torrent_store() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(data_str) = msg.data().as_string() {
|
if let Some(data_str) = msg.data().as_string() {
|
||||||
if let Ok(bytes) = BASE64.decode(&data_str) {
|
match BASE64.decode(&data_str) {
|
||||||
if let Ok(event) = rmp_serde::from_slice::<AppEvent>(&bytes) {
|
Ok(bytes) => {
|
||||||
match event {
|
match rmp_serde::from_slice::<AppEvent>(&bytes) {
|
||||||
AppEvent::FullList(list, _) => {
|
Ok(event) => {
|
||||||
torrents_for_sse.update(|map| {
|
match event {
|
||||||
let new_hashes: std::collections::HashSet<String> = list.iter().map(|t| t.hash.clone()).collect();
|
AppEvent::FullList(list, _) => {
|
||||||
map.retain(|hash, _| new_hashes.contains(hash));
|
torrents_for_sse.update(|map| {
|
||||||
for new_torrent in list { map.insert(new_torrent.hash.clone(), new_torrent); }
|
let new_hashes: std::collections::HashSet<String> = list.iter().map(|t| t.hash.clone()).collect();
|
||||||
});
|
map.retain(|hash, _| new_hashes.contains(hash));
|
||||||
}
|
for new_torrent in list { map.insert(new_torrent.hash.clone(), new_torrent); }
|
||||||
AppEvent::Update(patch) => {
|
});
|
||||||
if let Some(hash) = patch.hash.clone() {
|
}
|
||||||
torrents_for_sse.update(|map| { if let Some(t) = map.get_mut(&hash) { t.apply(patch); } });
|
AppEvent::Update(patch) => {
|
||||||
}
|
if let Some(hash) = patch.hash.clone() {
|
||||||
}
|
torrents_for_sse.update(|map| { if let Some(t) = map.get_mut(&hash) { t.apply(patch); } });
|
||||||
AppEvent::Stats(stats) => { global_stats_for_sse.set(stats); }
|
}
|
||||||
AppEvent::Notification(n) => {
|
}
|
||||||
show_toast(n.level.clone(), n.message.clone());
|
AppEvent::Stats(stats) => { global_stats_for_sse.set(stats); }
|
||||||
if n.message.contains("tamamlandı") || n.level == shared::NotificationLevel::Error {
|
AppEvent::Notification(n) => {
|
||||||
show_browser_notification("VibeTorrent", &n.message);
|
show_toast(n.level.clone(), n.message.clone());
|
||||||
|
if n.message.contains("tamamlandı") || n.level == shared::NotificationLevel::Error {
|
||||||
|
show_browser_notification("VibeTorrent", &n.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("[SSE] Failed to deserialize AppEvent: {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("[SSE] Failed to decode base64: {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const CACHE_NAME = "vibetorrent-v2";
|
const CACHE_NAME = "vibetorrent-v3";
|
||||||
const ASSETS_TO_CACHE = [
|
const ASSETS_TO_CACHE = [
|
||||||
"/",
|
"/",
|
||||||
"/index.html",
|
"/index.html",
|
||||||
@@ -51,6 +51,11 @@ self.addEventListener("activate", (event) => {
|
|||||||
self.addEventListener("fetch", (event) => {
|
self.addEventListener("fetch", (event) => {
|
||||||
const url = new URL(event.request.url);
|
const url = new URL(event.request.url);
|
||||||
|
|
||||||
|
// Skip unsupported schemes (like chrome-extension://)
|
||||||
|
if (!url.protocol.startsWith("http")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Network-first strategy for API calls
|
// Network-first strategy for API calls
|
||||||
if (url.pathname.startsWith("/api/")) {
|
if (url.pathname.startsWith("/api/")) {
|
||||||
event.respondWith(
|
event.respondWith(
|
||||||
@@ -75,10 +80,12 @@ self.addEventListener("fetch", (event) => {
|
|||||||
fetch(event.request)
|
fetch(event.request)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
// Cache the latest version of the HTML
|
// Cache the latest version of the HTML
|
||||||
const responseToCache = response.clone();
|
if (response && response.status === 200) {
|
||||||
caches.open(CACHE_NAME).then((cache) => {
|
const responseToCache = response.clone();
|
||||||
cache.put(event.request, responseToCache);
|
caches.open(CACHE_NAME).then((cache) => {
|
||||||
});
|
cache.put(event.request, responseToCache);
|
||||||
|
});
|
||||||
|
}
|
||||||
return response;
|
return response;
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user