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 committed Dec 6, 2024
1 parent b3ef307 commit b8779cc
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.

0 comments on commit b8779cc

Please sign in to comment.