From 0c8fed2543ee1413baff4c739c960831c8424835 Mon Sep 17 00:00:00 2001 From: Mara Date: Mon, 6 May 2024 09:42:26 +0200 Subject: [PATCH] feat: allow two commands to refresh set without reloading the plugin or obsidian --- src/commands/callback.ts | 28 ++++++++++++++++++---------- src/commands/file_menu.ts | 1 - 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/commands/callback.ts b/src/commands/callback.ts index 95a32354..d909da23 100644 --- a/src/commands/callback.ts +++ b/src/commands/callback.ts @@ -258,14 +258,15 @@ export function refreshOpenedSet(plugin: GithubPublisher) { if (!file) return []; return plugin.settings.github.otherRepo.filter((repo) => repo.set === file.path); }; - const file = plugin.app.workspace.getActiveFile(); + return { id: "publisher-refresh-opened-set", name: i18next.t("commands.refreshOpenedSet"), checkCallback: (checking) => { - if (file && findRepo(file).length > 0) { + const file = plugin.app.workspace.getActiveFile(); + const repos = findRepo(file); + if (file && repos.length > 0) { if (!checking) { - const repos = findRepo(file); repos.forEach((repo) => { plugin.repositoryFrontmatter[repo.smartKey] = plugin.app.metadataCache.getFileCache(file)?.frontmatter; }); @@ -281,13 +282,20 @@ export function refreshAllSets(plugin: GithubPublisher) { return { id: "publisher-refresh-all-sets", name: i18next.t("commands.refreshAllSets"), - callback: () => { - plugin.settings.github.otherRepo.forEach((repo) => { - if (!repo.set) return; - const file = plugin.app.vault.getAbstractFileByPath(repo.set); - if (!file || !(file instanceof TFile)) return; - plugin.repositoryFrontmatter[repo.smartKey] = plugin.app.metadataCache.getFileCache(file)?.frontmatter; - }); + checkCallback: (checking) => { + const allSets = plugin.settings.github.otherRepo.filter((repo) => repo.set !== "" || repo.set !== null); + if (allSets.length > 0) { + if (!checking) { + allSets.forEach((repo) => { + if (!repo.set) return; + const file = plugin.app.vault.getAbstractFileByPath(repo.set); + if (!file || !(file instanceof TFile)) return; + plugin.repositoryFrontmatter[repo.smartKey] = plugin.app.metadataCache.getFileCache(file)?.frontmatter; + }); + } + return true; + } + return false; } } as Command; } \ No newline at end of file diff --git a/src/commands/file_menu.ts b/src/commands/file_menu.ts index 60e45997..401d1959 100644 --- a/src/commands/file_menu.ts +++ b/src/commands/file_menu.ts @@ -137,7 +137,6 @@ export function addMenuFile(plugin: GithubPublisher, file: TFile, branchName: st return; } const fileName = plugin.getTitleFieldForCommand(file, plugin.app.metadataCache.getFileCache(file)?.frontmatter).replace(".md", ""); - if (!frontmatter || !frontmatter[plugin.settings.plugin.shareKey]) { const otherRepo = plugin.settings.github.otherRepo.find((repo) => repo.shareAll?.enable); if (otherRepo) getSharedKey = otherRepo;