diff --git a/app/actions/electron.js b/app/actions/electron.js index 4b82ca7..656b038 100644 --- a/app/actions/electron.js +++ b/app/actions/electron.js @@ -12,6 +12,7 @@ import { SET_BROWSER_VIEW_READY, SET_BROWSER_VIEW_URL, SET_BROWSER_WINDOW, + SET_INTERACTIVE_MODE, SHOW_CONFIGURATION, SHOW_DEV_TOOLS, OPEN_PDF @@ -94,6 +95,13 @@ export function showConfiguration(): Action { }; } +export function setInteractiveMode(interactiveModeEnabled: boolean): Action { + return { + type: SET_INTERACTIVE_MODE, + payload: interactiveModeEnabled + } +} + export function performScroll(name: BrowserViewName, deltaY: number): Action { return { type: PERFORM_SCROLL, diff --git a/app/components/BotOverlay.scss b/app/components/BotOverlay.scss index 75da9d0..afe6914 100644 --- a/app/components/BotOverlay.scss +++ b/app/components/BotOverlay.scss @@ -29,8 +29,8 @@ bottom: 0; } -$bot-illustration-offset-right: 10vh; -$bot-illustration-width: 15vh; +$bot-illustration-offset-right: 10vmax; +$bot-illustration-width: 15vmax; .botIllustration { position: absolute; bottom: -2px; @@ -39,15 +39,15 @@ $bot-illustration-width: 15vh; } $speech-bubble-color: $BOT_LIGHT; -$speech-bubble-anchor-width: 4vh; +$speech-bubble-anchor-width: 4vmax; .speechBubble { position: absolute; right: $bot-illustration-offset-right + $bot-illustration-width + - $speech-bubble-anchor-width - 1vh; - bottom: 3vh; + $speech-bubble-anchor-width - 1vmax; + bottom: 3vmax; background-color: $speech-bubble-color; color: #333; - font-size: calc(20px + 1vh); + font-size: calc(20px + 1vmax); padding: 0.5em 0.7em 0.4em; margin-left: 0.5em; } @@ -55,13 +55,13 @@ $speech-bubble-anchor-width: 4vh; content: ''; position: absolute; right: 0; - bottom: 1vh; + bottom: 1vmax; width: 0; height: 0; border: 0 solid transparent; - border-top-width: 2vh; - border-left: 4vh $speech-bubble-color solid; - margin-right: -4vh; + border-top-width: 2vmax; + border-left: 4vmax $speech-bubble-color solid; + margin-right: -4vmax; } .animations { diff --git a/app/constants/actionTypes.js b/app/constants/actionTypes.js index a5197f9..3335f6f 100644 --- a/app/constants/actionTypes.js +++ b/app/constants/actionTypes.js @@ -6,6 +6,7 @@ export const ELECTRON_ROUTING = 'ELECTRON_ROUTING'; export const INTERNAL_ADD_BROWSER_VIEW = 'INTERNAL_ADD_BROWSER_VIEW'; export const HIDE_CONFIGURATION = 'HIDE_CONFIGURATION'; export const SHOW_CONFIGURATION = 'SHOW_CONFIGURATION'; +export const SET_INTERACTIVE_MODE = 'SET_INTERACTIVE_MODE'; export const PERFORM_SCROLL = 'PERFORM_SCROLL'; export const SHOW_DEV_TOOLS = 'SHOW_DEV_TOOLS'; export const OPEN_PDF = 'OPEN_PDF'; diff --git a/app/middleware/bot.js b/app/middleware/bot.js index 9a8e72b..84fa257 100644 --- a/app/middleware/bot.js +++ b/app/middleware/bot.js @@ -11,17 +11,73 @@ import { calculateOverviewBoundingBoxes } from '../actions/overlay'; import { getFlatData, getOverviewData, refreshVerdicts } from '../actions/data'; import { FLAT_ACTION } from '../reducers/data'; import { sendFlatViewingNotificationMail } from '../actions/email'; -import { launchNextTask, queueInvestigateFlat } from '../actions/bot'; +import { launchNextTask, queueInvestigateFlat, setBotMessage } from '../actions/bot'; +import { setInteractiveMode } from '../actions/electron'; import { discardApplicationProcess, endApplicationProcess, generateApplicationTextAndSubmit } from '../actions/application'; import AbortionSystem, { ABORTION_MANUAL } from '../utils/abortionSystem'; +import ElectronUtils from '../utils/electronUtils'; export default (store: Store) => (next: (action: Action) => void) => async ( action: Action ) => { + const handlePuppetReady = async () => { + await sleep(5000); + + const { puppet } = store.getState().electron.views; + + puppet.browserView.webContents.insertCSS(` + #cmp-faktor-io-brand-consent-notice { + display: none !important; + } + `); + + const electronUtils = new ElectronUtils(puppet.browserView.webContents); + if ((await electronUtils.evaluate('document.title')).includes('Ich bin kein Roboter')) { + store.dispatch(setBotMessage('Mensch! Du bist dran.')); + + if (!puppet.browserView.webContents.isFocused()) { + puppet.browserView.webContents.focus(); + } + store.dispatch(setInteractiveMode(true)); + + while ((await electronUtils.evaluate('document.title')).includes('Ich bin kein Roboter')) { + await sleep(1000); + } + store.dispatch(setBotMessage('Geschafft, ich übernehme wieder!')); + store.dispatch(setInteractiveMode(false)); + + await sleep(5000); + await handlePuppetReady(); + return; + } + + if (puppet.url.startsWith('https://www.immobilienscout24.de/Suche')) { + setImmediate(() => store.dispatch(calculateOverviewBoundingBoxes())); + setTimeout( + () => store.dispatch(calculateOverviewBoundingBoxes()), + 1000 + ); + setTimeout( + () => store.dispatch(calculateOverviewBoundingBoxes()), + 5000 + ); + + await store.dispatch(getOverviewData()); + await store.dispatch(refreshVerdicts()); + await sleep(20000); + store.dispatch(launchNextTask()); + } + + if (puppet.url.startsWith('https://www.immobilienscout24.de/expose/')) { + await store.dispatch(getFlatData()); + store.dispatch(refreshVerdicts()); + } + } + if (action.type === RESET_BOT) { AbortionSystem.abort(ABORTION_MANUAL); store.dispatch(endApplicationProcess()); @@ -29,39 +85,7 @@ export default (store: Store) => (next: (action: Action) => void) => async ( if (action.type === SET_BROWSER_VIEW_READY) { if (action.payload.name === 'puppet' && action.payload.ready) { - setImmediate(async () => { - await sleep(5000); - - const { puppet } = store.getState().electron.views; - - puppet.browserView.webContents.insertCSS(` - #cmp-faktor-io-brand-consent-notice { - display: none !important; - } - `); - - if (puppet.url.startsWith('https://www.immobilienscout24.de/Suche')) { - setImmediate(() => store.dispatch(calculateOverviewBoundingBoxes())); - setTimeout( - () => store.dispatch(calculateOverviewBoundingBoxes()), - 1000 - ); - setTimeout( - () => store.dispatch(calculateOverviewBoundingBoxes()), - 5000 - ); - - await store.dispatch(getOverviewData()); - await store.dispatch(refreshVerdicts()); - await sleep(20000); - store.dispatch(launchNextTask()); - } - - if (puppet.url.startsWith('https://www.immobilienscout24.de/expose/')) { - await store.dispatch(getFlatData()); - store.dispatch(refreshVerdicts()); - } - }); + setImmediate(handlePuppetReady); } } diff --git a/app/middleware/electron.js b/app/middleware/electron.js index 1bb7399..a5d0cad 100644 --- a/app/middleware/electron.js +++ b/app/middleware/electron.js @@ -16,6 +16,7 @@ import { PERFORM_SCROLL, SCROLL_WHILE_IDLE, SET_BROWSER_WINDOW, + SET_INTERACTIVE_MODE, SHOW_CONFIGURATION, SHOW_DEV_TOOLS, STOP_SCROLLING_WHILE_IDLE @@ -114,6 +115,10 @@ export default (store: Store) => (next: (action: Action) => void) => async ( } } + if (action.type === SET_INTERACTIVE_MODE) { + setImmediate(() => resizeViews(store.getState().electron)); + } + if (action.type === PERFORM_SCROLL) { const electronUtils = new ElectronUtils( store.getState().electron.views[ diff --git a/app/reducers/electron.js b/app/reducers/electron.js index e2adf0d..73a0a17 100644 --- a/app/reducers/electron.js +++ b/app/reducers/electron.js @@ -6,7 +6,8 @@ import { INTERNAL_ADD_BROWSER_VIEW, SET_BROWSER_VIEW_READY, SET_BROWSER_VIEW_URL, - SET_BROWSER_WINDOW + SET_BROWSER_WINDOW, + SET_INTERACTIVE_MODE } from '../constants/actionTypes'; import type { Action } from './types'; @@ -28,13 +29,15 @@ export type Views = { export type electronStateType = { window: ?BrowserWindow, views: Views, - configurationHidden: boolean + configurationHidden: boolean, + interactiveMode: boolean }; const electronDefaultState: electronStateType = { views: {}, window: null, - configurationHidden: false + configurationHidden: false, + interactiveMode: false }; export default function electron( @@ -59,6 +62,9 @@ export default function electron( if (action.type === HIDE_CONFIGURATION) { return { ...state, configurationHidden: true }; } + if (action.type === SET_INTERACTIVE_MODE) { + return { ...state, interactiveMode: action.payload } + } return state; } diff --git a/app/utils/resizeViews.js b/app/utils/resizeViews.js index e4858f2..7e3ea0b 100644 --- a/app/utils/resizeViews.js +++ b/app/utils/resizeViews.js @@ -8,7 +8,8 @@ export default function resizeViews( ) { const { window, - views: { puppet, sidebar, botOverlay, configuration, devMenu } + views: { puppet, sidebar, botOverlay, configuration, devMenu }, + interactiveMode } = electronState; if (window === undefined || window === null) { // eslint-disable-next-line no-console @@ -30,12 +31,15 @@ export default function resizeViews( width: windowWidth - sideBarWidth, // - 20, // by not subtracting the offset we push the scrollbar out of view height: windowHeight - 20 }); + + const botOverlayHeightInManualMode = 150; botOverlay.browserView.setBounds({ x: sideBarWidth, - y: 0, + y: interactiveMode ? windowHeight - botOverlayHeightInManualMode : 0, width: windowWidth - sideBarWidth, - height: windowHeight + height: interactiveMode ? botOverlayHeightInManualMode : windowHeight }); + let configurationY = electronState.configurationHidden ? windowHeight : 0; if ( configurationVisibility !== undefined &&