mirror of
https://github.com/DustinBrett/daedalOS.git
synced 2026-01-15 12:15:02 +00:00
Lock session before reseting
This commit is contained in:
@@ -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.",
|
||||
|
||||
@@ -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: (
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user