diff --git a/globals/static/index.html b/globals/static/index.html
index 8fd5f25..44fb6d3 100644
--- a/globals/static/index.html
+++ b/globals/static/index.html
@@ -72,7 +72,13 @@
- RSS Reader
+
+ RSS Reader
+ << if gt .AutoUpdatePush 0 >>
+
+ {{ countdown }} s
+ << end >>
+
@@ -150,6 +156,8 @@
feeds: [],
showSEOFlag: true,
fullscreenLoading: true,
+ countdown: 60,
+ autoUpdatePush: << .AutoUpdatePush >>,
};
},
async created() {
@@ -159,6 +167,8 @@
const protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://';
const connect = () => {
const socket = new WebSocket(protocol + window.location.host + "/ws");
+ // 使用媒体查询判断设备类型
+ const isMobile = window.matchMedia('(max-width: 767px)').matches;
socket.onmessage = event => {
const feed = JSON.parse(event.data);
const existingFeed = this.feeds.find(f => f.link === feed.link);
@@ -179,14 +189,12 @@
}
}
socket.onclose = event => {
- console.log("WebSocket closed. Reconnecting...");
- // 使用媒体查询判断设备类型
- const isMobile = window.matchMedia('(max-width: 767px)').matches;
- if (!isMobile) {
+ if (!isMobile && this.autoUpdatePush > 0) {
+ console.log("WebSocket closed. Reconnecting...");
setInterval(reloadHtml, 3000);
}
};
- // Send heartbeat message every 120 seconds
+ // Send heartbeat message every 60 seconds
const sendHeartbeat = () => {
if (socket.readyState === WebSocket.OPEN) {
socket.send("heartbeat");
@@ -194,7 +202,16 @@
reloadHtml()
}
};
- setInterval(sendHeartbeat, 60000);
+ if (!isMobile && this.autoUpdatePush > 0) {
+ setInterval(sendHeartbeat, 60000);
+ setInterval(() => {
+ if (this.countdown > 0) {
+ this.countdown--;
+ } else {
+ this.countdown = 60;
+ }
+ }, 1000);
+ }
};
connect();
},