Skip to content

Commit

Permalink
fix(settings): allow deep merge of settings, preventing error with ne…
Browse files Browse the repository at this point in the history
…sted objet
  • Loading branch information
Mara-Li committed Nov 9, 2023
1 parent 26dbbdc commit a252eb9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
"typescript": "^5.2.2"
},
"dependencies": {
"dedent": "^0.7.0"
"dedent": "^0.7.0",
"ts-deepmerge": "^6.2.0"
},
"pnpm": {
"overrides": {
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

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

14 changes: 5 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Octokit} from "@octokit/core";
import i18next from "i18next";
import {FrontMatterCache, Menu, Plugin, TAbstractFile, TFile, TFolder} from "obsidian";
import merge from "ts-deepmerge";

import {
checkRepositoryValidityCallback,
Expand Down Expand Up @@ -179,14 +180,15 @@ export default class GithubPublisher extends Plugin {
*/
async onload(): Promise<void> {
console.info(`[GITHUB PUBLISHER] v.${this.manifest.version} (lang: ${translationLanguage}) loaded`);
await this.loadSettings();

await i18next.init({
lng: translationLanguage,
fallbackLng: "en",
resources,
returnNull: false,
});

await this.loadSettings();


const oldSettings = this.settings;
Expand Down Expand Up @@ -258,15 +260,9 @@ export default class GithubPublisher extends Plugin {
console.info("[Github Publisher] unloaded");
}

/**
* Get the settings of the plugin
*/
async loadSettings() {
this.settings = Object.assign(
{},
DEFAULT_SETTINGS,
await this.loadData()
);
const loadedData = await this.loadData();
this.settings = merge(DEFAULT_SETTINGS, loadedData) as unknown as GitHubPublisherSettings;
}

/**
Expand Down

0 comments on commit a252eb9

Please sign in to comment.