Skip to content

Commit ad97d1e

Browse files
committed
fix: bug failed to load on first install due to attempting to copy a function (fix #728, #746, #749)
1 parent 32bcef2 commit ad97d1e

File tree

3 files changed

+29
-37
lines changed

3 files changed

+29
-37
lines changed

src/main.ts

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,9 @@ export default class QuickAdd extends Plugin {
5555
return this.settings.devMode;
5656
}
5757

58-
const id: string = this.manifest.id,
59-
plugins = this.app.plugins;
60-
void plugins
61-
.disablePlugin(id)
62-
.then(() => plugins.enablePlugin(id));
58+
const id: string = this.manifest.id;
59+
const plugins = this.app.plugins;
60+
void plugins.disablePlugin(id).then(() => plugins.enablePlugin(id));
6361
},
6462
});
6563

@@ -71,7 +69,7 @@ export default class QuickAdd extends Plugin {
7169
return this.settings.devMode;
7270
}
7371

74-
console.log(`Test QuickAdd (dev)`);
72+
console.log("Test QuickAdd (dev)");
7573

7674
const fn = () => {
7775
new InfiniteAIAssistantCommandSettingsModal({
@@ -100,16 +98,16 @@ export default class QuickAdd extends Plugin {
10098
ChoiceSuggester.Open(this, this.settings.choices);
10199
});
102100
}
103-
101+
104102
this.addSettingTab(new QuickAddSettingsTab(this.app, this));
105103

106104
this.app.workspace.onLayoutReady(() =>
107105
new StartupMacroEngine(
108106
this.app,
109107
this,
110108
this.settings.macros,
111-
new ChoiceExecutor(this.app, this)
112-
).run()
109+
new ChoiceExecutor(this.app, this),
110+
).run(),
113111
);
114112
this.addCommandsForChoices(this.settings.choices);
115113

@@ -124,19 +122,17 @@ export default class QuickAdd extends Plugin {
124122

125123
async loadSettings() {
126124
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
127-
this.settings = Object.assign(
128-
{},
129-
DEFAULT_SETTINGS,
130-
await this.loadData()
131-
);
125+
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
132126
}
133127

134128
async saveSettings() {
135129
await this.saveData(this.settings);
136130
}
137131

138132
private addCommandsForChoices(choices: IChoice[]) {
139-
choices.forEach((choice) => this.addCommandForChoice(choice));
133+
for (const choice of choices) {
134+
this.addCommandForChoice(choice);
135+
}
140136
}
141137

142138
public addCommandForChoice(choice: IChoice) {
@@ -178,7 +174,7 @@ export default class QuickAdd extends Plugin {
178174
private getChoice(
179175
by: "name" | "id",
180176
targetPropertyValue: string,
181-
choices: IChoice[] = this.settings.choices
177+
choices: IChoice[] = this.settings.choices,
182178
): IChoice | null {
183179
for (const choice of choices) {
184180
if (choice[by] === targetPropertyValue) {
@@ -188,7 +184,7 @@ export default class QuickAdd extends Plugin {
188184
const subChoice = this.getChoice(
189185
by,
190186
targetPropertyValue,
191-
(choice as IMultiChoice).choices
187+
(choice as IMultiChoice).choices,
192188
);
193189
if (subChoice) {
194190
return subChoice;
@@ -208,9 +204,7 @@ export default class QuickAdd extends Plugin {
208204

209205
return this.app.vault
210206
.getFiles()
211-
.filter((file) =>
212-
file.path.startsWith(this.settings.templateFolderPath)
213-
);
207+
.filter((file) => file.path.startsWith(this.settings.templateFolderPath));
214208
}
215209

216210
private announceUpdate() {

src/migrations/setVersionAfterUpdateModalRelease.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import { settingsStore } from "src/settingsStore";
22
import type { Migration } from "./Migrations";
33

4+
/**
5+
* This was used with v. 0.14.0, which was the release version prior to the update modal release.
6+
* Previously, it set the version to 0.14.0, but now we want to set it to the current version.
7+
* It would otherwise break the plugin for new users.
8+
*/
9+
410
const setVersionAfterUpdateModalRelease: Migration = {
5-
description:
6-
"Set version to 0.14.0, which is the release version prior to the update modal release.",
11+
description: "Set version to the current plugin version.",
712
// eslint-disable-next-line @typescript-eslint/require-await
8-
migrate: async (_) => {
9-
settingsStore.setState({ version: "0.14.0" });
13+
migrate: async (plugin) => {
14+
settingsStore.setState({ version: plugin.manifest.version });
1015
},
1116
};
1217

src/settingsStore.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@ import { DEFAULT_SETTINGS } from "./quickAddSettingsTab";
44
import type { IMacro } from "./types/macros/IMacro";
55
import { QuickAddMacro } from "./types/macros/QuickAddMacro";
66

7-
// Define the state shape and actions for your store.
8-
type SettingsState = QuickAddSettings & {
9-
setSettings: (settings: Partial<QuickAddSettings>) => void;
10-
};
11-
12-
export const settingsStore = (function () {
13-
const useSettingsStore = createStore<SettingsState>((set, get) => ({
14-
...DEFAULT_SETTINGS,
15-
setSettings: (settings: Partial<QuickAddSettings>) =>
16-
set((state) => ({ ...state, ...settings })),
7+
type SettingsState = QuickAddSettings;
8+
9+
export const settingsStore = (() => {
10+
const useSettingsStore = createStore<SettingsState>((set, _get) => ({
11+
...structuredClone(DEFAULT_SETTINGS),
1712
}));
1813

1914
const { getState, setState, subscribe } = useSettingsStore;
@@ -24,9 +19,7 @@ export const settingsStore = (function () {
2419
subscribe,
2520
setMacro: (macroId: IMacro["id"], macro: IMacro) => {
2621
setState((state) => {
27-
const macroIdx = state.macros.findIndex(
28-
(m) => m.id === macroId
29-
);
22+
const macroIdx = state.macros.findIndex((m) => m.id === macroId);
3023
if (macroIdx === -1) {
3124
throw new Error("Macro not found");
3225
}

0 commit comments

Comments
 (0)