Skip to content

Commit

Permalink
add cookie support by using ipc to send delimited cookie to mainWindo…
Browse files Browse the repository at this point in the history
…w session
  • Loading branch information
kevinold committed Oct 28, 2016
1 parent f68663b commit 9cd8d6d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Modal.setAppElement(document.getElementById('react-root'));

import HTTPHeaderEditor from './HTTPHeaderEditor';


export default class App extends React.Component {
constructor() {
super();
Expand Down Expand Up @@ -151,7 +150,7 @@ export default class App extends React.Component {

graphQLFetcher = (graphQLParams) => {
const defaultHeaders = {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
};

const { endpoint, method, headers } = this.getCurrentTab();
Expand All @@ -163,15 +162,16 @@ export default class App extends React.Component {
}

url += url.indexOf('?') == -1 ? "?" : "&";

return fetch(url + "query=" + encodeURIComponent(graphQLParams['query']) + "&variables=" + encodeURIComponent(graphQLParams['variables']), {
credentials: 'include',
method: method,
credentials: 'include',
headers: Object.assign({}, defaultHeaders, headers),
body: null
}).then(response => response.json());
}
return fetch(endpoint, {
credentials: 'include',
method: method,
credentials: 'include',
headers: Object.assign({}, defaultHeaders, headers),
Expand Down
10 changes: 10 additions & 0 deletions app/components/HTTPHeaderEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import _ from 'lodash';
import React from 'react';
import ReactDOM from 'react-dom';
// import Radium from 'radium';
const ipcRenderer = window.require('electron').ipcRenderer;

export default class HTTPHeaderEditor extends React.Component {
constructor(props) {
Expand All @@ -28,6 +29,15 @@ export default class HTTPHeaderEditor extends React.Component {
}

completeAdd = () => {
if (ReactDOM.findDOMNode(this.newKeyInput).value === 'Cookie') {
var val = ReactDOM.findDOMNode(this.newValInput).value;
//console.log(val);
var cookieParts = val.split('!!!');
console.log('url: ', cookieParts[0]);
console.log('name: ', cookieParts[1]);
console.log('value: ', cookieParts[2]);
ipcRenderer.send('set-cookie', { url: cookieParts[0], name: cookieParts[1], value: cookieParts[2]});
};
this.setState({
headers: [
...this.state.headers,
Expand Down
11 changes: 11 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ app.on('ready', function() {

mainWindow = new BrowserWindow({ width: 1024, height: 728 });

electron.ipcMain.on('set-cookie', (event, arg) => {
//console.log('SET COOKIE E: ', event);
//console.log('SET COOKIE ARG: ', arg);
mainWindow.webContents.session.cookies.set(arg,
function(error, cookies) {
if (error) throw error;
console.log('Update Cookies!!!:', cookies);
}
);
});

if (process.env.HOT) {
mainWindow.loadURL('file://' + __dirname + '/app/hot-dev-app.html');
} else {
Expand Down

0 comments on commit 9cd8d6d

Please sign in to comment.