Skip to content

Commit

Permalink
Merge pull request #889 from Dygmalab/checkValidBkpFolder
Browse files Browse the repository at this point in the history
Alert the user when the backup folder is not valid before flashing
  • Loading branch information
alexpargon authored Sep 24, 2024
2 parents ed65e33 + 5e021d1 commit c9230ed
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/api/backup/Backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ export default class Backup {
return validCommands;
}

static backupFolderValid = () => {
const folder = store.get("settings.backupFolder") as string;
try {
const stats = fs.statSync(folder);
return stats.isDirectory();
} catch (error) {
return false;
}
};

/**
* The function is desgned to make a backup of the whole configuration pertaining the Raise keyboard
*
Expand Down
29 changes: 26 additions & 3 deletions src/renderer/modules/Firmware/FirmwareUpdatePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { IconBluetooth, IconLoader, IconUSB, IconWarning } from "@Renderer/compo
// Visual modules
import { FirmwareNeuronStatus, FirmwareVersionStatus } from "@Renderer/modules/Firmware";
import { useDevice } from "@Renderer/DeviceContext";
import Backup from "../../../api/backup";

const Style = Styled.div`
width: 100%;
Expand Down Expand Up @@ -173,6 +174,7 @@ function FirmwareUpdatePanel(props: FirmwareUpdatePanelProps) {
const { nextBlock, retryBlock, errorBlock, allowBeta } = props;
const { state: deviceState } = useDevice();
const [loading, setLoading] = useState(true);
const [isValidBkpFolder, setIsValidBkpFolder] = useState(Backup.backupFolderValid());
const [state, send] = useMachine(FirmwareSelection, { input: { allowBeta, deviceState } });

let flashButtonText = state.context.stateblock === 4 ? "Processing..." : "";
Expand All @@ -185,6 +187,7 @@ function FirmwareUpdatePanel(props: FirmwareUpdatePanelProps) {
}
if (state.value === "success") nextBlock(state.context);
if (state.value === "failure") errorBlock(state.context.error);
setIsValidBkpFolder(Backup.backupFolderValid());
}, [errorBlock, nextBlock, retryBlock, state]);

return (
Expand Down Expand Up @@ -242,7 +245,8 @@ function FirmwareUpdatePanel(props: FirmwareUpdatePanelProps) {
<div className="firmware-sidebar borderRightBottomRadius">
<div className="buttonActions">
{(state.context.firmwareList.length > 0 || state.context.typeSelected === "custom") &&
deviceState.currentDevice.type === "serial" ? (
deviceState.currentDevice.type === "serial" &&
isValidBkpFolder ? (
<Button
onClick={() => {
send({ type: "next-event" });
Expand All @@ -254,10 +258,24 @@ function FirmwareUpdatePanel(props: FirmwareUpdatePanelProps) {
</Button>
) : (
<>
{deviceState.currentDevice.type === "serial" ? (
{!isValidBkpFolder ? (
<div className="px-4 py-4">
<div className="px-4 py-4 rounded-md bg-gray-25 dark:bg-gray-600/50 flex gap-4 items-center animate-bounce-error">
<div className="inline-flex w-10 h-10 aspect-square items-center justify-center text-orange-900/50 bg-orange-200/50 dark:text-orange-200 dark:bg-orange-200/25 rounded-full">
<div className="inline-flex w-10 h-10 p-2 aspect-square items-center justify-center text-orange-900/50 bg-orange-200/50 dark:text-orange-200 dark:bg-orange-200/25 rounded-full">
<IconWarning />
</div>
<div className="flex flex-wrap gap-2 text-gray-400 dark:text-gray-25 text-sm">
Backup path is no longer valid, please modify.
</div>
</div>
</div>
) : (
""
)}
{deviceState.currentDevice.type === "serial" && isValidBkpFolder ? (
<div className="px-4 py-4">
<div className="px-4 py-4 rounded-md bg-gray-25 dark:bg-gray-600/50 flex gap-4 items-center animate-bounce-error">
<div className="inline-flex w-10 h-10 p-2 aspect-square items-center justify-center text-orange-900/50 bg-orange-200/50 dark:text-orange-200 dark:bg-orange-200/25 rounded-full">
<IconWarning />
</div>
<div className="flex flex-wrap gap-2 text-gray-400 dark:text-gray-25 text-sm">
Expand All @@ -266,6 +284,9 @@ function FirmwareUpdatePanel(props: FirmwareUpdatePanelProps) {
</div>
</div>
) : (
""
)}
{deviceState.currentDevice.type !== "serial" && isValidBkpFolder ? (
<div className="px-4 py-4">
<div className="px-4 py-4 rounded-md bg-gray-25 dark:bg-gray-700 flex flex-col items-center gap-2 text-sm animate-bounce-error">
<div className="flex w-full items-center px-2 py-0 rounded-xl text-2xxs font-semibold tracking-tight leading-tight bg-orange-200 text-orange-900 [&_svg]:w-4">
Expand All @@ -281,6 +302,8 @@ function FirmwareUpdatePanel(props: FirmwareUpdatePanelProps) {
</div>
</div>
</div>
) : (
""
)}
</>
)}
Expand Down

0 comments on commit c9230ed

Please sign in to comment.