Skip to content

Commit

Permalink
last try at a fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shabegom committed Aug 8, 2021
1 parent f489c36 commit 4c94d06
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"id": "buttons",
"name": "Buttons",
"description": "Create Buttons in your Obsidian notes to run commands, open links, and insert templates",
"version": "0.4.14",
"version": "0.4.15",
"author": "shabegom",
"authorUrl": "https://shbgm.ca",
"isDesktopOnly": false,
"minAppVersion": "0.10.8"
"minAppVersion": "0.12.8"
}
23 changes: 8 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class ButtonsPlugin extends Plugin {
private buttonEdit: EventRef;
private createButton: Button;
private storeEvents = new Events();
private indexComplete: boolean
private indexCount = 0;
private storeEventsRef: EventRef

private async addButtonInEdit(app: App) {
Expand Down Expand Up @@ -66,10 +66,13 @@ export default class ButtonsPlugin extends Plugin {
}
}
async onload(): Promise<void> {
initializeButtonStore(this.app, this.storeEvents);
this.buttonEvents = buttonEventListener(this.app, addButtonToStore);
this.closedFile = openFileListener(this.app, this.storeEvents, initializeButtonStore);
this.createButton = createButton as Button;
this.storeEventsRef = this.storeEvents.on('index-complete', () => {
this.indexCount++;
})
initializeButtonStore(this.app, this.storeEvents);

this.buttonEdit = openFileListener(
this.app,
Expand Down Expand Up @@ -107,28 +110,18 @@ export default class ButtonsPlugin extends Plugin {
const codeblocks = el.querySelectorAll("code");
for (let index = 0; index < codeblocks.length; index++) {
const codeblock = codeblocks.item(index);

const text = codeblock.innerText.trim();
if (text.startsWith("button")) {
const id = text.split("button-")[1].trim();
if (!this.indexComplete) {
if (this.app.isMobile) {
setTimeout(async () => {
const args = await getButtonById(this.app, id);
if (args) {
ctx.addChild(new InlineButton(codeblock, this.app, args, id))
}
this.indexComplete = true;
}, 1000);
} else {
if (this.indexCount < 2) {
this.storeEventsRef = this.storeEvents.on('index-complete', async () => {
this.indexComplete = true;
this.indexCount++;
const args = await getButtonById(this.app, id);
if (args) {
ctx.addChild(new InlineButton(codeblock, this.app, args, id))
}
})
}

} else {
const args = await getButtonById(this.app, id);
if (args) {
Expand Down

0 comments on commit 4c94d06

Please sign in to comment.