Skip to content

Commit

Permalink
0.3 Add repo button in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
TfTHacker committed Oct 6, 2021
1 parent c48c176 commit 22a4fa4
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
19 changes: 17 additions & 2 deletions src/AddNewPluginModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand All @@ -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 {
Expand Down Expand Up @@ -70,4 +74,15 @@ export default class AddNewPluginModal extends Modal {
});
});
}

async onClose(): Promise<void> {
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");
}

}
}
6 changes: 3 additions & 3 deletions src/BetaPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {<Promise><void>}
*/
async displayAddNewPluginModal(): Promise<void> {
const newPlugin = new AddNewPluginModal(this.plugin, this);
async displayAddNewPluginModal(openSettingsTabAfterwards = false): Promise<void> {
const newPlugin = new AddNewPluginModal(this.plugin, this, openSettingsTabAfterwards);
newPlugin.open();
}

Expand Down
10 changes: 10 additions & 0 deletions src/SettingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const DEFAULT_SETTINGS: Settings = {
*/
export async function addBetaPluginToList(plugin: ThePlugin, repositoryPath: string): Promise<void> {
if (!plugin.settings.pluginList.contains(repositoryPath)) {
plugin.settings.pluginList.push(repositoryPath);
plugin.settings.pluginList.unshift(repositoryPath);
plugin.saveSettings();
}
}
Expand Down

0 comments on commit 22a4fa4

Please sign in to comment.