Skip to content

Commit ec7d9ef

Browse files
committed
Fixed recipes toggling requiring toggling of the whole plugin
1 parent 199c5cf commit ec7d9ef

File tree

4 files changed

+40
-31
lines changed

4 files changed

+40
-31
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ column, and it will be preserved when you update the list.
1414

1515
- Open `Settings` > `Track-a-Lot`
1616
- Enable the required tracking recipe
17-
- Disable and re-enable the plugin using instructions above the recipes
1817

1918
## Usage
2019

src/main.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,30 @@ export default class TrackALotPlugin extends Plugin {
2222
const commandFactory = new PluginUpdateCommandFactory();
2323

2424
if (settingsManager.settings.hanayamaHuzzles.isActive) {
25-
const command = commandFactory.command(HanayamaHuzzlesRecipe.NAME, new HanayamaHuzzlesRecipe(
26-
markdownTableFactory,
27-
markdownTableConverter,
28-
trackablesUpdater,
25+
const command = commandFactory.command(
26+
HanayamaHuzzlesRecipe.NAME,
27+
new HanayamaHuzzlesRecipe(
28+
markdownTableFactory,
29+
markdownTableConverter,
30+
trackablesUpdater,
31+
settingsManager.settings.hanayamaHuzzles
32+
),
2933
settingsManager.settings.hanayamaHuzzles
30-
));
34+
);
3135

3236
this.addCommand(command);
3337
}
3438

3539
if (settingsManager.settings.iqPuzzles.isActive) {
36-
const command = commandFactory.command(IQPuzzlesRecipe.NAME, new IQPuzzlesRecipe(
37-
markdownTableFactory,
38-
markdownTableConverter,
39-
trackablesUpdater
40-
));
40+
const command = commandFactory.command(
41+
IQPuzzlesRecipe.NAME,
42+
new IQPuzzlesRecipe(
43+
markdownTableFactory,
44+
markdownTableConverter,
45+
trackablesUpdater
46+
),
47+
settingsManager.settings.iqPuzzles
48+
);
4149

4250
this.addCommand(command);
4351
}

src/plugin/PluginUpdateCommandFactory.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,35 @@
11
import { Command, Notice } from 'obsidian';
22
import { Recipe } from 'src/recipes/Recipe';
3+
import { RecipeSettingsToggleable } from 'src/settings/data/RecipeSettingsToggleable';
34

45
export class PluginUpdateCommandFactory {
5-
command(name: string, recipe: Recipe): Command {
6+
command(name: string, recipe: Recipe, settings: RecipeSettingsToggleable): Command {
67
return {
78
id: this.#identifier(`update-${name}-list`),
89
name: `Update ${name} list`,
9-
editorCallback: (editor, _view) => {
10-
const content = editor.getValue();
10+
editorCheckCallback: (checking, editor, _ctx) => {
11+
const isActive = settings.isActive;
1112

12-
new Notice(`${name} list update started`);
13-
const startDate = new Date();
13+
if (!isActive) {
14+
return false;
15+
}
1416

15-
recipe.updatedListInContent(content).then( newContent => {
16-
editor.setValue(newContent);
17+
if (!checking) {
18+
const content = editor.getValue();
1719

18-
const endDate = new Date();
19-
const seconds = (endDate.getTime() - startDate.getTime()) / 1000;
20-
new Notice(`${name} list update finished in ${seconds} seconds`);
21-
});
20+
new Notice(`${name} list update started`);
21+
const startDate = new Date();
22+
23+
recipe.updatedListInContent(content).then( newContent => {
24+
editor.setValue(newContent);
25+
26+
const endDate = new Date();
27+
const seconds = (endDate.getTime() - startDate.getTime()) / 1000;
28+
new Notice(`${name} list update finished in ${seconds} seconds`);
29+
});
30+
}
31+
32+
return true;
2233
}
2334
};
2435
}

src/settings/RecipesSettingsTab.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@ export class RecipesSettingsTab extends PluginSettingTab {
2323
.add('Recipes')
2424
.setHeading();
2525

26-
settingsAdder.add(
27-
'',
28-
this.containerEl.createFragment(
29-
this.containerEl.createText('span', '⚠️ Due to Obsidian Plugin limitations, you have to disable and re-enable the plugin from '),
30-
this.containerEl.createText('code', 'Settings > Community plugins > Installed plugins'),
31-
this.containerEl.createText('span', ' after toggling any recipe!')
32-
)
33-
);
34-
3526
const settings = this.settingsManager.settings;
3627

3728
this.#addHanayamaHuzzlesSettings(settings.hanayamaHuzzles, settingsAdder);

0 commit comments

Comments
 (0)