Skip to content

Commit 07b1e4c

Browse files
authored
opt: restore #47, optimize StopAtEntry message (#74)
* opt: restore #47, optimize StopAtEngry message * opt: restore #47, optimize StopAtEngry message * opt: restore #47, optimize StopAtEngry message
1 parent bf25f61 commit 07b1e4c

File tree

3 files changed

+100
-18
lines changed

3 files changed

+100
-18
lines changed

src/renderer/components/connection/DeviceSelect.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ import { useEffect, useMemo } from 'react';
1717
import './DeviceSelect.scss';
1818
import IconPlatform from './IconPlatform/IconPlatform';
1919
import useldtConnection from '@/renderer/ldt/store/ldtConnection';
20+
import { getStopAtEntry } from '@/renderer/utils/switchUtils';
2021

2122
export default function DeviceSelect() {
2223
const { deviceList, selectedDevice, setSelectedDevice } = useConnection();
2324
const { selectedDevice: currentDevice, setCurrentDevice } = useldtConnection();
2425

2526
useEffect(() => {
2627
setCurrentDevice(xdbDriver.getCurrentDevice());
28+
getStopAtEntry('DEFAULT');
29+
getStopAtEntry('MTS');
2730
}, [selectedDevice]);
2831

2932
function combieDevices(groupKey: 'App' | 'deviceModel' = 'App'): IDevice[] {

src/renderer/hooks/connection.ts

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import debugDriver from '../utils/debugDriver';
1818
import create from '../utils/flooks';
1919
import { queryService } from '../utils/query';
2020
import { sendStatisticsEvent } from '../utils/statisticsUtils';
21+
import * as switchUtils from '../utils/switchUtils';
2122

2223
export type ConnectionStoreType = ReturnType<typeof connectionStore>;
2324

@@ -390,42 +391,62 @@ const connectionStore = (store: any) => ({
390391
}
391392
},
392393

393-
async setStopAtEntry(value: boolean) {
394-
const { selectedDevice } = store() as ConnectionStoreType;
394+
async setStopAtEntryLegacy(value: boolean) {
395+
const { selectedDevice, deviceInfoMap } = store() as ConnectionStoreType;
395396
const { clientId } = selectedDevice;
396-
if (clientId) {
397+
if (clientId === undefined) {
398+
return;
399+
}
400+
try {
401+
const deviceInfo = deviceInfoMap[clientId];
402+
if (deviceInfo === undefined) {
403+
return;
404+
}
397405
await debugDriver.sendCustomMessageAsync({
398406
type: ECustomDataType.D2RStopAtEntry,
399407
params: { stop_at_entry: value },
400408
useParamsAsData: true,
401409
clientId
402410
});
403-
const { deviceInfoMap } = store() as ConnectionStoreType;
404-
const deviceInfo = deviceInfoMap[clientId];
405-
if (deviceInfo) {
406-
deviceInfo.stopAtEntry = value;
407-
store({ deviceInfoMap: { ...deviceInfoMap } });
408-
}
411+
deviceInfo.stopAtEntry = value;
412+
store({ deviceInfoMap: { ...deviceInfoMap } });
413+
} catch (error: any) {
414+
console.error(error.toString());
409415
}
410416
},
411-
async setStopLepusAtEntry(value: boolean) {
412-
const { selectedDevice } = store() as ConnectionStoreType;
417+
setStopAtEntry(value: boolean) {
418+
switchUtils.setStopAtEntry('DEFAULT', value);
419+
const { setStopAtEntryLegacy } = store();
420+
setStopAtEntryLegacy(value);
421+
},
422+
async setStopLepusAtEntryLegacy(value: boolean) {
423+
const { selectedDevice, deviceInfoMap } = store() as ConnectionStoreType;
413424
const { clientId } = selectedDevice;
414-
if (clientId) {
425+
if (clientId === undefined) {
426+
return;
427+
}
428+
try {
429+
const deviceInfo = deviceInfoMap[clientId];
430+
if (deviceInfo === undefined) {
431+
return;
432+
}
415433
await debugDriver.sendCustomMessageAsync({
416434
type: ECustomDataType.D2RStopLepusAtEntry,
417435
params: { stop_at_entry: value },
418436
useParamsAsData: true,
419437
clientId
420438
});
421-
const { deviceInfoMap } = store() as ConnectionStoreType;
422-
const deviceInfo = deviceInfoMap[clientId];
423-
if (deviceInfo) {
424-
deviceInfo.stopLepusAtEntry = value;
425-
store({ deviceInfoMap: { ...deviceInfoMap } });
426-
}
439+
deviceInfo.stopLepusAtEntry = value;
440+
store({ deviceInfoMap: { ...deviceInfoMap } });
441+
} catch (error: any) {
442+
console.error(error.toString());
427443
}
428444
},
445+
setStopLepusAtEntry(value: boolean) {
446+
switchUtils.setStopAtEntry('MTS', value);
447+
const { setStopLepusAtEntryLegacy } = store();
448+
setStopLepusAtEntryLegacy(value);
449+
},
429450
updateSessionScreenshot(sessionId: number, data: string) {
430451
const { deviceInfoMap, selectedDevice } = store() as ConnectionStoreType;
431452
const sessions = deviceInfoMap[selectedDevice.clientId ?? 0]?.sessions;

src/renderer/utils/switchUtils.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2024 The Lynx Authors. All rights reserved.
2+
// Licensed under the Apache License Version 2.0 that can be found in the
3+
// LICENSE file in the root directory of this source tree.
4+
5+
import debugDriver from './debugDriver';
6+
import { getStore } from './flooks';
7+
import useConnection from '../hooks/connection';
8+
9+
function updateStopAtEntry(type: string, value: boolean) {
10+
const currentClientId = debugDriver.getSelectClientId();
11+
if (currentClientId === undefined) {
12+
return;
13+
}
14+
const { deviceInfoMap, setDeviceInfoMap } = getStore(useConnection);
15+
const newDeviceInfoMap = { ...deviceInfoMap };
16+
const deviceInfo = newDeviceInfoMap[currentClientId];
17+
if (deviceInfo === undefined) {
18+
return;
19+
}
20+
if (type === 'MTS') {
21+
deviceInfo.stopLepusAtEntry = value;
22+
} else if (type === 'DEFAULT') {
23+
deviceInfo.stopAtEntry = value;
24+
}
25+
setDeviceInfoMap(newDeviceInfoMap);
26+
}
27+
28+
export async function getStopAtEntry(type: string) {
29+
try {
30+
const result = await debugDriver.sendCustomMessageAsync({
31+
type: 'GetStopAtEntry',
32+
params: { type }
33+
});
34+
const { value } = result;
35+
if (value === undefined) {
36+
return;
37+
}
38+
updateStopAtEntry(type, value);
39+
} catch (error: any) {
40+
console.error('getStopAtEntry error:', type, error);
41+
}
42+
}
43+
44+
export async function setStopAtEntry(type: string, value: boolean) {
45+
try {
46+
const result = await debugDriver.sendCustomMessageAsync({
47+
type: 'SetStopAtEntry',
48+
params: { type, value }
49+
});
50+
const { value: resultValue } = result;
51+
if (resultValue === undefined) {
52+
return;
53+
}
54+
updateStopAtEntry(type, resultValue);
55+
} catch (error: any) {
56+
console.error('setStopAtEntry error:', type, value, error);
57+
}
58+
}

0 commit comments

Comments
 (0)