generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsetting.ts
123 lines (107 loc) · 4.22 KB
/
setting.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import AOSRPlugin from "main";
import { App, PluginSettingTab, Setting } from "obsidian";
import i18n from 'i18next';
export interface AOSRSettings {
DefaultEase: number;
EasyBonus: number;
HardBonus: number;
WordTTSURL: string;
WaitingTimeoutBase: number;
HideContext: boolean;
}
const AOSR_DEFAULT_SETTINGS: AOSRSettings = {
DefaultEase: 250,
EasyBonus: 1,
HardBonus: 1,
WordTTSURL: "",
WaitingTimeoutBase: 7,
HideContext: false,
}
// i18n.t('someKey');
export let GlobalSettings: AOSRSettings
export function setGlobalSettings(s: AOSRSettings) {
let settings = Object.assign({}, AOSR_DEFAULT_SETTINGS, s);
GlobalSettings = settings
}
export class AOSRSettingTab extends PluginSettingTab {
plugin: AOSRPlugin;
constructor(app: App, plugin: AOSRPlugin) {
super(app, plugin);
this.plugin = plugin;
}
display(): void {
const { containerEl } = this;
containerEl.empty();
containerEl.createEl('h2', { text: i18n.t('SettingTextAosrSettings') || "" });
new Setting(containerEl)
.setName(i18n.t('SettingTextInitEase') || "")
.setDesc(i18n.t('SettingTextInitEaseDesc') || "")
.addText(text => text
.setPlaceholder('100-500')
.setValue(GlobalSettings.DefaultEase.toString())
.onChange(async (value) => {
GlobalSettings.DefaultEase = Number(value);
await this.plugin.saveSettings();
}));
new Setting(containerEl)
.setName(i18n.t('SettingTextEasyChoice') || "")
.setDesc(i18n.t('SettingTextEaseChoiceDesc') || "")
.addText(text => text
.setPlaceholder('0-10')
.setValue(GlobalSettings.EasyBonus.toString())
.onChange(async (value) => {
GlobalSettings.EasyBonus = Number(value);
await this.plugin.saveSettings();
}));
new Setting(containerEl)
.setName(i18n.t('SettingTextHardChoice') || "")
.setDesc(i18n.t('SettingTextHardChoiceDesc') || "")
.addText(text => text
.setPlaceholder('0-10')
.setValue(GlobalSettings.HardBonus.toString())
.onChange(async (value) => {
GlobalSettings.HardBonus = Number(value);
await this.plugin.saveSettings();
}));
new Setting(containerEl)
.setName(i18n.t('SettingTextWaitting') || "")
.setDesc(i18n.t('SettingTextWaittingDesc') || "")
.addSlider(slider => slider
.setDynamicTooltip()
.setLimits(0, 15, 0.5)
.setValue(GlobalSettings.WaitingTimeoutBase)
.onChange(async (value) => {
GlobalSettings.WaitingTimeoutBase = Number(value)
await this.plugin.saveSettings();
})
)
new Setting(containerEl)
.setName(i18n.t('SettingHideContext') || '')
.addToggle(toggle => toggle
.setValue(GlobalSettings.HideContext)
.onChange(async (value) => {
GlobalSettings.HideContext = value
await this.plugin.saveSettings();
})
)
new Setting(containerEl)
.setName('Word TTS [experiment]')
.setDesc('Input a TTS URL to pronounce the single word in the card. Use %s to represent word.')
.addText(text => text
.setPlaceholder('http://word.tts/%s')
.setValue(GlobalSettings.WordTTSURL)
.onChange(async (value) => {
GlobalSettings.WordTTSURL = value
await this.plugin.saveSettings();
}))
new Setting(containerEl)
.setName(i18n.t('SettingTextMigrateData') || "")
.setDesc(i18n.t('SettingTextMigrateDataDesc') || "")
.addButton(button => button
.setButtonText(i18n.t('SettingTextMigrateData') || "")
.onClick(async () => {
await this.plugin.migrateData();
}
))
}
}