Files
TheaninovOS/desktops/hyprland/ags/scripts/indicator.js
2023-11-15 16:09:26 +01:00

37 lines
756 B
JavaScript

import {Service, Utils} from "../imports.js"
const {exec, execAsync} = Utils
const clamp = (num, min, max) => Math.min(Math.max(num, min), max)
class IndicatorService extends Service {
static {
Service.register(this, {popup: ["double"]})
}
_delay = 1500
_count = 0
popup(value) {
this.emit("popup", value)
this._count++
Utils.timeout(this._delay, () => {
this._count--
if (this._count === 0) this.emit("popup", -1)
})
}
connectWidget(widget, callback) {
connect(this, widget, callback, "popup")
}
}
// the singleton instance
const service = new IndicatorService()
// make it global for easy use with cli
globalThis["indicator"] = service
// export to use in other modules
export default service