From 5585218560592f6aa66b1c50deac4299e661297e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1sztor=20D=C3=A1niel?= Date: Mon, 16 Dec 2024 16:25:38 +0100 Subject: [PATCH 01/10] Use drivelist, usb to automatically detect bootloader --- package.json | 2 + src/electron/main.ts | 3 + src/electron/src/firmware.ts | 148 +++++++++++++------------ src/renderer/main/FirmwareCheck.svelte | 92 ++------------- 4 files changed, 90 insertions(+), 155 deletions(-) diff --git a/package.json b/package.json index f0628a5dc..9df8fe47d 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "adm-zip": "^0.5.10", "chokidar": "^3.5.3", "discord.js": "^13.6.0", + "drivelist": "^12.0.2", "electron-dl": "^3.4.1", "electron-log": "^4.4.8", "electron-store": "^8.1.0", @@ -69,6 +70,7 @@ "svelte-watch-resize": "^1.0.3", "ts-jest": "^29.1.2", "typescript": "^5.0.0", + "usb": "^2.14.0", "uuid": "^9.0.0", "vite": "^4.5.2", "ws": "^7.5.8" diff --git a/src/electron/main.ts b/src/electron/main.ts index ae6990792..47660d1be 100644 --- a/src/electron/main.ts +++ b/src/electron/main.ts @@ -53,9 +53,12 @@ import { import { fetchUrlJSON } from "./src/fetch"; import { getLatestVideo } from "./src/youtube"; import { SerialPort } from "serialport"; +import { usb } from "usb"; log.info("App starting..."); +usb.on("attach", () => setTimeout(findBootloaderPath, 500)); + // 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. let mainWindow; diff --git a/src/electron/src/firmware.ts b/src/electron/src/firmware.ts index 4f8bdcfba..c1deab215 100644 --- a/src/electron/src/firmware.ts +++ b/src/electron/src/firmware.ts @@ -1,5 +1,7 @@ import nodeDiskInfo from "node-disk-info"; -import Drive from "node-disk-info/dist/classes/drive"; +//import Drive from "node-disk-info/dist/classes/drive"; + +import drivelist from "drivelist"; import log from "electron-log"; import fs from "fs-extra"; @@ -19,10 +21,11 @@ function delay(time) { } export async function findBootloaderPath() { - let diskInfo: Drive[] = []; + let diskInfo: drivelist.Drive[] = []; try { - diskInfo = nodeDiskInfo.getDiskInfoSync(); + console.log("START DRIVELIST CHECK"); + diskInfo = await drivelist.list(); } catch (error) { log.warn(error); } @@ -31,6 +34,8 @@ export async function findBootloaderPath() { return; } + console.log({ diskInfo }); + // log.info(diskInfo) // 7929 MAC || 15867 new // 3965 for Linux and 4059648 for Windows (old bootloader) @@ -39,75 +44,74 @@ export async function findBootloaderPath() { let gridDrive = diskInfo.find( (a) => // old bootloader Linux Mac Win - a.blocks === 3965 || - a.blocks === 7929 || - a.blocks === 4059648 || + a.size === 3965 || + a.size === 7929 || + a.size === 4059648 || // new bootloader Linux, Mac, M1Mac, Win - a.blocks === 7934 || - a.blocks === 15867 || - a.blocks === 15868 || - a.blocks === 8123904 || + a.size === 7934 || + a.size === 15867 || + a.size === 15868 || + a.size === 8123904 || // add esp32 bootloader block size here LINUX & M1 Mac, M1 Mac & WINDOWS - a.blocks === 32640 || - a.blocks === 65281 || - a.blocks === 65280 || - a.blocks === 33423360 + a.size === 32640 || + a.size === 65281 || + a.size === 65280 || + a.size === 33423360 ); //console.log("DiskInfo", diskInfo) - + console.log({ gridDrive }); + if (gridDrive === undefined) return; + let mountPath = gridDrive.mountpoints[0]; + console.log({ gridDrive, mountPath }); let data; - - if (gridDrive !== undefined) { - try { - data = fs.readFileSync(gridDrive.mounted + "/INFO_UF2.TXT", { - encoding: "utf8", - flag: "r", - }); - } catch (error) { - console.warn(error); - } + try { + data = fs.readFileSync(mountPath + "/INFO_UF2.TXT", { + encoding: "utf8", + flag: "r", + }); + } catch (error) { + console.warn(error); } + if (data === undefined) return; - if (data !== undefined && gridDrive !== undefined) { - // is it grid - if (data.indexOf("SAMD51N20A-GRID") !== -1) { - firmware.mainWindow.webContents.send("onFirmwareUpdate", { - message: "Grid D51 bootloader is detected!", - code: 3, - path: gridDrive.mounted, - }); - return { path: gridDrive.mounted, architecture: "d51", product: "grid" }; - } else if (data.indexOf("ESP32S3") !== -1 && data.indexOf("Grid") !== -1) { - firmware.mainWindow.webContents.send("onFirmwareUpdate", { - message: "Grid ESP32 bootloader is detected!", - code: 3, - path: gridDrive.mounted, - }); - return { - path: gridDrive.mounted, - architecture: "esp32", - product: "grid", - }; - } else if (data.indexOf("ESP32S3") !== -1 && data.indexOf("Knot") !== -1) { - firmware.mainWindow.webContents.send("onFirmwareUpdate", { - message: "Knot ESP32 bootloader is detected!", - code: 3, - path: gridDrive.mounted, - }); - return { - path: gridDrive.mounted, - architecture: "esp32", - product: "knot", - }; - } + // is it grid + if (data.indexOf("SAMD51N20A-GRID") !== -1) { + firmware.mainWindow.webContents.send("onFirmwareUpdate", { + message: "Grid D51 bootloader is detected!", + code: 3, + path: mountPath, + }); + return { path: mountPath, architecture: "d51", product: "grid" }; + } else if (data.indexOf("ESP32S3") !== -1 && data.indexOf("Grid") !== -1) { + firmware.mainWindow.webContents.send("onFirmwareUpdate", { + message: "Grid ESP32 bootloader is detected!", + code: 3, + path: mountPath, + }); + return { + path: mountPath, + architecture: "esp32", + product: "grid", + }; + } else if (data.indexOf("ESP32S3") !== -1 && data.indexOf("Knot") !== -1) { + firmware.mainWindow.webContents.send("onFirmwareUpdate", { + message: "Knot ESP32 bootloader is detected!", + code: 3, + path: mountPath, + }); + return { + path: mountPath, + architecture: "esp32", + product: "knot", + }; } } export async function firmwareDownload(targetFolder, product, arch, url) { const { path } = await findBootloaderPath(); - if (typeof path === "undefined") { + if (path === undefined) { //bootloader not found firmware.mainWindow.webContents.send("onFirmwareUpdate", { message: "Error: No device connected.", @@ -186,21 +190,23 @@ export async function firmwareDownload(targetFolder, product, arch, url) { await delay(1500); - if (path !== undefined) { - try { - fs.copySync( - targetFolder + "/temp/" + firmwareFileName, - path + "/" + firmwareFileName - ); - } catch (error) { - console.log("COPY ERROR UNBOUNT", error); - } + try { + fs.copySync( + targetFolder + "/temp/" + firmwareFileName, + path + "/" + firmwareFileName + ); + } catch (error) { + console.log("COPY ERROR UNBOUND", error); firmware.mainWindow.webContents.send("onFirmwareUpdate", { - message: "Update completed successfully!", - code: 5, + message: "Bootloader connection lost!", + code: 6, }); - } else { - log.warn("GRID_NOT_FOUND"); + return; } + + firmware.mainWindow.webContents.send("onFirmwareUpdate", { + message: "Update completed successfully!", + code: 5, + }); } diff --git a/src/renderer/main/FirmwareCheck.svelte b/src/renderer/main/FirmwareCheck.svelte index 579161b5a..a2e6b94d4 100644 --- a/src/renderer/main/FirmwareCheck.svelte +++ b/src/renderer/main/FirmwareCheck.svelte @@ -16,7 +16,6 @@ STATE 6 | Error | Button -> STATE 0 (Close notification) import { runtime } from "../runtime/runtime.store"; import { fade } from "svelte/transition"; - import { escape } from "svelte/internal"; import { Analytics } from "../runtime/analytics.js"; @@ -24,41 +23,12 @@ STATE 6 | Error | Button -> STATE 0 (Close notification) let fwMismatch = false; - let dotdotdot = ""; - - let flagBootloaderCheck = 0; - let booloaderConnectionCheck = undefined; - let bootloader_path = undefined; - const startBootloaderCheck = () => { - if (flagBootloaderCheck === 1) { - return; - } - - booloaderConnectionCheck = setInterval(() => find_bootloader_path(), 750); - flagBootloaderCheck = 1; - }; - - const stopBootloaderCheck = () => { - ////console.log("Stop Trying") - clearInterval(booloaderConnectionCheck); - flagBootloaderCheck = 0; - }; - // check for parsed modules $: { let firmwareMismatchFound = false; - if ($runtime.modules.length === 0) { - startBootloaderCheck(); - if ($appSettings.firmwareNotificationState == 1) { - $appSettings.firmwareNotificationState = 2; - } - } else { - stopBootloaderCheck(); - } - // check modules for firmware mismatch runtime.modules.forEach((device) => { if ($appSettings.firmwareNotificationState == 6) { @@ -91,11 +61,17 @@ STATE 6 | Error | Button -> STATE 0 (Close notification) fwMismatch = true; } } else { + if (fwMismatch) { + //All mismatched module have been removed, progress state + appSettings.update((s) => { + s.firmwareNotificationState = 2; + return s; + }); + } fwMismatch = false; } } - let text = ""; let uploadProgressText = ""; window.electron.firmware.onFirmwareUpdate((_event, value) => { @@ -124,58 +100,6 @@ STATE 6 | Error | Button -> STATE 0 (Close notification) } }); - onMount(() => { - startBootloaderCheck(); - - if (ctxProcess.platform() == "darwin") { - text = "Command + Shift + R"; - } else { - text = "Ctrl + Shift + R"; - } - }); - - async function find_bootloader_path() { - //console.log("Try Detect Bootloader") - - const value = await window.electron.firmware.findBootloaderPath(); - - if (value !== undefined) { - if ( - $appSettings.firmwareNotificationState == 1 || - $appSettings.firmwareNotificationState == 2 || - $appSettings.firmwareNotificationState == 6 - ) { - //console.log("Successfuly detection", value.path) - - bootloader_path = value.path; - } else { - //console.log("Dont care detection", value.path) - bootloader_path = value.path; - } - - //stopBootloaderCheck(); - } else { - if ( - $appSettings.firmwareNotificationState == 4 || - $appSettings.firmwareNotificationState == 5 || - $appSettings.firmwareNotificationState == 6 - ) { - bootloader_path = undefined; - //console.log("Disconnect but no problem") - } else { - //console.log("Disconnect from state", $appSettings.firmwareNotificationState) - - if (typeof bootloader_path !== "undefined") { - ////console.log("Disconnect because lost", $appSettings.firmwareNotificationState) - - bootloader_path = undefined; - uploadProgressText = "Bootloader connection lost!"; - $appSettings.firmwareNotificationState = 6; - } - } - } - } - async function firmwareDownload(nightly) { const folder = $appSettings.persistent.profileFolder; const { product, architecture } = @@ -281,7 +205,7 @@ STATE 6 | Error | Button -> STATE 0 (Close notification) >
- Waiting for the bootloader to enumerate {dotdotdot} + Waiting for the bootloader to enumerate
Connect the module in bootloader mode!
From fedf02fcf2a2445910399284a7c8428e32a27d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel?= Date: Mon, 16 Dec 2024 17:20:33 +0100 Subject: [PATCH 02/10] Fix bootloader size detection, ui text --- src/electron/main.ts | 2 +- src/electron/src/firmware.ts | 34 +++----------------------- src/renderer/main/FirmwareCheck.svelte | 11 +++++++-- 3 files changed, 13 insertions(+), 34 deletions(-) diff --git a/src/electron/main.ts b/src/electron/main.ts index 47660d1be..a9bbb429e 100644 --- a/src/electron/main.ts +++ b/src/electron/main.ts @@ -52,12 +52,12 @@ import { } from "./src/profiles"; import { fetchUrlJSON } from "./src/fetch"; import { getLatestVideo } from "./src/youtube"; -import { SerialPort } from "serialport"; import { usb } from "usb"; log.info("App starting..."); usb.on("attach", () => setTimeout(findBootloaderPath, 500)); +setTimeout(findBootloaderPath, 10000); //Initial check // 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. diff --git a/src/electron/src/firmware.ts b/src/electron/src/firmware.ts index c1deab215..0f6d4351d 100644 --- a/src/electron/src/firmware.ts +++ b/src/electron/src/firmware.ts @@ -1,5 +1,4 @@ import nodeDiskInfo from "node-disk-info"; -//import Drive from "node-disk-info/dist/classes/drive"; import drivelist from "drivelist"; @@ -8,8 +7,6 @@ import fs from "fs-extra"; import { extractArchiveToTemp, downloadInMainProcess } from "./library"; -import configuration from "../../../configuration.json"; - export const firmware = { mainWindow: undefined, }; @@ -24,7 +21,6 @@ export async function findBootloaderPath() { let diskInfo: drivelist.Drive[] = []; try { - console.log("START DRIVELIST CHECK"); diskInfo = await drivelist.list(); } catch (error) { log.warn(error); @@ -34,36 +30,12 @@ export async function findBootloaderPath() { return; } - console.log({ diskInfo }); - - // log.info(diskInfo) - // 7929 MAC || 15867 new - // 3965 for Linux and 4059648 for Windows (old bootloader) - // 7934 for Linux and 8123904 for Windows (new bootloader) - let gridDrive = diskInfo.find( - (a) => - // old bootloader Linux Mac Win - a.size === 3965 || - a.size === 7929 || - a.size === 4059648 || - // new bootloader Linux, Mac, M1Mac, Win - a.size === 7934 || - a.size === 15867 || - a.size === 15868 || - a.size === 8123904 || - // add esp32 bootloader block size here LINUX & M1 Mac, M1 Mac & WINDOWS - a.size === 32640 || - a.size === 65281 || - a.size === 65280 || - a.size === 33423360 + (a) => a.size < 64 * 1024 * 1024 && a.isUSB && !a.isSystem && !a.isReadOnly ); - - //console.log("DiskInfo", diskInfo) - console.log({ gridDrive }); if (gridDrive === undefined) return; - let mountPath = gridDrive.mountpoints[0]; - console.log({ gridDrive, mountPath }); + + let mountPath = gridDrive.mountpoints[0].path; let data; try { data = fs.readFileSync(mountPath + "/INFO_UF2.TXT", { diff --git a/src/renderer/main/FirmwareCheck.svelte b/src/renderer/main/FirmwareCheck.svelte index a2e6b94d4..adfbb38ee 100644 --- a/src/renderer/main/FirmwareCheck.svelte +++ b/src/renderer/main/FirmwareCheck.svelte @@ -86,6 +86,7 @@ STATE 6 | Error | Button -> STATE 0 (Close notification) //console.log("Set state from ", $appSettings.firmwareNotificationState, " to ", value.code) $appSettings.firmwareNotificationState = value.code; + bootloader_path = value.path; if (value.message !== undefined) { uploadProgressText = value.message; @@ -102,8 +103,14 @@ STATE 6 | Error | Button -> STATE 0 (Close notification) async function firmwareDownload(nightly) { const folder = $appSettings.persistent.profileFolder; - const { product, architecture } = - await window.electron.firmware.findBootloaderPath(); + let result = await window.electron.firmware.findBootloaderPath(); + if (result === undefined) { + $appSettings.firmwareNotificationState = 6; + bootloader_path = undefined; + uploadProgressText = "Bootloader connection lost!"; + return; + } + const { product, architecture } = result; Analytics.track({ event: "FirmwareCheck", From db09bfc0e7f8264ea4bcbf13e2b1fbd404279600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1sztor=20D=C3=A1niel?= Date: Mon, 16 Dec 2024 17:30:59 +0100 Subject: [PATCH 03/10] Add python setuptools step to github actions --- .github/workflows/nightly-matrix.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/nightly-matrix.yml b/.github/workflows/nightly-matrix.yml index e92823808..e93507611 100644 --- a/.github/workflows/nightly-matrix.yml +++ b/.github/workflows/nightly-matrix.yml @@ -33,6 +33,7 @@ jobs: echo "WORKFLOW_NAME=nightly" >> $GITHUB_ENV - name: Install dependencies + run: python3 -m pip install setuptools run: npm i - name: Update package.json From d6867ef6fa9658ddb7e80ff2dd5b99fc1878a6f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1sztor=20D=C3=A1niel?= Date: Mon, 16 Dec 2024 17:38:38 +0100 Subject: [PATCH 04/10] Fix actions --- .github/workflows/alpha-matrix.yml | 4 +++- .github/workflows/nightly-matrix.yml | 5 +++-- .github/workflows/stable-matrix.yml | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/alpha-matrix.yml b/.github/workflows/alpha-matrix.yml index ef4472467..885d90e7c 100644 --- a/.github/workflows/alpha-matrix.yml +++ b/.github/workflows/alpha-matrix.yml @@ -32,7 +32,9 @@ jobs: echo "WORKFLOW_NAME=alpha" >> $GITHUB_ENV - name: Install dependencies - run: npm i + run: | + python3 -m pip install setuptools + npm i - name: Update package.json run: node ./build-scripts/alpha-packageModifier.js diff --git a/.github/workflows/nightly-matrix.yml b/.github/workflows/nightly-matrix.yml index e93507611..bf5c9e71f 100644 --- a/.github/workflows/nightly-matrix.yml +++ b/.github/workflows/nightly-matrix.yml @@ -33,8 +33,9 @@ jobs: echo "WORKFLOW_NAME=nightly" >> $GITHUB_ENV - name: Install dependencies - run: python3 -m pip install setuptools - run: npm i + run: | + python3 -m pip install setuptools + npm i - name: Update package.json run: node ./build-scripts/nightly-packageModifier.js diff --git a/.github/workflows/stable-matrix.yml b/.github/workflows/stable-matrix.yml index 655205699..2d0a04225 100644 --- a/.github/workflows/stable-matrix.yml +++ b/.github/workflows/stable-matrix.yml @@ -32,7 +32,9 @@ jobs: node-version: "18.16.1" - name: Install dependencies - run: npm i + run: | + python3 -m pip install setuptools + npm i - name: Build run: npm run export From dc13659383f6eb99e13dbef4a970db1ac9fb27fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1sztor=20D=C3=A1niel?= Date: Mon, 16 Dec 2024 17:42:13 +0100 Subject: [PATCH 05/10] Try python install argument --- .github/workflows/alpha-matrix.yml | 2 +- .github/workflows/nightly-matrix.yml | 2 +- .github/workflows/stable-matrix.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/alpha-matrix.yml b/.github/workflows/alpha-matrix.yml index 885d90e7c..9fdce2a6a 100644 --- a/.github/workflows/alpha-matrix.yml +++ b/.github/workflows/alpha-matrix.yml @@ -33,7 +33,7 @@ jobs: - name: Install dependencies run: | - python3 -m pip install setuptools + python3 -m pip install setuptools --break-system-packages npm i - name: Update package.json diff --git a/.github/workflows/nightly-matrix.yml b/.github/workflows/nightly-matrix.yml index bf5c9e71f..6459b8591 100644 --- a/.github/workflows/nightly-matrix.yml +++ b/.github/workflows/nightly-matrix.yml @@ -34,7 +34,7 @@ jobs: - name: Install dependencies run: | - python3 -m pip install setuptools + python3 -m pip install setuptools --break-system-packages npm i - name: Update package.json diff --git a/.github/workflows/stable-matrix.yml b/.github/workflows/stable-matrix.yml index 2d0a04225..edefb6e0b 100644 --- a/.github/workflows/stable-matrix.yml +++ b/.github/workflows/stable-matrix.yml @@ -33,7 +33,7 @@ jobs: - name: Install dependencies run: | - python3 -m pip install setuptools + python3 -m pip install setuptools --break-system-packages npm i - name: Build From 571379e4e4016f0fab766b1003e43c9f98b51132 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1sztor=20D=C3=A1niel?= Date: Mon, 16 Dec 2024 17:45:27 +0100 Subject: [PATCH 06/10] Add --user flag to pip install --- .github/workflows/alpha-matrix.yml | 2 +- .github/workflows/nightly-matrix.yml | 2 +- .github/workflows/stable-matrix.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/alpha-matrix.yml b/.github/workflows/alpha-matrix.yml index 9fdce2a6a..4a6ff1c7c 100644 --- a/.github/workflows/alpha-matrix.yml +++ b/.github/workflows/alpha-matrix.yml @@ -33,7 +33,7 @@ jobs: - name: Install dependencies run: | - python3 -m pip install setuptools --break-system-packages + python3 -m pip install --break-system-packages --user setuptools npm i - name: Update package.json diff --git a/.github/workflows/nightly-matrix.yml b/.github/workflows/nightly-matrix.yml index 6459b8591..dc3e81eee 100644 --- a/.github/workflows/nightly-matrix.yml +++ b/.github/workflows/nightly-matrix.yml @@ -34,7 +34,7 @@ jobs: - name: Install dependencies run: | - python3 -m pip install setuptools --break-system-packages + python3 -m pip install --break-system-packages --user setuptools npm i - name: Update package.json diff --git a/.github/workflows/stable-matrix.yml b/.github/workflows/stable-matrix.yml index edefb6e0b..48e0282cb 100644 --- a/.github/workflows/stable-matrix.yml +++ b/.github/workflows/stable-matrix.yml @@ -33,7 +33,7 @@ jobs: - name: Install dependencies run: | - python3 -m pip install setuptools --break-system-packages + python3 -m pip install --break-system-packages --user setuptools npm i - name: Build From a806453e57309278c09ef07d541ef6b776100cbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1sztor=20D=C3=A1niel?= Date: Mon, 16 Dec 2024 17:54:57 +0100 Subject: [PATCH 07/10] Use macos brew instead --- .github/workflows/alpha-matrix.yml | 8 +++++--- .github/workflows/nightly-matrix.yml | 8 +++++--- .github/workflows/stable-matrix.yml | 8 +++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.github/workflows/alpha-matrix.yml b/.github/workflows/alpha-matrix.yml index 4a6ff1c7c..dcd5d712d 100644 --- a/.github/workflows/alpha-matrix.yml +++ b/.github/workflows/alpha-matrix.yml @@ -31,10 +31,12 @@ jobs: echo "BRANCH_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV echo "WORKFLOW_NAME=alpha" >> $GITHUB_ENV + - name: Install python setup-tools dependency + if: runner.os == "macOS" + run: brew install python-setuptools + - name: Install dependencies - run: | - python3 -m pip install --break-system-packages --user setuptools - npm i + run: npm i - name: Update package.json run: node ./build-scripts/alpha-packageModifier.js diff --git a/.github/workflows/nightly-matrix.yml b/.github/workflows/nightly-matrix.yml index dc3e81eee..75168ef36 100644 --- a/.github/workflows/nightly-matrix.yml +++ b/.github/workflows/nightly-matrix.yml @@ -32,10 +32,12 @@ jobs: echo "BRANCH_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV echo "WORKFLOW_NAME=nightly" >> $GITHUB_ENV + - name: Install python setup-tools dependency + if: runner.os == "macOS" + run: brew install python-setuptools + - name: Install dependencies - run: | - python3 -m pip install --break-system-packages --user setuptools - npm i + run: npm i - name: Update package.json run: node ./build-scripts/nightly-packageModifier.js diff --git a/.github/workflows/stable-matrix.yml b/.github/workflows/stable-matrix.yml index 48e0282cb..dfadfb215 100644 --- a/.github/workflows/stable-matrix.yml +++ b/.github/workflows/stable-matrix.yml @@ -31,10 +31,12 @@ jobs: with: node-version: "18.16.1" + - name: Install python setup-tools dependency + if: runner.os == "macOS" + run: brew install python-setuptools + - name: Install dependencies - run: | - python3 -m pip install --break-system-packages --user setuptools - npm i + run: npm i - name: Build run: npm run export From bc5bd5314abaa9a71bac2e3ac58f0f63dc77e9ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1sztor=20D=C3=A1niel?= Date: Mon, 16 Dec 2024 18:02:52 +0100 Subject: [PATCH 08/10] Fix yaml format --- .github/workflows/alpha-matrix.yml | 2 +- .github/workflows/nightly-matrix.yml | 2 +- .github/workflows/stable-matrix.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/alpha-matrix.yml b/.github/workflows/alpha-matrix.yml index dcd5d712d..5004f386b 100644 --- a/.github/workflows/alpha-matrix.yml +++ b/.github/workflows/alpha-matrix.yml @@ -32,7 +32,7 @@ jobs: echo "WORKFLOW_NAME=alpha" >> $GITHUB_ENV - name: Install python setup-tools dependency - if: runner.os == "macOS" + if: runner.os == 'macOS' run: brew install python-setuptools - name: Install dependencies diff --git a/.github/workflows/nightly-matrix.yml b/.github/workflows/nightly-matrix.yml index 75168ef36..6bcf06ddf 100644 --- a/.github/workflows/nightly-matrix.yml +++ b/.github/workflows/nightly-matrix.yml @@ -33,7 +33,7 @@ jobs: echo "WORKFLOW_NAME=nightly" >> $GITHUB_ENV - name: Install python setup-tools dependency - if: runner.os == "macOS" + if: runner.os == 'macOS' run: brew install python-setuptools - name: Install dependencies diff --git a/.github/workflows/stable-matrix.yml b/.github/workflows/stable-matrix.yml index dfadfb215..69100c349 100644 --- a/.github/workflows/stable-matrix.yml +++ b/.github/workflows/stable-matrix.yml @@ -32,7 +32,7 @@ jobs: node-version: "18.16.1" - name: Install python setup-tools dependency - if: runner.os == "macOS" + if: runner.os == 'macOS' run: brew install python-setuptools - name: Install dependencies From c5d4c1cbc11ef874d5b256bc25ad1aa3afd1f7d2 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 8 Jan 2025 12:30:50 +0100 Subject: [PATCH 09/10] Expand bootloader filtering to handle more cases --- src/electron/src/firmware.ts | 92 ++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/src/electron/src/firmware.ts b/src/electron/src/firmware.ts index 0f6d4351d..9ef4df48e 100644 --- a/src/electron/src/firmware.ts +++ b/src/electron/src/firmware.ts @@ -30,53 +30,55 @@ export async function findBootloaderPath() { return; } - let gridDrive = diskInfo.find( + let gridDrives = diskInfo.filter( (a) => a.size < 64 * 1024 * 1024 && a.isUSB && !a.isSystem && !a.isReadOnly ); - if (gridDrive === undefined) return; - - let mountPath = gridDrive.mountpoints[0].path; - let data; - try { - data = fs.readFileSync(mountPath + "/INFO_UF2.TXT", { - encoding: "utf8", - flag: "r", - }); - } catch (error) { - console.warn(error); - } - if (data === undefined) return; - - // is it grid - if (data.indexOf("SAMD51N20A-GRID") !== -1) { - firmware.mainWindow.webContents.send("onFirmwareUpdate", { - message: "Grid D51 bootloader is detected!", - code: 3, - path: mountPath, - }); - return { path: mountPath, architecture: "d51", product: "grid" }; - } else if (data.indexOf("ESP32S3") !== -1 && data.indexOf("Grid") !== -1) { - firmware.mainWindow.webContents.send("onFirmwareUpdate", { - message: "Grid ESP32 bootloader is detected!", - code: 3, - path: mountPath, - }); - return { - path: mountPath, - architecture: "esp32", - product: "grid", - }; - } else if (data.indexOf("ESP32S3") !== -1 && data.indexOf("Knot") !== -1) { - firmware.mainWindow.webContents.send("onFirmwareUpdate", { - message: "Knot ESP32 bootloader is detected!", - code: 3, - path: mountPath, - }); - return { - path: mountPath, - architecture: "esp32", - product: "knot", - }; + if (gridDrives.length === 0) return; + + for (const gridDrive of gridDrives) { + let mountPath = gridDrive.mountpoints[0].path; + let data: string; + try { + data = fs.readFileSync(mountPath + "/INFO_UF2.TXT", { + encoding: "utf8", + flag: "r", + }); + } catch (error) { + console.warn(error); + } + if (data === undefined) continue; + + // is it grid + if (data.indexOf("SAMD51N20A-GRID") !== -1) { + firmware.mainWindow.webContents.send("onFirmwareUpdate", { + message: "Grid D51 bootloader is detected!", + code: 3, + path: mountPath, + }); + return { path: mountPath, architecture: "d51", product: "grid" }; + } else if (data.indexOf("ESP32S3") !== -1 && data.indexOf("Grid") !== -1) { + firmware.mainWindow.webContents.send("onFirmwareUpdate", { + message: "Grid ESP32 bootloader is detected!", + code: 3, + path: mountPath, + }); + return { + path: mountPath, + architecture: "esp32", + product: "grid", + }; + } else if (data.indexOf("ESP32S3") !== -1 && data.indexOf("Knot") !== -1) { + firmware.mainWindow.webContents.send("onFirmwareUpdate", { + message: "Knot ESP32 bootloader is detected!", + code: 3, + path: mountPath, + }); + return { + path: mountPath, + architecture: "esp32", + product: "knot", + }; + } } } From d128d972cf1e5a83c67b318494951e93d8257b1e Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 8 Jan 2025 12:31:12 +0100 Subject: [PATCH 10/10] Retry usb detection after inceasing delays --- src/electron/main.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/electron/main.ts b/src/electron/main.ts index a9bbb429e..6df833c89 100644 --- a/src/electron/main.ts +++ b/src/electron/main.ts @@ -56,7 +56,18 @@ import { usb } from "usb"; log.info("App starting..."); -usb.on("attach", () => setTimeout(findBootloaderPath, 500)); +usb.on("attach", () => { + let delay = 500; + async function retryFind() { + let result = await findBootloaderPath(); + if (result) return; + + delay += 500; + if (delay > 1500) return; + setTimeout(retryFind, delay); + } + setTimeout(retryFind, delay); +}); setTimeout(findBootloaderPath, 10000); //Initial check // Keep a global reference of the window object, if you don't, the window will