Skip to content

Commit

Permalink
Fixed recipes toggling requiring toggling of the whole plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
revolter committed Feb 28, 2024
1 parent 199c5cf commit ec7d9ef
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 31 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ column, and it will be preserved when you update the list.

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

## Usage

Expand Down
28 changes: 18 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,30 @@ export default class TrackALotPlugin extends Plugin {
const commandFactory = new PluginUpdateCommandFactory();

if (settingsManager.settings.hanayamaHuzzles.isActive) {
const command = commandFactory.command(HanayamaHuzzlesRecipe.NAME, new HanayamaHuzzlesRecipe(
markdownTableFactory,
markdownTableConverter,
trackablesUpdater,
const command = commandFactory.command(
HanayamaHuzzlesRecipe.NAME,
new HanayamaHuzzlesRecipe(
markdownTableFactory,
markdownTableConverter,
trackablesUpdater,
settingsManager.settings.hanayamaHuzzles
),
settingsManager.settings.hanayamaHuzzles
));
);

this.addCommand(command);
}

if (settingsManager.settings.iqPuzzles.isActive) {
const command = commandFactory.command(IQPuzzlesRecipe.NAME, new IQPuzzlesRecipe(
markdownTableFactory,
markdownTableConverter,
trackablesUpdater
));
const command = commandFactory.command(
IQPuzzlesRecipe.NAME,
new IQPuzzlesRecipe(
markdownTableFactory,
markdownTableConverter,
trackablesUpdater
),
settingsManager.settings.iqPuzzles
);

this.addCommand(command);
}
Expand Down
33 changes: 22 additions & 11 deletions src/plugin/PluginUpdateCommandFactory.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
import { Command, Notice } from 'obsidian';
import { Recipe } from 'src/recipes/Recipe';
import { RecipeSettingsToggleable } from 'src/settings/data/RecipeSettingsToggleable';

export class PluginUpdateCommandFactory {
command(name: string, recipe: Recipe): Command {
command(name: string, recipe: Recipe, settings: RecipeSettingsToggleable): Command {
return {
id: this.#identifier(`update-${name}-list`),
name: `Update ${name} list`,
editorCallback: (editor, _view) => {
const content = editor.getValue();
editorCheckCallback: (checking, editor, _ctx) => {
const isActive = settings.isActive;

new Notice(`${name} list update started`);
const startDate = new Date();
if (!isActive) {
return false;
}

recipe.updatedListInContent(content).then( newContent => {
editor.setValue(newContent);
if (!checking) {
const content = editor.getValue();

const endDate = new Date();
const seconds = (endDate.getTime() - startDate.getTime()) / 1000;
new Notice(`${name} list update finished in ${seconds} seconds`);
});
new Notice(`${name} list update started`);
const startDate = new Date();

recipe.updatedListInContent(content).then( newContent => {
editor.setValue(newContent);

const endDate = new Date();
const seconds = (endDate.getTime() - startDate.getTime()) / 1000;
new Notice(`${name} list update finished in ${seconds} seconds`);
});
}

return true;
}
};
}
Expand Down
9 changes: 0 additions & 9 deletions src/settings/RecipesSettingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ export class RecipesSettingsTab extends PluginSettingTab {
.add('Recipes')
.setHeading();

settingsAdder.add(
'',
this.containerEl.createFragment(
this.containerEl.createText('span', '⚠️ Due to Obsidian Plugin limitations, you have to disable and re-enable the plugin from '),
this.containerEl.createText('code', 'Settings > Community plugins > Installed plugins'),
this.containerEl.createText('span', ' after toggling any recipe!')
)
);

const settings = this.settingsManager.settings;

this.#addHanayamaHuzzlesSettings(settings.hanayamaHuzzles, settingsAdder);
Expand Down

0 comments on commit ec7d9ef

Please sign in to comment.