Skip to content

Commit a5c39e3

Browse files
committed
Show a 'manual setup' button for iOS
1 parent e1c98ac commit a5c39e3

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import * as _ from 'lodash';
2+
import * as React from 'react';
3+
import { inject, observer } from 'mobx-react';
4+
import { when } from 'mobx';
5+
6+
import { Interceptor } from '../../../model/interception/interceptors';
7+
import { EventsStore } from '../../../model/events/events-store';
8+
import { SourceIcons } from '../../../icons';
9+
10+
@inject('eventsStore')
11+
@observer
12+
class ManualIOSConfig extends React.Component<{
13+
eventsStore?: EventsStore,
14+
15+
interceptor: Interceptor,
16+
17+
activateInterceptor: () => Promise<void>,
18+
reportStarted: () => void,
19+
reportSuccess: (options?: { showRequests?: boolean }) => void,
20+
closeSelf: () => void
21+
}> {
22+
23+
async componentDidMount() {
24+
const { eventsStore, reportStarted, reportSuccess, closeSelf } = this.props;
25+
closeSelf(); // We immediately unmount, but continue activating:
26+
27+
// Open the manual setup docs page:
28+
window.open(
29+
"https://httptoolkit.com/docs/guides/ios/",
30+
"_blank",
31+
"noreferrer noopener"
32+
);
33+
34+
reportStarted();
35+
36+
// When we receive the next iOS-appearing request, we consider this as successful
37+
// and then jump to the View page:
38+
const previousIOSRequestIds = getIOSRequestIds(eventsStore!);
39+
when(() =>
40+
_.difference(
41+
getIOSRequestIds(eventsStore!),
42+
previousIOSRequestIds
43+
).length > 0
44+
).then(() => {
45+
reportSuccess()
46+
});
47+
}
48+
49+
render() {
50+
return null; // This never actually displays - we just mount, open the page, and close
51+
}
52+
53+
}
54+
55+
function getIOSRequestIds(eventsStore: EventsStore) {
56+
return eventsStore.exchanges.filter((exchange) =>
57+
_.isEqual(exchange.request.source.icon, SourceIcons.iOS)
58+
).map(e => e.id);
59+
}
60+
61+
export const ManualIOSCustomUi = {
62+
columnWidth: 1,
63+
rowHeight: 1,
64+
configComponent: ManualIOSConfig
65+
};

src/model/interception/interceptors.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { AndroidAdbCustomUi } from "../../components/intercept/config/android-ad
1818
import { ExistingBrowserCustomUi } from "../../components/intercept/config/existing-browser-config";
1919
import { JvmCustomUi } from "../../components/intercept/config/jvm-config";
2020
import { DockerAttachCustomUi } from "../../components/intercept/config/docker-attach-config";
21+
import { ManualIOSCustomUi } from "../../components/intercept/config/manual-ios-config";
2122

2223
interface InterceptorConfig {
2324
name: string;
@@ -254,8 +255,16 @@ const INTERCEPT_OPTIONS: _.Dictionary<InterceptorConfig> = {
254255
uiConfig: AndroidDeviceCustomUi,
255256
tags: [...MOBILE_TAGS, ...ANDROID_TAGS]
256257
},
258+
'manual-ios-device': {
259+
name: 'iOS via manual setup',
260+
description: ["Manually intercept all HTTP(S) traffic from any iOS device"],
261+
iconProps: SourceIcons.iOS,
262+
clientOnly: true,
263+
uiConfig: ManualIOSCustomUi,
264+
tags: [...MOBILE_TAGS, ...IOS_TAGS]
265+
},
257266
'ios-device': {
258-
name: 'An iOS device',
267+
name: 'Automatic iOS device setup',
259268
description: ["Intercept all HTTP traffic from an iOS device on your network"],
260269
iconProps: SourceIcons.iOS,
261270
tags: [...MOBILE_TAGS, ...IOS_TAGS]

0 commit comments

Comments
 (0)