Skip to content

Commit

Permalink
Fixing bug that would prevent exported configuration files from being…
Browse files Browse the repository at this point in the history
… loaded (Fixes #158).
  • Loading branch information
coddingtonbear committed Jan 19, 2024
1 parent ac0b804 commit 6820e96
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const DefaultHeaders = {};
export const DefaultMethod = "put";

export const DefaultLocalSettings: ExtensionLocalSettings = {
version: "0.2",
version: "2.0",
host: "127.0.0.1",
insecureMode: false,
apiKey: "",
Expand Down Expand Up @@ -57,7 +57,7 @@ export const DefaultSearchMatchTemplate: OutputPreset = {
};

export const DefaultSyncSettings: ExtensionSyncSettings = {
version: "0.2",
version: "2.0",
presets: [
{
name: "Append to current daily note",
Expand Down
4 changes: 2 additions & 2 deletions src/options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,9 @@ const Options: React.FunctionComponent<Props> = ({ sandbox }) => {
if (
!parsed ||
!parsed.sync ||
compareVersions(parsed.sync.version, "0.2") > 0 ||
compareVersions(parsed.sync.version, "2.0") > 0 ||
!parsed.local ||
compareVersions(parsed.local.version, "0.2") > 0
compareVersions(parsed.local.version, "2.0") > 0
) {
alert(
"Could not parse configuration file! See console for details."
Expand Down
18 changes: 18 additions & 0 deletions src/settings_migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ export async function migrateLocalSettings(
local: chrome.storage.LocalStorageArea,
settings: Record<string, any>
): Promise<ExtensionLocalSettings> {
if (settings.version == "0.2") {
// In ac0b804b634fded00363f38e996068dcd42ec68e and before, we
// were erroneously setting the sync version to 2.0 in options.tsx;
// and having two different version numbers for sync/local that
// were 0.2 and 2.0 was going to be confusing -- let's just bump
// them both together to 2.0.
settings.version = "2.0";
await local.clear();
await local.set(settings);
}
return settings as ExtensionLocalSettings;
}

Expand Down Expand Up @@ -58,5 +68,13 @@ export async function migrateSyncSettings(
await sync.set(newSettings);
settings = newSettings;
}
if (settings.version == "0.2") {
// In ac0b804b634fded00363f38e996068dcd42ec68e and before, we
// were erroneously setting the sync version to 2.0 in options.tsx;
// so we need to just bump the version number up.
settings.version = "2.0";
await sync.clear();
await sync.set(settings);
}
return settings as ExtensionSyncSettings;
}

0 comments on commit 6820e96

Please sign in to comment.