Skip to content

Commit

Permalink
🎨 Adjust settings to save only the changed parts
Browse files Browse the repository at this point in the history
  • Loading branch information
mokeyish committed May 17, 2022
1 parent 89fd0b8 commit e1cbc56
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-enhancing-export",
"name": "Obsidian Enhancing Export",
"version": "1.0.8",
"version": "1.0.9",
"minAppVersion": "0.12.0",
"description": "This is a enhancing export plugin for Obsidian. It allows to export to formats like Html, DOCX, ePub and PDF or Markdown(Hugo) etc.",
"author": "YISH",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-enhancing-export",
"version": "1.0.8",
"version": "1.0.9",
"description": "This is a enhancing export plugin for Obsidian. It allows to export to formats like Html, DOCX, ePub and PDF or Markdown(Hugo) etc.",
"main": "dist/main.js",
"scripts": {
Expand Down
23 changes: 19 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import luaScripts from './lua';
import { App, Menu, Plugin, PluginManifest, TFile, Notice } from 'obsidian';
import { UniversalExportPluginSettings, DEFAULT_SETTINGS, getPlatformValue } from './settings';
import { UniversalExportPluginSettings, ExportSetting, DEFAULT_SETTINGS, getPlatformValue } from './settings';
import { ExportDialog } from './ui/export_dialog';
import { ExportSettingTab } from './ui/setting_tab';
import lang, { Lang } from './lang';
Expand All @@ -17,7 +17,7 @@ export default class UniversalExportPlugin extends Plugin {

async onload() {
await this.loadSettings();
const { lang, settings: globalSetting } = this;
const { lang } = this;

this.addSettingTab(new ExportSettingTab(this.app, this));

Expand Down Expand Up @@ -83,7 +83,11 @@ export default class UniversalExportPlugin extends Plugin {
}

public async loadSettings(): Promise<void> {
this.settings = Object.assign({}, JSON.parse(JSON.stringify(DEFAULT_SETTINGS)), await this.loadData());
const settings: UniversalExportPluginSettings = Object.assign({}, await this.loadData());
settings.items.forEach(v => {
Object.assign(v, DEFAULT_SETTINGS.items.find(o => o.name === v.name) ?? {}, v);
});
this.settings = settings;
if (this.settings.version !== this.manifest.version) {
await this.saveLuaScripts();
this.settings.version = this.manifest.version;
Expand All @@ -93,7 +97,18 @@ export default class UniversalExportPlugin extends Plugin {

public async saveSettings(): Promise<void> {
console.log('[obsidian-enhancing-export] saveSettings', this.settings);
await this.saveData(this.settings);
const settings: UniversalExportPluginSettings = JSON.parse(JSON.stringify(this.settings));
settings.items.forEach(v => {
const def = DEFAULT_SETTINGS.items.find(o => o.name === v.name);
if (def) {
Object.keys(v).forEach((k: keyof ExportSetting) => {
if (k !== 'name' && v[k] === def[k]) {
delete v[k];
}
});
}
});
await this.saveData(settings);
}

async saveLuaScripts(): Promise<void> {
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"1.0.5": "0.12.0",
"1.0.6": "0.12.0",
"1.0.7": "0.12.0",
"1.0.8": "0.12.0"
"1.0.8": "0.12.0",
"1.0.9": "0.12.0"
}

0 comments on commit e1cbc56

Please sign in to comment.