generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.ts
109 lines (94 loc) · 2.75 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { App, Plugin, PluginSettingTab, Setting, TFile } from "obsidian";
import FileService from "src/filehandler/FileService";
import FileRenderer from "./src/filehandler/FileRenderer";
import { DEFAULT_TEMPLATE } from "src/util/constants";
interface MeetingNotesSettings {
meetingNoteFolder: string;
template: string;
}
const DEFAULT_SETTINGS: MeetingNotesSettings = {
meetingNoteFolder: "MeetingNotes",
template: DEFAULT_TEMPLATE,
};
export default class MeetingNotes extends Plugin {
settings: MeetingNotesSettings;
fileHandler: FileRenderer;
fileService: FileService;
private registerServices() {
this.fileHandler = new FileRenderer(
this.app.vault,
this.app.fileManager
);
this.fileService = new FileService(this.fileHandler);
}
async onload() {
this.registerServices();
await this.loadSettings();
this.addSettingTab(new MeetingNotesSettingTab(this.app, this));
this.app.vault.on("create", async (file: TFile) => {
// on "create" callback is also triggered when folders are created, filter by checking wether the
// new file has an extension
if (file.extension !== undefined) {
await this.fileService.createFileCreationCallback(
file,
this.settings.meetingNoteFolder,
this.settings.template
);
}
});
console.log("Info: Community plugin Meeting notes loaded.");
}
onunload() {}
async loadSettings() {
this.settings = Object.assign(
{},
DEFAULT_SETTINGS,
await this.loadData()
);
}
async saveSettings() {
await this.saveData(this.settings);
}
}
class MeetingNotesSettingTab extends PluginSettingTab {
plugin: MeetingNotes;
constructor(app: App, plugin: MeetingNotes) {
super(app, plugin);
this.plugin = plugin;
}
display(): void {
const { containerEl } = this;
containerEl.empty();
containerEl.createEl("h2", { text: "Meeting Notes Settings" });
new Setting(containerEl)
.setName("Meeting Notes Folder Name")
.setDesc("Folder which will contain the generated notes")
.addText((text) =>
text
.setPlaceholder("Enter your meeting folder name")
.setValue(this.plugin.settings.meetingNoteFolder)
.onChange(async (value) => {
this.plugin.settings.meetingNoteFolder = value;
await this.plugin.saveSettings();
})
);
new Setting(containerEl)
.setName("Template")
.setDesc(
"Use the default template or define your own. Hint: {{Date}} will be resolved to the current date"
)
.addTextArea((text) =>
text
.setPlaceholder(DEFAULT_TEMPLATE)
.setValue(this.plugin.settings.template)
.onChange(async (value) => {
this.plugin.settings.template = value;
await this.plugin.saveSettings();
})
.then((text) => {
text.inputEl.style.width = "100%";
text.inputEl.rows = 10;
})
);
}
}