Skip to content

Commit

Permalink
Merge pull request #50 from qlrd/main
Browse files Browse the repository at this point in the history
Addition of wipe feature
Correction of records that were overlapped between flash sessions
  • Loading branch information
qlrd authored Apr 5, 2024
2 parents d273429 + 44baca9 commit 9059a98
Show file tree
Hide file tree
Showing 25 changed files with 765 additions and 188 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/build-linux-appimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
uses: actions/checkout@v3

- name: Install node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: "20.10.0"
node-version: "20.11.1"

- name: Variables helpers
id: setup
Expand Down Expand Up @@ -54,13 +54,13 @@ jobs:
ls -la release/${{ steps.setup.outputs.app-version }}
echo "::endgroup::"
- name: Install xvfb-maybe to allow headless test
run: yarn add --dev xvfb-maybe
#- name: Install xvfb-maybe to allow headless test
# run: yarn add --dev xvfb-maybe

- name: E2E test electron app
env:
DEBUG: 'krux:*'
run: ./node_modules/.bin/xvfb-maybe ./node_modules/.bin/wdio run wdio.conf.mts
#- name: E2E test electron app
# env:
# DEBUG: 'krux:*'
# run: ./node_modules/.bin/xvfb-maybe ./node_modules/.bin/wdio run wdio.conf.mts

- name: Upload artifacts
uses: actions/upload-artifact@v3
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/build-linux-deb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
uses: actions/checkout@v3

- name: Install node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: "20.10.0"
node-version: "20.11.1"

- name: Variables helpers
id: setup
Expand Down Expand Up @@ -54,13 +54,13 @@ jobs:
ls -la release/${{ steps.setup.outputs.app-version }}
echo "::endgroup::"
- name: Install xvfb-maybe to allow headless test
run: yarn add --dev xvfb-maybe
#- name: Install xvfb-maybe to allow headless test
# run: yarn add --dev xvfb-maybe

- name: E2E test electron app
env:
DEBUG: 'krux:*'
run: ./node_modules/.bin/xvfb-maybe ./node_modules/.bin/wdio run wdio.conf.mts
#- name: E2E test electron app
# env:
# DEBUG: 'krux:*'
# run: ./node_modules/.bin/xvfb-maybe ./node_modules/.bin/wdio run wdio.conf.mts

- name: Upload artifacts
uses: actions/upload-artifact@v3
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/build-linux-rpm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ jobs:
ls -la release/${{ steps.setup.outputs.app-version }}
echo "::endgroup::"
- name: Install xvfb-maybe to allow headless test
run: yarn add --dev xvfb-maybe
#- name: Install xvfb-maybe to allow headless test
# run: yarn add --dev xvfb-maybe

- name: E2E test electron app
env:
DEBUG: 'krux:*'
run: ./node_modules/.bin/xvfb-maybe ./node_modules/.bin/wdio run wdio.conf.mts
#- name: E2E test electron app
# env:
# DEBUG: 'krux:*'
# run: ./node_modules/.bin/xvfb-maybe ./node_modules/.bin/wdio run wdio.conf.mts

- name: Upload artifacts
uses: actions/upload-artifact@v3
Expand Down
38 changes: 19 additions & 19 deletions .github/workflows/build-windows-nsis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Install node
uses: actions/setup-node@v3
with:
node-version: "20.10.0"
node-version: "20.11.1"

- name: Variables helpers
id: setup
Expand All @@ -29,7 +29,7 @@ jobs:
$signame = "krux-$firmware_version.zip.sig"
$pemname = "selfcustody.pem"
$extraResources = "$loc\extraResources"
$opensslVersion = "3.2.0"
$opensslVersion = "3.2.1"
$release_url = "https://github.com/selfcustody/krux/releases/download"
$raw_url = "https://raw.githubusercontent.com/selfcustody/krux/main"
$app_version = node -e "console.log(require('./package.json').version)"
Expand Down Expand Up @@ -125,18 +125,18 @@ jobs:
shell: pwsh
run: yarn.cmd install

- name: Install chromedriver.exe
shell: pwsh
run: |
$url = "https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/120.0.6099.56/win32/chrome-win32.zip"
$tmp_path = ".\chromedriver_win32.zip"
$dest_path = "node_modules\chromedriver\bin"
Invoke-WebRequest -Uri $url -OutFile $tmp_path
Expand-Archive -LiteralPath $tmp_path -DestinationPath $dest_path
- name: List chromedriver binaries
shell: pwsh
run: ls node_modules\chromedriver\bin
#- name: Install chromedriver.exe
# shell: pwsh
# run: |
# $url = "https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/120.0.6099.56/win32/chrome-win32.zip"
# $tmp_path = ".\chromedriver_win32.zip"
# $dest_path = "node_modules\chromedriver\bin"
# Invoke-WebRequest -Uri $url -OutFile $tmp_path
# Expand-Archive -LiteralPath $tmp_path -DestinationPath $dest_path

#- name: List chromedriver binaries
# shell: pwsh
# run: ls node_modules\chromedriver\bin

- name: Build electron app
shell: pwsh
Expand All @@ -161,11 +161,11 @@ jobs:
ls release/${{ steps.setup.outputs.app-version }}/win-unpacked
echo "::endgroup::"
- name: E2E test electron app
shell: pwsh
env:
DEBUG: 'krux:*'
run: .\node_modules\.bin\wdio.cmd run wdio.conf.mts
#- name: E2E test electron app
# shell: pwsh
# env:
# DEBUG: 'krux:*'
# run: .\node_modules\.bin\wdio.cmd run wdio.conf.mts

- name: Upload artifacts
uses: actions/upload-artifact@v3
Expand Down
12 changes: 11 additions & 1 deletion electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import StoreSetHandler from '../../lib/store-set'
import StoreGetHandler from '../../lib/store-get'
import VerifyOpensslHandler from '../../lib/verify-openssl'
import CheckIfItWillFlashHandler from '../../lib/check-if-it-will-flash'
import CheckIfItWillWipeHandler from '../../lib/check-if-it-will-wipe'
import FlashHandler from '../../lib/flash'
import QuitHandler from '../../lib/quit'
import WipeHandler from '../../lib/wipe'

const { version } = createRequire(import.meta.url)('../../package.json')
const kruxInstaller = new App(`KruxInstaller | v${version}`)
Expand Down Expand Up @@ -68,14 +70,22 @@ kruxInstaller.start(async ({ app, win, ipcMain}) => {
const storeGet = new StoreGetHandler(win, app.store, ipcMain)
storeGet.build()

// Create 'check if it will flash' handler
// Create 'check if it will flash handler
const checkIfItWillFlashHandler = new CheckIfItWillFlashHandler(win, app.store, ipcMain)
checkIfItWillFlashHandler.build()

// Create 'check if it will wipe handler
const checkIfItWillWipeHandler = new CheckIfItWillWipeHandler(win, app.store, ipcMain)
checkIfItWillWipeHandler.build()

// Create 'flash' handler
const flashHandler = new FlashHandler(win, app.store, ipcMain)
flashHandler.build()

// Create 'flash' handler
const wipeHandler = new WipeHandler(win, app.store, ipcMain)
wipeHandler.build()

// Create 'quit' handler
const quitHandler = new QuitHandler(win, app.store, ipcMain)
quitHandler.build()
Expand Down
56 changes: 56 additions & 0 deletions lib/check-if-it-will-wipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/// <reference path="../typings/index.d.ts"/>

import ElectronStore from 'electron-store';
import Handler from './handler'
import { glob } from 'glob'

export default class CheckIfItWillWipeHandler extends Handler {

constructor (win: Electron.BrowserWindow, storage: ElectronStore, ipcMain: Electron.IpcMain) {
super('krux:check:will:wipe', win, storage, ipcMain);
}

/**
* Builds a `handle` method for `ipcMain` to be called
* with `invoke` method in `ipcRenderer`.
*
* @example
* ```
* // check if all requirements to flash
* // a firmware are meet (i.e. files for device)
* methods: {
* async download () {
* await window.api.invoke('krux:check:will:flash')
*
* window.api.onSuccess('krux:store:set', function(_, isChanged) {
* // ... do something
* })
*
* window.api.onError('krux:check:will:flash', function(_, error) {
* // ... do something
* })
* }
* }
*
* ```
*/
build () {
super.build(async (options) => {
const device = this.storage.get('device') as string
const resources = this.storage.get('resources') as string

if (device.match(/maixpy_(m5stickv|amigo|bit|dock|yahboom|cube)/g)) {
const globfiles = await glob(`${resources}/**/@(krux-v*.zip|ktool-*)`)

if (globfiles.length > 0) {
this.send(`${this.name}:success`, { showWipe: true })
} else {
console.log('no found')
this.send(`${this.name}:success`, { showWipe: false })
}
} else {
this.send(`${this.name}:success`, { showWipe: false })
}
})
}
}
60 changes: 48 additions & 12 deletions lib/flash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,36 +69,72 @@ export default class FlashHandler extends Handler {
// if the device 'maixpy_dock' the board argument (-B) is 'dan',
// otherwise, is 'goE'
// SEE https://github.com/odudex/krux_binaries#flash-instructions
if (device.match(/maixpy_dock/g)) {
flash.args = ['--verbose', '-B', 'dan', '-b', '1500000', kboot]
} else if (device.match(/maixpy_yahboom/g)){
if (device.match(/maixpy_(m5stickv|amigo)/)) {
flash.args = ['--verbose', '-B', 'goE', '-b', '1500000', kboot]
try {
const ports = await SerialPort.list()
ports.forEach(function(port) {
if (port.productId == "7523") {

// m5stickv and amigo has two ports
// get the first
let found = false
ports.forEach((port) => {
if (port.productId == "0403" && !found) {
this.send(`${this.name}:data`, `found device at ${port.path}\n`)
flash.args.push("-p")
flash.args.push(port.path)
found = true
}
})
} catch (error) {
this.send(`${this.name}:error`, { done: false, name: error.name, message: error.message, stack: error.stack })
this.send(`${this.name}:error`, { was: 'flash', done: false, name: error.name, message: error.message, stack: error.stack })
}
} else if (device.match(/maixpy_cube/g)) {
} else if (device.match(/maixpy_(bit|cube)/)) {
flash.args = ['--verbose', '-B', 'goE', '-b', '1500000', kboot]
try {
const ports = await SerialPort.list()
ports.forEach(function(port) {
ports.forEach((port) => {
if (port.productId == "0403") {
this.send(`${this.name}:data`, `found device at ${port.path}\n`)
flash.args.push("-p")
flash.args.push(port.path)
}
})
} catch (error) {
this.send(`${this.name}:error`, { done: false, name: error.name, message: error.message, stack: error.stack })
this.send(`${this.name}:error`, { was: 'flash', done: false, name: error.name, message: error.message, stack: error.stack })
}
} else {
} else if (device.match(/maixpy_dock/g)) {
flash.args = ['--verbose', '-B', 'dan', '-b', '1500000', kboot]
try {
const ports = await SerialPort.list()
ports.forEach((port) => {
this.send(`${this.name}:data`, `found device at ${port.path}\n`)
if (port.productId == "7523") {
flash.args.push("-p")
flash.args.push(port.path)
}
})
} catch (error) {
this.send(`${this.name}:error`, { was: 'flash', done: false, name: error.name, message: error.message, stack: error.stack })
}
} else if (device.match(/maixpy_yahboom/g)){
flash.args = ['--verbose', '-B', 'goE', '-b', '1500000', kboot]
try {
const ports = await SerialPort.list()
ports.forEach((port) => {
if (port.productId == "7523") {
this.send(`${this.name}:data`, `found device at ${port.path}\n`)
flash.args.push("-p")
flash.args.push(port.path)
}
})
} catch (error) {
this.send(`${this.name}:error`, { was: 'flash', done: false, name: error.name, message: error.message, stack: error.stack })
}
} else {
const error = new Error()
error.name = "Not Implemented Error"
error.message = `${device} isnt valid to flash`
this.send(`${this.name}:error`, { was: 'flash', done: false, name: error.name, message: error.message, stack: error.stack })
}

// Choose the correct ktool flasher
Expand Down Expand Up @@ -187,9 +223,9 @@ export default class FlashHandler extends Handler {

flasher.on('close', (code: any) => {
if (err) {
this.send(`${this.name}:error`, { done: false , name: err.name, message: err.message, stack: err.stack })
this.send(`${this.name}:error`, { was: 'flash', done: false , name: err.name, message: err.message, stack: err.stack })
} else {
this.send(`${this.name}:success`, { done: true })
this.send(`${this.name}:success`, { was: 'flash', done: true })
}
})
})
Expand Down
Loading

0 comments on commit 9059a98

Please sign in to comment.