Skip to content

Commit

Permalink
Github theme url opening support
Browse files Browse the repository at this point in the history
  • Loading branch information
TfTHacker committed Nov 3, 2021
1 parent e2f887d commit 7a51ea9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/githubUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,14 @@ export const grabCommmunityPluginList = async(): Promise<JSON> => {
} catch (error) {
console.log("error in grabCommmunityPluginList", error)
}
}

export const grabCommmunityThemesList = async(): Promise<JSON> => {
const themesURL = `https://raw.githubusercontent.com/obsidianmd/obsidian-releases/HEAD/community-css-themes.json`;
try {
const response = await request({ url: themesURL });
return (response === "404: Not Found" ? null : await JSON.parse(response));
} catch (error) {
console.log("error in grabCommmunityThemesList", error)
}
}
10 changes: 7 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SettingsTab } from "./SettingsTab";
import { Settings, DEFAULT_SETTINGS } from "./settings";
import BetaPlugins from "./BetaPlugins";
import { GenericFuzzySuggester, SuggesterItem } from "./GenericFuzzySuggester";
import { grabCommmunityPluginList } from "./githubUtils";
import { grabCommmunityPluginList, grabCommmunityThemesList } from "./githubUtils";

export default class ThePlugin extends Plugin {
appName = "Obsidian42 - Beta Reviewer's Auto-update Tool (BRAT)";
Expand Down Expand Up @@ -67,12 +67,15 @@ export default class ThePlugin extends Plugin {

this.addCommand({
id: "BRAT-openGitHubRepository",
name: "Open the GitHub repository for a plugin",
name: "Open the GitHub repository for a plugin or theme",
callback: async () => {
const communityPlugins = await grabCommmunityPluginList();
const communityPluginList: SuggesterItem[] = Object.values(communityPlugins).map((p) => { return { display: `Community: ${p.name} (${p.repo})`, info: p.repo } });
const communityPluginList: SuggesterItem[] = Object.values(communityPlugins).map((p) => { return { display: `Plugin: ${p.name} (${p.repo})`, info: p.repo } });
const bratList: SuggesterItem[] = Object.values(this.settings.pluginList).map((p) => { return { display: "BRAT: " + p, info: p } });
communityPluginList.forEach(si => bratList.push(si));
const communityTheme = await grabCommmunityThemesList();
const communityThemeList: SuggesterItem[] = Object.values(communityTheme).map((p) => { return { display: `Theme: ${p.name} (${p.repo})`, info: p.repo } });
communityThemeList.forEach(si => bratList.push(si));
const gfs = new GenericFuzzySuggester(this);
gfs.setSuggesterData(bratList);
await gfs.display(async (results) => {
Expand All @@ -81,6 +84,7 @@ export default class ThePlugin extends Plugin {
}
});


this.addCommand({
id: "BRAT-disablePlugin",
name: "Disable a plugin - toggle it off",
Expand Down

0 comments on commit 7a51ea9

Please sign in to comment.