generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
54 lines (43 loc) · 1.47 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import {Notice, Plugin} from 'obsidian';
import {SettingsTab} from './src/tabs/SettingsTab';
import {NostrPublishConfiguration} from './src/types';
import NostrService from "./src/services/NostrService";
import {DEFAULT_EXPLICIT_RELAY_URLS} from "./src/utilities";
import Publish from "./src/modals/Publish";
export default class NostrArticlePublishPlugin extends Plugin {
configuration: NostrPublishConfiguration
nostrService: NostrService;
async onload() {
await this.loadConfiguration();
this.startService();
// This adds a settings tab so the user can configure various aspects of the plugin
this.addSettingTab(new SettingsTab(this.app, this));
this.addRibbonIcon('newspaper', 'Publish to Nostr', async (evt: MouseEvent) => {
if (!this.configuration.privateKey) {
new Notice(`No private key set for Nostr Article Publish cannot publish ${evt.doc.title}`);
}
const file = this.app.workspace.getActiveFile()
if (file) {
if (this.nostrService.Connected()) {
new Publish(this.app, this.nostrService, file, this).open()
}
}
});
}
onunload() {
}
startService() {
this.nostrService = new NostrService(this, this.app, this.configuration);
}
async loadConfiguration() {
this.configuration = Object.assign({}, {
privateKey: "",
relayConfigurationEnabled: false,
relayURLs: DEFAULT_EXPLICIT_RELAY_URLS,
statusBarEnabled: true
}, await this.loadData());
}
async saveConfiguration() {
await this.saveData(this.configuration);
}
}