Skip to content

Commit

Permalink
Use __json_name mark property
Browse files Browse the repository at this point in the history
  • Loading branch information
AlttiRi committed Nov 1, 2024
1 parent 3134a58 commit 27b5734
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion manifest-ff.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "__MSG_extension_name__",
"short_name": "__MSG_extension_short_name__",
"description": "__MSG_extension_description__",
"version": "1.36.1.20241101",
"version": "1.37.0.20241101",
"content_scripts": [
{
"matches": ["<all_urls>"],
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "__MSG_extension_name__",
"short_name": "__MSG_extension_short_name__",
"description": "__MSG_extension_description__",
"version": "1.36.1.20241101",
"version": "1.37.0.20241101",
"content_scripts": [
{
"matches": ["<all_urls>"],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "i-have-been-here",
"keywords": ["extension", "bookmarks", "screenshots", "visits", "typescript", "vue"],
"version": "1.36.1.20241101",
"version": "1.37.0.20241101",
"type": "module",
"license": "GPL-3.0",
"devDependencies": {
Expand Down
9 changes: 7 additions & 2 deletions src/bg/store-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {getScdId} from "@/common/image-data";
import {commonSettingsDefault} from "@/common/reactive-store";


const lastStoreVersion = 5;
const lastStoreVersion = 6;
let wasInstalled = false;

/**
Expand Down Expand Up @@ -210,7 +210,12 @@ export async function updateStoreModel(): Promise<void> {

await bumpVersion(); // -> 5
}

if (version === 5) {
await setToStoreLocal("__json_name", "ihbh-extension-storage");
await bumpVersion(); // -> 6
}
}
// [note] Do not forget to update `lastStoreVersion` above! And use `bumpVersion()`.

// todo (?) handle errors/broken data
// todo?: handle errors/broken data
2 changes: 1 addition & 1 deletion src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type StoreLocalModel = {
visits: Visit[] | undefined
screenshots: ScreenshotInfo[] | undefined
[scd_id: ScreenshotDataId]: Base64
// __json_name: "ihbh-extension-storage" // todo: use this value to mark the storage JSON
__json_name: "ihbh-extension-storage"
} & StoreLocalBase;

export type ScreenshotEntry = [ScreenshotDataId, StoreLocalModel[ScreenshotDataId]];
Expand Down
16 changes: 15 additions & 1 deletion src/vue-pages/settings/storage-backup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {downloadBlob} from "@alttiri/util-js";
import {logOrange} from "@/utils/util";

/** To export the entire `chrome.storage.local`. */
export function exportStore(browserName = "") {
Expand Down Expand Up @@ -41,10 +42,23 @@ export function importStore() {
input.addEventListener("change", async event => {
// @ts-ignore
const json = JSON.parse(await input.files[0].text());
if (!("version" in json)) {

if (Array.isArray(json) || typeof json !== "object") {
logOrange("[importStore] json is not an object")();
return;
}
if (!("version" in json)) { // todo: remove later
json.version = 1;
}

if (json.__json_name !== "ihbh-extension-storage") {
logOrange(`Missed or wrong "__json_name" mark property`)();
const response = confirm(`Missed or wrong "__json_name" mark property. Import?`);
if (!response) {
return;
}
}

console.log("json", json);
// @ts-ignore
globalThis.json = json;
Expand Down

0 comments on commit 27b5734

Please sign in to comment.