mirror of
https://github.com/bastienwirtz/homer.git
synced 2026-01-20 14:22:09 +01:00
fix: simplify scheduler implementation
This commit is contained in:
13
AGENTS.md
13
AGENTS.md
@@ -32,6 +32,19 @@ All service components follow this architecture:
|
||||
- Use the `service.js` mixin (`src/mixins/service.js`) for common API functionality
|
||||
- Use a custom `fetch` method provided by the service mixin to seamlessly support proxy configuration, custom headers, and credentials.
|
||||
|
||||
### Auto-Update Configuration
|
||||
|
||||
Services support automatic data refreshing using a centralized scheduler system with global and per-service configuration:
|
||||
|
||||
#### Global Configuration
|
||||
|
||||
`autoUpdate: 30000` - Set default interval for all services (30 seconds)
|
||||
|
||||
#### Service Configuration
|
||||
- **Service-specific interval**: `updateInterval: 10000` - Override global default
|
||||
- **Disable per service**: `autoUpdateInterval: false` - Disable for specific service
|
||||
- **Use global default**: Omit `autoUpdateInterval` to use global setting
|
||||
|
||||
### Configuration & Routing
|
||||
|
||||
- **Multi-page Support**: Hash-based routing without Vue Router
|
||||
|
||||
@@ -13,7 +13,6 @@ class UpdateScheduler {
|
||||
this.registeredComponents = new Map();
|
||||
this.globalTimer = null;
|
||||
this.tickCount = 0;
|
||||
this.isRunning = false;
|
||||
}
|
||||
|
||||
register(component, intervalMs, updateMethod) {
|
||||
@@ -32,6 +31,11 @@ class UpdateScheduler {
|
||||
const intervalSeconds = Math.floor(intervalMs / 1000);
|
||||
const componentId = this.generateComponentId(component);
|
||||
|
||||
if (!componentId) {
|
||||
console.error(`UpdateScheduler: invalid component id`);
|
||||
return;
|
||||
}
|
||||
|
||||
this.registeredComponents.set(componentId, {
|
||||
component,
|
||||
interval: intervalSeconds,
|
||||
@@ -60,12 +64,11 @@ class UpdateScheduler {
|
||||
|
||||
generateComponentId(component) {
|
||||
// Use component's unique identifier or Vue instance uid
|
||||
return component._uid || component.$.uid || Symbol("component");
|
||||
return component._uid || component.$.uid
|
||||
}
|
||||
|
||||
startGlobalTimer() {
|
||||
if (!this.globalTimer && !this.isRunning) {
|
||||
this.isRunning = true;
|
||||
if (!this.globalTimer) {
|
||||
this.tickCount = 0;
|
||||
|
||||
this.globalTimer = setInterval(() => {
|
||||
@@ -81,7 +84,6 @@ class UpdateScheduler {
|
||||
if (this.globalTimer) {
|
||||
clearInterval(this.globalTimer);
|
||||
this.globalTimer = null;
|
||||
this.isRunning = false;
|
||||
this.tickCount = 0;
|
||||
console.log("UpdateScheduler: Global timer stopped");
|
||||
}
|
||||
@@ -99,30 +101,6 @@ class UpdateScheduler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pause() {
|
||||
if (this.globalTimer) {
|
||||
clearInterval(this.globalTimer);
|
||||
this.globalTimer = null;
|
||||
this.isRunning = false;
|
||||
console.log("UpdateScheduler: Paused");
|
||||
}
|
||||
}
|
||||
|
||||
resume() {
|
||||
if (!this.globalTimer && this.registeredComponents.size > 0) {
|
||||
this.startGlobalTimer();
|
||||
console.log("UpdateScheduler: Resumed");
|
||||
}
|
||||
}
|
||||
|
||||
getStatus() {
|
||||
return {
|
||||
isRunning: this.isRunning,
|
||||
registeredCount: this.registeredComponents.size,
|
||||
tickCount: this.tickCount,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Create and export global singleton instance
|
||||
@@ -132,9 +110,9 @@ const updateScheduler = new UpdateScheduler();
|
||||
if (typeof document !== "undefined") {
|
||||
document.addEventListener("visibilitychange", () => {
|
||||
if (document.hidden) {
|
||||
updateScheduler.pause();
|
||||
} else {
|
||||
updateScheduler.resume();
|
||||
updateScheduler.stopGlobalTimer();
|
||||
} else if (updateScheduler.registeredComponents.size > 0) {
|
||||
updateScheduler.startGlobalTimer();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user