Lock session before reseting

This commit is contained in:
Dustin Brett
2022-08-10 12:58:39 -07:00
parent 8df596b4ca
commit 5ea6e0fd71
3 changed files with 11 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ import StyledSidebar from "components/system/StartMenu/Sidebar/StyledSidebar";
import { useFileSystem } from "contexts/fileSystem";
import { resetStorage } from "contexts/fileSystem/functions";
import { useProcesses } from "contexts/process";
import { useSession } from "contexts/session";
import { useEffect, useMemo, useRef, useState } from "react";
import { useTheme } from "styled-components";
import { HOME, TASKBAR_HEIGHT } from "utils/constants";
@@ -36,6 +37,7 @@ type SidebarProps = {
const Sidebar: FC<SidebarProps> = ({ height }) => {
const { rootFs } = useFileSystem();
const { open } = useProcesses();
const { setHaltSession } = useSession();
const [collapsed, setCollapsed] = useState(true);
const expandTimer = useRef<number>();
const clearTimer = (): void => {
@@ -103,8 +105,10 @@ const Sidebar: FC<SidebarProps> = ({ height }) => {
}
: undefined,
{
action: () =>
resetStorage(rootFs).finally(() => window.location.reload()),
action: () => {
setHaltSession(true);
resetStorage(rootFs).finally(() => window.location.reload());
},
icon: <Power />,
name: "Power",
tooltip: "Clears session data and reloads the page.",

View File

@@ -47,6 +47,7 @@ export type SessionContextState = SessionData & {
sessionLoaded: boolean;
setClockSource: React.Dispatch<React.SetStateAction<ClockSource>>;
setForegroundId: React.Dispatch<React.SetStateAction<string>>;
setHaltSession: React.Dispatch<React.SetStateAction<boolean>>;
setIconPositions: React.Dispatch<React.SetStateAction<IconPositions>>;
setRunHistory: React.Dispatch<React.SetStateAction<string[]>>;
setSortOrder: (

View File

@@ -55,9 +55,10 @@ const useSessionContextState = (): SessionContextState => {
},
[]
);
const [haltSession, setHaltSession] = useState(false);
useEffect(() => {
if (sessionLoaded) {
if (sessionLoaded && !haltSession) {
writeFile(
SESSION_FILE,
JSON.stringify({
@@ -75,6 +76,7 @@ const useSessionContextState = (): SessionContextState => {
}
}, [
clockSource,
haltSession,
iconPositions,
runHistory,
sessionLoaded,
@@ -149,6 +151,7 @@ const useSessionContextState = (): SessionContextState => {
sessionLoaded,
setClockSource,
setForegroundId,
setHaltSession,
setIconPositions,
setRunHistory,
setSortOrder,