diff --git a/src/features/BetaPlugins.ts b/src/features/BetaPlugins.ts index 758869b..6d3bf2a 100644 --- a/src/features/BetaPlugins.ts +++ b/src/features/BetaPlugins.ts @@ -138,7 +138,7 @@ export default class BetaPlugins { 'manifest.json', this.plugin.settings.debuggingMode ) - : '', + : '', styles: await grabReleaseFileFromRepository( repositoryPath, version, @@ -197,7 +197,8 @@ export default class BetaPlugins { seeIfUpdatedOnly = false, reportIfNotUpdted = false, specifyVersion = '', - forceReinstall = false + forceReinstall = false, + enableAfterInstall = this.plugin.settings.enableAfterInstall ): Promise { if (this.plugin.settings.debuggingMode) console.log( @@ -207,7 +208,8 @@ export default class BetaPlugins { seeIfUpdatedOnly, reportIfNotUpdted, specifyVersion, - forceReinstall + forceReinstall, + enableAfterInstall ); const noticeTimeout = 10; @@ -226,9 +228,8 @@ export default class BetaPlugins { } 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); return false; @@ -239,8 +240,7 @@ 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 ` + @@ -284,8 +284,13 @@ export default class BetaPlugins { if (releaseFiles === null) return false; await this.writeReleaseFilesToPluginFolder(primaryManifest.id, releaseFiles); if (!forceReinstall) - // only add to list if not a force reinstall addBetaPluginToList(this.plugin, repositoryPath, specifyVersion); + if (enableAfterInstall) { + const { plugins } = this.plugin.app; + const pluginTargetFolderPath = normalizePath(plugins.getPluginFolder() + '/' + primaryManifest.id); + await plugins.loadManifest(pluginTargetFolderPath); + await plugins.enablePlugin(primaryManifest.id); + } await this.plugin.app.plugins.loadManifests(); if (forceReinstall) { // reload if enabled @@ -298,7 +303,10 @@ export default class BetaPlugins { ); } else { const versionText = specifyVersion === '' ? '' : ` (version: ${specifyVersion})`; - const msg = `${repositoryPath}${versionText}\nThe plugin has been registered with BRAT. You may still need to enable it the Community Plugin List.`; + 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."; + } await this.plugin.log(msg, true); toastMessage(this.plugin, msg, noticeTimeout); } @@ -360,7 +368,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, () => { @@ -377,7 +385,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, () => { @@ -508,12 +516,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) + ); } } diff --git a/src/settings.ts b/src/settings.ts index 777a901..03d63cc 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -18,6 +18,7 @@ export interface Settings { themesList: ThemeInforamtion[]; updateAtStartup: boolean; updateThemesAtStartup: boolean; + enableAfterInstall: boolean; loggingEnabled: boolean; loggingPath: string; loggingVerboseEnabled: boolean; @@ -31,6 +32,7 @@ export const DEFAULT_SETTINGS: Settings = { themesList: [], updateAtStartup: true, updateThemesAtStartup: true, + enableAfterInstall: true, loggingEnabled: false, loggingPath: 'BRAT-log', loggingVerboseEnabled: false, diff --git a/src/ui/AddNewPluginModal.ts b/src/ui/AddNewPluginModal.ts index 8af8280..2ed361a 100644 --- a/src/ui/AddNewPluginModal.ts +++ b/src/ui/AddNewPluginModal.ts @@ -14,6 +14,7 @@ export default class AddNewPluginModal extends Modal { address: string; openSettingsTabAfterwards: boolean; readonly useFrozenVersion: boolean; + enableAfterInstall: boolean; version: string; constructor( @@ -28,6 +29,7 @@ export default class AddNewPluginModal extends Modal { this.address = ''; this.openSettingsTabAfterwards = openSettingsTabAfterwards; this.useFrozenVersion = useFrozenVersion; + this.enableAfterInstall = plugin.settings.enableAfterInstall; this.version = ''; } @@ -92,6 +94,20 @@ 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('button', { attr: { type: 'button' }, text: 'Never mind' }) .addEventListener('click', () => { diff --git a/src/ui/SettingsTab.ts b/src/ui/SettingsTab.ts index 3e47e18..c14a79e 100644 --- a/src/ui/SettingsTab.ts +++ b/src/ui/SettingsTab.ts @@ -43,6 +43,19 @@ export class BratSettingsTab extends PluginSettingTab { }); }); + new Setting(containerEl) + .setName('Auto-enable plugins after installation') + .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.' + ) + .addToggle((cb: ToggleComponent) => { + cb.setValue(this.plugin.settings.enableAfterInstall); + cb.onChange(async (value: boolean) => { + this.plugin.settings.enableAfterInstall = value; + await this.plugin.saveSettings(); + }); + }); + new Setting(containerEl) .setName('Auto-update themes at startup') .setDesc(