|
1 | 1 | import * as _ from 'lodash';
|
2 | 2 | import * as React from 'react';
|
3 |
| -import { computed, observable, action, autorun, flow } from 'mobx'; |
| 3 | +import { computed, observable, action, autorun, flow, runInAction } from 'mobx'; |
4 | 4 | import { observer, inject, disposeOnUnmount } from 'mobx-react';
|
5 | 5 |
|
6 | 6 | import { delay } from '../../../util/promise';
|
@@ -140,8 +140,8 @@ class FridaConfig extends React.Component<{
|
140 | 140 | closeSelf: () => void
|
141 | 141 | }> {
|
142 | 142 |
|
143 |
| - @computed private get fridaHosts(): Array<FridaHost> { |
144 |
| - return this.props.interceptor.metadata?.hosts || []; |
| 143 | + @computed private get fridaHosts(): Record<string, FridaHost> { |
| 144 | + return this.props.interceptor.metadata?.hosts || {}; |
145 | 145 | }
|
146 | 146 |
|
147 | 147 | @observable fridaTargets: Array<FridaTarget> = [];
|
@@ -176,16 +176,22 @@ class FridaConfig extends React.Component<{
|
176 | 176 | }
|
177 | 177 |
|
178 | 178 | async componentDidMount() {
|
179 |
| - if (this.fridaHosts.length === 1 && this.fridaHosts[0].state === 'available') { |
180 |
| - this.selectHost(this.fridaHosts[0].id); |
| 179 | + // Auto-open the first host, if there's only one: |
| 180 | + const hosts = Object.values(this.fridaHosts); |
| 181 | + if (hosts.length === 1 && hosts[0].state === 'available') { |
| 182 | + this.selectHost(hosts[0].id); |
181 | 183 | }
|
182 | 184 |
|
183 | 185 | disposeOnUnmount(this, autorun(() => {
|
184 |
| - if (this.selectedHostId && !this.fridaHosts.some(host => host.id === this.selectedHostId)) { |
| 186 | + // If the selected host disappears or becomes unavailable, deselect it: |
| 187 | + if ( |
| 188 | + this.selectedHostId && |
| 189 | + this.fridaHosts[this.selectedHostId]?.state !== 'available' |
| 190 | + ) { |
185 | 191 | this.deselectHost();
|
186 | 192 | }
|
187 | 193 |
|
188 |
| - if (this.fridaHosts?.length === 0) { |
| 194 | + if (Object.keys(this.fridaHosts).length === 0) { |
189 | 195 | this.props.closeSelf();
|
190 | 196 | }
|
191 | 197 | }));
|
@@ -220,7 +226,7 @@ class FridaConfig extends React.Component<{
|
220 | 226 | }
|
221 | 227 |
|
222 | 228 | private getHost(hostId: string) {
|
223 |
| - return this.fridaHosts.find(host => host.id === hostId); |
| 229 | + return this.fridaHosts[hostId]; |
224 | 230 | }
|
225 | 231 |
|
226 | 232 | @action.bound
|
@@ -381,7 +387,7 @@ class FridaConfig extends React.Component<{
|
381 | 387 | return <ConfigContainer>
|
382 | 388 | <FridaTargetList
|
383 | 389 | spinnerText={`Waiting for ${this.deviceClassName} devices to attach to...`}
|
384 |
| - targets={this.fridaHosts.map(host => { |
| 390 | + targets={Object.values(this.fridaHosts).map(host => { |
385 | 391 | const { id, name, state } = host;
|
386 | 392 | const activating = this.hostProgress[id] !== undefined;
|
387 | 393 |
|
|
0 commit comments