mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-20 15:26:06 +08:00
Update mailsync and IdentityStore to allow a null identity
This commit is contained in:
parent
5aebb5da1e
commit
c3d4d3ff52
|
@ -2,7 +2,7 @@ import _ from 'underscore';
|
|||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { RetinaImg, Flexbox } from 'mailspring-component-kit';
|
||||
import { localized, MailspringAPIRequest } from 'mailspring-exports';
|
||||
import { IdentityStore, localized, MailspringAPIRequest } from 'mailspring-exports';
|
||||
|
||||
interface NewsletterSignupProps {
|
||||
name: string;
|
||||
|
@ -54,6 +54,11 @@ export default class NewsletterSignup extends React.Component<
|
|||
|
||||
_onGetStatus = async (props = this.props) => {
|
||||
this._setState({ status: 'Pending' });
|
||||
|
||||
if (!IdentityStore.identity()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const { status } = await MailspringAPIRequest.makeRequest({
|
||||
server: 'identity',
|
||||
|
@ -144,6 +149,10 @@ export default class NewsletterSignup extends React.Component<
|
|||
}
|
||||
|
||||
render() {
|
||||
if (!IdentityStore.identity()) {
|
||||
return <span />;
|
||||
}
|
||||
|
||||
return (
|
||||
<Flexbox direction="row" height="auto" style={{ textAlign: 'left' }}>
|
||||
<div style={{ minWidth: 15 }}>{this._renderControl()}</div>
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
import { localized, AccountStore, Account, IdentityStore } from 'mailspring-exports';
|
||||
import {
|
||||
localized,
|
||||
AccountStore,
|
||||
Account,
|
||||
IdentityStore,
|
||||
IdentityAuthResponse,
|
||||
} from 'mailspring-exports';
|
||||
import { ipcRenderer } from 'electron';
|
||||
import MailspringStore from 'mailspring-store';
|
||||
|
||||
|
@ -111,17 +117,22 @@ class OnboardingStore extends MailspringStore {
|
|||
this.trigger();
|
||||
};
|
||||
|
||||
_onIdentityJSONReceived = async json => {
|
||||
_onIdentityJSONReceived = async (json: IdentityAuthResponse) => {
|
||||
const isFirstAccount = AccountStore.accounts().length === 0;
|
||||
const emptyAccount = this._account.clone();
|
||||
|
||||
await IdentityStore.saveIdentity(json);
|
||||
if ('skipped' in json) {
|
||||
await IdentityStore.saveIdentity(null);
|
||||
} else {
|
||||
await IdentityStore.saveIdentity(json);
|
||||
|
||||
emptyAccount.name = `${json.firstName || ''} ${json.lastName || ''}`;
|
||||
emptyAccount.emailAddress = json.emailAddress;
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
if (isFirstAccount) {
|
||||
const next = this._account.clone();
|
||||
next.name = `${json.firstName || ''} ${json.lastName || ''}`;
|
||||
next.emailAddress = json.emailAddress;
|
||||
this._onSetAccount(next);
|
||||
this._onSetAccount(emptyAccount);
|
||||
OnboardingActions.moveToPage('account-choose');
|
||||
} else {
|
||||
this._onOnboardingComplete();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import React from 'react';
|
||||
import { PropTypes, MailspringAPIRequest } from 'mailspring-exports';
|
||||
import qs from 'querystring';
|
||||
import { PropTypes, MailspringAPIRequest, IdentityAuthResponse } from 'mailspring-exports';
|
||||
import { Webview } from 'mailspring-component-kit';
|
||||
import * as OnboardingActions from './onboarding-actions';
|
||||
|
||||
|
@ -11,23 +12,23 @@ export default class AuthenticatePage extends React.Component {
|
|||
};
|
||||
|
||||
_src() {
|
||||
const n1Version = AppEnv.getVersion();
|
||||
return `${MailspringAPIRequest.rootURLForServer(
|
||||
'identity'
|
||||
)}/onboarding?utm_medium=N1&utm_source=OnboardingPage&N1_version=${n1Version}&client_edition=basic`;
|
||||
return `${MailspringAPIRequest.rootURLForServer('identity')}/onboarding?${qs.stringify({
|
||||
version: AppEnv.getVersion(),
|
||||
skipSupported: true,
|
||||
})}`;
|
||||
}
|
||||
|
||||
_onDidFinishLoad = webview => {
|
||||
_onDidFinishLoad = async (webview: Electron.WebviewTag) => {
|
||||
const receiveUserInfo = `
|
||||
var a = document.querySelector('#identity-result');
|
||||
result = a ? a.innerText : null;
|
||||
`;
|
||||
webview.executeJavaScript(receiveUserInfo, false, result => {
|
||||
this.setState({ ready: true, webviewLoading: false });
|
||||
if (result !== null) {
|
||||
OnboardingActions.identityJSONReceived(JSON.parse(atob(result)));
|
||||
}
|
||||
});
|
||||
const result = await webview.executeJavaScript(receiveUserInfo, false);
|
||||
this.setState({ ready: true, webviewLoading: false });
|
||||
if (result !== null) {
|
||||
const parsed = JSON.parse(atob(result)) as IdentityAuthResponse;
|
||||
OnboardingActions.identityJSONReceived(parsed);
|
||||
}
|
||||
|
||||
const openExternalLink = `
|
||||
var el = document.querySelector('.open-external');
|
||||
|
|
|
@ -269,9 +269,8 @@ export default class Application extends EventEmitter {
|
|||
|
||||
const accounts = this.config.get('accounts');
|
||||
const hasAccount = accounts && accounts.length > 0;
|
||||
const hasIdentity = this.config.get('identity.id');
|
||||
|
||||
if (hasAccount && hasIdentity) {
|
||||
if (hasAccount) {
|
||||
this.windowManager.ensureWindow(WindowManager.MAIN_WINDOW);
|
||||
} else {
|
||||
this.windowManager.ensureWindow(WindowManager.ONBOARDING_WINDOW, {
|
||||
|
@ -357,6 +356,19 @@ export default class Application extends EventEmitter {
|
|||
win.browserWindow.inspectElement(x, y);
|
||||
});
|
||||
|
||||
this.on('application:add-identity', () => {
|
||||
const onboarding = this.windowManager.get(WindowManager.ONBOARDING_WINDOW);
|
||||
if (onboarding) {
|
||||
onboarding.show();
|
||||
onboarding.focus();
|
||||
} else {
|
||||
this.windowManager.ensureWindow(WindowManager.ONBOARDING_WINDOW, {
|
||||
title: localized('Welcome to Mailspring'),
|
||||
windowProps: {},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
this.on('application:add-account', ({ existingAccountJSON } = {}) => {
|
||||
const onboarding = this.windowManager.get(WindowManager.ONBOARDING_WINDOW);
|
||||
if (onboarding) {
|
||||
|
|
|
@ -59,7 +59,7 @@ export default class BillingModal extends React.Component<BillingModalProps, Bil
|
|||
this._mounted = false;
|
||||
}
|
||||
|
||||
_onDidFinishLoad = webview => {
|
||||
_onDidFinishLoad = async (webview: Electron.WebviewTag) => {
|
||||
/**
|
||||
* Ahh webviews…
|
||||
*
|
||||
|
@ -73,28 +73,28 @@ export default class BillingModal extends React.Component<BillingModalProps, Bil
|
|||
var a = document.querySelector('#payment-success-data');
|
||||
result = a ? a.innerText : null;
|
||||
`;
|
||||
webview.executeJavaScript(receiveUserInfo, false, async result => {
|
||||
if (!result) return;
|
||||
if (result !== IdentityStore.identityId()) {
|
||||
AppEnv.reportError(
|
||||
new Error(
|
||||
'id.getmailspring.com/payment_success did not have a valid #payment-success-data field'
|
||||
)
|
||||
);
|
||||
}
|
||||
const listenForContinue = `
|
||||
|
||||
const result = await webview.executeJavaScript(receiveUserInfo, false);
|
||||
if (!result) return;
|
||||
if (result !== IdentityStore.identityId()) {
|
||||
AppEnv.reportError(
|
||||
new Error(
|
||||
'id.getmailspring.com/payment_success did not have a valid #payment-success-data field'
|
||||
)
|
||||
);
|
||||
}
|
||||
const listenForContinue = `
|
||||
var el = document.querySelector('#continue-btn');
|
||||
if (el) {el.addEventListener('click', function(event) {console.log("continue clicked")})}
|
||||
`;
|
||||
webview.executeJavaScript(listenForContinue);
|
||||
webview.addEventListener('console-message', e => {
|
||||
if (e.message === 'continue clicked') {
|
||||
// See comment on componentWillUnmount
|
||||
Actions.closeModal();
|
||||
}
|
||||
});
|
||||
await IdentityStore.fetchIdentity();
|
||||
webview.executeJavaScript(listenForContinue);
|
||||
webview.addEventListener('console-message', e => {
|
||||
if (e.message === 'continue clicked') {
|
||||
// See comment on componentWillUnmount
|
||||
Actions.closeModal();
|
||||
}
|
||||
});
|
||||
await IdentityStore.fetchIdentity();
|
||||
|
||||
/**
|
||||
* If we see any links on the page, we should open them in new
|
||||
|
|
|
@ -29,6 +29,8 @@ export interface IIdentity {
|
|||
};
|
||||
}
|
||||
|
||||
export type IdentityAuthResponse = IIdentity | { skipped: true };
|
||||
|
||||
export const EMPTY_IDENTITY: IIdentity = {
|
||||
id: '',
|
||||
token: '',
|
||||
|
@ -103,7 +105,7 @@ class _IdentityStore extends MailspringStore {
|
|||
}, 1000 * 60 * 10); // 10 minutes
|
||||
}
|
||||
|
||||
async saveIdentity(identity) {
|
||||
async saveIdentity(identity: IIdentity | null) {
|
||||
if (!identity) {
|
||||
this._identity = null;
|
||||
await KeyManager.deletePassword(KEYCHAIN_NAME);
|
||||
|
|
2
mailsync
2
mailsync
|
@ -1 +1 @@
|
|||
Subproject commit d2a77e77f2d037ca8dc1f123bb52b2a2ed6e6421
|
||||
Subproject commit c4577574c6f989b639de1aa2a26c993589d63ed0
|
Loading…
Reference in a new issue