Skip to content

Fix RDT #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions FrameworkDevtools/crxToZip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* crxToZip
* Copyright (c) 2013 Rob Wu <[email protected]>
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

module.exports = (buf) => {
function calcLength(a, b, c, d) {
let length = 0;

length += a << 0;
length += b << 8;
length += c << 16;
length += d << 24 >>> 0;
return length;
}

// 50 4b 03 04
// This is actually a zip file
if (buf[0] === 80 && buf[1] === 75 && buf[2] === 3 && buf[3] === 4) {
return buf;
}

// 43 72 32 34 (Cr24)
if (buf[0] !== 67 || buf[1] !== 114 || buf[2] !== 50 || buf[3] !== 52) {
throw new Error("Invalid header: Does not start with Cr24");
}

// 02 00 00 00
// or
// 03 00 00 00
const isV3 = buf[4] === 3;
const isV2 = buf[4] === 2;

if ((!isV2 && !isV3) || buf[5] || buf[6] || buf[7]) {
throw new Error("Unexpected crx format version number.");
}

if (isV2) {
const publicKeyLength = calcLength(buf[8], buf[9], buf[10], buf[11]);
const signatureLength = calcLength(buf[12], buf[13], buf[14], buf[15]);

// 16 = Magic number (4), CRX format version (4), lengths (2x4)
const zipStartOffset = 16 + publicKeyLength + signatureLength;

return buf.subarray(zipStartOffset, buf.length);
}
// v3 format has header size and then header
const headerSize = calcLength(buf[8], buf[9], buf[10], buf[11]);
const zipStartOffset = 12 + headerSize;

return buf.subarray(zipStartOffset, buf.length);
};
81 changes: 53 additions & 28 deletions FrameworkDevtools/main.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,57 @@
const { app } = require("electron");
const devtools = require("electron-devtools-installer");
const fs = require("fs-extra");
const { session, app } = require("electron");
const path = require("path");

// const broadcast = require("@kernel/core/broadcast");
// // const { OriginalBrowserWindow } = require("@kernel/core/BrowserWindowPatcher");
const https = require("https");
const fs = require("fs");
const devtools = require("electron-devtools-installer");
const crxToZip = require("./crxToZip");
const AdmZip = require('adm-zip');

module.exports.default = {
start() {
console.log("Starting FrameworkDevtools");
app.on("ready", () => {
const enabledDevtools = fs.readJSONSync(
path.join(__dirname, "index.json")
).options.devtools;
for (const devtool of enabledDevtools) {
devtools
.default(devtools[devtool], {
loadExtensionOptions: { allowFileAccess: true },
forceDownload: true,
})
.then((name) => console.log(`Added Extension: ${name}`))
.catch((err) =>
console.error("Failed to add devtools extensions:", err)
);
}
});
},
stop() {
console.log("Restart the app to unload the devtools.");
},
start() {
console.log("Starting FrameworkDevtools");
app.on("ready", async () => {
const enabledDevtools = JSON.parse(fs.readFileSync(
path.join(__dirname, "index.json")
)).options.devtools;

for (const devtool of enabledDevtools) {
// temporary patch until electron supports manifest v3
if (devtool === 'REACT_DEVELOPER_TOOLS') {
const url = "https://clients2.googleusercontent.com/crx/blobs/Acy1k0YTNVjurDjs0Ykedxwea0PfCT8fzhxRR-IfyKi2e-u8YladfVsFWx-5-_ounQNmgOCKWhCo8omB48nkUKGAts0hmSuZlKlzfjzPuzeJlRDVWcspAMZSmuUN8b65ifrcdPOHDcNkseF6HMOpXQ/extension_4_25_0_0.crx";
const dir = path.join(__dirname, 'react-devtools');

if (!fs.existsSync(dir)) {
const buf = await new Promise((res) => {
https.get(url, (msg) => {
const data = [];
msg.on('data', (chunk) => {
data.push(chunk);
}).on('end', () => {
res(Buffer.concat(data));
});
});
});

new AdmZip(crxToZip(buf))
.extractAllTo(dir);
}

session.defaultSession.loadExtension(dir);
} else {
devtools
.default(devtools[devtool], {
loadExtensionOptions: { allowFileAccess: true },
forceDownload: true,
})
.then((name) => console.log(`Added Extension: ${name}`))
.catch((err) =>
console.error("Failed to add devtools extensions:", err)
);
}
}
});
},
stop() {
console.log("Restart the app to unload the devtools.");
},
};
8 changes: 4 additions & 4 deletions FrameworkDevtools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dependencies": {
"electron-devtools-installer": "^3.2.0",
"fs-extra": "^10.0.0"
}
"dependencies": {
"adm-zip": "^0.5.10",
"electron-devtools-installer": "^3.2.0"
}
}
205 changes: 205 additions & 0 deletions FrameworkDevtools/pnpm-lock.yaml

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