Skip to content

Commit

Permalink
Feature/175 package detail page (#190)
Browse files Browse the repository at this point in the history
* Show maintainer label
* Allow installation/removal of package
* Use different config file `schemaV2.json` for configurator as to not break compatibility with CLI schema
  • Loading branch information
stylesuxx authored Oct 9, 2022
1 parent 41947ca commit cd79327
Show file tree
Hide file tree
Showing 10 changed files with 299 additions and 74 deletions.
32 changes: 11 additions & 21 deletions src/AdbRouter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
} from "./features/device/deviceSlice";

import {
selectCheckedMaster,
selectChecked as selectCheckedMaster,
selectIsMaster,
} from "./features/tabGovernor/tabGovernorSlice";

Expand All @@ -57,15 +57,12 @@ export default function AdbRouter() {
const [adb, setAdb] = useState(null);
const [device, setDevice] = useState(null);
const [intervalId, setIntervalId] = useState(null);
const [watcher, setWatcher] = useState(null);

const [canAutoConnect, setCanAutoConnect] = useState(false);

const adbRef = useRef();
const deviceRef = useRef();
const devicePromiseRef = useRef();
const intervalRef = useRef();
const watcherRef = useRef();
const devicePromiseRef = useRef();

const connectToDevice = useCallback(async (device) => {
if(device && !adb) {
Expand Down Expand Up @@ -133,13 +130,14 @@ export default function AdbRouter() {
* connect to.
*/
const autoConnect = useCallback(async() => {
const canAutoConnect = (!devicePromiseRef.current && checkedMasterState && isMaster);
if(canAutoConnect) {
const devices = await AdbWebUsbBackend.getDevices();
if(devices.length > 0) {
await connectToDevice(devices[0]);
}
}
}, [canAutoConnect, connectToDevice]);
}, [connectToDevice, checkedMasterState, devicePromiseRef, isMaster]);

// Handle button press for device connection
const handleDeviceConnect = useCallback(async() => {
Expand All @@ -155,15 +153,14 @@ export default function AdbRouter() {
}
}, [connectToDevice, devicePromiseRef, dispatch]);

// Check if we are able to auto connect to the device
useEffect(() => {
setCanAutoConnect(!devicePromiseRef.current && checkedMasterState && isMaster);
}, [checkedMasterState, devicePromiseRef, isMaster]);

// Set watcher to monitor WebUSB devices popping up or going away
useEffect(() => {
if(!watcher && window.navigator.usb) {
const watcher = new AdbWebUsbBackendWatcher(async (id) => {
if(window.navigator.usb) {
if(watcherRef.current) {
watcherRef.current.dispose();
}

watcherRef.current = new AdbWebUsbBackendWatcher(async (id) => {
if(!id) {
setAdb(null);
dispatch(resetDevice());
Expand All @@ -173,10 +170,8 @@ export default function AdbRouter() {
await autoConnect();
}
});

setWatcher(watcher);
}
}, [autoConnect, connectToDevice, dispatch, watcher]);
}, [autoConnect, dispatch, watcherRef]);

// Automatically try to connect to device when application starts up
useEffect(() => {
Expand Down Expand Up @@ -212,7 +207,6 @@ export default function AdbRouter() {
setAdb(null);
setDevice(null);
setIntervalId(null);
setWatcher(null);
};
}, [dispatch]);

Expand All @@ -229,10 +223,6 @@ export default function AdbRouter() {
intervalRef.current = intervalId;
}, [intervalId]);

useEffect(() => {
watcherRef.current = watcher;
}, [watcher]);

return(
<Routes>
<Route
Expand Down
10 changes: 4 additions & 6 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ import Device from "./features/device/Device";
import Error404 from "./features/404/404";
import Header from "./features/navigation/Header";
import Healthcheck from "./features/healthcheck/Healthcheck";
import Install from "./features/setup/Install";
import Home from "./features/home/Main";
import Packages from "./features/packages/Packages";
import Package from "./features/package/Package";
import Startup from "./features/startup/Startup";

import Setup from "./features/setup/Setup";
import Install from "./features/setup/Install";
import Packages from "./features/packages/Packages";
import Remove from "./features/setup/Remove";
import Setup from "./features/setup/Setup";
import Startup from "./features/startup/Startup";
import Update from "./features/setup/Update";

import {
Expand All @@ -44,7 +43,6 @@ import { selectPassed } from "./features/healthcheck/healthcheckSlice";

import { selectCanClaim } from "./features/tabGovernor/tabGovernorSlice";


function App({
adb,
handleAdbConnectClick,
Expand Down
4 changes: 2 additions & 2 deletions src/Router.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import AdbRouter from "./AdbRouter";
import TabGovernor from "./utils/TabGovernor";

import {
checkedMaster,
setCanClaim,
setChecked,
setMaster,
} from "./features/tabGovernor/tabGovernorSlice";

Expand All @@ -39,7 +39,7 @@ export default function Router() {
if(!tabGovernor) {
const tabGovernor = new TabGovernor((isMaster) => {
dispatch(setMaster(isMaster));
dispatch(checkedMaster(true));
dispatch(setChecked());
}, (canClaim) => {
dispatch(setCanClaim(canClaim));
});
Expand Down
31 changes: 31 additions & 0 deletions src/features/overlays/Spinner.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import PropTypes from "prop-types";
import React from "react";

import Box from "@mui/material/Box";

import Spinner from "../loading/Spinner";

export default function SpinnerOverlay({ text }) {
return(
<Box
sx={{
background: "rgba(0, 0, 0, 0.75)",
position: "absolute",
left: "0px",
top: "0px",
width: "100%",
height: "100%",
zIndex: "100",
display: "flex",
justifyContent: "center",
alignItems: "center",
}}
>
<Spinner text={text} />
</Box>
);
}

SpinnerOverlay.defaultProps = { text: "" };

SpinnerOverlay.propTypes = { text: PropTypes.string };
Loading

0 comments on commit cd79327

Please sign in to comment.