in src/com.jetbrains.youtrack.sdPlugin/app.js [104:173]
start() {
let restartPeriodicPoll = () => {
this.destroy();
IndicateOngoingRefresh();
this.timers.newPeriodicTask("periodic-poll", refreshValue, this.settings["refresh-interval"] * 1000 || 60 * 1000);
}
let sendRequest = async () => {
let ticketCount = await this.youTrack.GetTicketsCount();
let count = -1;
try {
count = ticketCount.toString();
} catch (e) {
console.error("Could not get ticket count from response: ", +ticketCount);
}
if (this.settings["hide-zero"] === "on" && ticketCount === 0) {
count = "";
}
return count;
}
let refreshValue = async () => {
let ticketCount = await sendRequest()
this.timers.stopByName("refreshIndicator")
if (ticketCount !== -1) {
updateLastResult(ticketCount)
setTileValue(ticketCount)
} else {
setTileValue("!ERR")
}
}
let updateLastResult = (ticketCount) => {
this.settings["last-result"] = ticketCount;
$SD.setSettings(this.context, this.settings);
}
let IndicateOngoingRefresh = (wait = 500) => {
let dots = "";
let title = "";
let indicatorFunction = () => {
dots += ".";
if (dots.length > 3) {
dots = "";
}
// If there is a cached result, blinks the title while polling (indicating that the cached result is shown)
if (this.settings["last-result"] && this.settings["last-result"] !== "" && this.settings["last-result"] !== undefined) {
if (dots.length % 2 !== 0) {
title = this.settings["last-result"];
} else {
title = "♻"
}
} else {
title = dots;
}
if (this.timers.timerNameExists("refreshIndicator")) {
setTileValue(title);
}
}
this.timers.newPeriodicTask("refreshIndicator", indicatorFunction, wait);
}
let setTileValue = (str) => {
let name = this.settings["yt-search-name"] || "";
let title = name.length > 0 ? name + "\n" + str : str;
// console.log("setting title to: " + title.replace(/\n/g, "\\n"));
$SD.setTitle(this.context, title);
}
this.fillYTSettings(this.settings);
restartPeriodicPoll()
}