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+ } ;
0 commit comments