Skip to content

Commit

Permalink
Stub out features that try to access the server
Browse files Browse the repository at this point in the history
  • Loading branch information
notpushkin committed Feb 3, 2020
1 parent da83bda commit 50af089
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 223 deletions.
33 changes: 3 additions & 30 deletions app/internal_packages/activity/lib/dashboard/share-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,39 +59,12 @@ export default class ShareButton extends React.Component<{}, { link: string; loa
this._mounted = false;
}

_onShareReport = async () => {
this.setState({
loading: true,
});

const link = await MailspringAPIRequest.postStaticPage({
key: `activity-${Date.now()}`,
html: buildShareHTML(
document.querySelector('style[source-path*="activity/styles/index.less"]'),
document.querySelector('.activity-dashboard')
),
});
if (!this._mounted) {
return;
}
this.setState(
{
loading: false,
link: link,
},
() => {
if (this._linkEl) {
this._linkEl.setSelectionRange(0, this._linkEl.value.length);
this._linkEl.focus();
}
}
);
};
_onShareReport = async () => {};

render() {
return (
<div style={{ display: 'flex' }}>
<div className="btn" onClick={this._onShareReport} style={{ minWidth: 150 }}>
{/* <div className="btn" onClick={this._onShareReport} style={{ minWidth: 150 }}>
{localized('Share this Report')}
{this.state.loading && (
<RetinaImg
Expand All @@ -114,7 +87,7 @@ export default class ShareButton extends React.Component<{}, { link: string; loa
<RetinaImg name="icon-copytoclipboard.png" mode={RetinaImg.Mode.ContentIsMask} />
</div>
</div>
)}
)} */}
</div>
);
}
Expand Down
25 changes: 1 addition & 24 deletions app/internal_packages/localizer-help/lib/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,7 @@ class SubmitLocalizationsBar extends React.Component {
}

onSubmit = async () => {
const { current, suggestion } = this.state;

try {
const { status } = await MailspringAPIRequest.makeRequest({
server: 'identity',
method: 'POST',
body: { current, suggestion, language: window.navigator.language },
path: '/api/localization-suggestion',
json: true,
});
if (status === 'success') {
remote.dialog.showMessageBox({
type: 'info',
buttons: [localized('OK')],
message: localized('Thank you!'),
title: localized('Thank you!'),
detail: localized(
`Your updated localization will be reviewed and included in a future version of Mailspring.`
),
});
}
} catch (err) {
AppEnv.showErrorDialog(err.toString());
}
AppEnv.showErrorDialog("Localization suggestions aren't supported in this build!");
};

onSelectionBogusClick = event => {
Expand Down
50 changes: 5 additions & 45 deletions app/internal_packages/onboarding/lib/newsletter-signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,57 +53,17 @@ export default class NewsletterSignup extends React.Component<
}

_onGetStatus = async (props = this.props) => {
this._setState({ status: 'Pending' });
try {
const { status } = await MailspringAPIRequest.makeRequest({
server: 'identity',
method: 'GET',
path: this._path(props),
});
if (status === 'Never Subscribed') {
this._onSubscribe();
} else {
this._setState({ status });
}
} catch (err) {
this._setState({ status: 'Error' });
}
this._setState({ status: 'Unsubscribed' });
};

_onSubscribe = async () => {
this._setState({ status: 'Pending' });
try {
const { status } = await MailspringAPIRequest.makeRequest({
server: 'identity',
method: 'POST',
path: this._path(),
});
this._setState({ status });
} catch (err) {
this._setState({ status: 'Error' });
}
this._setState({ status: 'Subscribed' });
};

_onUnsubscribe = async () => {
this._setState({ status: 'Pending' });
try {
const { status } = await MailspringAPIRequest.makeRequest({
server: 'identity',
method: 'DELETE',
path: this._path(),
});
this._setState({ status });
} catch (err) {
this._setState({ status: 'Error' });
}
this._setState({ status: 'Unsubscribed' });
};

_path(props = this.props) {
return `/api/newsletter/first-account/${encodeURIComponent(
props.emailAddress
)}?name=${encodeURIComponent(props.name)}`;
}

_renderControl() {
if (this.state.status === 'Pending') {
return (
Expand Down Expand Up @@ -146,10 +106,10 @@ export default class NewsletterSignup extends React.Component<
render() {
return (
<Flexbox direction="row" height="auto" style={{ textAlign: 'left' }}>
<div style={{ minWidth: 15 }}>{this._renderControl()}</div>
{/* <div style={{ minWidth: 15 }}>{this._renderControl()}</div>
<label htmlFor="subscribe-check" style={{ paddingLeft: 4, flex: 1 }}>
{localized('Notify me about new features and plugins via this email address.')}
</label>
</label> */}
</Flexbox>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { MailspringAPIRequest, Utils } from 'mailspring-exports';
const { makeRequest } = MailspringAPIRequest;

const CACHE_SIZE = 200;
const CACHE_INDEX_KEY = 'pp-cache-v3-keys';
Expand Down Expand Up @@ -30,16 +29,8 @@ class ParticipantProfileDataSource {

let body = null;

try {
body = await makeRequest({
server: 'identity',
method: 'GET',
path: `/api/info-for-email-v2/${email}?phrase=${encodeURIComponent(name)}`,
});
} catch (err) {
// we don't care about errors
return {};
}
// not supported
return {};

if (!body.person) {
body.person = { email };
Expand Down
9 changes: 1 addition & 8 deletions app/internal_packages/translation/lib/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,7 @@ export async function translateMessageBody(

let response = null;
try {
response = await MailspringAPIRequest.makeRequest({
server: 'identity',
method: 'POST',
path: `/api/translate`,
json: true,
body: { lang: targetLang, text: translationHTML, format: 'html' },
timeout: 5000,
});
throw new Error('Not supported in this build :(');
} catch (error) {
Actions.closePopover();
if (!silent) {
Expand Down
12 changes: 0 additions & 12 deletions app/src/components/evented-iframe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import _ from 'underscore';
import path from 'path';
import fs from 'fs';

const { rootURLForServer } = MailspringAPIRequest;

type EventedIFrameProps = {
searchable?: boolean;
onResize?: (...args: any[]) => any;
Expand Down Expand Up @@ -218,16 +216,6 @@ export class EventedIFrame extends React.Component<

e.preventDefault();

// If this is a link to our billing site, attempt single sign on instead of
// just following the link directly
if (rawHref.startsWith(rootURLForServer('identity'))) {
const path = rawHref.split(rootURLForServer('identity')).pop();
IdentityStore.fetchSingleSignOnURL(path, { source: 'SingleSignOnEmail' }).then(href => {
AppEnv.windowEventHandler.openLink({ href, metaKey: e.metaKey });
});
return;
}

// It's important to send the raw `href` here instead of the target.
// The `target` comes from the document context of the iframe, which
// as of Electron 0.36.9, has different constructor function objects
Expand Down
3 changes: 1 addition & 2 deletions app/src/components/webview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import classnames from 'classnames';
import networkErrors from 'chromium-net-errors';
import { localized } from 'mailspring-exports';

import { rootURLForServer } from '../flux/mailspring-api-request';
import { RetinaImg } from './retina-img';
import { Disposable } from 'event-kit';

Expand Down Expand Up @@ -56,7 +55,7 @@ class InitialLoadingCover extends React.Component<
if (this.props.error) {
message = this.props.error;
} else if (this.state.slow) {
message = localized(`Still trying to reach %@…`, rootURLForServer('identity'));
message = localized(`Still trying to reach identity server (why?!)…`);
} else {
message = '&nbsp;';
}
Expand Down
4 changes: 1 addition & 3 deletions app/src/error-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ module.exports = ErrorLogger = (function() {
crashReporter.start({
productName: 'Mailspring',
companyName: 'Mailspring',
submitURL: `https://id.getmailspring.com/report-crash?ver=${appVersion}&platform=${
process.platform
}`,
submitURL: `https://invalid.localhost/report-crash?ver=${appVersion}&platform=${process.platform}`,
uploadToServer: true,
autoSubmit: true,
extra: {
Expand Down
67 changes: 4 additions & 63 deletions app/src/flux/mailspring-api-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export function rootURLForServer(server) {
}

if (server === 'identity') {
return 'http://localhost:5101';
return {
development: 'http://localhost:5101',
staging: 'https://id-staging.getmailspring.com',
Expand All @@ -50,75 +51,15 @@ export function rootURLForServer(server) {
}

export async function postStaticAsset({ filename, blob }) {
const body = new FormData();
body.set('filename', filename);
if (typeof blob === 'string') {
body.set('file', new Blob([blob], { type: 'text/plain' }), filename);
} else {
body.set('file', blob, filename);
}
let resp = await makeRequest({
server: 'identity',
method: 'POST',
path: `/api/save-public-asset`,
body: body,
});
return resp.link;
throw new Error('not supported');
}

export async function postStaticPage({ html, key }) {
const json = await makeRequest({
server: 'identity',
method: 'POST',
path: '/api/share-static-page',
json: true,
body: { key, html },
timeout: 1500,
});
return json.link;
throw new Error('not supported');
}

export async function makeRequest(options) {
// for some reason when `fetch` completes, the stack trace has been lost.
// In case the request failsm capture the stack now.
const root = rootURLForServer(options.server);

options.headers = options.headers || new Headers();
options.headers.set('Accept', 'application/json');
options.credentials = 'include';

if (!options.auth && options.auth !== false) {
if (options.server === 'identity') {
IdentityStore = IdentityStore || require('./stores/identity-store').IdentityStore;
const username = IdentityStore.identity().token;
options.headers.set('Authorization', `Basic ${btoa(`${username}:`)}`);
}
}

if (options.path) {
options.url = `${root}${options.path}`;
}

if (options.body && !(options.body instanceof FormData)) {
options.headers.set('Content-Type', 'application/json');
options.body = JSON.stringify(options.body);
}

const error = new APIError(`${options.method || 'GET'} ${options.url} failed`);
let resp = null;
try {
resp = await fetch(options.url, options);
} catch (uselessFetchError) {
throw error;
}
if (!resp.ok) {
error.statusCode = resp.status;
error.message = `${options.method || 'GET'} ${options.url} returned ${resp.status} ${
resp.statusText
}`;
throw error;
}
return resp.json();
throw new Error('not supported');
}

export default {
Expand Down
29 changes: 4 additions & 25 deletions app/src/flux/stores/update-channel-store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import MailspringStore from 'mailspring-store';
import { remote } from 'electron';
import { makeRequest } from '../mailspring-api-request';

const autoUpdater = remote.getGlobal('application').autoUpdateManager;
const preferredChannel = autoUpdater.preferredChannel;
Expand Down Expand Up @@ -31,15 +30,8 @@ class UpdateChannelStore extends MailspringStore {
async refreshChannel() {
// TODO BG
try {
const { current, available } = await makeRequest({
server: 'identity',
method: 'GET',
path: `/api/update-channel`,
qs: Object.assign({ preferredChannel: preferredChannel }, autoUpdater.parameters()),
json: true,
});
this._current = current || { name: 'Channel API Not Available' };
this._available = available || [];
this._current = { name: 'Builtin updater disabled in this build' };
this._available = [];
this.trigger();
} catch (err) {
// silent
Expand All @@ -49,21 +41,8 @@ class UpdateChannelStore extends MailspringStore {

async setChannel(channelName) {
try {
const { current, available } = await makeRequest({
server: 'identity',
method: 'POST',
path: `/api/update-channel`,
qs: Object.assign(
{
channel: channelName,
preferredChannel: preferredChannel,
},
autoUpdater.parameters()
),
json: true,
});
this._current = current || { name: 'Channel API Not Available' };
this._available = available || [];
this._current = { name: 'Builtin updater disabled in this build' };
this._available = [];
this.trigger();
} catch (err) {
AppEnv.showErrorDialog(err.toString());
Expand Down

0 comments on commit 50af089

Please sign in to comment.