Skip to content

Commit

Permalink
0.8.2 New setting to automatically enable new plugins that are installed
Browse files Browse the repository at this point in the history
  • Loading branch information
TfTHacker committed Dec 20, 2023
1 parent 4f0f8e1 commit 10369ab
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 56 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 0.8.2

### New

- A new setting controls if a beta plugin is auto-enabled after installation. This means after it is installed, it will be enabled in settings. This reduces the additional step of manually enabling a plugin after installation. This setting is now enabled by default.
- chore: update all dependencies.

# 0.8.1

### New
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": "BRAT",
"version": "0.8.1",
"version": "0.8.2",
"minAppVersion": "1.4.16",
"description": "Easily install a beta version of a plugin for testing.",
"author": "TfTHacker",
Expand Down
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,36 @@
"devDependencies": {
"typescript": "5.3.3",
"tslib": "^2.6.2",
"@types/node": "^20.10.4",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"@typescript-eslint/utils": "^6.13.2",
"@types/node": "^20.10.5",
"@typescript-eslint/eslint-plugin": "^6.15.0",
"@typescript-eslint/parser": "^6.15.0",
"@typescript-eslint/utils": "^6.15.0",
"builtin-modules": "3.3.0",
"esbuild": "0.19.9",
"eslint": "^8.55.0",
"eslint-config-prettier": "^9.0.0",
"esbuild": "0.19.10",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-css": "^0.8.1",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-jsonc": "^2.10.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsonc": "^2.11.2",
"eslint-plugin-mdx": "^3.0.0",
"eslint-plugin-only-warn": "^1.1.0",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-prettier": "^5.1.0",
"eslint-plugin-tsdoc": "^0.2.17",
"eslint-plugin-yml": "^1.10.0",
"eslint-plugin-yml": "^1.11.0",
"@html-eslint/eslint-plugin": "^0.22.0",
"@html-eslint/parser": "^0.22.0",
"husky": "^8.0.3",
"jsdom": "^23.0.0",
"jsdom": "^23.0.1",
"lint-staged": "^15.2.0",
"prettier": "^3.1.1",
"remark-preset-lint-consistent": "^5.1.2",
"remark-preset-lint-markdown-style-guide": "^5.1.3",
"remark-preset-lint-recommended": "^6.1.3",
"remark-preset-prettier": "^2.0.1",
"ts-node": "^10.9.2",
"typedoc": "^0.25.3",
"typedoc": "^0.25.4",
"@types/obsidian-typings": "github:Fevol/obsidian-typings",
"obsidian": "1.4.11"
},
Expand Down
40 changes: 22 additions & 18 deletions src/features/BetaPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default class BetaPlugins {
'manifest.json',
this.plugin.settings.debuggingMode
)
: '',
: '',
styles: await grabReleaseFileFromRepository(
repositoryPath,
version,
Expand Down Expand Up @@ -223,15 +223,16 @@ export default class BetaPlugins {
if (primaryManifest === null) {
const msg = `${repositoryPath}\nA manifest.json or manifest-beta.json file does not exist in the root directory of the repository. This plugin cannot be installed.`;
await this.plugin.log(msg, true);
toastMessage(this.plugin, `${msg}`, noticeTimeout);
toastMessage(this.plugin, msg, noticeTimeout);
return false;
}

if (!Object.hasOwn(primaryManifest, 'version')) {
const msg = `${repositoryPath}\nThe manifest${usingBetaManifest ? '-beta' : ''
}.json file in the root directory of the repository does not have a version number in the file. This plugin cannot be installed.`;
const msg = `${repositoryPath}\nThe manifest${
usingBetaManifest ? '-beta' : ''
}.json file in the root directory of the repository does not have a version number in the file. This plugin cannot be installed.`;
await this.plugin.log(msg, true);
toastMessage(this.plugin, `${msg}`, noticeTimeout);
toastMessage(this.plugin, msg, noticeTimeout);
return false;
}

Expand All @@ -240,13 +241,14 @@ export default class BetaPlugins {
if (!requireApiVersion(primaryManifest.minAppVersion)) {
const msg =
`Plugin: ${repositoryPath}\n\n` +
`The manifest${usingBetaManifest ? '-beta' : ''
`The manifest${
usingBetaManifest ? '-beta' : ''
}.json for this plugin indicates that the Obsidian ` +
`version of the app needs to be ${primaryManifest.minAppVersion}, ` +
`but this installation of Obsidian is ${apiVersion}. \n\nYou will need to update your ` +
`Obsidian to use this plugin or contact the plugin developer for more information.`;
await this.plugin.log(msg, true);
toastMessage(this.plugin, `${msg}`, 30);
toastMessage(this.plugin, msg, 30);
return false;
}
}
Expand All @@ -273,7 +275,7 @@ export default class BetaPlugins {
if (rFiles.mainJs === null) {
const msg = `${repositoryPath}\nThe release is not complete and cannot be download. main.js is missing from the Release`;
await this.plugin.log(msg, true);
toastMessage(this.plugin, `${msg}`, noticeTimeout);
toastMessage(this.plugin, msg, noticeTimeout);
return null;
}
return rFiles;
Expand All @@ -287,7 +289,9 @@ export default class BetaPlugins {
addBetaPluginToList(this.plugin, repositoryPath, specifyVersion);
if (enableAfterInstall) {
const { plugins } = this.plugin.app;
const pluginTargetFolderPath = normalizePath(plugins.getPluginFolder() + '/' + primaryManifest.id);
const pluginTargetFolderPath = normalizePath(
plugins.getPluginFolder() + '/' + primaryManifest.id
);
await plugins.loadManifest(pluginTargetFolderPath);
await plugins.enablePlugin(primaryManifest.id);
}
Expand All @@ -305,7 +309,7 @@ export default class BetaPlugins {
const versionText = specifyVersion === '' ? '' : ` (version: ${specifyVersion})`;
let msg = `${repositoryPath}${versionText}\nThe plugin has been registered with BRAT.`;
if (!enableAfterInstall) {
msg += " You may still need to enable it the Community Plugin List.";
msg += ' You may still need to enable it the Community Plugin List.';
}
await this.plugin.log(msg, true);
toastMessage(this.plugin, msg, noticeTimeout);
Expand Down Expand Up @@ -368,7 +372,7 @@ export default class BetaPlugins {
const msg = `There is an update available for ${primaryManifest.id} from version ${localManifestJson.version} to ${primaryManifest.version}. `;
await this.plugin.log(
msg +
`[Release Info](https://github.com/${repositoryPath}/releases/tag/${primaryManifest.version})`,
`[Release Info](https://github.com/${repositoryPath}/releases/tag/${primaryManifest.version})`,
true
);
toastMessage(this.plugin, msg, 30, () => {
Expand All @@ -385,7 +389,7 @@ export default class BetaPlugins {
const msg = `${primaryManifest.id}\nPlugin has been updated from version ${localManifestJson.version} to ${primaryManifest.version}. `;
await this.plugin.log(
msg +
`[Release Info](https://github.com/${repositoryPath}/releases/tag/${primaryManifest.version})`,
`[Release Info](https://github.com/${repositoryPath}/releases/tag/${primaryManifest.version})`,
true
);
toastMessage(this.plugin, msg, 30, () => {
Expand Down Expand Up @@ -516,12 +520,12 @@ export default class BetaPlugins {
(p) => p.manifest
);
return enabled ?
manifests.filter((manifest) =>
enabledPlugins.find((pluginName) => manifest.id === pluginName.id)
)
manifests.filter((manifest) =>
enabledPlugins.find((pluginName) => manifest.id === pluginName.id)
)
: manifests.filter(
(manifest) =>
!enabledPlugins.find((pluginName) => manifest.id === pluginName.id)
);
(manifest) =>
!enabledPlugins.find((pluginName) => manifest.id === pluginName.id)
);
}
}
4 changes: 2 additions & 2 deletions src/features/themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const themeSave = async (
}

void plugin.log(msg + `[Theme Info](https://github.com/${cssGithubRepository})`, false);
toastMessage(plugin, `${msg}`, 20, (): void => {
toastMessage(plugin, msg, 20, (): void => {
window.open(`https://github.com/${cssGithubRepository}`);
});
return true;
Expand Down Expand Up @@ -159,7 +159,7 @@ export const themeDelete = (plugin: ThePlugin, cssGithubRepository: string): voi
void plugin.saveSettings();
const msg = `Removed ${cssGithubRepository} from BRAT themes list and will no longer be updated. However, the theme files still exist in the vault. To remove them, go into Settings > Appearance and remove the theme.`;
void plugin.log(msg, true);
toastMessage(plugin, `${msg}`);
toastMessage(plugin, msg);
};

/**
Expand Down
34 changes: 20 additions & 14 deletions src/ui/AddNewPluginModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ export default class AddNewPluginModal extends Modal {
false,
false,
false,
this.version
this.version,
false,
this.enableAfterInstall
);
if (result) {
this.close();
Expand Down Expand Up @@ -94,19 +96,23 @@ export default class AddNewPluginModal extends Modal {
}

formEl.createDiv('modal-button-container', (buttonContainerEl) => {
buttonContainerEl.createEl("label", {
cls: "mod-checkbox"
}, (labelEl) => {
const checkboxEl = labelEl.createEl("input", {
attr: { tabindex: -1 },
type: "checkbox"
});
checkboxEl.checked = this.enableAfterInstall;
checkboxEl.addEventListener("click", () => {
this.enableAfterInstall = checkboxEl.checked;
});
labelEl.appendText('Enable after installing the plugin');
});
buttonContainerEl.createEl(
'label',
{
cls: 'mod-checkbox',
},
(labelEl) => {
const checkboxEl = labelEl.createEl('input', {
attr: { tabindex: -1 },
type: 'checkbox',
});
checkboxEl.checked = this.enableAfterInstall;
checkboxEl.addEventListener('click', () => {
this.enableAfterInstall = checkboxEl.checked;
});
labelEl.appendText('Enable after installing the plugin');
}
);

buttonContainerEl
.createEl('button', { attr: { type: 'button' }, text: 'Never mind' })
Expand Down
16 changes: 8 additions & 8 deletions src/ui/SettingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@ export class BratSettingsTab extends PluginSettingTab {
containerEl.empty();

new Setting(containerEl)
.setName('Auto-update plugins at startup')
.setName('Auto-enable plugins after installation')
.setDesc(
'If enabled all beta plugins will be checked for updates each time Obsidian starts. Note: this does not update frozen version plugins.'
'If enabled beta plugins will be automatically enabled after installtion by default. Note: you can toggle this on and off for each plugin in the "Add Plugin" form.'
)
.addToggle((cb: ToggleComponent) => {
cb.setValue(this.plugin.settings.updateAtStartup);
cb.setValue(this.plugin.settings.enableAfterInstall);
cb.onChange(async (value: boolean) => {
this.plugin.settings.updateAtStartup = value;
this.plugin.settings.enableAfterInstall = value;
await this.plugin.saveSettings();
});
});

new Setting(containerEl)
.setName('Auto-enable plugins after installation')
.setName('Auto-update plugins at startup')
.setDesc(
'If enabled beta plugins will be automatically enabled after installtion by default. Note: you can toggle this on and off for each plugin in the "Add Plugin" form.'
'If enabled all beta plugins will be checked for updates each time Obsidian starts. Note: this does not update frozen version plugins.'
)
.addToggle((cb: ToggleComponent) => {
cb.setValue(this.plugin.settings.enableAfterInstall);
cb.setValue(this.plugin.settings.updateAtStartup);
cb.onChange(async (value: boolean) => {
this.plugin.settings.enableAfterInstall = value;
this.plugin.settings.updateAtStartup = value;
await this.plugin.saveSettings();
});
});
Expand Down

0 comments on commit 10369ab

Please sign in to comment.