@notes-sync/service
Version:
Background service for AI-powered note synchronization
46 lines • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WakeDetector = void 0;
class WakeDetectorClass {
constructor() {
this.onWakeCallbacks = [];
this.interval = null;
this.previousTime = Date.now();
}
start(wakeInterval = 20000) {
if (this.interval)
return; // already running
this.interval = setInterval(() => {
const now = Date.now();
const diff = now - this.previousTime;
if (diff > wakeInterval) {
console.log('wake');
for (const cb of this.onWakeCallbacks) {
try {
cb();
}
catch { }
}
}
this.previousTime = now;
}, 10000);
}
stop() {
if (this.interval) {
clearInterval(this.interval);
this.interval = null;
}
}
onWake(callback) {
this.onWakeCallbacks.push(callback);
return { stopListening: () => this.offWake(callback) };
}
offWake(callback) {
this.onWakeCallbacks = this.onWakeCallbacks.filter(cb => cb !== callback);
}
isRunning() {
return this.interval !== null;
}
}
exports.WakeDetector = new WakeDetectorClass();
//# sourceMappingURL=wake-detect.js.map