forked from longy2k/obsidian-bmo-chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.ts
151 lines (125 loc) · 5.32 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
142
143
144
145
146
147
148
149
150
151
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 information
const { containerEl } = this;
containerEl.empty();
containerEl.createEl('h1', { text: 'BMO Chatbot Settings' });
// Create a container for the links
const linkContainer = containerEl.createEl('div');
// Define link data
const links = [
{ text: 'Changelog', href: 'https://github.com/longy2k/obsidian-bmo-chatbot/releases' },
{ text: 'Wiki', href: 'https://github.com/longy2k/obsidian-bmo-chatbot/wiki' },
{ text: 'Report a Bug', href: 'https://github.com/longy2k/obsidian-bmo-chatbot/issues' },
{ text: 'Support Me', href: 'https://ko-fi.com/longy2k' }
];
// Create links and separators
links.forEach((link, index) => {
if (index > 0) {
linkContainer.createEl('span', {
text: ' | ',
attr: { style: 'font-size: 0.8rem; margin-right: 5px;' }
});
}
const linkEl = linkContainer.createEl('a', {
text: link.text,
href: link.href,
attr: { style: 'font-size: 0.8rem;' }
});
if (index < links.length - 1) {
linkEl.style.marginRight = '5px';
}
});
containerEl.createEl('p', { text: 'Type `/help` in chat for commands.' });
// Add horizontal rule
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);
// Add horizontal rule
addHorizontalRule(this.containerEl);
// Display settings
addOllamaSettings(this.containerEl, this.plugin, this);
addRESTAPIURLSettings(this.containerEl, this.plugin, this);
addAPIConnectionSettings(this.containerEl, this.plugin, this);
// Add horizontal rule
addHorizontalRule(this.containerEl);
// Add reset button
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);
}