forked from longy2k/obsidian-bmo-chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.ts
141 lines (115 loc) · 5.07 KB
/
settings.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { App, PluginSettingTab, TFile } from 'obsidian';
import BMOGPT, { DEFAULT_SETTINGS, updateSettingsFromFrontMatter } from './main';
import { addGeneralSettings } from './components/settings/GeneralSettings';
import { addAppearanceSettings } from './components/settings/AppearanceSettings';
import { addChatHistorySettings } from './components/settings/ChatHistorySettings';
import { addOllamaSettings } from './components/settings/OllamaSettings';
import { addAPIConnectionSettings } from './components/settings/ConnectionSettings';
import { addProfileSettings } from './components/settings/ProfileSettings';
import { addRESTAPIURLSettings } from './components/settings/RESTAPIURLSettings';
import { addEditorSettings } from './components/settings/EditorSettings';
import { addPromptSettings } from './components/settings/PromptSettings';
export class BMOSettingTab extends PluginSettingTab {
plugin: BMOGPT;
constructor(app: App, plugin: BMOGPT) {
super(app, plugin);
this.plugin = plugin;
}
async display(): Promise<void> {
// Display settings
const {containerEl} = this;
containerEl.empty();
containerEl.createEl('h1', {text: 'BMO Chatbot Settings'});
// Create a container for the links
const linkContainer = containerEl.createEl('div');
// Changelog link
const changeLogLink = linkContainer.createEl('a', {
text: 'Changelog',
href: 'https://github.com/longy2k/obsidian-bmo-chatbot/releases',
});
changeLogLink.style.fontSize = '0.8rem';
changeLogLink.style.marginRight = '5px'; // Add some space before the separator
// Separator
const separator = linkContainer.createEl('span', {
text: ' | ',
});
separator.style.fontSize = '0.8rem';
separator.style.marginRight = '5px'; // Add some space after the separator
// Wiki link
const wikiLink = linkContainer.createEl('a', {
text: 'Wiki',
href: 'https://github.com/longy2k/obsidian-bmo-chatbot/wiki',
});
wikiLink.style.fontSize = '0.8rem';
containerEl.createEl('p', {text: 'Type `/help` in chat for commands.'});
addHorizontalRule(this.containerEl);
// Display settings
addProfileSettings(this.containerEl, this.plugin, this);
addGeneralSettings(this.containerEl, this.plugin, this);
addPromptSettings(this.containerEl, this.plugin, this);
addAppearanceSettings(this.containerEl, this.plugin, this);
addChatHistorySettings(this.containerEl, this.plugin, this);
addEditorSettings(this.containerEl, this.plugin, this);
addHorizontalRule(this.containerEl);
addOllamaSettings(this.containerEl, this.plugin, this);
addRESTAPIURLSettings(this.containerEl, this.plugin, this);
addAPIConnectionSettings(this.containerEl, this.plugin, this);
addHorizontalRule(this.containerEl);
const resetButton = containerEl.createEl('a', {
text: 'Reset Settings',
href: '#',
attr: {
style: 'display: block; text-align: center; margin: 1rem 0; font-size: 0.7rem; color: #ff6666;'
}
});
resetButton.addEventListener('click', async (event) => {
event.preventDefault();
const confirmReset = confirm('Are you sure you want to reset all settings to default?');
if (confirmReset) {
const profilePathFile = this.plugin.settings.profiles.profileFolderPath + '/' + this.plugin.settings.profiles.profile;
const profilePath = this.plugin.app.vault.getAbstractFileByPath(profilePathFile) as TFile;
const defaultProfilePathFile = DEFAULT_SETTINGS.profiles.profileFolderPath + '/' + DEFAULT_SETTINGS.profiles.profile;
const defaultProfilePath = this.plugin.app.vault.getAbstractFileByPath(defaultProfilePathFile) as TFile;
if (profilePath) {
if (profilePath.path === defaultProfilePath.path) {
this.plugin.settings = DEFAULT_SETTINGS;
await this.plugin.saveSettings();
// @ts-ignore
await this.plugin.app.plugins.disablePlugin(this.plugin.manifest.id);
// @ts-ignore
await this.plugin.app.plugins.enablePlugin(this.plugin.manifest.id);
}
else {
const filenameMessageHistory = './.obsidian/plugins/bmo-chatbot/data/' + 'messageHistory_' + defaultProfilePath.name.replace('.md', '.json');
this.app.vault.adapter.remove(filenameMessageHistory);
this.plugin.app.vault.delete(profilePath);
this.plugin.settings.profiles.profile = DEFAULT_SETTINGS.profiles.profile;
await updateSettingsFromFrontMatter(this.plugin, defaultProfilePath);
await this.plugin.saveSettings();
}
}
requestAnimationFrame(() => {
// @ts-ignore
const refreshTab = this.plugin.app.setting.openTabById('bmo-chatbot');
if (refreshTab) {
refreshTab.display();
} else {
new BMOSettingTab(this.app, this.plugin).display();
}
});
}
});
// const resetNotice = containerEl.createEl('p', {
// text: 'Please reset your settings if you have recently updated from version <2.0.0.',
// attr: {
// style: 'font-size: 0.7rem; text-align: center;'
// }
// });
// containerEl.appendChild(resetNotice);
}
}
function addHorizontalRule(containerEl: HTMLElement) {
const separator = document.createElement('hr');
separator.style.margin = '1rem 0';
containerEl.appendChild(separator);
}