Skip to content

Commit

Permalink
fix: reset settings
Browse files Browse the repository at this point in the history
  • Loading branch information
longy2k committed Mar 16, 2024
1 parent 5edb371 commit 71d5fed
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bmo-chatbot",
"version": "1.8.9",
"version": "1.9.0",
"description": "Generate and brainstorm ideas while creating your notes using Large Language Models (LLMs) from Ollama, LM Studio, Anthropic, OpenAI, Mistral AI, and more for Obsidian.",
"main": "main.js",
"scripts": {
Expand Down
35 changes: 27 additions & 8 deletions src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { App, PluginSettingTab } from 'obsidian';
import BMOGPT, { DEFAULT_SETTINGS } from './main';
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';
Expand Down Expand Up @@ -62,12 +62,31 @@ export class BMOSettingTab extends PluginSettingTab {
event.preventDefault();
const confirmReset = confirm('Are you sure you want to reset all settings to default?');
if (confirmReset) {
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);
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
Expand Down
4 changes: 3 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"1.8.7": "1.0.0",
"1.8.8": "1.0.0"
"1.8.8": "1.0.0",
"1.8.9": "1.0.0",
"1.9.0": "1.8.9"
}

0 comments on commit 71d5fed

Please sign in to comment.