From 22a4fa4a539e0eddad4110e7db0829a763a917f4 Mon Sep 17 00:00:00 2001 From: CK <69121180+TfTHacker@users.noreply.github.com> Date: Wed, 6 Oct 2021 17:59:04 +0200 Subject: [PATCH] 0.3 Add repo button in settings --- README.md | 3 ++- manifest.json | 2 +- src/AddNewPluginModal.ts | 19 +++++++++++++++++-- src/BetaPlugins.ts | 6 +++--- src/SettingsTab.ts | 10 ++++++++++ src/main.ts | 2 +- src/settings.ts | 2 +- 7 files changed, 35 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e5236a7..67687cb 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,8 @@ Please note, it might take 5 to 15 minutes for an updated beta plugin to update. ## See if there are upates, but don't update them The command palette command "Only check for updates to beta plugins, but don't Update" will look for updates to beta plugins, but will not do any updates. -## TBD - manually update one plugin +## Manually update one plugin +To update just a specific plugin, use the "Choose a single plugin to update" command in the command palette. ## Restart a plugin You may not need this often, but this is a useful feature for developers. Using the Restart a plugin command from command palette, you can force a plugin to be reloaded. diff --git a/manifest.json b/manifest.json index 2a4429e..88c94fd 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian42-brat", "name": "Obsidian42 - BRAT", - "version": "0.2", + "version": "0.3", "minAppVersion": "0.9.12", "description": "Easi.y install a beta version of a plugin for testing.", "author": "TfTHacker", diff --git a/src/AddNewPluginModal.ts b/src/AddNewPluginModal.ts index 4f0fe06..2a698a8 100644 --- a/src/AddNewPluginModal.ts +++ b/src/AddNewPluginModal.ts @@ -10,12 +10,14 @@ export default class AddNewPluginModal extends Modal { plugin: ThePlugin; betaPlugins: BetaPlugins; address: string; + openSettingsTabAfterwards: boolean; - constructor(plugin: ThePlugin, betaPlugins: BetaPlugins) { + constructor(plugin: ThePlugin, betaPlugins: BetaPlugins, openSettingsTabAfterwards = false) { super(plugin.app); this.plugin = plugin; this.betaPlugins = betaPlugins; this.address = ""; + this.openSettingsTabAfterwards = openSettingsTabAfterwards; } async submitForm(): Promise { @@ -26,7 +28,9 @@ export default class AddNewPluginModal extends Modal { return; } const result = await this.betaPlugins.addPlugin(scrubbedAddress); - if (result) this.close(); + if (result) { + this.close(); + } } onOpen(): void { @@ -70,4 +74,15 @@ export default class AddNewPluginModal extends Modal { }); }); } + + async onClose(): Promise { + console.log('close',this.openSettingsTabAfterwards) + if(this.openSettingsTabAfterwards) { + //@ts-ignore + await this.plugin.app.setting.open(); + //@ts-ignore + await this.plugin.app.setting.openTabById("obsidian42-brat"); + } + + } } \ No newline at end of file diff --git a/src/BetaPlugins.ts b/src/BetaPlugins.ts index 092e59b..01bde85 100644 --- a/src/BetaPlugins.ts +++ b/src/BetaPlugins.ts @@ -25,11 +25,11 @@ export default class BetaPlugins { /** * opens the AddNewPluginModal to get info for a new beta plugin - * + * @param {boolean} openSettingsTabAfterwards will open settings screen afterwards. Used when this command is called from settings tab * @return {} */ - async displayAddNewPluginModal(): Promise { - const newPlugin = new AddNewPluginModal(this.plugin, this); + async displayAddNewPluginModal(openSettingsTabAfterwards = false): Promise { + const newPlugin = new AddNewPluginModal(this.plugin, this, openSettingsTabAfterwards); newPlugin.open(); } diff --git a/src/SettingsTab.ts b/src/SettingsTab.ts index a5329c5..256f71d 100644 --- a/src/SettingsTab.ts +++ b/src/SettingsTab.ts @@ -36,6 +36,16 @@ export class SettingsTab extends PluginSettingTab { .createEl("b", { text: "Note: " }) containerEl.createSpan({ text: "This does not delete the plugin, this should be done from the Community Plugins tab in Settings." }); + new Setting(containerEl) + .addButton((cb: ButtonComponent)=>{ + cb.setButtonText("Add Beta plugin") + cb.onClick(async ()=>{ + // @ts-ignore + this.plugin.app.setting.close(); + await this.plugin.betaPlugins.displayAddNewPluginModal(true); + }) + }); + for (const bp of this.plugin.settings.pluginList) { new Setting(containerEl) .setName(bp) diff --git a/src/main.ts b/src/main.ts index 9da27fb..1b91f51 100644 --- a/src/main.ts +++ b/src/main.ts @@ -37,7 +37,7 @@ export default class ThePlugin extends Plugin { this.addCommand({ id: "BRAT-updateOnePlugin", - name: "Update a plugin if an update is available", + name: "Choose a single plugin to update", callback: async () => { const pluginList: SuggesterItem[] = Object.values(this.settings.pluginList).map((m) => { return { display: m, info: m } }); const gfs = new GenericFuzzySuggester(this); diff --git a/src/settings.ts b/src/settings.ts index 966f1dc..677a68d 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -20,7 +20,7 @@ export const DEFAULT_SETTINGS: Settings = { */ export async function addBetaPluginToList(plugin: ThePlugin, repositoryPath: string): Promise { if (!plugin.settings.pluginList.contains(repositoryPath)) { - plugin.settings.pluginList.push(repositoryPath); + plugin.settings.pluginList.unshift(repositoryPath); plugin.saveSettings(); } }