2019-12-18 15:57:02 +09:00
|
|
|
import log from 'electron-log';
|
|
|
|
|
2019-11-09 17:29:02 +09:00
|
|
|
export interface AnimationQueueObject {
|
|
|
|
context: any;
|
|
|
|
func: (...args: any[]) => Promise<any>;
|
|
|
|
args: any[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export class AnimationQueue {
|
|
|
|
private running = false;
|
|
|
|
private queue: AnimationQueueObject[] = [];
|
|
|
|
|
|
|
|
push(o: AnimationQueueObject): void {
|
|
|
|
if (this.running) {
|
|
|
|
this.queue.push(o);
|
|
|
|
} else {
|
|
|
|
this.running = true;
|
|
|
|
this.animate(o);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
animate(o: AnimationQueueObject): void {
|
|
|
|
const self = this;
|
|
|
|
try {
|
|
|
|
(o.func.apply(o.context, o.args) as Promise<any>)
|
|
|
|
.then(() => {
|
|
|
|
if (self.queue.length > 0) {
|
|
|
|
self.animate.call(self, self.queue.shift());
|
|
|
|
} else {
|
|
|
|
self.running = false;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(reason => {
|
2019-12-18 15:57:02 +09:00
|
|
|
log.error(reason);
|
2019-11-09 17:29:02 +09:00
|
|
|
});
|
|
|
|
} catch (e) {
|
2019-12-18 15:57:02 +09:00
|
|
|
log.error(e);
|
2019-11-09 17:29:02 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
clear(): void {
|
|
|
|
this.queue = [];
|
|
|
|
}
|
|
|
|
}
|