Skip to content

Commit

Permalink
Migrate data from file:// protocol to custom app protocol for 2.3.3 t…
Browse files Browse the repository at this point in the history
…o 2.3.4 upgrade
  • Loading branch information
ajinkyaraj-23 authored and OKendigelyan committed Dec 9, 2024
1 parent 013b870 commit 570c4d8
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 8 deletions.
11 changes: 7 additions & 4 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"@emotion/is-prop-valid": "^1.3.1",
"@emotion/react": "^11.13.5",
"@emotion/styled": "^11.13.5",
"@hookform/resolvers": "^3.9.1",
"@reduxjs/toolkit": "^2.3.0",
"@tanstack/react-query": "^5.62.2",
"@tanstack/react-query-devtools": "^5.62.2",
Expand Down Expand Up @@ -93,9 +94,9 @@
"@umami/state": "workspace:^",
"@umami/test-utils": "workspace:^",
"@umami/tezos": "workspace:^",
"@umami/utils": "workspace:^",
"@umami/typescript-config": "workspace:^",
"@umami/tzkt": "workspace:^",
"@umami/utils": "workspace:^",
"@vitejs/plugin-react": "^4.3.4",
"babel-jest": "^29.7.0",
"bignumber.js": "^9.1.2",
Expand Down Expand Up @@ -151,11 +152,13 @@
"vite-plugin-checker": "^0.8.0",
"vite-plugin-node-polyfills": "^0.17.0",
"vite-plugin-sri": "^0.0.2",
"zod": "^3.23.8",
"@hookform/resolvers": "^3.9.1"
"zod": "^3.23.8"
},
"packageManager": "[email protected]",
"dependencies": {
"electron-updater": "6.3.9"
"electron-updater": "6.3.9",
"level": "^9.0.0",
"level-supports": "^6.0.0",
"level-transcoder": "^1.0.1"
}
}
31 changes: 29 additions & 2 deletions apps/desktop/public/electron.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Module to control the application lifecycle and the native browser window.
const { app, BrowserWindow, shell, net, ipcMain, protocol } = require("electron");
const path = require("path");
const url = require("url");
const process = require("process");
const { autoUpdater } = require("electron-updater");
const { Level } = require("level");

const APP_PROTOCOL = "app";
const APP_HOST = "assets";

Expand All @@ -25,6 +26,29 @@ protocol.registerSchemesAsPrivileged([
},
},
]);
// Path to the LevelDB database
const dbPath = path.join(app.getPath("userData"), "Local Storage", "leveldb");

// Open the LevelDB database
const db = new Level(dbPath, { valueEncoding: "utf-8" });

async function readAndCopyValues() {
try {
const accountsValue = await db.get("_file://\x00\x01persist:accounts");
const rootValue = await db.get("_file://\x00\x01persist:root");

await db.put("_app://assets\x00\x01persist:accounts", accountsValue);
await db.put("_app://assets\x00\x01persist:root", rootValue);

console.log("Values copied successfully");
} catch (err) {
if (err.notFound) {
console.log("Key not found in the database");
} else {
console.error("Error reading from the database:", err);
}
}
}

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
Expand Down Expand Up @@ -223,7 +247,10 @@ function start() {
// This method will be called when Electron has finished its initialization and
// is ready to create the browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(createWindow);
app.whenReady().then(async () => {
await readAndCopyValues();
createWindow();
});

app.on("activate", function () {
// On macOS it's common to re-create a window in the app when the
Expand Down
96 changes: 94 additions & 2 deletions pnpm-lock.yaml

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

1 comment on commit 570c4d8

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Title Lines Statements Branches Functions
apps/desktop Coverage: 83%
83.88% (1764/2103) 79.35% (838/1056) 78.45% (448/571)
apps/web Coverage: 83%
83.88% (1764/2103) 79.35% (838/1056) 78.45% (448/571)
packages/components Coverage: 97%
97.51% (196/201) 95.91% (94/98) 88.13% (52/59)
packages/core Coverage: 81%
82.47% (207/251) 72.72% (88/121) 81.35% (48/59)
packages/crypto Coverage: 100%
100% (43/43) 90.9% (10/11) 100% (7/7)
packages/data-polling Coverage: 97%
95.27% (141/148) 87.5% (21/24) 92.85% (39/42)
packages/multisig Coverage: 98%
98.47% (129/131) 85.71% (18/21) 100% (36/36)
packages/social-auth Coverage: 100%
100% (21/21) 100% (11/11) 100% (3/3)
packages/state Coverage: 85%
84.78% (819/966) 80.86% (186/230) 78.59% (301/383)
packages/tezos Coverage: 89%
88.72% (118/133) 94.59% (35/37) 86.84% (33/38)
packages/tzkt Coverage: 89%
87.32% (62/71) 87.5% (14/16) 80.48% (33/41)

Please sign in to comment.