chore: wrap timer functions

This commit is contained in:
vorotamoroz
2026-05-31 19:03:43 +09:00
parent 39014b2294
commit 56a234e6d7
4 changed files with 15 additions and 12 deletions
+8 -7
View File
@@ -1,6 +1,7 @@
import { ButtonComponent } from "@/deps.ts";
import { App, FuzzySuggestModal, MarkdownRenderer, Modal, Plugin, Setting } from "../../../deps.ts";
import { EVENT_PLUGIN_UNLOADED, eventHub } from "../../../common/events.ts";
import { compatGlobal } from "@lib/common/coreEnvFunctions.ts";
class AutoClosableModal extends Modal {
_closeByUnload() {
@@ -121,7 +122,7 @@ export class PopoverSelectString extends FuzzySuggestModal<string> {
this.callback = undefined;
}
override onClose(): void {
setTimeout(() => {
compatGlobal.setTimeout(() => {
if (this.callback) {
this.callback("");
this.callback = undefined;
@@ -139,7 +140,7 @@ export class MessageBox<T extends readonly string[]> extends AutoClosableModal {
isManuallyClosed = false;
defaultAction: string | undefined;
timeout: number | undefined;
timer: ReturnType<typeof setInterval> | undefined = undefined;
timer: ReturnType<typeof compatGlobal.setInterval> | undefined = undefined;
defaultButtonComponent: ButtonComponent | undefined;
wideButton: boolean;
@@ -165,12 +166,12 @@ export class MessageBox<T extends readonly string[]> extends AutoClosableModal {
this.timeout = timeout;
this.wideButton = wideButton;
if (this.timeout) {
this.timer = setInterval(() => {
this.timer = compatGlobal.setInterval(() => {
if (this.timeout === undefined) return;
this.timeout--;
if (this.timeout < 0) {
if (this.timer) {
clearInterval(this.timer);
compatGlobal.clearInterval(this.timer);
this.defaultButtonComponent?.setButtonText(`${defaultAction}`);
this.timer = undefined;
}
@@ -213,7 +214,7 @@ export class MessageBox<T extends readonly string[]> extends AutoClosableModal {
if (this.timer) {
labelWrapper.empty();
labelWrapper.style.display = "none";
clearInterval(this.timer);
compatGlobal.clearInterval(this.timer);
this.timer = undefined;
this.defaultButtonComponent?.setButtonText(`${this.defaultAction}`);
}
@@ -224,7 +225,7 @@ export class MessageBox<T extends readonly string[]> extends AutoClosableModal {
this.isManuallyClosed = true;
this.result = button;
if (this.timer) {
clearInterval(this.timer);
compatGlobal.clearInterval(this.timer);
this.timer = undefined;
}
this.close();
@@ -247,7 +248,7 @@ export class MessageBox<T extends readonly string[]> extends AutoClosableModal {
const { contentEl } = this;
contentEl.empty();
if (this.timer) {
clearInterval(this.timer);
compatGlobal.clearInterval(this.timer);
this.timer = undefined;
}
if (this.isManuallyClosed) {