Skip to content

Commit

Permalink
v0.3.15: update dfu.html (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
taichunmin authored Jul 16, 2024
2 parents 6ff9950 + 98cf64f commit f31fc71
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 126 deletions.
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"module": "./dist/index.mjs",
"name": "chameleon-ultra.js",
"type": "commonjs",
"version": "0.3.14",
"version": "0.3.15",
"bugs": {
"url": "https://github.com/taichunmin/chameleon-ultra.js/issues"
},
Expand All @@ -21,7 +21,7 @@
],
"dependencies": {
"@taichunmin/buffer": "^0.13.6",
"@taichunmin/crc": "^0.0.8",
"@taichunmin/crc": "^0.0.13",
"debug": "^4.3.5",
"jszip": "^3.10.1",
"lodash": "^4.17.21",
Expand All @@ -36,14 +36,14 @@
"@types/html-minifier": "^4.0.5",
"@types/jest": "^29.5.12",
"@types/livereload": "^0.9.5",
"@types/lodash": "^4.17.6",
"@types/lodash": "^4.17.7",
"@types/node": "^20.14.10",
"@types/pug": "^2.0.10",
"@types/serve-static": "^1.15.7",
"@types/uglify-js": "^3.17.5",
"@types/web-bluetooth": "^0.0.20",
"@typescript-eslint/eslint-plugin": "^7.15.0",
"@typescript-eslint/parser": "^7.15.0",
"@typescript-eslint/eslint-plugin": "^7.16.1",
"@typescript-eslint/parser": "^7.16.1",
"chokidar": "^3.6.0",
"concurrently": "^8.2.2",
"dayjs": "^1.11.11",
Expand All @@ -66,15 +66,15 @@
"node-watch": "^0.7.4",
"nodemon": "^3.1.4",
"pug": "^3.0.3",
"rimraf": "^5.0.8",
"rimraf": "^6.0.1",
"serve-static": "^1.15.0",
"supports-color": "^9.4.0",
"ts-jest": "^29.1.5",
"ts-jest": "^29.2.2",
"ts-node": "^10.9.2",
"tsup": "^8.1.0",
"tsx": "^4.16.2",
"typedoc": "^0.26.3",
"typedoc-plugin-mdn-links": "^3.2.3",
"typedoc": "^0.26.4",
"typedoc-plugin-mdn-links": "^3.2.4",
"typedoc-plugin-missing-exports": "^3.0.0",
"typedoc-plugin-rename-defaults": "^0.7.1",
"typedoc-plugin-zod": "^1.2.0",
Expand Down
37 changes: 26 additions & 11 deletions pug/src/dfu.pug
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ block content
.form-group.letter-spacing-n1px.mb-3
label Choose firmware:
.custom-file.form-control-sm.letter-spacing-n1px
input.custom-file-input#imageSelected(type="file", v-model="imageSelected", ref="imageSelected", accept=".zip,application/zip,application/x-zip-compressed")
label.custom-file-label(for="imageSelected", :class="['','text-muted'][+_.isEmpty(imageSelected)]") {{ getFilename(imageSelected) || 'Choose firmware...' }}
input.custom-file-input#zipSelected(type="file", v-model="zipSelected", ref="zipSelected", @change="onZipSelected($event?.target?.files[0])", accept=".zip,application/zip,application/x-zip-compressed")
label.custom-file-label(for="zipSelected", :class="['','text-muted'][+_.isEmpty(zipSelected)]") {{ getZipInfo() || 'Choose firmware...' }}
button.btn.btn-block.btn-outline-primary.letter-spacing-n1px.mb-2(@click="btnUpdateSelected") #[i.fa.mr-1.fa-puzzle-piece] Update selected

block script
Expand All @@ -70,8 +70,10 @@ block script
ss: {
tagName: '',
},
imageSelected: '',
image: null,
imageGitVersion: null,
manifest: {},
zipSelected: '',
},
async mounted () {
// 自動儲存功能
Expand Down Expand Up @@ -190,12 +192,8 @@ block script
this.showLoading({ html })
}
try {
this.showLoading({ text: 'Unzip firmware...' })
const dfuFile = this.$refs.imageSelected.files[0]
if (_.isNil(dfuFile)) throw new Error('Please browse a firmware file.')
const dfuZip = new DfuZip(new Buffer(await dfuFile.arrayBuffer()))
const image = await dfuZip.getAppImage()
const imageGitVersion = await dfuZip.getGitVersion()
const { image, imageGitVersion } = this
if (_.isNil(image)) throw new Error('Please browse a firmware file.')
this.showLoading({ text: 'Connect device...' })
if (!ultra.isConnected()) await ultra.connect()
if (!ultra.isDfu()) {
Expand Down Expand Up @@ -225,6 +223,19 @@ block script
}
ultra.emitter.removeListener('progress', showProgress)
},
async onZipSelected (zip) {
const { ultra } = this
try {
this.image = null
this.imageGitVersion = null
if (_.isNil(zip)) throw new Error('zip is nil')
const dfuZip = new DfuZip(new Buffer(await zip.arrayBuffer()))
this.image = await dfuZip.getAppImage()
this.imageGitVersion = await dfuZip.getGitVersion()
} catch (err) {
ultra.emitter.emit('error', err)
}
},
async sleep (t) {
await new Promise(resolve => setTimeout(resolve, t))
},
Expand All @@ -246,8 +257,12 @@ block script
Swal.fire(args).then(res => { isConfirmed = res.isConfirmed })
})
},
getFilename (str) {
return str.replaceAll(/.*[/\\]/g, '')
getZipInfo () {
let str = ''
const { imageGitVersion, zipSelected } = this
if (!_.isNil(zipSelected)) str += zipSelected.replaceAll(/.*[/\\]/g, '')
if (!_.isNil(imageGitVersion)) str += ` (${imageGitVersion})`
return str
},
showLoading (opts = {}) {
opts = {
Expand Down
1 change: 1 addition & 0 deletions src/EventAsyncGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function createResolvable<T> (): Resolvable<T> {
const resolvable = new Promise<T>((...args) => {
;[resolve, reject] = args
}) as Resolvable<T>
// eslint-disable-next-line @typescript-eslint/no-floating-promises
Object.assign(resolvable, { resolve, reject })
return resolvable
}
Loading

0 comments on commit f31fc71

Please sign in to comment.