Skip to content

Commit

Permalink
[CP-3185] Minor refactor of device-flash
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarski committed Oct 15, 2024
1 parent 56752cd commit 8314fad
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/

export * from "./select-flashing-state.selector"
export * from "./select-flashing-state"
export * from "./select-flashing-abort-controller"
export * from "./select-flashing-process-state"
export * from "./select-is-flashing-in-active-phases"
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { createSelector } from "@reduxjs/toolkit"
import { flashingState } from "./select-flashing-state.selector"
import { flashingState } from "./select-flashing-state"

export const selectFlashingAbortController = createSelector(
flashingState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { createSelector } from "@reduxjs/toolkit"
import { flashingState } from "./select-flashing-state.selector"
import { flashingState } from "./select-flashing-state"

export const selectFlashingProcessState = createSelector(
flashingState,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/

import path from "path"
import { execPromise, execCommandWithSudo } from "shared/utils"
import {
execPromise,
execCommandWithSudo,
splitPathToDirNameAndBaseName,
} from "shared/utils"
import IDeviceFlash from "../device-flash.interface"
import LinuxPartitionParser from "./linux-partition-parser"

Expand Down Expand Up @@ -36,7 +39,7 @@ class LinuxDeviceFlashService implements IDeviceFlash {
const ejectDeviceCommand = await this.getEjectDeviceCommand(device)

const command = `${unmountDeviceCommand} && ${flashImageToDeviceCommand} && ${ejectDeviceCommand}`
await execCommandWithSudo(command, { name: "Mudita Auto Flash" })
await execCommandWithSudo(command)

console.log("Flash process completed successfully")
}
Expand All @@ -55,9 +58,8 @@ class LinuxDeviceFlashService implements IDeviceFlash {
imagePath: string,
scriptPath: string
): Promise<string> {
const [path, scriptBasename] =
this.splitPathToDirnameAndBasename(scriptPath)
const [, imageBasename] = this.splitPathToDirnameAndBasename(imagePath)
const [path, scriptBasename] = splitPathToDirNameAndBaseName(scriptPath)
const [, imageBasename] = splitPathToDirNameAndBaseName(imagePath)
return `chmod +x ${scriptPath} && cd ${path} && ./${scriptBasename} ${imageBasename} /dev/${device}`
}

Expand All @@ -77,12 +79,6 @@ class LinuxDeviceFlashService implements IDeviceFlash {
)
return LinuxPartitionParser.parsePartitions(partitions ?? "")
}

private splitPathToDirnameAndBasename(currentPath: string) {
const dirname = path.dirname(currentPath)
const basename = path.basename(currentPath)
return [dirname, basename]
}
}

export default LinuxDeviceFlashService
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ const getFlashingImageDetails = async (
await dispatch(
getMscFlashingFilesDetails({
signal,
platform,
product: Product.MscHarmony,
environment: RELEASE_SPACE,
platform: platform,
})
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ export const RestartingDeviceModal: FunctionComponent<
const dispatch = useDispatch<Dispatch>()

useEffect(() => {
const timer = setTimeout(() => {
dispatch(setFlashingProcessState(FlashingProcessState.Failed))
}, 2 * 60 * 1000)
let timeoutId: NodeJS.Timeout

return () => clearTimeout(timer)
}, [dispatch])
if (open) {
timeoutId = setTimeout(() => {
dispatch(setFlashingProcessState(FlashingProcessState.Failed))
}, 2 * 60 * 1000)
}

return () => clearTimeout(timeoutId)
}, [dispatch, open])

return (
<LoaderModal
Expand Down
1 change: 1 addition & 0 deletions libs/shared/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export * from "./lib/prevent-default-shortcuts"
export * from "./lib/register-shortcuts"
export * from "./lib/routes-history.context"
export * from "./lib/settings-service.interface"
export * from "./lib/split-path-to-dir-name-and-base-name"
export * from "./lib/use-debounced-events-handler"
export * from "./lib/exec-command"
export * from "./lib/exec-command-with-sudo"
Expand Down
2 changes: 1 addition & 1 deletion libs/shared/utils/src/lib/exec-command-with-sudo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import sudoPrompt from "@vscode/sudo-prompt"

export const execCommandWithSudo = (
command: string,
options: { name?: string; icns?: string; env?: { [key: string]: string } }
options?: { name?: string; icns?: string; env?: { [key: string]: string } }
): Promise<string | void> => {
return new Promise((resolve, reject) => {
sudoPrompt.exec(command, options, (error, stdout, stderr) => {
Expand Down
14 changes: 14 additions & 0 deletions libs/shared/utils/src/lib/split-path-to-dir-name-and-base-name.ts
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 path from "path"

export const splitPathToDirNameAndBaseName = (
currentPath: string
): [string, string] => {
const dirName = path.dirname(currentPath)
const baseName = path.basename(currentPath)
return [dirName, baseName]
}

0 comments on commit 8314fad

Please sign in to comment.