Created
September 27, 2023 15:29
-
-
Save ragusa87/f0ab3f814e8de896df2cc54d3164c080 to your computer and use it in GitHub Desktop.
Kwin script setTimeout (typescript) with QTimer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface QTimer { | |
timeout: QSignal; | |
start(durationMs: number): void; | |
stop(): void; | |
} | |
declare interface QSignal { | |
connect(callback: any): void; | |
disconnect(callback: any): void; | |
} | |
let timers: QTimer[] = []; | |
function setTimeout (callback: any, duration: number): number{ | |
// @ts-ignore QTime is exposed by KWIN/QT, so it exists anyway. | |
let timer = new QTimer(); | |
timers.push(timer); | |
timer.singleShot = true; | |
timer.timeout.connect(callback); | |
timer.start(duration); | |
return timers.length -1 | |
} | |
function cancelTimeout(timerId: number): boolean{ | |
if(timers[timerId] === undefined){ | |
return false; | |
} | |
timers[timerId].stop(); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment