diff --git a/source/main.ts b/source/main.ts index ac46173..e45512c 100644 --- a/source/main.ts +++ b/source/main.ts @@ -96,7 +96,11 @@ export default class UNITADE_PLUGIN extends Plugin { return; } } catch (error) { - console.error('Error creating regular expression:', error); + if (!this.settings.silence_errors) { + console.error(error); + } else { + console.debug(`[UNITADE-ERROR]: Error is silenced, error: ${error}`); + } } } } @@ -128,9 +132,13 @@ export default class UNITADE_PLUGIN extends Plugin { this.settings.mobile_settings.extensions = __mb_settings.join(';'); } } catch (err: any) { - new Notification('Error from UNITADE plugin:', { body: `Error with on-load registry of: ${filename.last()!}};` }); + if (!this.settings.silence_errors) { + new Notification('Error from UNITADE plugin:', { body: `Error with on-load registry of: ${err}` }); - console.error(err); + console.error(err); + } else { + console.debug(`[UNITADE-ERROR]: Error is silenced, error: ${err}`); + } } } @@ -163,9 +171,13 @@ export default class UNITADE_PLUGIN extends Plugin { this.settings.mobile_settings.extensions = __mb_settings.join(';'); } } catch (err: any) { - new Notification('Error from UNITADE plugin:', { body: `Error with on-load registry of: ${extensions}` }); + if (!this.settings.silence_errors) { + new Notification('Error from UNITADE plugin:', { body: `Error with on-load registry of: ${extensions}` }); - console.error(err); + console.error(err); + } else { + console.debug(`[UNITADE-ERROR]: Error is silenced, error: ${err}`); + } } } } @@ -270,7 +282,13 @@ export default class UNITADE_PLUGIN extends Plugin { try { this.registerExtensions(['.md'], 'markdown'); } catch (err: any) { - console.error(err); + if (!this.settings.silence_errors) { + new Notification('Error from UNITADE plugin:', { body: err }); + + console.error(err); + } else { + console.debug(`[UNITADE-ERROR]: Error is silenced, error: ${err}`); + } this.settings.errors['markdown_override'] = `Error with reregistering extensions: ${err}`; } @@ -320,11 +338,15 @@ export default class UNITADE_PLUGIN extends Plugin { return new UNITADE_VIEW(leaf, extension); }); } catch (err: any) { - new Notification('Error from UNITADE plugin:', { body: `${err}` }); - this.settings.errors[extension] = `Error from UNITADE plugin: ${err}`; - console.error(err); + if (!this.settings.silence_errors) { + new Notification('Error from UNITADE plugin:', { body: `${err}` }); + + console.error(err); + } else { + console.debug(`[UNITADE-ERROR]: Error is silenced, error: ${err}`); + } } } } @@ -365,9 +387,13 @@ export default class UNITADE_PLUGIN extends Plugin { _msg = `Could not register extension: ${filetype} to view as ${view}.\n${err}`; } - new Notification('Error from UNITADE plugin:', { body: _msg }); + if (!this.settings.silence_errors) { + new Notification('Error from UNITADE plugin:', { body: _msg }); - console.error(_msg); + console.error(_msg); + } else { + console.debug(`[UNITADE-ERROR]: Error is silenced, error: ${_msg}`); + } this._settings.errors[filetype] = _msg; } @@ -425,11 +451,15 @@ export default class UNITADE_PLUGIN extends Plugin { } catch (err: any) { const _msg = `Couldn't unregistry extension: ${extension};` - new Notification('Error from UNITADE plugin:', { body: _msg }); - this.settings.errors[extension] = _msg; - console.error(_msg); + if (!this.settings.silence_errors) { + new Notification('Error from UNITADE plugin:', { body: _msg }); + + console.error(_msg); + } else { + console.debug(`[UNITADE-ERROR]: Error is silenced, error: ${_msg}`); + } } } } diff --git a/source/settings.ts b/source/settings.ts index 75c1d2e..84e88d0 100644 --- a/source/settings.ts +++ b/source/settings.ts @@ -58,6 +58,7 @@ export interface UNITADE_SETTINGS { errors: Record, debug_mode: boolean, + silence_errors: boolean, } export const DEFAULT_SETTINGS: UNITADE_SETTINGS = { @@ -84,6 +85,7 @@ export const DEFAULT_SETTINGS: UNITADE_SETTINGS = { errors: {}, debug_mode: false, + silence_errors: false } export default class UNITADE_SETTINGS_TAB extends PluginSettingTab { @@ -633,6 +635,49 @@ export default class UNITADE_SETTINGS_TAB extends PluginSettingTab { groupExtInp.inputEl.style.width = '100%'; groupExtInp.inputEl.style.height = '48px'; groupExtInp.inputEl.style.minHeight = '36px'; + + containerEl.createEl('h3', { text: 'Additionals' }); + + new Setting(containerEl) + .setName('Debug mode:') + .setDesc('This mode starts output in application\'s console about actions you do.') + .setTooltip('Do not use this mode if you are not developer or familliar with console.') + .addToggle(toggle => { + toggle + .setValue(this.plugin.settings.debug_mode) + .onChange(async (value) => { + let next = { + ...this.plugin.settings, + debug_mode: value, + }; + + await this.plugin.uptSettings(next); + + this.__updateErrors(); + }); + + return toggle; + }); + + new Setting(containerEl) + .setName('Silence errors:') + .setDesc('This mode silences every error and disables notifications: could help in case of error spamming.') + .addToggle(toggle => { + toggle + .setValue(this.plugin.settings.silence_errors) + .onChange(async (value) => { + let next = { + ...this.plugin.settings, + silence_errors: value, + }; + + await this.plugin.uptSettings(next); + + this.__updateErrors(); + }); + + return toggle; + }); } private __uptMbConfig(mbConfigInput: TextAreaComponent, mbConfigEnabled: boolean): void {