mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-06-04 05:22:58 +00:00
chore: wrap timer functions
This commit is contained in:
+1
-1
Submodule src/lib updated: 8e8944ca41...faf5c55fd7
@@ -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) {
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
hiddenFilesProcessingCount,
|
||||
} from "../../lib/src/mock_and_interop/stores.ts";
|
||||
import type { LiveSyncCore } from "../../main.ts";
|
||||
import { compatGlobal } from "@lib/common/coreEnvFunctions.ts";
|
||||
|
||||
export class ModuleObsidianEvents extends AbstractObsidianModule {
|
||||
_everyOnloadStart(): Promise<boolean> {
|
||||
@@ -222,9 +223,9 @@ export class ModuleObsidianEvents extends AbstractObsidianModule {
|
||||
);
|
||||
});
|
||||
this.plugin.registerInterval(
|
||||
setInterval(() => {
|
||||
compatGlobal.setInterval(() => {
|
||||
__tick.value++;
|
||||
}, 1000) as unknown as number
|
||||
}, 1000)
|
||||
);
|
||||
|
||||
let stableCheck = 3;
|
||||
|
||||
@@ -16,6 +16,7 @@ import { fireAndForget, getDocData, readContent } from "../../../lib/src/common/
|
||||
import { isPlainText, stripPrefix } from "../../../lib/src/string_and_binary/path.ts";
|
||||
import { scheduleOnceIfDuplicated } from "octagonal-wheels/concurrency/lock";
|
||||
import type { LiveSyncBaseCore } from "@/LiveSyncBaseCore.ts";
|
||||
import { compatGlobal } from "@lib/common/coreEnvFunctions.ts";
|
||||
|
||||
function isImage(path: string) {
|
||||
const ext = path.split(".").splice(-1)[0].toLowerCase();
|
||||
@@ -501,9 +502,9 @@ export class DocumentHistoryModal extends Modal {
|
||||
searchInput.addClass("history-search-input");
|
||||
searchInput.addEventListener("input", () => {
|
||||
if (this.searchTimeout) {
|
||||
clearTimeout(this.searchTimeout);
|
||||
compatGlobal.clearTimeout(this.searchTimeout);
|
||||
}
|
||||
this.searchTimeout = window.setTimeout(() => {
|
||||
this.searchTimeout = compatGlobal.setTimeout(() => {
|
||||
void this.performSearch(searchInput.value);
|
||||
}, 500);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user