Skip to content

Commit

Permalink
feat: allow two commands to refresh set without reloading the plugin …
Browse files Browse the repository at this point in the history
…or obsidian
  • Loading branch information
Mara-Li committed May 6, 2024
1 parent c3cd9dd commit 0c8fed2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
28 changes: 18 additions & 10 deletions src/commands/callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand All @@ -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;
}
1 change: 0 additions & 1 deletion src/commands/file_menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0c8fed2

Please sign in to comment.