Skip to content

Commit 6b77287

Browse files
committed
plugin: add background metadata refresh
1 parent cebd2af commit 6b77287

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

plugin/src/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ import { type App, Plugin } from "obsidian";
66
import { TodoistApiClient } from "@/api";
77
import { ObsidianFetcher } from "@/api/fetcher";
88
import { registerCommands } from "@/commands";
9+
import { secondsToMillis } from "@/infra/time";
910
import { QueryInjector } from "@/query/injector";
1011
import { makeServices, type Services } from "@/services";
1112
import { type Settings, useSettingsStore } from "@/settings";
1213
import { SettingsTab } from "@/ui/settings";
1314

15+
// biome-ignore lint/style/noMagicNumbers: 600 seconds is easily recognizable as 10 minutes
16+
const metadataSyncIntervalMs = secondsToMillis(600);
17+
1418
// biome-ignore lint/style/noDefaultExport: We must use default export for Obsidian plugins
1519
export default class TodoistPlugin extends Plugin {
1620
public readonly services: Services;
@@ -36,6 +40,12 @@ export default class TodoistPlugin extends Plugin {
3640
this.app.workspace.onLayoutReady(async () => {
3741
await this.loadApiClient();
3842
});
43+
44+
this.registerInterval(
45+
window.setInterval(async () => {
46+
await this.services.todoist.sync();
47+
}, metadataSyncIntervalMs),
48+
);
3949
}
4050

4151
private async loadApiClient(): Promise<void> {

0 commit comments

Comments
 (0)