Skip to content

Commit

Permalink
feat: allow to obtain access-key via click of a button in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
xeroc committed Dec 2, 2023
1 parent 567e52e commit 01687b1
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ export default class RelayMdPLugin extends Plugin {

async onload() {
await this.loadSettings();

// To make obtaining the access-token easier,
// we register a protocol handler
this.registerObsidianProtocolHandler("relay.md:access-token", (params) =>{
if (!params.token) {
return;
}
this.settings.api_key = params.token;
this.settings.base_uri = DEFAULT_SETTINGS.base_uri; // also potentially reset the base uri
this.saveSettings();
new Notice("Access credentials for relay.md have been succesfully installed!");
});

this.addCommand({
id: "relay-md-send-current-active-file",
Expand Down Expand Up @@ -243,16 +255,28 @@ class RelayMDSettingTab extends PluginSettingTab {
await this.plugin.saveSettings();
}));

new Setting(containerEl)
.setName('Setting #1')
.setDesc('It\'s a secret')
.addText(text => text
.setPlaceholder('Enter your API-Key')
.setValue(this.plugin.settings.api_key)
.onChange(async (value) => {
this.plugin.settings.api_key = value;
await this.plugin.saveSettings();
}));
if (this.plugin.settings.api_key == DEFAULT_SETTINGS.api_key) {
new Setting(containerEl)
.setName('API Access')
.setDesc('Authenticate against the relay.md API')
.addButton((button) =>
button.setButtonText("Obtain access to relay.md").onClick(async () => {
window.open("localhost:5000/configure/obsidian");
})
);
} else {
new Setting(containerEl)
.setName('API Access')
.setDesc('Authenticate against the relay.md API')
.addButton((button) =>
button.setButtonText("reset").onClick(async () => {
this.plugin.settings.api_key = DEFAULT_SETTINGS.api_key;
await this.plugin.saveSettings();
// refresh settings page
this.display();
})
);
}

new Setting(containerEl)
.setName('Vault relay.md inbox')
Expand Down

0 comments on commit 01687b1

Please sign in to comment.