Skip to content

Commit 1b87faf

Browse files
committed
fix(settings): Default settings data at startup.
1 parent 7fb93dd commit 1b87faf

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

src/main.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
clearExpiredSyncPlanRecords,
3535
} from "./localdb";
3636
import { RemoteClient, ServerDomain } from "./remote";
37-
import { InvioSettingTab, DEFAULT_SETTINGS } from "./settings";
37+
import { InvioSettingTab, getDEFAULT_SETTINGS } from "./settings";
3838
import { fetchMetadataFile, parseRemoteItems, SyncStatusType, RemoteSrcPrefix, syncAttachment, LocalConflictPrefix, RemoteConflictPrefix } from "./sync";
3939
import { doActualSync, getSyncPlan, isPasswordOk, fetchRemoteFileMD, pruneTouchedFiles } from "./sync";
4040
import { messyConfigToNormal, normalConfigToMessy } from "./configPersist";
@@ -1133,12 +1133,9 @@ export default class InvioPlugin extends Plugin {
11331133
}
11341134
this.settings = Object.assign(
11351135
{},
1136-
cloneDeep(DEFAULT_SETTINGS),
1137-
rawConf ? {} : messyConfigToNormal(rawConf)
1136+
getDEFAULT_SETTINGS(),
1137+
messyConfigToNormal(rawConf) || {}
11381138
);
1139-
if (!this.settings.s3) {
1140-
this.settings.s3 = DEFAULT_SETTINGS.s3
1141-
}
11421139
if (this.settings.s3.partsConcurrency === undefined) {
11431140
this.settings.s3.partsConcurrency = 20;
11441141
}

src/settings.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
requireApiVersion,
1010
} from "obsidian";
1111
import type { TextComponent } from "obsidian";
12+
import cloneDeep from "lodash/cloneDeep";
1213
import { createElement, Eye, EyeOff } from "lucide";
1314
import {
1415
InvioPluginSettings,
@@ -53,8 +54,8 @@ import { ProjectImportModal } from './components/ProjectImportModal';
5354
export const settingsPrefix = `Invio-Settings>`;
5455
export const settingsSuffix = `<&`
5556

56-
export const DEFAULT_SETTINGS: InvioPluginSettings = {
57-
s3: DEFAULT_S3_CONFIG,
57+
const DEFAULT_SETTINGS: InvioPluginSettings = {
58+
s3: cloneDeep(DEFAULT_S3_CONFIG),
5859
useHost: false,
5960
hostConfig: {
6061
hostPair: null,
@@ -78,6 +79,33 @@ export const DEFAULT_SETTINGS: InvioPluginSettings = {
7879
skipSizeLargerThan: -1,
7980
};
8081

82+
export const getDEFAULT_SETTINGS = (): InvioPluginSettings => {
83+
return cloneDeep({
84+
s3: cloneDeep(DEFAULT_S3_CONFIG),
85+
useHost: false,
86+
hostConfig: {
87+
hostPair: null,
88+
token: '',
89+
user: null,
90+
},
91+
password: "",
92+
remoteDomain: '',
93+
serviceType: "s3",
94+
currLogLevel: "info",
95+
// vaultRandomID: "", // deprecated
96+
autoRunEveryMilliseconds: -1,
97+
initRunAfterMilliseconds: -1,
98+
agreeToUploadExtraMetadata: false,
99+
concurrency: 5,
100+
syncConfigDir: false,
101+
localWatchDir: "PublishDocs",
102+
syncUnderscoreItems: true,
103+
lang: "auto",
104+
logToDB: false,
105+
skipSizeLargerThan: -1,
106+
});
107+
}
108+
81109
class PasswordModal extends Modal {
82110
plugin: InvioPlugin;
83111
newPassword: string;

0 commit comments

Comments
 (0)