Skip to content

Commit

Permalink
0.2 Beta update
Browse files Browse the repository at this point in the history
  • Loading branch information
TfTHacker committed Oct 6, 2021
1 parent 41edb66 commit c48c176
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 25 deletions.
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@
Simply add the GitHub repository path for the beta Obsidian plugin to the list for testing and now you can just check for updates. Updates are downloaded and the plugin is reloaded. No more having to create folders, download files, copy them to right place and so on. This plugin takes care of all that for you.

# How to use the plugin
The first thing you need is the GitHub Repository path for the beta plugin. This sounds way more complicated than it is. Plugins are developed using GitHub. Each developer has their own account on GitHub and create a unique repository for their plugin. Likely the developer will give you this information, but you can ascertain it for yourself using your own powerful brain.
The first thing you need is the GitHub Repository path for the beta plugin. This sounds way more complicated than it is. Plugins are developed using GitHub. Each developer has their own account on GitHub and creates a unique repository for their plugin. Likely the developer will give you this information, but you can ascertain it for yourself using your own powerful ability to think, reason and understand.

This is the info you need: The GitHub user name for the developer followed by the repository name. So for example, for this plugin, the repository is located at: `https://github.com/TfTHacker/obsidian42-brat`. From this, you can ignore "https://github.com". But the next block of text is the user name, then a forward slash / then the repository name. So the GitHub repository path in this case is:

`TfTHacker/obsidian42-brat`

That is all you need. Once you have the repository path, open the command palette and find the "Add a beta plugin for testing" command and then you will be prompted for the repository path. Once you add it, this will install the beta plugin into your vault.

## Check for Updates
From the command palette, use the "Check for updates to beta plugins" to check if there are updates. Updates will be downloaded, installed and the plugin will reload so that you can continue testing.
## Updating beta plugins
From the command palette, use the "Check for updates to beta plugins and UPDATE" to check if there are updates. Updates will be downloaded, installed and the plugin will reload so that you can continue testing.

Also, in the settings tab for BRAT, you can configure that at startup of Obsidian that all beta plugins are checked for updates.

Please note, it might 5 to 15 minutes for an updated beta plugin to update. This has to do with how GitHub caches information. So, if the developer tells you an update is available, you might need to wait a brief period of time before check updates works.
Please note, it might take 5 to 15 minutes for an updated beta plugin to update. This has to do with how GitHub caches information. So, if the developer tells you an update is available, you might need to wait a brief period of time before check updates works.

## 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

## 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 All @@ -29,10 +34,18 @@ Most of you won't need this, but its useful to developers. I bet you wish I told
# Special notes for Developers
The following is a brief explanation of how the plugin works.

BRAT examines your repository looking first for a manifest-beta.json. If it finds this file, it will use that file for information about which GitHub release to use from your repository. If that file doesn't exists, it uses the default manifest.json file for your plugin.
Obsidian looks at a plugin repository for a manifest.json file in the root folder of the repository. The manifest.json file contains a version number for the plugin. Obsidian uses that version number to look for a "release" in that GitHub repository with the same version number. Once the matching release is found based on that version number, the main.js, manifest.json and styles.css are downloaded by Obsidian and installed into your vault. BRAT doesn't replace this process, rather it uses the same process. BRAT emulates the Obsidian install/update process.

BRAT adds one addditional feature. You can also define in the root of your plugin repository another file called manifest-beta.json which is used by BRAT to override the version number in manifest.json. This gives two advantages: (1) your plugin once released continues to use the required manifest.json file, however (2) you can continue to do beta testing on your plugin with the manifest-beta.json file. So your testers in this case would not install your plugin via the commmunity plugins tab in Settings, rather they would use BRAT to install your plugin which will use manifest-beta.json. In effect you then have a "live" channel for your plugin and a "beta" channel for your plugin.

With that in mind, BRAT examines your repository looking FIRST for a manifest-beta.json. If it finds this file, it will use that file for information about which GitHub release to use from your repository for beta testing. If a manifest-beta.json file doesn't exists, BRAT will then use the default manifest.json file in the root directory of the repository for testing your plugin.

This allows you to control what release version beta testers are using, while leaving the "published" version available to the general community plugins list.

If you choose to use manifest-beta.json, it needs to be formatted with the same structure of a manifest.json file.
If you choose to use manifest-beta.json, it needs to be formatted with the same structure of a manifest.json file. Again, manifest-beta.json file is completly optional.

Again, manifest-beta.json file is completly optional. However there needs to be at least one of these files.
Few additional notes:
* manifest-beta.json does not need to be in the GitHub release, it just needs to be on the root of the repository itself.
* manifest-beta.json should have the exact same details as your manifest.json file, except the version number in this file should point to the release you want tested.
* A GitHub release must contain a main.js and a manifest.json file. The styles.css file is optional.
* For additional instructions on plugin requirements, see the plugins documentation provided by obsidian: [Obsidian Sample Plugin](https://github.com/obsidianmd/obsidian-sample-plugin)
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.12",
"version": "0.2",
"minAppVersion": "0.9.12",
"description": "Easi.y install a beta version of a plugin for testing.",
"author": "TfTHacker",
Expand Down
33 changes: 21 additions & 12 deletions src/BetaPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ export default class BetaPlugins {
* existing plugins.
*
* @param {string} repositoryPath path to GitHub repository formated as USERNAME/repository
* @param {[type]} updatePluginFiles true if this is just an update not an install
* @param {boolean} updatePluginFiles true if this is just an update not an install
* @param {boolean} seeIfUpdatedOnly if true, and updatePluginFiles true, will just check for updates, but not do the update. will report to user that there is a new plugin
* @param {boolean} reportIfNotUpdted if true, report if an update has not succed
*
* @return {Promise<boolean>} true if succeeds
*/
async addPlugin(repositoryPath: string, updatePluginFiles = false): Promise<boolean> {
async addPlugin(repositoryPath: string, updatePluginFiles = false, seeIfUpdatedOnly = false, reportIfNotUpdted = false): Promise<boolean> {
const manifestJson = await this.validateRepository(repositoryPath, false, true);
const noticeTimeout = 60000;
if (manifestJson === null) return false;
Expand Down Expand Up @@ -147,10 +149,15 @@ export default class BetaPlugins {
}
const localManifestJSON = await JSON.parse(localManifestContents);
if (localManifestJSON.version !== remoteManifestJSON.version) { //manifest files are not the same, do an update
await this.writeReleaseFilesToPluginFolder(remoteManifestJSON.id, releaseFiles);
await this.reloadPlugin(remoteManifestJSON.id)
new Notice(`BRAT\n${remoteManifestJSON.id}\nplugin has been updated and reloaded`, noticeTimeout);
}
if (seeIfUpdatedOnly) { // dont update, just report it
new Notice(`BRAT\nThere is an update available for ${remoteManifestJSON.id}`);
} else {
await this.writeReleaseFilesToPluginFolder(remoteManifestJSON.id, releaseFiles);
await this.reloadPlugin(remoteManifestJSON.id)
new Notice(`BRAT\n${remoteManifestJSON.id}\nplugin has been updated and reloaded`, noticeTimeout);
}
} else
if (reportIfNotUpdted) new Notice(`BRAT\nNo update available for ${repositoryPath}`, 3000);
}
return true;
}
Expand All @@ -175,14 +182,16 @@ export default class BetaPlugins {
/**
* updates a beta plugin
*
* @param {string<void>} repositoryPath repository path on GitHub
* @param {string} repositoryPath repository path on GitHub
* @param {boolean} onlyCheckDontUpdate only looks for update
*
* @return {Promise<void>}
*/
async updatePlugin(repositoryPath: string): Promise<void> {
const result = await this.addPlugin(repositoryPath, true);
if (result === false)
async updatePlugin(repositoryPath: string, onlyCheckDontUpdate = false, reportIfNotUpdted = false): Promise<boolean> {
const result = await this.addPlugin(repositoryPath, true, onlyCheckDontUpdate, reportIfNotUpdted);
if (result === false && onlyCheckDontUpdate === false)
new Notice(`BRAT\n${repositoryPath}\nUpdate of plugin failed.`)
return result;
}

/**
Expand All @@ -191,10 +200,10 @@ export default class BetaPlugins {
* @param {boolean} showInfo should this with a started/completed message - useful when ran from CP
* @return {Promise<void>}
*/
async checkForUpdates(showInfo = false): Promise<void> {
async checkForUpdatesAndInstallUpdates(showInfo = false, onlyCheckDontUpdate = false): Promise<void> {
if (showInfo) new Notice(`BRAT\nChecking for plugin updates STARTED`, 30000);
for (const bp of this.plugin.settings.pluginList) {
await this.updatePlugin(bp)
await this.updatePlugin(bp, onlyCheckDontUpdate);
}
if (showInfo) new Notice(`BRAT\nChecking for plugin updates COMPLETED`, 10000);
}
Expand Down
30 changes: 25 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,33 @@ export default class ThePlugin extends Plugin {
});

this.addCommand({
id: "BRAT-checkForUpdates",
name: "Check for updates to beta plugins",
callback: async () => { await this.betaPlugins.checkForUpdates(true) }
id: "BRAT-checkForUpdatesAndUpdate",
name: "Check for updates to all beta plugins and UPDATE",
callback: async () => { await this.betaPlugins.checkForUpdatesAndInstallUpdates(true, false) }
});

this.addCommand({
id: "BRAT-restart plugin",
id: "BRAT-checkForUpdatesAndDontUpdate",
name: "Only check for updates to beta plugins, but don't Update",
callback: async () => { await this.betaPlugins.checkForUpdatesAndInstallUpdates(true, true) }
});

this.addCommand({
id: "BRAT-updateOnePlugin",
name: "Update a plugin if an update is available",
callback: async () => {
const pluginList: SuggesterItem[] = Object.values(this.settings.pluginList).map((m) => { return { display: m, info: m } });
const gfs = new GenericFuzzySuggester(this);
gfs.setSuggesterData(pluginList);
await gfs.display(async (results) => {
new Notice(`BRAT\nChecking for updates for ${results.info}`,3000);
await this.betaPlugins.updatePlugin(results.info, false, true);
});
}
});

this.addCommand({
id: "BRAT-restartPlugin",
name: "Restart a plugin that is already installed",
callback: async () => {
// @ts-ignore
Expand All @@ -46,7 +66,7 @@ export default class ThePlugin extends Plugin {

this.app.workspace.onLayoutReady((): void => {
if (this.settings.updateAtStartup) // let obsidian load and calm down before check
setTimeout(async () => { await this.betaPlugins.checkForUpdates(false) }, 60000);
setTimeout(async () => { await this.betaPlugins.checkForUpdatesAndInstallUpdates(false) }, 60000);
});
}

Expand Down

0 comments on commit c48c176

Please sign in to comment.