Skip to content

Commit

Permalink
[chore] lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ottomated committed Jan 9, 2021
1 parent c29b62a commit 3fcfcf7
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 86 deletions.
84 changes: 43 additions & 41 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ function createMainWindow() {
if (overlayWindow != null) {
try {
overlayWindow.close();
} catch (_) {}
} catch (_) {
console.error(_);
}
overlayWindow = null;
}
});
Expand All @@ -93,6 +95,46 @@ function createMainWindow() {
return window;
}

function createOverlay() {
const window = new BrowserWindow({
width: 400,
height: 300,
webPreferences: {
nodeIntegration: true,
webSecurity: false,
},
...electronOverlayWindow.WINDOW_OPTS,
});

if (isDevelopment) {
window.loadURL(
`http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}?version=${autoUpdater.currentVersion.version}&view=overlay`
);
} else {
window.loadURL(
formatUrl({
pathname: joinPath(__dirname, 'index.html'),
protocol: 'file',
query: {
version: autoUpdater.currentVersion.version,
view: 'overlay',
},
slashes: true,
})
);
}
window.setIgnoreMouseEvents(true);
electronOverlayWindow.attachTo(window, 'Among Us');

if (isDevelopment) {
// Force devtools into detached mode otherwise they are unusable
window.webContents.openDevTools({
mode: 'detach',
});
}
return window;
}

const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
Expand Down Expand Up @@ -159,46 +201,6 @@ if (!gotTheLock) {
}
});

function createOverlay() {
const window = new BrowserWindow({
width: 400,
height: 300,
webPreferences: {
nodeIntegration: true,
webSecurity: false,
},
...electronOverlayWindow.WINDOW_OPTS,
});

if (isDevelopment) {
window.loadURL(
`http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}?version=${autoUpdater.currentVersion.version}&view=overlay`
);
} else {
window.loadURL(
formatUrl({
pathname: joinPath(__dirname, 'index.html'),
protocol: 'file',
query: {
version: autoUpdater.currentVersion.version,
view: 'overlay',
},
slashes: true,
})
);
}
window.setIgnoreMouseEvents(true);
electronOverlayWindow.attachTo(window, 'Among Us');

if (isDevelopment) {
// Force devtools into detached mode otherwise they are unusable
window.webContents.openDevTools({
mode: 'detach',
});
}
return window;
}

// quit application when all windows are closed
app.on('window-all-closed', () => {
// on macOS it is common for applications to stay open until the user explicitly quits
Expand Down
93 changes: 51 additions & 42 deletions src/renderer/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {
Dispatch,
ErrorInfo,
ReactChild,
SetStateAction,
useEffect,
useReducer,
Expand Down Expand Up @@ -116,12 +117,18 @@ enum AppState {
VOICE,
}

interface ErrorBoundaryProps {
children: ReactChild;
}
interface ErrorBoundaryState {
error?: Error;
}

class ErrorBoundary extends React.Component<{}, ErrorBoundaryState> {
constructor(props: {}) {
class ErrorBoundary extends React.Component<
ErrorBoundaryProps,
ErrorBoundaryState
> {
constructor(props: ErrorBoundaryProps) {
super(props);
this.state = {};
}
Expand All @@ -135,7 +142,7 @@ class ErrorBoundary extends React.Component<{}, ErrorBoundaryState> {
console.error('React Error: ', error, errorInfo);
}

render() {
render(): ReactChild {
if (this.state.error) {
return (
<div style={{ paddingTop: 16 }}>
Expand Down Expand Up @@ -170,7 +177,7 @@ class ErrorBoundary extends React.Component<{}, ErrorBoundaryState> {
}
}

export default function App() {
const App: React.FC = function () {
const [state, setState] = useState<AppState>(AppState.MENU);
const [gameState, setGameState] = useState<AmongUsState>({} as AmongUsState);
const [settingsOpen, setSettingsOpen] = useState(false);
Expand Down Expand Up @@ -289,52 +296,54 @@ export default function App() {
setSettingsOpen={setSettingsOpen}
/>
<ErrorBoundary>
<Settings
open={settingsOpen}
onClose={() => setSettingsOpen(false)}
/>
<Dialog fullWidth open={updaterState.state !== 'unavailable'}>
<DialogTitle>Updating...</DialogTitle>
<DialogContent>
{(updaterState.state === 'downloading' ||
updaterState.state === 'downloaded') &&
updaterState.progress && (
<>
<LinearProgress
variant={
updaterState.state === 'downloaded'
? 'indeterminate'
: 'determinate'
}
value={updaterState.progress.percent}
/>
<DialogContentText>
{prettyBytes(updaterState.progress.transferred)} /{' '}
{prettyBytes(updaterState.progress.total)}
</DialogContentText>
</>
<>
<Settings
open={settingsOpen}
onClose={() => setSettingsOpen(false)}
/>
<Dialog fullWidth open={updaterState.state !== 'unavailable'}>
<DialogTitle>Updating...</DialogTitle>
<DialogContent>
{(updaterState.state === 'downloading' ||
updaterState.state === 'downloaded') &&
updaterState.progress && (
<>
<LinearProgress
variant={
updaterState.state === 'downloaded'
? 'indeterminate'
: 'determinate'
}
value={updaterState.progress.percent}
/>
<DialogContentText>
{prettyBytes(updaterState.progress.transferred)} /{' '}
{prettyBytes(updaterState.progress.total)}
</DialogContentText>
</>
)}
{updaterState.state === 'error' && (
<DialogContentText color="error">
{updaterState.error}
</DialogContentText>
)}
</DialogContent>
{updaterState.state === 'error' && (
<DialogContentText color="error">
{updaterState.error}
</DialogContentText>
<DialogActions>
<Button href="https://github.com/ottomated/CrewLink/releases/latest">
Download Manually
</Button>
</DialogActions>
)}
</DialogContent>
{updaterState.state === 'error' && (
<DialogActions>
<Button href="https://github.com/ottomated/CrewLink/releases/latest">
Download Manually
</Button>
</DialogActions>
)}
</Dialog>
{page}
</Dialog>
{page}
</>
</ErrorBoundary>
</ThemeProvider>
</SettingsContext.Provider>
</LobbySettingsContext.Provider>
</GameStateContext.Provider>
);
}
};

ReactDOM.render(<App />, document.getElementById('app'));
8 changes: 5 additions & 3 deletions src/renderer/Overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface UseStylesProps {
hudHeight: number;
}

const useStyles = makeStyles((theme) => ({
const useStyles = makeStyles(() => ({
meetingHud: {
position: 'absolute',
top: '50%',
Expand Down Expand Up @@ -81,7 +81,7 @@ const playerColors = [

const iPadRatio = 854 / 579;

export default function Overlay() {
const Overlay: React.FC = function () {
const [gameState, setGameState] = useState<AmongUsState>(
(undefined as unknown) as AmongUsState
);
Expand Down Expand Up @@ -135,7 +135,7 @@ export default function Overlay() {
)}
</>
);
}
};

interface AvatarOverlayProps {
voiceState: VoiceState;
Expand Down Expand Up @@ -278,3 +278,5 @@ const MeetingHud: React.FC<MeetingHudProps> = ({
};

ReactDOM.render(<Overlay />, document.getElementById('app'));

export default Overlay;

0 comments on commit 3fcfcf7

Please sign in to comment.