update at 2025-10-16 18:10:27

This commit is contained in:
douboer
2025-10-16 18:10:27 +08:00
parent 411b7bbdb4
commit 8d40fbb01f
10 changed files with 1030 additions and 29 deletions

View File

@@ -11,28 +11,41 @@ export interface ProgressOptions {
autoHide?: boolean;
}
export class ProgressIndicator {
private notice: Notice | null = null;
class GlobalProgressManager {
private static instance: GlobalProgressManager | null = null;
private currentNotice: Notice | null = null;
private startTime: number = 0;
static getInstance(): GlobalProgressManager {
if (!GlobalProgressManager.instance) {
GlobalProgressManager.instance = new GlobalProgressManager();
}
return GlobalProgressManager.instance;
}
start(message: string, options: ProgressOptions = {}): void {
this.startTime = Date.now();
const { duration = 0 } = options;
// 如果已有通知,先关闭
if (this.currentNotice) {
this.currentNotice.hide();
}
this.notice = new Notice(`🔄 ${message}...`, duration);
this.startTime = Date.now();
const { duration = 10000 } = options; // 默认10秒自动消失防止卡住
this.currentNotice = new Notice(`🔄 ${message}...`, duration);
}
update(message: string, progress?: number): void {
if (!this.notice) return;
if (!this.currentNotice) return;
const progressText = progress ? ` (${Math.round(progress)}%)` : '';
this.notice.setMessage(`🔄 ${message}${progressText}...`);
const progressText = progress !== undefined ? ` (${Math.round(progress)}%)` : '';
this.currentNotice.setMessage(`🔄 ${message}${progressText}...`);
}
finish(message: string, success: boolean = true): void {
if (this.notice) {
this.notice.hide();
this.notice = null;
if (this.currentNotice) {
this.currentNotice.hide();
this.currentNotice = null;
}
const duration = Date.now() - this.startTime;
@@ -43,17 +56,49 @@ export class ProgressIndicator {
}
error(message: string): void {
this.finish(message, false);
if (this.currentNotice) {
this.currentNotice.hide();
this.currentNotice = null;
}
const duration = Date.now() - this.startTime;
const durationText = duration > 1000 ? ` (${(duration / 1000).toFixed(1)}s)` : '';
new Notice(`${message}${durationText}`, 5000);
}
hide(): void {
if (this.notice) {
this.notice.hide();
this.notice = null;
if (this.currentNotice) {
this.currentNotice.hide();
this.currentNotice = null;
}
}
}
export class ProgressIndicator {
private manager = GlobalProgressManager.getInstance();
start(message: string, options: ProgressOptions = {}): void {
this.manager.start(message, options);
}
update(message: string, progress?: number): void {
this.manager.update(message, progress);
}
finish(message: string, success: boolean = true): void {
this.manager.finish(message, success);
}
error(message: string): void {
this.manager.error(message);
}
hide(): void {
this.manager.hide();
}
}
export class BatchProgressIndicator {
private currentProgress: ProgressIndicator | null = null;
private totalItems: number = 0;