Skip to content

Commit

Permalink
feat: andle electron routing management
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Mar 7, 2022
1 parent 601c7de commit 2e0a38d
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"engines": {
"node": ">=15.0.1"
},
"proxy": "http://localhost:3030",
"proxy": "http://localhost:31310",
"dependencies": {
"@emotion/react": "^11.5.0",
"@emotion/styled": "^11.3.0",
Expand Down
39 changes: 21 additions & 18 deletions public/electron.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Module to control the application lifecycle and the native browser window.
const { app, BrowserWindow, protocol } = require("electron");
const path = require("path");
const url = require("url");
const { app, BrowserWindow, protocol } = require('electron');
const path = require('path');
const url = require('url');

// Create the native browser window.
function createWindow() {
Expand All @@ -11,7 +11,7 @@ function createWindow() {
// Set the path of an additional "preload" script that can be used to
// communicate between the node-land and the browser-land.
webPreferences: {
preload: path.join(__dirname, "preload.js"),
preload: path.join(__dirname, 'preload.js'),
},
});

Expand All @@ -20,13 +20,17 @@ function createWindow() {
// In development, set it to localhost to allow live/hot-reloading.
const appURL = app.isPackaged
? url.format({
pathname: path.join(__dirname, "index.html"),
protocol: "file:",
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true,
})
: "http://localhost:3000";
: 'http://localhost:3000';
mainWindow.loadURL(appURL);

mainWindow.webContents.on('did-fail-load', () => {
mainWindow.loadURL(appURL);
});

// Automatically open Chrome's DevTools in development mode.
if (!app.isPackaged) {
mainWindow.webContents.openDevTools();
Expand All @@ -37,14 +41,14 @@ function createWindow() {
// them from the local production bundle (e.g.: local fonts, etc...).
function setupLocalFilesNormalizerProxy() {
protocol.registerHttpProtocol(
"file",
'file',
(request, callback) => {
const url = request.url.substr(8);
callback({ path: path.normalize(`${__dirname}/${url}`) });
},
(error) => {
if (error) console.error("Failed to register protocol");
}
error => {
if (error) console.error('Failed to register protocol');
},
);
}

Expand All @@ -55,7 +59,7 @@ app.whenReady().then(() => {
createWindow();
setupLocalFilesNormalizerProxy();

app.on("activate", function () {
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) {
Expand All @@ -67,18 +71,18 @@ app.whenReady().then(() => {
// Quit when all windows are closed, except on macOS.
// There, it's common for applications and their menu bar to stay active until
// the user quits explicitly with Cmd + Q.
app.on("window-all-closed", function () {
if (process.platform !== "darwin") {
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit();
}
});

// If your app has no need to navigate or only needs to navigate to known pages,
// it is a good idea to limit navigation outright to that known scope,
// disallowing any other kinds of navigation.
const allowedNavigationDestinations = "https://my-app.com";
app.on("web-contents-created", (event, contents) => {
contents.on("will-navigate", (event, navigationURL) => {
const allowedNavigationDestinations = 'https://my-app.com';
app.on('web-contents-created', (event, contents) => {
contents.on('will-navigate', (event, navigationURL) => {
const parsedURL = new URL(navigationURL);
if (!allowedNavigationDestinations.includes(parsedURL.origin)) {
event.preventDefault();
Expand All @@ -88,4 +92,3 @@ app.on("web-contents-created", (event, contents) => {

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

2 changes: 1 addition & 1 deletion src/components/blocks/MyAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const MyAccount = () => {
variant={InputVariantEnum.default}
value={serverAddress}
onChange={value => setServerAddress(value)}
placeholderText="http://0.0.0.0:3030"
placeholderText="http://0.0.0.0:31310"
/>
</InputContainer>
{(serverAddress === null ||
Expand Down
2 changes: 1 addition & 1 deletion src/components/layout/SocketStatusContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const StatusColor = styled('div')`
`};
`;

const WS_HOST = `http://localhost:3030/v1/ws`;
const WS_HOST = `http://localhost:31310/v1/ws`;
const transports = ['websocket', 'polling'];

let socket = socketIO(WS_HOST, {
Expand Down
2 changes: 1 addition & 1 deletion src/constants/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default {
API_HOST: 'http://localhost:3030/v1',
API_HOST: 'http://localhost:31310/v1',
MAX_TABLE_SIZE: 7,
HEADER_HEIGHT: 64, // Needed to be used to calculate max height for body components
THEME: {
Expand Down
7 changes: 4 additions & 3 deletions src/navigation/AppNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { Suspense, useEffect } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { useIntl } from 'react-intl';
import { Router } from 'react-router';
import { Route } from 'react-router-dom';
import { Route, Redirect } from 'react-router-dom';
import { IndeterminateProgressOverlay, Dashboard } from '../components/';
import { NotificationContainer } from 'react-notifications';

Expand Down Expand Up @@ -79,8 +79,8 @@ const AppNavigator = () => {
<Router history={history}>
<Dashboard>
<Suspense fallback={<IndeterminateProgressOverlay />}>
<Route exact path="/">
<Pages.Home />
<Route exact path="/" render={() => <Redirect to="/projects" />}>
<Pages.Projects />
</Route>
<Route exact path="/units">
<Pages.Units />
Expand All @@ -97,6 +97,7 @@ const AppNavigator = () => {
<Route exact path="/storybook">
<Pages.StoryBook />
</Route>
<Route path="*" render={() => <Redirect to="/" />} />
</Suspense>
</Dashboard>
</Router>
Expand Down
4 changes: 3 additions & 1 deletion src/pages/Home/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React, { useEffect } from 'react';
import { useHistory } from 'react-router-dom';
import { IndeterminateProgressOverlay } from '../../components';

const Home = () => {
const history = useHistory();
useEffect(() => {
window.location.href = './projects';
history.push('/projects');
});
return <IndeterminateProgressOverlay />;
};
Expand Down
2 changes: 1 addition & 1 deletion src/store/actions/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const reconnectSocket = dispatch => {
export const initiateSocket = () => {
disconnectSocket();

const WS_HOST = `http://localhost:3030/v1/ws`;
const WS_HOST = `http://localhost:31310/v1/ws`;
const transports = ['websocket', 'polling'];

socket = socketIO(WS_HOST, {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/xlsxUtils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const downloadTxtFile = async (type, searchParams) => {
searchParams.delete('myRegistry');
await fetch(
`http://localhost:3030/v1/${`${type}?`}${`${searchParams.toString()}&`}xls=true`,
`http://localhost:31310/v1/${`${type}?`}${`${searchParams.toString()}&`}xls=true`,
)
.then(async result => await result.blob())
.then(async response => {
Expand Down

0 comments on commit 2e0a38d

Please sign in to comment.