Skip to content

Commit b1bb3cc

Browse files
committed
Switch to id-map Frida API metadata
1 parent b46492b commit b1bb3cc

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/components/intercept/config/frida-config.tsx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as _ from 'lodash';
22
import * as React from 'react';
3-
import { computed, observable, action, autorun, flow } from 'mobx';
3+
import { computed, observable, action, autorun, flow, runInAction } from 'mobx';
44
import { observer, inject, disposeOnUnmount } from 'mobx-react';
55

66
import { delay } from '../../../util/promise';
@@ -140,8 +140,8 @@ class FridaConfig extends React.Component<{
140140
closeSelf: () => void
141141
}> {
142142

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 || {};
145145
}
146146

147147
@observable fridaTargets: Array<FridaTarget> = [];
@@ -176,16 +176,22 @@ class FridaConfig extends React.Component<{
176176
}
177177

178178
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);
181183
}
182184

183185
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+
) {
185191
this.deselectHost();
186192
}
187193

188-
if (this.fridaHosts?.length === 0) {
194+
if (Object.keys(this.fridaHosts).length === 0) {
189195
this.props.closeSelf();
190196
}
191197
}));
@@ -220,7 +226,7 @@ class FridaConfig extends React.Component<{
220226
}
221227

222228
private getHost(hostId: string) {
223-
return this.fridaHosts.find(host => host.id === hostId);
229+
return this.fridaHosts[hostId];
224230
}
225231

226232
@action.bound
@@ -381,7 +387,7 @@ class FridaConfig extends React.Component<{
381387
return <ConfigContainer>
382388
<FridaTargetList
383389
spinnerText={`Waiting for ${this.deviceClassName} devices to attach to...`}
384-
targets={this.fridaHosts.map(host => {
390+
targets={Object.values(this.fridaHosts).map(host => {
385391
const { id, name, state } = host;
386392
const activating = this.hostProgress[id] !== undefined;
387393

0 commit comments

Comments
 (0)