fix: update autoSyncTimeout type and ensure window context for setTimeout calls

This commit is contained in:
Jiaxin Peng
2025-11-01 00:32:35 +00:00
parent 2738498dc2
commit e2a965e3d6

View File

@@ -13,7 +13,7 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
commands: ribbonCommands; commands: ribbonCommands;
app: App; app: App;
modifyEventRef: EventRef | null = null; modifyEventRef: EventRef | null = null;
autoSyncTimeout: NodeJS.Timeout | null = null; autoSyncTimeout: number | null = null;
private syncingFiles: Set<string> = new Set(); private syncingFiles: Set<string> = new Set();
private lastFrontmatterCache: Map<string, any> = new Map(); private lastFrontmatterCache: Map<string, any> = new Map();
private lastContentHashCache: Map<string, string> = new Map(); private lastContentHashCache: Map<string, string> = new Map();
@@ -207,7 +207,7 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
// Set a new timeout to trigger sync after user-configured delay (in seconds) // Set a new timeout to trigger sync after user-configured delay (in seconds)
const delayMs = (this.settings.autoSyncDelay || 2) * 1000; const delayMs = (this.settings.autoSyncDelay || 2) * 1000;
this.autoSyncTimeout = setTimeout(async () => { this.autoSyncTimeout = window.setTimeout(async () => {
await this.autoSyncFile(file); await this.autoSyncFile(file);
}, delayMs); }, delayMs);
}); });
@@ -380,7 +380,7 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
// After sync completes, update cache with the latest frontmatter (including updated NotionIDs) // After sync completes, update cache with the latest frontmatter (including updated NotionIDs)
// Wait a bit for metadata cache to update // Wait a bit for metadata cache to update
setTimeout(async () => { window.setTimeout(async () => {
const updatedFrontmatter = this.app.metadataCache.getFileCache(file)?.frontmatter; const updatedFrontmatter = this.app.metadataCache.getFileCache(file)?.frontmatter;
const updatedContent = await this.app.vault.read(file); const updatedContent = await this.app.vault.read(file);
const updatedHash = this.simpleHash(updatedContent); const updatedHash = this.simpleHash(updatedContent);