-
Notifications
You must be signed in to change notification settings - Fork 0
/
SyrinscapeSettingsTab.ts
79 lines (68 loc) · 3.11 KB
/
SyrinscapeSettingsTab.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
import { App, ButtonComponent, PluginSettingTab, Setting } from 'obsidian';
import SyrinscapePlugin from 'main';
import { DEFAULT_SETTINGS } from 'main';
export class SyrinscapeSettingsTab extends PluginSettingTab {
plugin: SyrinscapePlugin;
constructor(app: App, plugin: SyrinscapePlugin) {
super(app, plugin);
this.plugin = plugin;
}
display() {
const { containerEl } = this;
containerEl.empty();
containerEl.createEl('h2', { text: 'Syrinscape Plugin Settings' });
// create an anchor link to the Syrinscape control panel
const desc:DocumentFragment=new DocumentFragment();
desc.appendText("Enter your Syrinscape Auth token here. You can find it in your ")
desc.append(desc.createEl('a', {"href": "https://syrinscape.com/online/cp/", text: "Syrinscape control panel."}))
new Setting(containerEl)
.setName('Auth Token')
.setDesc(desc)
.addText(text => text
.setPlaceholder(DEFAULT_SETTINGS.authToken)
.setValue(this.plugin.settings.authToken)
.onChange(async (value) => {
this.plugin.settings.authToken = value;
await this.plugin.saveData(this.plugin.settings);
}));
// Number setting for the maximum cache age, in days
new Setting(containerEl)
.setName('Cache Age')
.setDesc(`Enter the maximum age of the cache in days. Default is ${DEFAULT_SETTINGS.maxCacheAge.toString()} days.`)
.addText(text => text
.setPlaceholder(DEFAULT_SETTINGS.maxCacheAge.toString())
.setValue(this.plugin.settings.maxCacheAge.toString())
.onChange(async (value) => {
this.plugin.settings.maxCacheAge = parseInt(value);
await this.plugin.saveData(this.plugin.settings);
}));
// String setting for the trigger word, e.g. `syrinscape` or `sscape`
new Setting(containerEl)
.setName('Trigger Word')
.setDesc('Enter the word that the Syrinscape player plugin will look for. Default is "syrinscape"')
.addText(text => text
.setPlaceholder(DEFAULT_SETTINGS.triggerWord)
.setValue(this.plugin.settings.triggerWord)
.onChange(async (value) => {
this.plugin.settings.triggerWord = value;
await this.plugin.saveData(this.plugin.settings);
}));
// Create a button which will call the method to clear the CSV content
const buttonDesc: DocumentFragment = new DocumentFragment();
buttonDesc.appendText("This plugin will cache remote control links for at most 24 hours.");
buttonDesc.append(desc.createEl('br'));
buttonDesc.appendText("You can manually clear the Remote Links that were downloaded from Syrinscape on ");
const dateText = buttonDesc.createEl('b');
dateText.appendText(this.plugin.settings.lastUpdated?this.plugin.settings.lastUpdated.toDateString():'never');
buttonDesc.append(dateText);
new Setting(containerEl)
.setName('Clear Remote Links')
.setDesc(buttonDesc)
.addButton(button => button
.setButtonText('Clear Remote Links')
.onClick(async () => {
this.plugin.clearCache();
this.plugin.fetchRemoteLinks();
}));
}
}