Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/features/root/Root.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ import {
fail,
reset,
root,
selecting,
success,
selectAttempted,
selectRooting,
selectSelecting,
} from "./rootSlice";

import {
Expand Down Expand Up @@ -78,6 +80,7 @@ export default function Root() {
const attempted = useSelector(selectAttempted);
const hasAdb = useSelector(selectHasAdb);
const rooting = useSelector(selectRooting);
const isSelecting = useSelector(selectSelecting);

let runUnlock;

Expand Down Expand Up @@ -348,6 +351,8 @@ export default function Root() {
} catch (e) {
console.log("Failed closing port:", e);
}

dispatch(fail());
}

running.current = false;
Expand Down Expand Up @@ -414,6 +419,11 @@ export default function Root() {
const port = await navigator.serial.requestPort({ filters });
await exploit.openPort(port);

ReactGA.gtag("event", "rootClicked");
timeStarted.current = new Date();

dispatch(root());

runUnlock();
} catch(e) {
dispatch(reset());
Expand All @@ -437,10 +447,7 @@ export default function Root() {
}, [disconnectListener]);

const handleClick = useCallback(async() => {
ReactGA.gtag("event", "rootClicked");
timeStarted.current = new Date();

dispatch(root());
dispatch(selecting());
triggerUnlock();
}, [dispatch, triggerUnlock]);

Expand Down Expand Up @@ -480,7 +487,7 @@ export default function Root() {
</Alert>}

<Button
disabled={rooting || !window.navigator.serial}
disabled={isSelecting || rooting || !window.navigator.serial}
onClick={handleClick}
variant="contained"
>
Expand Down
10 changes: 9 additions & 1 deletion src/features/root/rootSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createSlice } from "@reduxjs/toolkit";

const initialState = {
attempted: false,
selecting: false,
rooting: false,
success: false,
};
Expand All @@ -10,17 +11,22 @@ export const rootSlice = createSlice({
name: "root",
initialState,
reducers: {
selecting: (state) => {
state.selecting = true;
},
root: (state) => {
state.selecting = false;
state.attempted = true;
state.log = [];
state.rooting = true;
state.success = false;
},
success: (state) => {
state.selecting = false;
state.rooting = false;
state.success = true;
},
fail: (state) => {
state.selecting = false;
state.rooting = false;
state.success = false;
},
Expand All @@ -32,11 +38,13 @@ export const {
fail,
reset,
root,
selecting,
success,
} = rootSlice.actions;

export const selectAttempted = (state) => state.root.attempted;
export const selectRooting = (state) => state.root.rooting;
export const selectSelecting = (state) => state.root.selecting;
export const selectSuccess = (state) => state.root.success;

export default rootSlice.reducer;