diff --git a/src/main.ts b/src/main.ts index 63f6d4e..1ac08cb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -55,11 +55,9 @@ export default class QuickAdd extends Plugin { return this.settings.devMode; } - const id: string = this.manifest.id, - plugins = this.app.plugins; - void plugins - .disablePlugin(id) - .then(() => plugins.enablePlugin(id)); + const id: string = this.manifest.id; + const plugins = this.app.plugins; + void plugins.disablePlugin(id).then(() => plugins.enablePlugin(id)); }, }); @@ -71,7 +69,7 @@ export default class QuickAdd extends Plugin { return this.settings.devMode; } - console.log(`Test QuickAdd (dev)`); + console.log("Test QuickAdd (dev)"); const fn = () => { new InfiniteAIAssistantCommandSettingsModal({ @@ -100,7 +98,7 @@ export default class QuickAdd extends Plugin { ChoiceSuggester.Open(this, this.settings.choices); }); } - + this.addSettingTab(new QuickAddSettingsTab(this.app, this)); this.app.workspace.onLayoutReady(() => @@ -108,8 +106,8 @@ export default class QuickAdd extends Plugin { this.app, this, this.settings.macros, - new ChoiceExecutor(this.app, this) - ).run() + new ChoiceExecutor(this.app, this), + ).run(), ); this.addCommandsForChoices(this.settings.choices); @@ -124,11 +122,7 @@ export default class QuickAdd extends Plugin { async loadSettings() { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - this.settings = Object.assign( - {}, - DEFAULT_SETTINGS, - await this.loadData() - ); + this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); } async saveSettings() { @@ -136,7 +130,9 @@ export default class QuickAdd extends Plugin { } private addCommandsForChoices(choices: IChoice[]) { - choices.forEach((choice) => this.addCommandForChoice(choice)); + for (const choice of choices) { + this.addCommandForChoice(choice); + } } public addCommandForChoice(choice: IChoice) { @@ -178,7 +174,7 @@ export default class QuickAdd extends Plugin { private getChoice( by: "name" | "id", targetPropertyValue: string, - choices: IChoice[] = this.settings.choices + choices: IChoice[] = this.settings.choices, ): IChoice | null { for (const choice of choices) { if (choice[by] === targetPropertyValue) { @@ -188,7 +184,7 @@ export default class QuickAdd extends Plugin { const subChoice = this.getChoice( by, targetPropertyValue, - (choice as IMultiChoice).choices + (choice as IMultiChoice).choices, ); if (subChoice) { return subChoice; @@ -208,9 +204,7 @@ export default class QuickAdd extends Plugin { return this.app.vault .getFiles() - .filter((file) => - file.path.startsWith(this.settings.templateFolderPath) - ); + .filter((file) => file.path.startsWith(this.settings.templateFolderPath)); } private announceUpdate() { diff --git a/src/migrations/setVersionAfterUpdateModalRelease.ts b/src/migrations/setVersionAfterUpdateModalRelease.ts index b9ef4c4..d8f9eda 100644 --- a/src/migrations/setVersionAfterUpdateModalRelease.ts +++ b/src/migrations/setVersionAfterUpdateModalRelease.ts @@ -1,12 +1,17 @@ import { settingsStore } from "src/settingsStore"; import type { Migration } from "./Migrations"; +/** + * This was used with v. 0.14.0, which was the release version prior to the update modal release. + * Previously, it set the version to 0.14.0, but now we want to set it to the current version. + * It would otherwise break the plugin for new users. + */ + const setVersionAfterUpdateModalRelease: Migration = { - description: - "Set version to 0.14.0, which is the release version prior to the update modal release.", + description: "Set version to the current plugin version.", // eslint-disable-next-line @typescript-eslint/require-await - migrate: async (_) => { - settingsStore.setState({ version: "0.14.0" }); + migrate: async (plugin) => { + settingsStore.setState({ version: plugin.manifest.version }); }, }; diff --git a/src/settingsStore.ts b/src/settingsStore.ts index f39858f..7aa2fb9 100644 --- a/src/settingsStore.ts +++ b/src/settingsStore.ts @@ -4,16 +4,11 @@ import { DEFAULT_SETTINGS } from "./quickAddSettingsTab"; import type { IMacro } from "./types/macros/IMacro"; import { QuickAddMacro } from "./types/macros/QuickAddMacro"; -// Define the state shape and actions for your store. -type SettingsState = QuickAddSettings & { - setSettings: (settings: Partial) => void; -}; - -export const settingsStore = (function () { - const useSettingsStore = createStore((set, get) => ({ - ...DEFAULT_SETTINGS, - setSettings: (settings: Partial) => - set((state) => ({ ...state, ...settings })), +type SettingsState = QuickAddSettings; + +export const settingsStore = (() => { + const useSettingsStore = createStore((set, _get) => ({ + ...structuredClone(DEFAULT_SETTINGS), })); const { getState, setState, subscribe } = useSettingsStore; @@ -24,9 +19,7 @@ export const settingsStore = (function () { subscribe, setMacro: (macroId: IMacro["id"], macro: IMacro) => { setState((state) => { - const macroIdx = state.macros.findIndex( - (m) => m.id === macroId - ); + const macroIdx = state.macros.findIndex((m) => m.id === macroId); if (macroIdx === -1) { throw new Error("Macro not found"); }