Skip to content

Commit fb9c21a

Browse files
authored
Merge branch 'main' into testing
2 parents a36b0a9 + d6924a6 commit fb9c21a

File tree

16 files changed

+554
-64
lines changed

16 files changed

+554
-64
lines changed

__tests__/componentReducer.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ import { State, Action, Component, ChildElement } from '../app/src/interfaces/In
33

44
import initialState from '../app/src/context/initialState';
55

6-
76
describe('Testing componentReducer functionality', function () {
87
let state: State = initialState;
98

10-
119
// TEST 'ADD COMPONENT'
1210
describe('ADD COMPONENT reducer', () => {
1311
it('should add new reuseable component to state', () => {

__tests__/enzyme.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import HTMLPanel from '../app/src/components/left/HTMLPanel';
1414
import HTMLItem from '../app/src/components/left/HTMLItem';
1515
import LeftContainer from '../app/src/containers/LeftContainer';
1616

17+
// npm test -- -u
18+
19+
1720
describe('Test the CanvasContainer component', () => {
1821
const target = shallow(<CanvasContainer />);
1922
it('Matches snapshot', () => {

app/electron/main.js

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ const {
44
dialog,
55
BrowserWindow,
66
session,
7-
ipcMain
7+
ipcMain,
8+
webContents
89
} = require('electron');
910

1011
// The splash screen is what appears while the app is loading
@@ -23,6 +24,7 @@ const MenuBuilder = require('./menu');
2324

2425
const path = require('path');
2526
// const fs = require('fs');
27+
require('dotenv').config();
2628

2729
const isDev =
2830
process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test';
@@ -224,20 +226,20 @@ app.on('web-contents-created', (event, contents) => {
224226
selfHost,
225227
'http://localhost:5000',
226228
'https://reactype.herokuapp.com',
227-
'https://github.com/',
229+
'https://github.com',
228230
'https://nextjs.org',
231+
'https://www.facebook.com',
229232
'https://developer.mozilla.org'
230233
];
231-
console.log('parsed URL origin', parsedUrl.origin);
232234
// Log and prevent the app from navigating to a new page if that page's origin is not whitelisted
233235
if (!validOrigins.includes(parsedUrl.origin)) {
234236
console.error(
235-
`The application tried to navigate to the following address: '${parsedUrl}'. This origin is not whitelisted and the attempt to navigate was blocked.`
237+
`The application tried to navigate to the following address: '${parsedUrl}'. This origin is not whitelisted attempt to navigate was blocked.`
236238
);
237239
// if the requested URL is not in the whitelisted array, then don't navigate there
238240
event.preventDefault();
239241
return;
240-
} else console.log(`Successful navigation to ${parsedUrl}`);
242+
}
241243
});
242244

243245
contents.on('will-redirect', (event, navigationUrl) => {
@@ -246,9 +248,10 @@ app.on('web-contents-created', (event, contents) => {
246248
selfHost,
247249
'http://localhost:5000',
248250
'https://reactype.herokuapp.com',
249-
'https://github.com/',
251+
'https://github.com',
250252
'https://nextjs.org',
251-
'https://developer.mozilla.org'
253+
'https://developer.mozilla.org',
254+
'https://www.facebook.com',
252255
];
253256

254257
// Log and prevent the app from redirecting to a new page
@@ -262,7 +265,7 @@ app.on('web-contents-created', (event, contents) => {
262265

263266
event.preventDefault();
264267
return;
265-
} else console.log('Successful link sent to browser');
268+
}
266269
});
267270

268271
// https://electronjs.org/docs/tutorial/security#11-verify-webview-options-before-creation
@@ -286,11 +289,11 @@ app.on('web-contents-created', (event, contents) => {
286289
selfHost,
287290
'http://localhost:5000',
288291
'https://reactype.herokuapp.com',
289-
'https://github.com/',
290292
'https://nextjs.org',
291-
'https://developer.mozilla.org'
293+
'https://developer.mozilla.org',
294+
'https://github.com',
295+
'https://www.facebook.com'
292296
];
293-
console.log('parsed URL origin', parsedUrl.origin);
294297
// Log and prevent the app from navigating to a new page if that page's origin is not whitelisted
295298
if (!validOrigins.includes(parsedUrl.origin)) {
296299
console.error(
@@ -299,9 +302,7 @@ app.on('web-contents-created', (event, contents) => {
299302
// if the requested URL is not in the whitelisted array, then don't navigate there
300303
event.preventDefault();
301304
return;
302-
} else console.log(`Successful new window to ${parsedUrl}`);
303-
// event.preventDefault();
304-
// return;
305+
}
305306
});
306307
});
307308

@@ -382,10 +383,11 @@ ipcMain.on('delete_cookie', event => {
382383

383384
// opens new window for github oauth when button on sign in page is clicked
384385
ipcMain.on('github', event => {
385-
// your github applications credentials
386+
// your applications credentials
387+
const githubUrl = 'https://github.com/login/oauth/authorize?';
386388
const options = {
387-
client_id: 'your_client_id',
388-
client_secret: 'your_client_secret',
389+
client_id: process.env.GITHUB_ID,
390+
client_secret: process.env.GITHUB_SECRET,
389391
scopes: ['user:email', 'notifications']
390392
};
391393
// create new browser window object with size, title, security options
@@ -402,15 +404,50 @@ ipcMain.on('github', event => {
402404
zoomFactor: 1.0
403405
}
404406
});
405-
const githubUrl = 'https://github.com/login/oauth/authorize?';
407+
// const authUrl =
408+
// githubUrl + 'client_id=' + options.client_id + '&scope=' + options.scopes;
406409
const authUrl =
407-
githubUrl + 'client_id=' + options.client_id + '&scope=' + options.scopes;
408-
// redirects to relevant server endpoint
410+
`${githubUrl}client_id=${process.env.GITHUB_ID}`;
409411
github.loadURL(authUrl);
410-
// show window
411412
github.show();
413+
const handleCallback = (url) => {
414+
415+
const raw_code = /code=([^&]\*)/.exec(url) || null;
416+
const code = raw_code && raw_code.length > 1 ? raw_code[1] : null;
417+
const error = /\?error=(.+)\$/.exec(url);
418+
419+
if (code || error) {
420+
// Close the browser if code found or error
421+
authWindow.destroy();
422+
}
423+
424+
// If there is a code, proceed to get token from github
425+
if (code) {
426+
self.requestGithubToken(options, code);
427+
} else if (error) {
428+
alert(
429+
"Oops! Something went wrong and we couldn't" +
430+
'log you in using Github. Please try again.'
431+
);
432+
}
433+
}
434+
435+
github.webContents.on('will-navigate', (e, url) => handleCallback(url));
436+
437+
github.webContents.on('did-finish-load', (e, url, a, b) => {
438+
github.webContents.selectAll();
439+
})
440+
441+
github.webContents.on('did-get-redirect-request', (e, oldUrl, newUrl) => handleCallback(newUrl));
442+
443+
// Reset the authWindow on close
444+
github.on('close', () => authWindow = null, false);
445+
412446
// if final callback is reached and we get a redirect from server back to our app, close oauth window
413447
github.webContents.on('will-redirect', (e, callbackUrl) => {
448+
const matches = callbackUrl.match(/(?<=\?=).*/);
449+
const ssid = matches ? matches[0] : '';
450+
callbackUrl = callbackUrl.replace(/\?=.*/, '');
414451
let redirectUrl = 'app://rse/';
415452
if (isDev) {
416453
redirectUrl = 'http://localhost:8080/';
@@ -423,6 +460,9 @@ ipcMain.on('github', event => {
423460
message: 'Github Oauth Successful!'
424461
});
425462
github.close();
463+
win.webContents.executeJavaScript(`window.localStorage.setItem('ssid', '${ssid}')`)
464+
.then(result => win.loadURL(selfHost))
465+
.catch(err => console.log(err))
426466
}
427467
});
428468
});

0 commit comments

Comments
 (0)