Skip to content

Commit 4b2087d

Browse files
committed
feat(auto-refresh): centralized auto refresh System
1 parent ee57fa0 commit 4b2087d

21 files changed

+310
-114
lines changed

src/App.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ export default {
130130
DarkMode,
131131
DynamicTheme,
132132
},
133+
provide() {
134+
return {
135+
config: () => this.config,
136+
};
137+
},
133138
data: function () {
134139
return {
135140
loaded: false,

src/components/services/DockerSocketProxy.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ export default {
4848
};
4949
},
5050
created: function () {
51-
const checkInterval = parseInt(this.item.checkInterval, 10) || 0;
52-
if (checkInterval > 0) {
53-
setInterval(() => this.fetchData(), checkInterval);
54-
}
51+
// Set up auto-update method for the scheduler
52+
this.autoUpdateMethod = this.fetchData;
53+
54+
// Initial data fetch
5555
this.fetchData();
5656
},
5757
methods: {

src/components/services/FreshRSS.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ export default {
4040
};
4141
},
4242
created: function () {
43-
const updateInterval = parseInt(this.item.updateInterval, 10) || 0;
44-
if (updateInterval > 0)
45-
setInterval(() => this.fetchConfig(), updateInterval);
43+
// Set up auto-update method for the scheduler
44+
this.autoUpdateMethod = this.fetchConfig;
4645
46+
// Initial data fetch
4747
this.fetchConfig();
4848
},
4949
methods: {

src/components/services/Glances.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ export default {
2929
error: null,
3030
}),
3131
created() {
32-
const updateInterval = parseInt(this.item.updateInterval, 10) || 0;
33-
if (updateInterval > 0) {
34-
setInterval(() => this.fetchStat(), updateInterval);
35-
}
32+
// Set up auto-update method for the scheduler
33+
this.autoUpdateMethod = this.fetchStat;
34+
35+
// Initial data fetch
3636
this.fetchStat();
3737
},
3838
methods: {

src/components/services/Immich.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ export default {
6262
},
6363
},
6464
created: function () {
65-
const updateInterval = parseInt(this.item.updateInterval, 10) || 0;
66-
if (updateInterval > 0) {
67-
setInterval(() => this.fetchConfig(), updateInterval);
68-
}
65+
// Set up auto-update method for the scheduler
66+
this.autoUpdateMethod = this.fetchConfig;
67+
68+
// Initial data fetch
6969
this.fetchConfig();
7070
},
7171
methods: {

src/components/services/Lidarr.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,11 @@ export default {
4343
serverError: false,
4444
};
4545
},
46-
created: function () {
47-
const checkInterval = parseInt(this.item.checkInterval, 10) || 0;
48-
if (checkInterval > 0) {
49-
setInterval(() => this.fetchConfig(), checkInterval);
50-
}
46+
created() {
47+
// Set up auto-update method for the scheduler
48+
this.autoUpdateMethod = this.fetchConfig;
5149
50+
// Initial data fetch
5251
this.fetchConfig();
5352
},
5453
methods: {

src/components/services/PiAlert.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ export default {
4444
};
4545
},
4646
created() {
47-
const updateInterval = parseInt(this.item.updateInterval, 10) || 0;
48-
if (updateInterval > 0) {
49-
setInterval(() => this.fetchStatus(), updateInterval);
50-
}
47+
// Set up auto-update method for the scheduler
48+
this.autoUpdateMethod = this.fetchStatus;
49+
50+
// Initial data fetch
5151
this.fetchStatus();
5252
},
5353
methods: {

src/components/services/PiHole.vue

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ export default {
3939
retryCount: 0,
4040
maxRetries: 3,
4141
retryDelay: 5000,
42-
localCheckInterval: 1000, // Default value or a fallback
43-
pollInterval: null,
4442
}),
4543
computed: {
4644
percentage: function () {
@@ -57,40 +55,23 @@ export default {
5755
},
5856
created() {
5957
if (parseInt(this.item.apiVersion, 10) === 6) {
60-
// Set the interval to the checkInterval or default to 5 minutes
61-
this.localCheckInterval = parseInt(this.item.checkInterval, 10) || 300000;
6258
this.loadCachedSession();
63-
this.startStatusPolling();
59+
60+
// Set up auto-update method for the scheduler
61+
this.autoUpdateMethod = this.fetchStatus;
6462
} else {
65-
this.fetchStatus_v5();
66-
}
67-
},
68-
beforeUnmount() {
69-
if (parseInt(this.item.apiVersion, 10) === 6) {
70-
this.stopStatusPolling();
63+
// Set up auto-update method for the scheduler
64+
this.autoUpdateMethod = this.fetchStatus_v5();
7165
}
66+
// Initial data fetch
67+
this.autoUpdateMethod();
7268
},
7369
methods: {
7470
handleError: function (error, status) {
7571
console.error(error);
7672
this.subtitle = error;
7773
this.status = status;
7874
},
79-
startStatusPolling: function () {
80-
this.fetchStatus();
81-
if (this.localCheckInterval < 1000) {
82-
this.localCheckInterval = 1000;
83-
}
84-
this.pollInterval = setInterval(
85-
this.fetchStatus,
86-
this.localCheckInterval,
87-
);
88-
},
89-
stopStatusPolling: function () {
90-
if (this.pollInterval) {
91-
clearInterval(this.pollInterval);
92-
}
93-
},
9475
loadCachedSession: function () {
9576
try {
9677
const cachedSession = localStorage.getItem(

src/components/services/Ping.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ export default {
4141
},
4242
},
4343
created() {
44-
const updateInterval = parseInt(this.item.updateInterval, 10) || 0;
45-
if (updateInterval > 0) {
46-
setInterval(this.fetchStatus, updateInterval);
47-
}
44+
// Set up auto-update method for the scheduler
45+
this.autoUpdateMethod = this.fetchStatus;
4846
47+
// Initial data fetch
4948
this.fetchStatus();
5049
},
5150
methods: {

src/components/services/Plex.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ export default {
5252
};
5353
},
5454
created: function () {
55-
const checkInterval = parseInt(this.item.checkInterval, 10) || 0;
56-
if (checkInterval > 0) {
57-
setInterval(() => this.fetchData(), checkInterval);
58-
}
55+
// Set up auto-update method for the scheduler
56+
this.autoUpdateMethod = this.fetchData;
57+
58+
// Initial data fetch
5959
this.fetchData();
6060
},
6161
methods: {

0 commit comments

Comments
 (0)