Skip to content

Commit

Permalink
Exclusively lock device, clean renderer code
Browse files Browse the repository at this point in the history
  • Loading branch information
retrixe committed Nov 4, 2024
1 parent dd46549 commit ba4e99f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 25 deletions.
2 changes: 1 addition & 1 deletion app/dd.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func FlashFileToBlockDevice(iff string, of string) {
} else if fileStat.Mode().IsDir() {
log.Fatalln("The specified source file is a folder!")
}
dest, err := os.OpenFile(destPath, os.O_WRONLY, os.ModePerm) // os.O_RDWR|os.O_EXCL|os.O_CREATE
dest, err := os.OpenFile(destPath, os.O_WRONLY|os.O_EXCL, os.ModePerm)
if err != nil {
log.Fatalln("An error occurred while opening the dest.", err)
}
Expand Down
25 changes: 1 addition & 24 deletions renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,6 @@ import { css } from '@emotion/react'
import JSBI from 'jsbi'
import Dialog from './Dialog'

declare global {
/* eslint-disable no-var */
// Flash and cancel flash.
var flash: (filePath: string, devicePath: string) => void
var cancelFlash: () => void
// UI update prompts.
var promptForFile: () => void
var refreshDevices: () => void
// Export React state to the global scope.
var setFileReact: (file: string) => void
var setSpeedReact: (speed: string) => void
var setDialogReact: (dialog: string) => void
var setDevicesReact: (devices: string[]) => void
var setFileSizeReact: (fileSize: number) => void
var setProgressReact: (progress: number | string | null) => void
var setSelectedDeviceReact: (selectedDevice: string) => void
} /* eslint-enable no-var */

// const floor = (num: number) => Math.floor(num * 100) / 100
// const varToString = varObj => Object.keys(varObj)[0]; const s = (setObj, value) => {
// const name = varToString(setObj); setObj[name](value); window[name + 'Go'](value)}

const App = (): JSX.Element => {
const [file, setFile] = useState('')
const [speed, setSpeed] = useState('')
Expand All @@ -34,15 +12,14 @@ const App = (): JSX.Element => {
const [fileSize, setFileSize] = useState(0)
const [progress, setProgress] = useState<number | string | null>(null)
const [selectedDevice, setSelectedDevice] = useState('N/A')
// useEffect(() => globalThis.setFileGo(file), [file])
useEffect(() => globalThis.refreshDevices(), [])
globalThis.setFileReact = setFile
globalThis.setSpeedReact = setSpeed
globalThis.setDialogReact = setDialog
globalThis.setDevicesReact = setDevices
globalThis.setProgressReact = setProgress
globalThis.setFileSizeReact = setFileSize
globalThis.setSelectedDeviceReact = setSelectedDevice
useEffect(() => globalThis.refreshDevices(), [])

const inProgress = typeof progress === 'number'
useEffect(() => setConfirm(false), [inProgress])
Expand Down
16 changes: 16 additions & 0 deletions renderer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
import { createRoot } from 'react-dom/client'
import App from './App'

declare global { /* eslint-disable no-var */

Check failure on line 4 in renderer/index.tsx

View workflow job for this annotation

GitHub Actions / Build (ubuntu-20.04)

Insert `⏎·`

Check failure on line 4 in renderer/index.tsx

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Insert `⏎·`
// Exports from Go app process.
var flash: (filePath: string, devicePath: string) => void
var cancelFlash: () => void
var promptForFile: () => void
var refreshDevices: () => void
// Export React state to the global scope.
var setFileReact: (file: string) => void
var setSpeedReact: (speed: string) => void
var setDialogReact: (dialog: string) => void
var setDevicesReact: (devices: string[]) => void
var setFileSizeReact: (fileSize: number) => void
var setProgressReact: (progress: number | string | null) => void
var setSelectedDeviceReact: (selectedDevice: string) => void
} /* eslint-enable no-var */

// LOW-TODO: Use SWC Emotion plugin in future once Parcel reads .swcrc files...
const el = document.getElementById('app')
if (el !== null) {
Expand Down

0 comments on commit ba4e99f

Please sign in to comment.