feature: global timer manager; reconstruct: accesscontrol; fix: chat manager

feature:
- add global timer manager
reconstruct:
- use new cli framework for accesscontrol
- use chat manager for accesscontrol
fix:
- chat manager only send one time
This commit is contained in:
2025-11-01 13:16:42 +08:00
parent 959ec0c424
commit 796bf1c2dc
5 changed files with 377 additions and 538 deletions

36
src/lib/TimerManager.ts Normal file
View File

@@ -0,0 +1,36 @@
import { pullEventAs, TimerEvent } from "./event";
import { Result, Ok, Err, Option, Some, None } from "./thirdparty/ts-result-es";
class TimerManager {
private isRunning = false;
private timerTaskMap = new Map<number, () => void>();
// Don't put heavy logic on callback function
public setTimeOut(delay: number, callback: () => void): void {
const timerId = os.startTimer(delay);
this.timerTaskMap.set(timerId, callback);
}
public run() {
this.isRunning = true;
while (this.isRunning) {
const event = pullEventAs(TimerEvent, "timer");
if (event === undefined) continue;
const task = this.timerTaskMap.get(event.id);
if (task === undefined) continue;
task();
}
}
public stop() {
this.isRunning = false;
}
public status(): boolean {
return this.isRunning;
}
}
export const gTimerManager = new TimerManager();