From ba4e99faf8afd27a5cfd99fc64329296be11757c Mon Sep 17 00:00:00 2001 From: Ibrahim Ansari Date: Tue, 5 Nov 2024 03:37:08 +0530 Subject: [PATCH] Exclusively lock device, clean renderer code --- app/dd.go | 2 +- renderer/App.tsx | 25 +------------------------ renderer/index.tsx | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/app/dd.go b/app/dd.go index 094d5eb..3230d3f 100644 --- a/app/dd.go +++ b/app/dd.go @@ -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) } diff --git a/renderer/App.tsx b/renderer/App.tsx index 1add4aa..7e06e14 100644 --- a/renderer/App.tsx +++ b/renderer/App.tsx @@ -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('') @@ -34,8 +12,6 @@ const App = (): JSX.Element => { const [fileSize, setFileSize] = useState(0) const [progress, setProgress] = useState(null) const [selectedDevice, setSelectedDevice] = useState('N/A') - // useEffect(() => globalThis.setFileGo(file), [file]) - useEffect(() => globalThis.refreshDevices(), []) globalThis.setFileReact = setFile globalThis.setSpeedReact = setSpeed globalThis.setDialogReact = setDialog @@ -43,6 +19,7 @@ const App = (): JSX.Element => { globalThis.setProgressReact = setProgress globalThis.setFileSizeReact = setFileSize globalThis.setSelectedDeviceReact = setSelectedDevice + useEffect(() => globalThis.refreshDevices(), []) const inProgress = typeof progress === 'number' useEffect(() => setConfirm(false), [inProgress]) diff --git a/renderer/index.tsx b/renderer/index.tsx index 3c14d38..130f886 100644 --- a/renderer/index.tsx +++ b/renderer/index.tsx @@ -1,6 +1,22 @@ import { createRoot } from 'react-dom/client' import App from './App' +declare global { /* eslint-disable no-var */ + // 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) {