-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CP-3185] Integrate the flashing mechanism with the application on Wi…
…ndows (#2126)
- Loading branch information
Showing
10 changed files
with
171 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
libs/msc-flash/msc-flash-harmony/src/lib/selectors/select-is-flashing-in-state.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Copyright (c) Mudita sp. z o.o. All rights reserved. | ||
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md | ||
*/ | ||
|
||
import { createSelector } from "@reduxjs/toolkit" | ||
import { FlashingProcessState } from "../constants" | ||
import { selectFlashingProcessState } from "./select-flashing-process-state" | ||
|
||
export const selectIsFlashingInState = (targetState: FlashingProcessState) => | ||
createSelector( | ||
selectFlashingProcessState, | ||
(flashingProcessState) => flashingProcessState === targetState | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...h/msc-flash-harmony/src/lib/services/device-flash/windows/windows-device-flash.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* Copyright (c) Mudita sp. z o.o. All rights reserved. | ||
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md | ||
*/ | ||
|
||
import { | ||
execCommandWithSudo, | ||
execPromise, | ||
splitPathToDirNameAndBaseName, | ||
} from "shared/utils" | ||
import IDeviceFlash from "../device-flash.interface" | ||
|
||
interface DiskInformation { | ||
DiskNumber: number | ||
FriendlyName: string | ||
Size: string | ||
OperationalStatus: string | ||
} | ||
|
||
class WindowsDeviceFlashService implements IDeviceFlash { | ||
async findDeviceByDeviceName(deviceName: string): Promise<string> { | ||
console.log( | ||
`Searching for the device with the friendly name: ${deviceName}` | ||
) | ||
|
||
const getDiskResult = await execPromise( | ||
`powershell.exe -Command "Get-Disk | Where-Object { $_.FriendlyName -eq '${deviceName}' }| ConvertTo-Json"` | ||
) | ||
|
||
if (!getDiskResult) { | ||
throw new Error(`Disk not found for friendly name: ${deviceName}`) | ||
} | ||
|
||
const diskInformation: DiskInformation = JSON.parse(getDiskResult) | ||
|
||
console.log( | ||
`Disk information retrieved successfully: Disk Number - ${diskInformation.DiskNumber}, Size - ${diskInformation.Size} bytes, Status - ${diskInformation.OperationalStatus}` | ||
) | ||
|
||
return String(diskInformation.DiskNumber) | ||
} | ||
|
||
async execute( | ||
device: string, | ||
imagePath: string, | ||
scriptPath: string | ||
): Promise<void> { | ||
await this.flashDevice(device, imagePath, scriptPath) | ||
console.log("Flash process completed successfully") | ||
} | ||
|
||
private async flashDevice( | ||
device: string, | ||
imagePath: string, | ||
scriptPath: string | ||
): Promise<void> { | ||
const [path, scriptBasename] = splitPathToDirNameAndBaseName(scriptPath) | ||
const [, imageBasename] = splitPathToDirNameAndBaseName(imagePath) | ||
const command = `cd ${path} && powershell.exe -ExecutionPolicy Bypass -File ${scriptBasename} -file ${imageBasename} -diskid ${device} -force` | ||
|
||
try { | ||
await execCommandWithSudo(command) | ||
} catch (error) { | ||
throw new Error( | ||
`An error occurred during flashing: ${JSON.stringify(error)}` | ||
) | ||
} | ||
} | ||
} | ||
|
||
export default WindowsDeviceFlashService |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters