Skip to content

Commit

Permalink
General Bug Fixes/Additons (#96)
Browse files Browse the repository at this point in the history
* added app name/version

* added size options grouped in the size dropdown

* fixed broken edit menu toggle

* progress on site data autofill

* updated test cases

* added site autocomplete && proxy location dropdown in the server page

* added core server impl.

* added core server impl.

* fixed css issues for windows

* alignment changes

* added more css adjustments

* Fix Horizontal Scrolling for Create Task Size Select

This commit changes the styling for multi value selects to allow for horizontal scrolling when selected items overflow the select containers area. This is done by setting `flex-wrap` to `nowrap` and `overflow-x` to `scroll` on the value container (when we are a multi value container), and setting the `flex-shrink` to 0 on multi value items.

* captcha window changes

* captcha window logic impl.

* added edit sizes cases

* progress on site autofill bugs

* progress on site autofill bugs

* buggy site autofill fixed

* rm console log

* small change in site matching logic

* simplified site matching

* hotfix for http site autofill matching

* progress on updating taskReducers~ test

* max 5 captcha windows + map to control them, still buggy

* fixed buggy captcha windows

* clearing session still buggy, and closing a yt win -> trying to close captcha window is wrong too

* captcha window manager split out

* progress on captcha window manager

* closing all windows finished, closing consecutive captcha windows is still busted

* progress on youtube + captcha closing

* fixed captcha windows + youtube pairing

* fixed else clause

* added closing youtube pair when captcha closes

* hotfix for closing all captchas -> youtubes

* fixed taskReducer tests

* more test fixes

* pr changes

* added recaptcha path to api

* fixing broken tests progress

* tests fixed

* increase test coverage

* added app name/version

* added size options grouped in the size dropdown

* fixed broken edit menu toggle

* progress on site data autofill

* updated test cases

* added site autocomplete && proxy location dropdown in the server page

* added core server impl.

* added core server impl.

* fixed css issues for windows

* alignment changes

* added more css adjustments

* Fix Horizontal Scrolling for Create Task Size Select

This commit changes the styling for multi value selects to allow for horizontal scrolling when selected items overflow the select containers area. This is done by setting `flex-wrap` to `nowrap` and `overflow-x` to `scroll` on the value container (when we are a multi value container), and setting the `flex-shrink` to 0 on multi value items.

* captcha window changes

* captcha window logic impl.

* added edit sizes cases

* progress on site autofill bugs

* progress on site autofill bugs

* buggy site autofill fixed

* rm console log

* small change in site matching logic

* simplified site matching

* hotfix for http site autofill matching

* progress on updating taskReducers~ test

* max 5 captcha windows + map to control them, still buggy

* fixed buggy captcha windows

* clearing session still buggy, and closing a yt win -> trying to close captcha window is wrong too

* captcha window manager split out

* progress on captcha window manager

* closing all windows finished, closing consecutive captcha windows is still busted

* progress on youtube + captcha closing

* fixed captcha windows + youtube pairing

* fixed else clause

* added closing youtube pair when captcha closes

* hotfix for closing all captchas -> youtubes

* fixed taskReducer tests

* more test fixes

* pr changes

* added recaptcha path to api

* fixing broken tests progress

* tests fixed

* increase test coverage

* added in token check into constructor

* updated init state in initialProxyOptionsState to match reducer

* fixed category foreach

* small changes/fixes

* fixed serverListReducer connect test

* edits busted.. :(

* fixed tokenContainer rename

* added more serverListReducer tests && progress on the taskReducer edit bug

* updated flow from requested changes

* fixed renderer bug's test case
  • Loading branch information
walmat authored and pr1sm committed Oct 23, 2018
1 parent 9293835 commit 3860687
Show file tree
Hide file tree
Showing 63 changed files with 1,852 additions and 510 deletions.
15 changes: 14 additions & 1 deletion frontend/lib/_electron/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const { default: installExtension, REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS } = req
* Application entry point.
*/
class App {

/**
* Initialize instance.
*/
Expand All @@ -38,6 +37,12 @@ class App {
*/
this._shell = Electron.shell;

/**
* The application's session storage
* @type {session}
*/
this._session = Electron.session;

/**
* Manage the window.
* @type {WindowManager}
Expand Down Expand Up @@ -73,6 +78,14 @@ class App {
return this._shell;
}

/**
* Get the session module.
* @return {session} Application session
*/
get session() {
return this._session;
}

/**
* Get the window manager.
*
Expand Down
2 changes: 1 addition & 1 deletion frontend/lib/_electron/authManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,4 @@ class AuthManager {
}
}

module.exports = AuthManager;
module.exports = AuthManager;
184 changes: 184 additions & 0 deletions frontend/lib/_electron/captchaWindowManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
const IPCKeys = require('../common/constants');
const moment = require('moment');
const _ = require('underscore');

const TokenContainer = require('../common/classes/tokenContainer');

class CaptchaWindowManager {
constructor(context, captchaWindow, session) {
/**
* Application context
*/
this._context = context;

/**
* Main window reference
*/
this._main = this._context._windowManager._main;

/**
* Captcha window that the manager takes care of
*/
this._captchaWindow = captchaWindow;

/**
* Window Manager reference
*/
this._windowManager = this._context._windowManager;

/**
* YouTube window that the manager takes care of
*/
this._youtubeWindow = null;

/**
* All harvested tokens for this window
*/
this._tokens = [];

/**
* Session that the captcha window will use / YouTube window will set
*/
this._session = session;

/**
* IPC Function Definitions
*/
context.ipc.on(IPCKeys.RequestLaunchYoutube, this._onRequestLaunchYoutube.bind(this));
context.ipc.on(IPCKeys.RequestEndSession, this._onRequestEndSession.bind(this));
context.ipc.on(IPCKeys.RequestHarvestToken, this._onRequestHarvestToken.bind(this));
context.ipc.on(
IPCKeys.RequestRefreshCaptchaWindow,
this._onRequestRefreshCaptchaWindow.bind(this),
);

/**
* Constantly check for expired tokens every second
*/
this._checkTokens = setInterval(this.checkTokens, 1000);
}

/**
* Check harvested captcha tokens to see if they're expired or not
*/
checkTokens() {
if (this._tokens && this._tokens.length > 0) {
this._tokens.forEach((token) => {
token.setTimestamp(110 - moment().diff(moment(token.timestamp, 'seconds')));
if (this.isTokenExpired(token)) {
this.removeExpiredToken(token);
}
});
} else {
// don't run the interval check if no tokens are present
clearInterval(this._checkTokens);
this._checkTokens = null;
}
}

static isTokenExpired(token) {
// if token has existed for > 110 seconds
if (moment().diff(moment(token.timestamp), 'seconds') > 110) {
return true;
} return false;
}

/**
* Get the current session
*/
getSession() {
return this._session;
}

/**
* Sets the session
* @param {Object} session - session object to use
*/
setSession(session) {
this._session = session;
}

/**
* See what the proxy is for the given url
* @param {String} url - urk to ping
*/
resolveProxy(url) {
return this._session.resolveProxy(url, proxy => proxy);
}

/**
* Sets the proxy for the window's session
*
* @param {String} proxy proxyRules = schemeProxies[";"<schemeProxies>]
schemeProxies = [<urlScheme>"="]<proxyURIList>
urlScheme = "http" | "https" | "ftp" | "socks"
proxyURIList = <proxyURL>[","<proxyURIList>]
proxyURL = [<proxyScheme>"://"]<proxyHost>[":"<proxyPort>]
*
*
*/
setProxy(proxy) {
this._session.setProxy({
pacScript: null,
proxyRules: proxy,
proxyBypassRules: null,
}, () => {
const p = this.resolveProxy('https://www.google.com/');
console.log(`Using proxy: ${p}`);
});
}

/**
* Sets the 'User-Agent' header for the session
* @param {String} userAgent - user agent to set on all headers
* @param {String} acceptLanguages - the incoming languages to accept from the response (optional)
* should be a comma separated list: "en-US,fr,de,ko,zh-CN,ja"
*/
setUserAgent(userAgent, acceptLanguages) {
this._session.setUserAgent(userAgent, acceptLanguages);
}

/**
* Gets the 'User-Agent' header for the session
*/
getUserAgent() {
return this._session.getUserAgent();
}

removeExpiredToken(token) {
this._tokens = _.reject(this._tokens, el => el.token === token);
}

/**
* Clears the storage data and cache for the session
*/
_onRequestEndSession() {
this._session.flushStorageData();
this._session.clearStorageData([], () => {});
this._session.clearCache(() => {});
}

_onRequestHarvestToken(ev, token, host, sitekey) {
this._tokens.push(new TokenContainer(token, moment(), host, sitekey));
if (this._checkTokens === null) {
this._checkTokens = setInterval(this.checkTokens, 1000);
}
}

/**
* Refresh window object
*/
_onRequestRefreshCaptchaWindow() {
this._captchaWindow.reload();
}

async _onRequestLaunchYoutube() {
if (this._youtubeWindow === null) {
const w = await this._windowManager.createNewWindow('youtube');
this._youtubeWindow = w;
} else {
this._youtubeWindow.show();
}
}
}
module.exports = CaptchaWindowManager;
56 changes: 42 additions & 14 deletions frontend/lib/_electron/preload.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { remote } = require('electron');
const { dialog } = require('electron').remote;
const { dialog, app } = require('electron').remote;
const { ipcRenderer, webFrame } = require('electron');
const IPCKeys = require('../common/Constants');
const IPCKeys = require('../common/constants');
const nebulaEnv = require('../_electron/env');

// setup environment
Expand All @@ -14,7 +14,7 @@ webFrame.setLayoutZoomLevelLimits(0, 0);
/**
* Sends IPCMain an event trigger
* @param {String} channel definition for which trigger to look for
* @param {*} msg any object to send along with the event
* @param {*} msg any object to send along with the event || null
*/
const _sendEvent = (channel, msg) => {
ipcRenderer.send(channel, msg);
Expand All @@ -27,6 +27,22 @@ const _deactivate = () => {
_sendEvent(IPCKeys.AuthRequestDeactivate);
};

/**
* Prevent dragover events globally
*/
window.addEventListener('dragover', (event) => {
event.preventDefault();
return false;
}, false);

/**
* Prevent drop events globally
*/
window.addEventListener('drop', (event) => {
event.preventDefault();
return false;
}, false);

/**
* Sends the deactivate trigger to authManager.js
*
Expand All @@ -44,41 +60,51 @@ const _close = () => {
_sendEvent(IPCKeys.RequestCloseWindow, id);
};

const _closeAllCaptchaWindows = () => {
_sendEvent(IPCKeys.RequestCloseAllCaptchaWindows);
};

/**
* Sends the launch youtube window trigger to windowManager.js
*/
const _launchYoutube = () => {
_sendEvent(IPCKeys.RequestCreateNewWindow, 'youtube');
_sendEvent(IPCKeys.RequestLaunchYoutube);
};

/**
* Sends the launch captcha window trigger to windowManager.js
*/
const _launchHarvester = () => {
const _launchCaptchaHarvester = () => {
_sendEvent(IPCKeys.RequestCreateNewWindow, 'captcha');
};

/**
* Sends the end session trigger to windowManager.js
*/
const _endSession = () => {
_sendEvent(IPCKeys.RequestEndSession);
const _endCaptchaSession = () => {
const { id } = remote.getCurrentWindow();
_sendEvent(IPCKeys.RequestEndSession, id);
};

/**
* Sends the harvest captcha trigger to windowManager.js
*/
const _harvest = (token) => {
const _harvestCaptchaToken = (token) => {
_sendEvent(IPCKeys.HarvestCaptcha, token);
};

/**
* Sends the refresh window trigger to windowManager.js
*/
const _refresh = (window) => {
_sendEvent(IPCKeys.RequestRefresh, window);
const _refreshCaptchaWindow = () => {
_sendEvent(IPCKeys.RequestRefresh);
};

/**
* Send app name/version to the renderer
*/
const _getAppData = () => ({ name: app.getName(), version: app.getVersion() });

/**
* ... TODO!
* Sends the confirmation dialog trigger to windowManager.js
Expand All @@ -100,11 +126,13 @@ process.once('loaded', () => {
window.Bridge = window.Bridge || {};
/* BRIDGED EVENTS */
window.Bridge.launchYoutube = _launchYoutube;
window.Bridge.launchHarvester = _launchHarvester;
window.Bridge.launchCaptchaHarvester = _launchCaptchaHarvester;
window.Bridge.closeAllCaptchaWindows = _closeAllCaptchaWindows;
window.Bridge.close = _close;
window.Bridge.refresh = _refresh;
window.Bridge.harvest = _harvest;
window.Bridge.endSession = _endSession;
window.Bridge.refreshCaptchaWindow = _refreshCaptchaWindow;
window.Bridge.harvestCaptchaToken = _harvestCaptchaToken;
window.Bridge.endCaptchaSession = _endCaptchaSession;
window.Bridge.getAppData = _getAppData;
window.Bridge.deactivate = _deactivate;
window.Bridge.authenticate = _authenticate;
window.Bridge.confirmDialog = _confirmDialog;
Expand Down
Loading

0 comments on commit 3860687

Please sign in to comment.