Skip to content

Commit

Permalink
0.4 bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TfTHacker committed Oct 7, 2021
1 parent 86d1001 commit 7ad8078
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
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.3",
"version": "0.4",
"minAppVersion": "0.9.12",
"description": "Easily install a beta version of a plugin for testing.",
"author": "TfTHacker",
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
"url": "git://github.com/TfTHacker/obsidian42-brat.git"
},
"devDependencies": {
"@types/node": "^16.9.1",
"@typescript-eslint/eslint-plugin": "^4.31.1",
"@typescript-eslint/parser": "^4.31.1",
"@types/node": "^16.10.3",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"eslint": "^7.32.0",
"obsidian": "^0.12.16",
"obsidian": "^0.12.17",
"tslib": "^2.3.1",
"typescript": "^4.4.3"
},
Expand Down
9 changes: 3 additions & 6 deletions src/AddNewPluginModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class AddNewPluginModal extends Modal {
if (this.address === "") return;
const scrubbedAddress = this.address.replace("https://github.com/","");
if (await existBetaPluginInList(this.plugin, scrubbedAddress)) {
new Notice(`BRAT\nThis plugin is already in the list for beta testing`, 20000);
new Notice(`BRAT\nThis plugin is already in the list for beta testing`, 10000);
return;
}
const result = await this.betaPlugins.addPlugin(scrubbedAddress);
Expand Down Expand Up @@ -76,12 +76,9 @@ 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");
await (this.plugin as any).app.setting.open();
await (this.plugin as any).app.setting.openTabById("obsidian42-brat");
}

}
Expand Down
24 changes: 17 additions & 7 deletions src/BetaPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class BetaPlugins {
* @return {Promise<PluginManifest>} the manifest file if found, or null if its incomplete
*/
async validateRepository(repositoryPath: string, getBetaManifest = false, reportIsues = false): Promise<PluginManifest> {
const noticeTimeout = 60000;
const noticeTimeout = 10000;
const manifestJson = await grabManifestJsonFromRepository(repositoryPath, !getBetaManifest);
if (!manifestJson) { // this is a plugin with a manifest json, try to see if there is a beta version
if (reportIsues) new Notice(`BRAT\n${repositoryPath}\nThis does not seem to be an obsidian plugin, as there is no manifest.json file.`, noticeTimeout);
Expand Down Expand Up @@ -111,24 +111,34 @@ export default class BetaPlugins {
*/
async addPlugin(repositoryPath: string, updatePluginFiles = false, seeIfUpdatedOnly = false, reportIfNotUpdted = false): Promise<boolean> {
const manifestJson = await this.validateRepository(repositoryPath, false, true);
const noticeTimeout = 60000;
const noticeTimeout = 10000;
if (manifestJson === null) return false;
const betaManifestJson = await this.validateRepository(repositoryPath, true, false);
const primaryManifest: PluginManifest = betaManifestJson ? betaManifestJson : manifestJson; // if there is a beta manifest, use that

if(!primaryManifest.hasOwnProperty('version')) {
new Notice(`BRAT\n${repositoryPath}\nThe manifest file in the root directory of the repository does not have a version number in the file. This plugin cannot be installed.`, noticeTimeout);
return false;
}

const releaseFiles = await this.getAllReleaseFiles(repositoryPath, primaryManifest)

if (releaseFiles.mainJs === "Not Found") {
new Notice(`BRAT\n${repositoryPath}\nThe release is not complete and cannot be download. main.js is missing from the release`, noticeTimeout);
if (releaseFiles.mainJs === null) {
new Notice(`BRAT\n${repositoryPath}\nThe release is not complete and cannot be download. main.js is missing from the Release`, noticeTimeout);
return false;
}

if (releaseFiles.manifest === "Not Found") {
new Notice(`BRAT\n${repositoryPath}\nThe release is not complete and cannot be download. manifest.json is missing from the release`, noticeTimeout);
if (releaseFiles.manifest === null) {
new Notice(`BRAT\n${repositoryPath}\nThe release is not complete and cannot be download. manifest.json is missing from the Release`, noticeTimeout);
return false;
}
const remoteManifestJSON = JSON.parse(releaseFiles.manifest);

if(!remoteManifestJSON.hasOwnProperty('version')) {
new Notice(`BRAT\n${repositoryPath}\nThe manifest file in the Release does not have a version number in the file. This plugin cannot be installed`, noticeTimeout);
return false;
}

if (updatePluginFiles === false) {
await this.writeReleaseFilesToPluginFolder(remoteManifestJSON.id, releaseFiles);
await addBetaPluginToList(this.plugin, repositoryPath);
Expand Down Expand Up @@ -201,7 +211,7 @@ export default class BetaPlugins {
* @return {Promise<void>}
*/
async checkForUpdatesAndInstallUpdates(showInfo = false, onlyCheckDontUpdate = false): Promise<void> {
if (showInfo) new Notice(`BRAT\nChecking for plugin updates STARTED`, 30000);
if (showInfo) new Notice(`BRAT\nChecking for plugin updates STARTED`, 10000);
for (const bp of this.plugin.settings.pluginList) {
await this.updatePlugin(bp, onlyCheckDontUpdate);
}
Expand Down
2 changes: 1 addition & 1 deletion src/githubUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const GITHUB_RAW_USERCONTENT_PATH = "https://raw.githubusercontent.com/";
export const grabReleaseFileFromRepository = async (repository: string, version: string, fileName: string): Promise<string> => {
try {
const download = await request({ url: `https://github.com/${repository}/releases/download/${version}/${fileName}` });
return (download === "Not Found" ? null : download);
return ( ( download === "Not Found" || download === `{"error":"Not Found"}`) ? null : download);
} catch (error) {
console.log("error in grabReleaseFileFromRepository", error)
}
Expand Down

0 comments on commit 7ad8078

Please sign in to comment.