From 1128b5ac65c0bc84e5158175f934bbb011fbc946 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Thu, 7 Sep 2023 16:40:59 +0200 Subject: [PATCH] #655 - Refresh settings --- CHANGELOG.md | 1 + package.json | 12 +++++++++- package.nls.de.json | 3 ++- package.nls.ja.json | 3 ++- package.nls.json | 3 ++- src/constants/Extension.ts | 3 +++ src/helpers/SettingsHelper.ts | 44 ++++++++++++++++++++--------------- 7 files changed, 46 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cfde035..91426c06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### ✨ New features - [#650](https://github.com/estruyf/vscode-front-matter/issues/650): Added template support for [Astro Starlight](https://starlight.astro.build/) +- [#655](https://github.com/estruyf/vscode-front-matter/issues/655): Added a new command to manually refresh the settings of the Front Matter CMS ### 🎨 Enhancements diff --git a/package.json b/package.json index 862b993c..2084d605 100644 --- a/package.json +++ b/package.json @@ -1766,6 +1766,12 @@ "category": "Front Matter", "icon": "$(arrow-swap)" }, + { + "command": "frontMatter.settings.refresh", + "title": "%command.frontMatter.settings.refresh%", + "category": "Front Matter", + "icon": "$(refresh)" + }, { "command": "frontMatter.config.reload", "title": "%command.frontMatter.config.reload%", @@ -2360,9 +2366,13 @@ "group": "navigation@3", "when": "view == frontMatter.explorer && frontMatter:project:switch:enabled" }, + { + "command": "frontMatter.settings.refresh", + "group": "navigation@4" + }, { "command": "frontMatter.dashboard", - "group": "navigation@4", + "group": "navigation@5", "when": "view == frontMatter.explorer || view == explorer" } ] diff --git a/package.nls.de.json b/package.nls.de.json index 97d31bde..a0fbff97 100644 --- a/package.nls.de.json +++ b/package.nls.de.json @@ -241,5 +241,6 @@ "setting.frontMatter.taxonomy.modifiedField.deprecationMessage": "Diese Einstellung ist veraltet und wird in der nÀchsten Hauptversion entfernt. Bitte verwenden Sie stattdessen die neuen `isModifiedDate`-Einstellungen in den Datumsfeldern Ihrer Content-Typen.", "setting.frontMatter.taxonomy.contentTypes.items.properties.fields.items.properties.customType.description": "🚧: Specify the name of the custom field type to use.", "setting.frontMatter.taxonomy.contentTypes.items.properties.fields.items.properties.clearEmpty.description": "🚧: Specify if the empty values should be cleared.", - "setting.frontMatter.website.host.markdownDescription": "🚧: Specify the host URL of your website. [Check in the docs](https://frontmatter.codes/docs/settings/overview#frontmatter.website.url)" + "setting.frontMatter.website.host.markdownDescription": "🚧: Specify the host URL of your website. [Check in the docs](https://frontmatter.codes/docs/settings/overview#frontmatter.website.url)", + "command.frontMatter.settings.refresh": "🚧: Refresh Front Matter Settings" } \ No newline at end of file diff --git a/package.nls.ja.json b/package.nls.ja.json index 6f43b1df..e1ee8fcd 100644 --- a/package.nls.ja.json +++ b/package.nls.ja.json @@ -242,5 +242,6 @@ "setting.frontMatter.global.disabledNotifications.markdownDescription": "🚧: This is an array with the notifications types that can be disabled for Front Matter CMS. [Check in the docs](https://frontmatter.codes/docs/settings/overview#frontmatter.global.disablednotifications)", "setting.frontMatter.taxonomy.contentTypes.items.properties.fields.items.properties.customType.description": "🚧: Specify the name of the custom field type to use.", "setting.frontMatter.taxonomy.contentTypes.items.properties.fields.items.properties.clearEmpty.description": "🚧: Specify if the empty values should be cleared.", - "setting.frontMatter.website.host.markdownDescription": "🚧: Specify the host URL of your website. [Check in the docs](https://frontmatter.codes/docs/settings/overview#frontmatter.website.url)" + "setting.frontMatter.website.host.markdownDescription": "🚧: Specify the host URL of your website. [Check in the docs](https://frontmatter.codes/docs/settings/overview#frontmatter.website.url)", + "command.frontMatter.settings.refresh": "🚧: Refresh Front Matter Settings" } \ No newline at end of file diff --git a/package.nls.json b/package.nls.json index 2a958382..4789a27f 100644 --- a/package.nls.json +++ b/package.nls.json @@ -241,5 +241,6 @@ "setting.frontMatter.taxonomy.modifiedField.deprecationMessage": "This setting is deprecated and will be removed in the next major version. Please use the new `isModifiedDate` settings instead in your content types date fields.", "setting.frontMatter.taxonomy.contentTypes.items.properties.fields.items.properties.customType.description": "Specify the name of the custom field type to use.", "setting.frontMatter.taxonomy.contentTypes.items.properties.fields.items.properties.clearEmpty.description": "Specify if the empty values should be cleared.", - "setting.frontMatter.website.host.markdownDescription": "Specify the host URL of your website. [Check in the docs](https://frontmatter.codes/docs/settings/overview#frontmatter.website.url)" + "setting.frontMatter.website.host.markdownDescription": "Specify the host URL of your website. [Check in the docs](https://frontmatter.codes/docs/settings/overview#frontmatter.website.url)", + "command.frontMatter.settings.refresh": "Refresh Front Matter Settings" } \ No newline at end of file diff --git a/src/constants/Extension.ts b/src/constants/Extension.ts index 36dc64ad..a46b4782 100644 --- a/src/constants/Extension.ts +++ b/src/constants/Extension.ts @@ -42,6 +42,9 @@ export const COMMAND_NAME = { showOutputChannel: getCommandName('showOutputChannel'), + // Settings + settingsRefresh: getCommandName('settings.refresh'), + // Insert dashboards insertMedia: getCommandName('insertMedia'), insertSnippet: getCommandName('insertSnippet'), diff --git a/src/helpers/SettingsHelper.ts b/src/helpers/SettingsHelper.ts index 70f14833..fbfd33af 100644 --- a/src/helpers/SettingsHelper.ts +++ b/src/helpers/SettingsHelper.ts @@ -61,6 +61,7 @@ export class Settings { private static fileDeleteListener: vscode.Disposable; private static readConfigPromise: Promise | undefined = undefined; private static project: Project | undefined = undefined; + private static configDebouncer = debounceCallback(); public static async init() { await Settings.readConfig(); @@ -94,6 +95,8 @@ export class Settings { commands.registerCommand(COMMAND_NAME.reloadConfig, Settings.rebindWatchers); } + commands.registerCommand(COMMAND_NAME.settingsRefresh, Settings.reloadConfig); + Settings.config = vscode.workspace.getConfiguration(CONFIG_KEY); Settings.attachListener('settings-init', async () => { @@ -220,7 +223,6 @@ export class Settings { */ public static onConfigChange() { const projectConfig = Settings.projectConfigPath; - const configDebouncer = debounceCallback(); workspace.onDidChangeConfiguration(() => { Settings.triggerListeners(); @@ -246,25 +248,10 @@ export class Settings { ); Settings.fileChangeWatcher.onDidChange(async () => { Logger.info(`Config change detected - ${projectConfig} changed`); - configDebouncer(() => Settings.triggerListeners(), 200); + Settings.configDebouncer(() => Settings.triggerListeners(), 200); }); } - const reloadConfig = async (debounced: boolean = true) => { - Logger.info(`Reloading config...`); - if (Settings.readConfigPromise === undefined) { - Settings.readConfigPromise = Settings.readConfig(); - } - await Settings.readConfigPromise; - - Logger.info(`Reloaded config...`); - if (debounced) { - configDebouncer(() => Settings.triggerListeners(), 200); - } else { - Settings.triggerListeners(); - } - }; - if (Settings.fileSaveListener) { Settings.fileSaveListener.dispose(); } @@ -274,7 +261,7 @@ export class Settings { if (Settings.checkProjectConfig(filename)) { Logger.info(`Config change detected - ${filename} saved`); - await reloadConfig(); + await Settings.reloadConfig(); } }); @@ -285,7 +272,7 @@ export class Settings { Settings.fileDeleteListener = workspace.onDidDeleteFiles(async (e) => { const needCallback = e?.files.find((f) => Settings.checkProjectConfig(f.fsPath)); if (needCallback) { - await reloadConfig(false); + await Settings.reloadConfig(false); } }); } @@ -1034,4 +1021,23 @@ export class Settings { return config; } + + /** + * Reload the config + * @param debounced + */ + private static async reloadConfig(debounced: boolean = true) { + Logger.info(`Reloading config...`); + if (Settings.readConfigPromise === undefined) { + Settings.readConfigPromise = Settings.readConfig(); + } + await Settings.readConfigPromise; + + Logger.info(`Reloaded config...`); + if (debounced) { + Settings.configDebouncer(() => Settings.triggerListeners(), 200); + } else { + Settings.triggerListeners(); + } + } }