Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies, fix reconnection and implement darkmode #192

Closed
wants to merge 6 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
insert_final_newline = true
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
"jest": true,
"browser": true
},
parser: "babel-eslint",
parser: "@babel/eslint-parser",
extends: [
"airbnb",
"plugin:prettier/recommended",
Expand Down
1 change: 1 addition & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
// But in some cases ESLing and Prettier confuse eachother
module.exports = {
trailingComma: "es5", // Makes diffs nicer
endOfLine: "auto", // To not freak out on Windows
}
2 changes: 2 additions & 0 deletions app/main/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import installExtension, {
import {
initListeners,
initRateLimiter,
setDarkMode,
ensureEnv,
} from "./initialize-project/initialize-project";
import { windows } from "../shared/resources/Windows/Windows";
Expand Down Expand Up @@ -78,6 +79,7 @@ if (!gotTheLock) {

app.whenReady().then(() => {
ensureEnv();
setDarkMode();

// Subscribing to the listeners happens even before creating the window to be ready to actively respond to initial events coming from renderer.
initListeners();
Expand Down
8 changes: 7 additions & 1 deletion app/main/initialize-project/initialize-project.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ipcMain, dialog } from "electron";
import { ipcMain, dialog, nativeTheme } from "electron";
import GlobalStore from "../../shared/GlobalStore/GlobalStore";
import { ipcEvents } from "../../shared/resources/IPCEvents/IPCEvents";
import { storeKeys } from "../../shared/resources/StoreKeys/StoreKeys";
Expand Down Expand Up @@ -104,3 +104,9 @@ export const initRateLimiter = () =>
// The reservoir's value must be decremented by one because the initialization contains a fetch which already counts towards the rate limit.
return HttpRequestLimiter.incrementReservoir(-1);
});

export const setDarkMode = () => {
const globalStore = GlobalStore.getInstance();

globalStore.set(storeKeys.DARK_MODE, nativeTheme.shouldUseDarkColors);
}
17 changes: 9 additions & 8 deletions app/main/web-sockets/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,26 +126,26 @@ const connect = id =>

ws.socket.on("close", () => {
devLog(
`SOCKET CLOSE - ${ws.searchUrl} / ${ws.id} ${ws.error.code} ${ws.error.reason}`
`SOCKET CLOSE - ${ws.searchUrl} / ${ws.id} ${ws.error?.code} ${ws.error?.reason}`
);

updateState(ws.id, ws.socket);

if (ws.error.code === 429) {
if (ws.error?.code === 429) {
sendError(
`Rate limit exceded! Closing connection for ${ws.searchUrl}. This should not happen, please open an issue.`
);
return;
}

if (ws.error.code === 404) {
if (ws.error?.code === 404) {
sendError(
`Search not found. Closing connection for ${ws.searchUrl}.`
);
return;
}

if (ws.error.code === 401) {
if (ws.error?.code === 401) {
sendError(
`Unauthorized. Closing connection for ${ws.searchUrl}. Check Session ID.`
);
Expand Down Expand Up @@ -208,11 +208,12 @@ export const updateConnections = () => {
return disconnectAll();
};

export const reconnect = id => disconnect(id);
export const reconnect = id => {
disconnect(id);
connect(id); // socket close event has auto-reconnect, but abnormal disconnection does not. So force connect when user requests it.
}

export const reconnectAll = () => {
disconnectAll();
// Disconnect triggers a re-connect in case the socket was already open.
// In case sockets were not open before we also call connect
connectAll();
connectAll(); // socket close event has auto-reconnect, but abnormal disconnection does not. So force connect when user requests it.
};
5 changes: 0 additions & 5 deletions app/renderer/SetupEnzymeTests/SetupEnzymeTests.js

This file was deleted.

4 changes: 1 addition & 3 deletions app/renderer/components/NavigationBar/NavigationBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import RateLimitFeedback from "./RateLimitFeedback/RateLimitFeedback";
import { useNavigationBarStyles } from "./NavigationBar.style";

export default () => {
const classes = useNavigationBarStyles();

return (
<Paper className={classes.container}>
<Paper sx={useNavigationBarStyles.container}>
<RateLimitFeedback />
<NavigationItems />
<RightSide />
Expand Down
14 changes: 6 additions & 8 deletions app/renderer/components/NavigationBar/NavigationBar.style.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import makeStyles from "@mui/styles/makeStyles";

export const useNavigationBarStyles = makeStyles({
export const useNavigationBarStyles = {
container: {
display: "flex",
position: "relative",
justifyContent: "space-evenly",
alignItems: "center",
padding: 5,
marginBottom: 15,
marginTop: 10,
},
});
padding: 1,
marginBottom: 2,
marginTop: 1,
}
};
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import React from "react";
import Breadcrumbs from "@mui/material/Breadcrumbs";
import Link from '@mui/material/Link';
import { NavLink } from "react-router-dom";
import { routes } from "../../../resources/Routes/Routes";

const navigationItems = () => (
<Breadcrumbs separator="">
{routes.map(route => (
<NavLink
<Link
component={NavLink}
key={route.displayName}
style={{ color: "#000000" }}
activeStyle={{ fontWeight: "bold" }}
style={({ isActive }) => ({ fontWeight: isActive ? 'bold' : 'normal' })}
to={route.path}
>
{route.displayName}
</NavLink>
</Link>
))}
</Breadcrumbs>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ipcEvents } from "../../../../shared/resources/IPCEvents/IPCEvents";
import { useRateLimitFeedbackStyles } from "./RateLimitFeedback.style";

export default () => {
const classes = useRateLimitFeedbackStyles();
const classes = useRateLimitFeedbackStyles;

const [requestsExhausted, setRequestsExhausted] = useState(false);

Expand Down Expand Up @@ -37,11 +37,11 @@ export default () => {
}

return (
<Tooltip title={buildMessage()} classes={{ tooltip: classes.tooltip }}>
<Tooltip title={buildMessage()} sx={ classes.tooltip }>
{requestsExhausted ? (
<WarningIcon className={classes.warningIcon} />
<WarningIcon sx={ classes.warningIcon } />
) : (
<CheckCircleIcon className={classes.checkCircleIcon} />
<CheckCircleIcon sx={ classes.checkCircleIcon } />
)}
</Tooltip>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import makeStyles from "@mui/styles/makeStyles";

export const useRateLimitFeedbackStyles = makeStyles({
export const useRateLimitFeedbackStyles = {
tooltip: {
maxWidth: "none",
fontSize: 14,
Expand All @@ -10,5 +8,5 @@ export const useRateLimitFeedbackStyles = makeStyles({
},
checkCircleIcon: {
color: "#228B22",
},
});
}
};
5 changes: 3 additions & 2 deletions app/renderer/components/NavigationBar/RightSide/RightSide.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import * as baseUrls from "../../../../shared/resources/BaseUrls/BaseUrls";
import { useRightSideStyles } from "./RightSide.style";

export default () => {
const classes = useRightSideStyles();
const classes = useRightSideStyles;

return (
<Box display="flex" alignItems="center">
<Typography variant="subtitle2">{process.env.REVISION}</Typography>

<Button
className={classes.button}
sx={classes.button}
onClick={() => electronUtils.openExternalUrl(baseUrls.reportIssue)}
>
Report issue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import makeStyles from "@mui/styles/makeStyles";

export const useRightSideStyles = makeStyles({
export const useRightSideStyles = {
button: {
textTransform: "none",
marginLeft: 10,
},
});
marginLeft: 1,
}
};
2 changes: 1 addition & 1 deletion app/renderer/components/Screens/Account/Account.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default () => {
justifyContent="space-between"
>
<Typography variant="h6" gutterBottom>
{`Logged in as anonymus`}
Logged in as anonymous
</Typography>
</Box>
<SessionIdEditor />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import * as baseUrls from "../../../../../../shared/resources/BaseUrls/BaseUrls"
import { useInfoButtonStyles } from "./InfoButton.style";

export default () => {
const classes = useInfoButtonStyles();
const classes = useInfoButtonStyles;

return (
<IconButton
className={classes.iconButton}
sx={classes.iconButton}
onClick={() => electronUtils.openExternalUrl(baseUrls.sessionIdWiki)}
size="large"
>
<HelpOutline className={classes.helpIcon} />
<HelpOutline sx={classes.helpIcon} />
</IconButton>
);
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import makeStyles from "@mui/styles/makeStyles";

export const useInfoButtonStyles = makeStyles({
export const useInfoButtonStyles = {
iconButton: {
padding: 0,
marginLeft: 5,
Expand All @@ -9,4 +7,4 @@ export const useInfoButtonStyles = makeStyles({
color: "#FFFFFF",
fontSize: "35px",
},
});
};
4 changes: 2 additions & 2 deletions app/renderer/components/Screens/News/News.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "../../../../shared/utils/JavaScriptUtils/JavaScriptUtils";

export default () => {
const classes = useNewsStyles();
const classes = useNewsStyles;
const [githubReleaseNotes, setGithubReleaseNotes] = useState([]);

useEffect(() => {
Expand All @@ -24,7 +24,7 @@ export default () => {
}, []);

return (
<Paper className={classes.root}>
<Paper sx={classes.root}>
{Announcements.map(announcement => {
return (
<Announcement
Expand Down
10 changes: 4 additions & 6 deletions app/renderer/components/Screens/News/News.style.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import makeStyles from "@mui/styles/makeStyles";

export const useNewsStyles = makeStyles({
export const useNewsStyles = {
root: {
overflow: "auto",
height: "600px",
padding: 20,
padding: 2,
"& > div": {
marginBottom: 30,
marginBottom: 4,
"&:last-child": {
marginBottom: 0,
},
},
},
});
};
6 changes: 3 additions & 3 deletions app/renderer/components/Screens/News/Types/Announcement.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ const Announcement = ({ ...details }) => (
{moment(details.date).format("DD.MM.YYYY")}
</Typography>
<ReactMarkdown
source={details.description}
renderers={{
children={details.description}
components={{
link: props => <Url {...props} />,
}}
plugins={[breaks]}
remarkPlugins={[breaks]}
/>
<Divider />
</div>
Expand Down
6 changes: 3 additions & 3 deletions app/renderer/components/Screens/News/Types/ReleaseNote.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ const ReleaseNote = ({ ...details }) => (
{moment(details.published_at).format("DD.MM.YYYY")}
</Typography>
<ReactMarkdown
source={details.body}
renderers={{
children={details.body}
components={{
link: props => <Url {...props} />,
}}
plugins={[breaks]}
remarkPlugins={[breaks]}
/>
<Divider />
</div>
Expand Down
5 changes: 3 additions & 2 deletions app/renderer/components/Screens/Results/Results.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import React, { useState, useEffect } from "react";
import { clipboard, ipcRenderer } from "electron";
import Box from "@mui/material/Box";
import MaterialTable from "@material-table/core";
import { Link } from "react-router-dom";
import { Link as ReactLink } from "react-router-dom";
import Link from '@mui/material/Link';
import { ipcEvents } from "../../../../shared/resources/IPCEvents/IPCEvents";
import GlobalStore from "../../../../shared/GlobalStore/GlobalStore";
import { storeKeys } from "../../../../shared/resources/StoreKeys/StoreKeys";
Expand Down Expand Up @@ -65,7 +66,7 @@ export default () => {
Pagination: () => (
<Box component="td" padding={2} fontSize="13px">
Result count: <b>{results.length}</b>
<Link to="/settings" style={{ marginLeft: 3 }}>
<Link to="/settings" style={{ marginLeft: 3 }} component={ReactLink}>
(limit: <b>{resultsLimit}</b>)
</Link>
</Box>
Expand Down
16 changes: 8 additions & 8 deletions app/renderer/components/Screens/Screens.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import React from "react";
import { Switch, Route } from "react-router-dom";
import { Routes, Route } from "react-router-dom";
import News from "./News/News";
import Searches from "./Searches/Searches";
import Account from "./Account/Account";
import Settings from "./Settings/Settings";
import Results from "./Results/Results";

const Screens = () => (
<Switch>
<Route path="/account" component={Account} />
<Route path="/searches" component={Searches} />
<Route path="/settings" component={Settings} />
<Route path="/results" component={Results} />
<Route component={News} />
</Switch>
<Routes>
<Route path="/account" element={<Account />} />
<Route path="/searches" element={<Searches />} />
<Route path="/settings" element={<Settings />} />
<Route path="/results" element={<Results />} />
<Route path="/news" element={<News />} />
</Routes>
);

export default Screens;
Loading