Skip to content

Commit 1afd5d8

Browse files
committed
2 parents 06aed17 + bfa287b commit 1afd5d8

File tree

18 files changed

+640
-66
lines changed

18 files changed

+640
-66
lines changed

__tests__/__snapshots__/enzyme.test.tsx.snap

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
exports[`Test the BottomTabs component Matches snapshot 1`] = `
44
<div
55
className="makeStyles-root-1"
6+
style={null}
67
>
78
<Styled(MuiBox)
89
display="flex"
@@ -28,9 +29,94 @@ exports[`Test the BottomTabs component Matches snapshot 1`] = `
2829
disableRipple={true}
2930
label="Code Preview"
3031
/>
32+
<WithStyles(ForwardRef(Tab))
33+
classes={
34+
Object {
35+
"root": "makeStyles-tabRoot-5",
36+
"selected": "makeStyles-tabSelected-6",
37+
}
38+
}
39+
disableRipple={true}
40+
label="Component Tree"
41+
/>
3142
</WithStyles(ForwardRef(Tabs))>
43+
<WithStyles(ForwardRef(FormControl))>
44+
<div
45+
className="flex-container"
46+
>
47+
<div
48+
className="flex1"
49+
>
50+
Change Theme:
51+
</div>
52+
<WithStyles(ForwardRef(NativeSelect))
53+
className="flex2"
54+
onChange={[Function]}
55+
style={
56+
Object {
57+
"color": "white",
58+
}
59+
}
60+
value="monokai"
61+
>
62+
<option
63+
style={
64+
Object {
65+
"backgroundColor": "#252526",
66+
}
67+
}
68+
value="monokai"
69+
>
70+
Monokai
71+
</option>
72+
<option
73+
style={
74+
Object {
75+
"backgroundColor": "#252526",
76+
}
77+
}
78+
value="github"
79+
>
80+
Github
81+
</option>
82+
<option
83+
style={
84+
Object {
85+
"backgroundColor": "#252526",
86+
}
87+
}
88+
value="solarized_dark"
89+
>
90+
Solarized Dark
91+
</option>
92+
<option
93+
style={
94+
Object {
95+
"backgroundColor": "#252526",
96+
}
97+
}
98+
value="terminal"
99+
>
100+
Terminal
101+
</option>
102+
<option
103+
style={
104+
Object {
105+
"backgroundColor": "#252526",
106+
}
107+
}
108+
value="solarized_light"
109+
>
110+
Solarized Light
111+
</option>
112+
</WithStyles(ForwardRef(NativeSelect))>
113+
</div>
114+
</WithStyles(ForwardRef(FormControl))>
32115
</Styled(MuiBox)>
33-
<CodePreview />
116+
<CodePreview
117+
setTheme={[Function]}
118+
theme="monokai"
119+
/>
34120
</div>
35121
`;
36122

__tests__/componentReducer.test.ts

Lines changed: 1 addition & 3 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;
9-
10-
8+
119
// TEST 'ADD COMPONENT'
1210
describe('ADD COMPONENT reducer', () => {
1311
it('should add new reuseable component to state', () => {

__tests__/enzyme.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import CodePreview from '../app/src/components/bottom/CodePreview';
88
import CanvasContainer from '../app/src/components/main/CanvasContainer';
99
import Canvas from '../app/src/components/main/Canvas';
1010

11+
// npm test -- -u
1112

1213
describe('Test the CanvasContainer component', () => {
1314
const target = shallow(<CanvasContainer />);

app/electron/main.js

Lines changed: 60 additions & 20 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) => {
@@ -248,7 +250,8 @@ app.on('web-contents-created', (event, contents) => {
248250
'https://reactype.herokuapp.com',
249251
'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
});

app/electron/menu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var MenuBuilder = function(mainWindow, appName) {
2727
contextIsolation: true,
2828
enableRemoteModule: false,
2929
zoomFactor: 1.0,
30-
devTools: false
30+
// devTools: false
3131
}
3232
});
3333
tutorial.loadURL(`http://localhost:8080/#/tutorial`);

0 commit comments

Comments
 (0)