From 06598f8fef43a97e63320b5c8ef7fda0d84f0b7e Mon Sep 17 00:00:00 2001 From: CK <69121180+TfTHacker@users.noreply.github.com> Date: Wed, 3 Nov 2021 22:07:50 +0100 Subject: [PATCH] 0.5.12 Update - starting work on themes --- README.md | 3 ++- package.json | 6 +++--- src/main.ts | 35 ++++++++++++++++++++++++++++++----- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index fe0048e..e231954 100644 --- a/README.md +++ b/README.md @@ -63,9 +63,10 @@ You can enable a plugin that is currently disabled or disable a plugin that is c ## Open a GitHub repository (This is way more cool than it sounds) The command palette contains a command **BRAT: Open the GitHub repository for a plugin**. This gives you a list of all beta plugins registered with BRAT, but also all plugins from the community plugin list. By selecting a plugin from the list, the GitHub repository will be opened in your browser - Click image for video demo! +## Working with Themes +BRAT can also open Github repositories for Obsidian Themes, in addition to switching themes from the command palette. --- diff --git a/package.json b/package.json index 7d425fe..1af4941 100644 --- a/package.json +++ b/package.json @@ -17,9 +17,9 @@ "devDependencies": { "@types/node": "^16.11.6", "eslint": "^8.1.0", - "@typescript-eslint/eslint-plugin": "^5.2.0", - "@typescript-eslint/parser": "^5.2.0", - "esbuild": "0.13.8", + "@typescript-eslint/eslint-plugin": "^5.3.0", + "@typescript-eslint/parser": "^5.3.0", + "esbuild": "0.13.12", "obsidian": "^0.12.17", "tslib": "^2.3.1", "typescript": "^4.4.4" diff --git a/src/main.ts b/src/main.ts index 71007ae..5129cd3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -67,15 +67,12 @@ export default class ThePlugin extends Plugin { this.addCommand({ id: "BRAT-openGitHubRepository", - name: "Open the GitHub repository for a plugin or theme", + name: "Open the GitHub repository for a plugin", callback: async () => { const communityPlugins = await grabCommmunityPluginList(); 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) => { @@ -84,7 +81,6 @@ export default class ThePlugin extends Plugin { } }); - this.addCommand({ id: "BRAT-disablePlugin", name: "Disable a plugin - toggle it off", @@ -113,6 +109,35 @@ export default class ThePlugin extends Plugin { } }); + this.addCommand({ + id: "BRAT-openGitHubRepoTheme", + name: "Open the GitHub repository for a theme ", + callback: async () => { + const communityTheme = await grabCommmunityThemesList(); + const communityThemeList: SuggesterItem[] = Object.values(communityTheme).map((p) => { return { display: `Theme: ${p.name} (${p.repo})`, info: p.repo } }); + const gfs = new GenericFuzzySuggester(this); + gfs.setSuggesterData(communityThemeList); + await gfs.display(async (results) => { + if (results.info) window.open(`https://github.com/${results.info}`) + }); + } + }); + + this.addCommand({ + id: "BRAT-switchTheme", + name: "Switch Active Theme ", + callback: async () => { + // @ts-ignore + const communityThemeList: SuggesterItem[] = Object.values(this.app.customCss.themes).map((t) => { return { display: t, info: t } }); + const gfs = new GenericFuzzySuggester(this); + gfs.setSuggesterData(communityThemeList); + await gfs.display(async (results) => { + // @ts-ignore + this.app.customCss.setTheme(results.info); + }); + } + }); + this.app.workspace.onLayoutReady((): void => { if (this.settings.updateAtStartup) // let obsidian load and calm down before check setTimeout(async () => { await this.betaPlugins.checkForUpdatesAndInstallUpdates(false) }, 60000);