mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-10-13 12:52:31 +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 { ButtonComponent } from "@/deps.ts";
|
||||||
import { App, FuzzySuggestModal, MarkdownRenderer, Modal, Plugin, Setting } from "../../../deps.ts";
|
import { App, FuzzySuggestModal, MarkdownRenderer, Modal, Plugin, Setting } from "../../../deps.ts";
|
||||||
import { EVENT_PLUGIN_UNLOADED, eventHub } from "../../../common/events.ts";
|
import { EVENT_PLUGIN_UNLOADED, eventHub } from "../../../common/events.ts";
|
||||||
|
import { compatGlobal } from "@lib/common/coreEnvFunctions.ts";
|
||||||
|
|
||||||
class AutoClosableModal extends Modal {
|
class AutoClosableModal extends Modal {
|
||||||
_closeByUnload() {
|
_closeByUnload() {
|
||||||
@@ -121,7 +122,7 @@ export class PopoverSelectString extends FuzzySuggestModal<string> {
|
|||||||
this.callback = undefined;
|
this.callback = undefined;
|
||||||
}
|
}
|
||||||
override onClose(): void {
|
override onClose(): void {
|
||||||
setTimeout(() => {
|
compatGlobal.setTimeout(() => {
|
||||||
if (this.callback) {
|
if (this.callback) {
|
||||||
this.callback("");
|
this.callback("");
|
||||||
this.callback = undefined;
|
this.callback = undefined;
|
||||||
@@ -139,7 +140,7 @@ export class MessageBox<T extends readonly string[]> extends AutoClosableModal {
|
|||||||
isManuallyClosed = false;
|
isManuallyClosed = false;
|
||||||
defaultAction: string | undefined;
|
defaultAction: string | undefined;
|
||||||
timeout: number | undefined;
|
timeout: number | undefined;
|
||||||
timer: ReturnType<typeof setInterval> | undefined = undefined;
|
timer: ReturnType<typeof compatGlobal.setInterval> | undefined = undefined;
|
||||||
defaultButtonComponent: ButtonComponent | undefined;
|
defaultButtonComponent: ButtonComponent | undefined;
|
||||||
wideButton: boolean;
|
wideButton: boolean;
|
||||||
|
|
||||||
@@ -165,12 +166,12 @@ export class MessageBox<T extends readonly string[]> extends AutoClosableModal {
|
|||||||
this.timeout = timeout;
|
this.timeout = timeout;
|
||||||
this.wideButton = wideButton;
|
this.wideButton = wideButton;
|
||||||
if (this.timeout) {
|
if (this.timeout) {
|
||||||
this.timer = setInterval(() => {
|
this.timer = compatGlobal.setInterval(() => {
|
||||||
if (this.timeout === undefined) return;
|
if (this.timeout === undefined) return;
|
||||||
this.timeout--;
|
this.timeout--;
|
||||||
if (this.timeout < 0) {
|
if (this.timeout < 0) {
|
||||||
if (this.timer) {
|
if (this.timer) {
|
||||||
clearInterval(this.timer);
|
compatGlobal.clearInterval(this.timer);
|
||||||
this.defaultButtonComponent?.setButtonText(`${defaultAction}`);
|
this.defaultButtonComponent?.setButtonText(`${defaultAction}`);
|
||||||
this.timer = undefined;
|
this.timer = undefined;
|
||||||
}
|
}
|
||||||
@@ -213,7 +214,7 @@ export class MessageBox<T extends readonly string[]> extends AutoClosableModal {
|
|||||||
if (this.timer) {
|
if (this.timer) {
|
||||||
labelWrapper.empty();
|
labelWrapper.empty();
|
||||||
labelWrapper.style.display = "none";
|
labelWrapper.style.display = "none";
|
||||||
clearInterval(this.timer);
|
compatGlobal.clearInterval(this.timer);
|
||||||
this.timer = undefined;
|
this.timer = undefined;
|
||||||
this.defaultButtonComponent?.setButtonText(`${this.defaultAction}`);
|
this.defaultButtonComponent?.setButtonText(`${this.defaultAction}`);
|
||||||
}
|
}
|
||||||
@@ -224,7 +225,7 @@ export class MessageBox<T extends readonly string[]> extends AutoClosableModal {
|
|||||||
this.isManuallyClosed = true;
|
this.isManuallyClosed = true;
|
||||||
this.result = button;
|
this.result = button;
|
||||||
if (this.timer) {
|
if (this.timer) {
|
||||||
clearInterval(this.timer);
|
compatGlobal.clearInterval(this.timer);
|
||||||
this.timer = undefined;
|
this.timer = undefined;
|
||||||
}
|
}
|
||||||
this.close();
|
this.close();
|
||||||
@@ -247,7 +248,7 @@ export class MessageBox<T extends readonly string[]> extends AutoClosableModal {
|
|||||||
const { contentEl } = this;
|
const { contentEl } = this;
|
||||||
contentEl.empty();
|
contentEl.empty();
|
||||||
if (this.timer) {
|
if (this.timer) {
|
||||||
clearInterval(this.timer);
|
compatGlobal.clearInterval(this.timer);
|
||||||
this.timer = undefined;
|
this.timer = undefined;
|
||||||
}
|
}
|
||||||
if (this.isManuallyClosed) {
|
if (this.isManuallyClosed) {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
hiddenFilesProcessingCount,
|
hiddenFilesProcessingCount,
|
||||||
} from "../../lib/src/mock_and_interop/stores.ts";
|
} from "../../lib/src/mock_and_interop/stores.ts";
|
||||||
import type { LiveSyncCore } from "../../main.ts";
|
import type { LiveSyncCore } from "../../main.ts";
|
||||||
|
import { compatGlobal } from "@lib/common/coreEnvFunctions.ts";
|
||||||
|
|
||||||
export class ModuleObsidianEvents extends AbstractObsidianModule {
|
export class ModuleObsidianEvents extends AbstractObsidianModule {
|
||||||
_everyOnloadStart(): Promise<boolean> {
|
_everyOnloadStart(): Promise<boolean> {
|
||||||
@@ -222,9 +223,9 @@ export class ModuleObsidianEvents extends AbstractObsidianModule {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
this.plugin.registerInterval(
|
this.plugin.registerInterval(
|
||||||
setInterval(() => {
|
compatGlobal.setInterval(() => {
|
||||||
__tick.value++;
|
__tick.value++;
|
||||||
}, 1000) as unknown as number
|
}, 1000)
|
||||||
);
|
);
|
||||||
|
|
||||||
let stableCheck = 3;
|
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 { isPlainText, stripPrefix } from "../../../lib/src/string_and_binary/path.ts";
|
||||||
import { scheduleOnceIfDuplicated } from "octagonal-wheels/concurrency/lock";
|
import { scheduleOnceIfDuplicated } from "octagonal-wheels/concurrency/lock";
|
||||||
import type { LiveSyncBaseCore } from "@/LiveSyncBaseCore.ts";
|
import type { LiveSyncBaseCore } from "@/LiveSyncBaseCore.ts";
|
||||||
|
import { compatGlobal } from "@lib/common/coreEnvFunctions.ts";
|
||||||
|
|
||||||
function isImage(path: string) {
|
function isImage(path: string) {
|
||||||
const ext = path.split(".").splice(-1)[0].toLowerCase();
|
const ext = path.split(".").splice(-1)[0].toLowerCase();
|
||||||
@@ -501,9 +502,9 @@ export class DocumentHistoryModal extends Modal {
|
|||||||
searchInput.addClass("history-search-input");
|
searchInput.addClass("history-search-input");
|
||||||
searchInput.addEventListener("input", () => {
|
searchInput.addEventListener("input", () => {
|
||||||
if (this.searchTimeout) {
|
if (this.searchTimeout) {
|
||||||
clearTimeout(this.searchTimeout);
|
compatGlobal.clearTimeout(this.searchTimeout);
|
||||||
}
|
}
|
||||||
this.searchTimeout = window.setTimeout(() => {
|
this.searchTimeout = compatGlobal.setTimeout(() => {
|
||||||
void this.performSearch(searchInput.value);
|
void this.performSearch(searchInput.value);
|
||||||
}, 500);
|
}, 500);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user