diff --git a/src/main.ts b/src/main.ts index 8962ea6..f8c0c92 100644 --- a/src/main.ts +++ b/src/main.ts @@ -72,6 +72,13 @@ export default class JustSharePleasePlugin extends Plugin { } } })); + this.registerEvent(this.app.vault.on("modify", f => { + if (this.settings.autoUpdateShares && f instanceof TFile) { + let shared = this.getSharedItem(f.path); + if (shared) + this.updateFile(shared, f, false); + } + })); this.addCommand({ id: "share", @@ -177,12 +184,10 @@ export default class JustSharePleasePlugin extends Plugin { new Notice(`Successfully updated ${file.basename} on JSP`); return true; } catch (e) { - if (notice) { - new Notice(createFragment(f => { - f.createSpan({text: `There was an error updating ${file.basename}: `}); - f.createEl("code", {text: e}); - }), 10000); - } + new Notice(createFragment(f => { + f.createSpan({text: `There was an error updating ${file.basename}: `}); + f.createEl("code", {text: e}); + }), 10000); console.log(e); } @@ -205,12 +210,10 @@ export default class JustSharePleasePlugin extends Plugin { new Notice(`Successfully deleted ${name} from JSP`); return true; } catch (e) { - if (notice) { - new Notice(createFragment(f => { - f.createSpan({text: `There was an error deleting ${name}: `}); - f.createEl("code", {text: e}); - }), 10000); - } + new Notice(createFragment(f => { + f.createSpan({text: `There was an error deleting ${name}: `}); + f.createEl("code", {text: e}); + }), 10000); console.log(e); } } diff --git a/src/settings-tab.ts b/src/settings-tab.ts index e10432a..37abc88 100644 --- a/src/settings-tab.ts +++ b/src/settings-tab.ts @@ -14,7 +14,6 @@ export class JSPSettingsTab extends PluginSettingTab { display(): void { this.containerEl.empty(); this.containerEl.createEl("h2", {text: "Just Share Please Settings"}); - new Setting(this.containerEl) .setName("Just Share Please Server") .setDesc(createFragment(f => { @@ -31,7 +30,6 @@ export class JSPSettingsTab extends PluginSettingTab { await this.plugin.saveSettings(); }); }); - new Setting(this.containerEl) .setName("Strip Frontmatter") .setDesc("Whether document frontmatter (also known as properties) should be removed from the uploaded share.") @@ -42,7 +40,6 @@ export class JSPSettingsTab extends PluginSettingTab { await this.plugin.saveSettings(); }); }); - new Setting(this.containerEl) .setName("Include Note Name") .setDesc("Whether the name of the shared note should be included in the share as a heading.") @@ -53,7 +50,6 @@ export class JSPSettingsTab extends PluginSettingTab { await this.plugin.saveSettings(); }); }); - new Setting(this.containerEl) .setName("Unshare Deleted Files") .setDesc("Whether shares of files should be removed automatically when they are deleted. Only supported when deleting from within Obsidian.") @@ -64,6 +60,16 @@ export class JSPSettingsTab extends PluginSettingTab { await this.plugin.saveSettings(); }); }); + new Setting(this.containerEl) + .setName("Automatically Update Shares") + .setDesc("Whether a file's share should automatically be updated when the file is changed from within Obsidian.") + .addToggle(t => { + t.setValue(this.plugin.settings.autoUpdateShares); + t.onChange(async v => { + this.plugin.settings.autoUpdateShares = v; + await this.plugin.saveSettings(); + }); + }); this.containerEl.createEl("hr"); this.containerEl.createEl("p", {text: "If you like this plugin and want to support its development, you can do so through my website by clicking this fancy image!"}); diff --git a/src/settings.ts b/src/settings.ts index e36d6e9..1e5397d 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -3,10 +3,10 @@ export const defaultSettings: JSPSettings = { shared: [], stripFrontmatter: true, includeNoteName: true, - unshareDeletedFiles: true + unshareDeletedFiles: true, + autoUpdateShares: false }; -// TODO add a setting for auto-refreshing uploads when saving export interface JSPSettings { url: string; @@ -14,6 +14,7 @@ export interface JSPSettings { stripFrontmatter: boolean; includeNoteName: boolean; unshareDeletedFiles: boolean; + autoUpdateShares: boolean; } diff --git a/test-vault/.obsidian/plugins/just-share-please/data.json b/test-vault/.obsidian/plugins/just-share-please/data.json index 233094f..52e5071 100644 --- a/test-vault/.obsidian/plugins/just-share-please/data.json +++ b/test-vault/.obsidian/plugins/just-share-please/data.json @@ -1,7 +1,14 @@ { "url": "http://localhost:8080", - "shared": [], + "shared": [ + { + "id": "234df7b7", + "password": "0ef1504bfe83cd9ca812434caa7aacf4", + "path": "Cool Test Note.md" + } + ], "stripFrontmatter": true, "includeNoteName": true, - "unshareDeletedFiles": false + "unshareDeletedFiles": false, + "autoUpdateShares": false } \ No newline at end of file diff --git a/test-vault/Cool Test Note.md b/test-vault/Cool Test Note.md index 6186347..01799a5 100644 --- a/test-vault/Cool Test Note.md +++ b/test-vault/Cool Test Note.md @@ -24,6 +24,8 @@ $.ajax({ cool!! +blah blah i added and removed this + The following is $x^2 = 7$, but more complicated! $$ x^2 + \sum_{i = 1}^{10000} x^2 \cdot 0 = 7