Skip to content

Commit

Permalink
release: 0.3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
RyotaUshio committed Dec 21, 2023
1 parent 8258ee2 commit bfa04c2
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 12 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "math-in-callout",
"name": "Better Math in Callouts & Blockquotes",
"version": "0.3.6",
"version": "0.3.7",
"minAppVersion": "1.3.15",
"description": "Add better Live Preview support for math rendering inside callouts & blockquotes.",
"author": "Ryota Ushio",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "math-in-callout",
"version": "0.3.6",
"version": "0.3.7",
"description": "Add a better Live Preview support for math rendering inside callouts & blockquotes.",
"scripts": {
"dev": "node esbuild.config.mjs",
Expand Down
37 changes: 29 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,35 @@ import { MarkdownView, Notice, Plugin } from 'obsidian';
import { createCalloutDecorator } from 'decorations';
import { quoteInfoField } from 'quote-field';
import { patchDecoration } from 'patch-widget-type';
import { DEFAULT_SETTINGS, MathInCalloutSettingTab, MathInCalloutSettings } from 'settings';

export default class MathInCalloutPlugin extends Plugin {
patchSucceeded: boolean;
notReadyNotice: Notice | null = null;
settings: MathInCalloutSettings;

async onload() {
await this.loadSettings();
await this.saveSettings();
this.addSettingTab(new MathInCalloutSettingTab(this));

this.patchSucceeded = false;

this.registerEditorExtension(quoteInfoField);

// Wait for a second to avoid showing the "You're not ready yet" notification when it's not necessary
let notReadyNotice: Notice;
this.app.workspace.onLayoutReady(() => setTimeout(() => {
if (!this.patchSucceeded) {
notReadyNotice = new Notice(`${this.manifest.name}: You're not ready yet. In Live Preview, type some math expression outside callouts.`, 0);
}
}, 1000));
this.app.workspace.onLayoutReady(() => setTimeout(() => this.showNotReadyNotice(), 1000));

patchDecoration(this, (builtInMathWidget) => {
// Wait for the view update to finish
setTimeout(() => {
if (notReadyNotice) notReadyNotice.hide();
new Notice(`${this.manifest.name}: You're ready!`, 1500);
if (this.notReadyNotice) {
this.notReadyNotice.hide();
this.notReadyNotice = null;
if (this.settings.notification) {
new Notice(`${this.manifest.name}: You're ready! (Note: this notifiction can be turned off in the plugin setting.)`, 1500);
}
}
this.registerEditorExtension(createCalloutDecorator(builtInMathWidget));
this.rerender()
}, 100);
Expand All @@ -40,4 +47,18 @@ export default class MathInCalloutPlugin extends Plugin {
}
});
}

showNotReadyNotice() {
if (!this.patchSucceeded && this.settings.notification) {
this.notReadyNotice = new Notice(`${this.manifest.name}: You're not ready yet. In Live Preview, type some math expression outside callouts.`, 0);
}
}

async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}

async saveSettings() {
await this.saveData(this.settings);
}
}
38 changes: 38 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { PluginSettingTab, Setting } from 'obsidian';
import MyPlugin from 'main';


export interface MathInCalloutSettings {
notification: boolean;
}

export const DEFAULT_SETTINGS: MathInCalloutSettings = {
notification: true,
};

// Inspired by https://stackoverflow.com/a/50851710/13613783
export type KeysOfType<Obj, Type> = NonNullable<{ [k in keyof Obj]: Obj[k] extends Type ? k : never }[keyof Obj]>;

export class MathInCalloutSettingTab extends PluginSettingTab {
constructor(public plugin: MyPlugin) {
super(plugin.app, plugin);
}

display(): void {
this.containerEl.empty();

new Setting(this.containerEl)
.setDesc('If something is not working, type some math expression outside callouts in Live Preview.')

new Setting(this.containerEl)
.setName("Show setup guidance notifications")
.addToggle((toggle) => {
toggle.setValue(this.plugin.settings.notification)
.onChange(async (value) => {
this.plugin.settings.notification = value;
await this.plugin.saveSettings();
this.plugin.showNotReadyNotice();
});
});
}
}

0 comments on commit bfa04c2

Please sign in to comment.