-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…ctivate account automatically
- Loading branch information
Showing
20 changed files
with
294 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const GoogleService = require('./GoogleService') | ||
const { ipcRenderer } = require('electron') | ||
const req = require('../req') | ||
const extensionLoader = require('../Extensions/extensionLoader') | ||
const { WAVEBOX_CONTENT_IMPL_ENDPOINTS } = req.shared('extensionApis') | ||
const { WB_BROWSER_GOOGLE_CALENDAR_ALERT_PRESENTED } = req.shared('ipcEvents') | ||
const uuid = require('uuid') | ||
|
||
class GoogleCalendar extends GoogleService { | ||
/* **************************************************************************/ | ||
// Lifecycle | ||
/* **************************************************************************/ | ||
|
||
constructor () { | ||
super() | ||
this.apiKey = uuid.v4() | ||
window.addEventListener('message', this.handleWindowMessage.bind(this)) | ||
extensionLoader.loadWaveboxGuestApi(WAVEBOX_CONTENT_IMPL_ENDPOINTS.GOOGLE_CALENDAR_ALERT, this.apiKey) | ||
} | ||
|
||
/* **************************************************************************/ | ||
// Message handling | ||
/* **************************************************************************/ | ||
|
||
/** | ||
* Handles a new window message | ||
* @param evt: the event that fired | ||
*/ | ||
handleWindowMessage (evt) { | ||
if (evt.origin === window.location.origin && evt.isTrusted) { | ||
let data | ||
try { | ||
data = JSON.parse(evt.data) | ||
} catch (ex) { return } | ||
if (!data.wavebox) { return } | ||
if (data.apiKey !== this.apiKey) { return } | ||
|
||
if (data.type === 'wavebox-alert-present') { | ||
ipcRenderer.sendToHost({ | ||
type: WB_BROWSER_GOOGLE_CALENDAR_ALERT_PRESENTED, | ||
data: { message: data.message } | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
|
||
module.exports = GoogleCalendar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const elconsole = require('../elconsole') | ||
try { | ||
const GoogleCalendar = require('../Google/GoogleCalendar') | ||
/*eslint-disable */ | ||
const googleCalendar = new GoogleCalendar() | ||
/*eslint-enable */ | ||
} catch (ex) { | ||
elconsole.error('Error', ex) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* global WB_API_KEY */ | ||
|
||
(function () { | ||
const polyfillAlert = function (window) { | ||
const original = window.alert | ||
window.alert = function () { | ||
window.top.postMessage(JSON.stringify({ | ||
apiKey: WB_API_KEY, | ||
wavebox: true, | ||
type: 'wavebox-alert-present', | ||
message: arguments[0] | ||
}), '*') | ||
return original.apply(this, Array.from(arguments)) | ||
} | ||
} | ||
|
||
polyfillAlert(window) | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...ilboxes/src/Scenes/AppScene/Mailbox/MailboxWebView/Google/GoogleMailboxCalendarWebView.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
import MailboxWebViewHibernator from '../MailboxWebViewHibernator' | ||
import CoreService from 'shared/Models/Accounts/CoreService' | ||
import Resolver from 'Runtime/Resolver' | ||
import { mailboxActions, GoogleCalendarServiceReducer } from 'stores/mailbox' | ||
import shallowCompare from 'react-addons-shallow-compare' | ||
import { | ||
WB_BROWSER_NOTIFICATION_PRESENT, | ||
WB_BROWSER_GOOGLE_CALENDAR_ALERT_PRESENTED | ||
} from 'shared/ipcEvents' | ||
|
||
const REF = 'mailbox_tab' | ||
|
||
export default class GoogleMailboxCalendarWebView extends React.Component { | ||
/* **************************************************************************/ | ||
// Class | ||
/* **************************************************************************/ | ||
|
||
static propTypes = { | ||
mailboxId: PropTypes.string.isRequired | ||
} | ||
|
||
/* **************************************************************************/ | ||
// Browser Events | ||
/* **************************************************************************/ | ||
|
||
/** | ||
* Dispatches browser IPC messages to the correct call | ||
* @param evt: the event that fired | ||
*/ | ||
dispatchBrowserIPCMessage = (evt) => { | ||
switch (evt.channel.type) { | ||
case WB_BROWSER_NOTIFICATION_PRESENT: this.handleBrowserNotificationPresented(); break | ||
case WB_BROWSER_GOOGLE_CALENDAR_ALERT_PRESENTED: this.handleBrowserAlertPresented(); break | ||
default: break | ||
} | ||
} | ||
|
||
/** | ||
* Handles the browser presenting a notification or alert | ||
*/ | ||
handleBrowserNotificationPresented = () => { | ||
mailboxActions.reduceServiceIfInactive( | ||
this.props.mailboxId, | ||
CoreService.SERVICE_TYPES.CALENDAR, | ||
GoogleCalendarServiceReducer.notificationPresented | ||
) | ||
} | ||
|
||
/** | ||
* Auto changes the browser active mailbox to this service on presentation | ||
*/ | ||
handleBrowserAlertPresented = () => { | ||
mailboxActions.changeActive(this.props.mailboxId, CoreService.SERVICE_TYPES.CALENDAR) | ||
} | ||
|
||
/* **************************************************************************/ | ||
// Rendering | ||
/* **************************************************************************/ | ||
|
||
shouldComponentUpdate (nextProps, nextState) { | ||
return shallowCompare(this, nextProps, nextState) | ||
} | ||
|
||
render () { | ||
const { mailboxId } = this.props | ||
return ( | ||
<MailboxWebViewHibernator | ||
ref={REF} | ||
preload={Resolver.guestPreload('googleCalendar')} | ||
mailboxId={mailboxId} | ||
serviceType={CoreService.SERVICE_TYPES.CALENDAR} | ||
ipcMessage={this.dispatchBrowserIPCMessage} /> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/scenes/mailboxes/src/stores/mailbox/GoogleCalendarServiceReducer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import ServiceReducer from './ServiceReducer' | ||
|
||
class GoogleCalendarServiceReducer extends ServiceReducer { | ||
/* **************************************************************************/ | ||
// Notifications | ||
/* **************************************************************************/ | ||
|
||
/** | ||
* Sets that a notification was presented | ||
* @param mailbox: the mailbox that contains the service | ||
* @param service: the service to update | ||
*/ | ||
static notificationPresented (mailbox, service) { | ||
return service.changeData({ lastUnseenNotificationTime: new Date().getTime() }) | ||
} | ||
|
||
/** | ||
* Clears the unseen notifications | ||
* @param mailbox: the mailbox that contains the service | ||
* @param service: the service to update | ||
*/ | ||
static clearUnseenNotifications (mailbox, service) { | ||
return service.changeData({ lastUnseenNotificationTime: null }) | ||
} | ||
} | ||
|
||
export default GoogleCalendarServiceReducer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.