@@ -11,25 +11,92 @@ import debugDriver from '@/renderer/utils/debugDriver';
1111import { setSimulatorViewMode } from '@/renderer/utils/ldtApi' ;
1212import { IDevice } from '@lynx-js/devtool-plugin-core/renderer' ;
1313import { DesktopOutlined , MobileOutlined } from '@ant-design/icons' ;
14- import { Dropdown , Button } from 'antd' ;
14+ import { Dropdown , Button , notification } from 'antd' ;
1515import { MenuProps } from 'antd' ;
1616import { useEffect , useMemo } from 'react' ;
1717import './DeviceSelect.scss' ;
1818import IconPlatform from './IconPlatform/IconPlatform' ;
1919import useldtConnection from '@/renderer/ldt/store/ldtConnection' ;
20- import { getStopAtEntry , getFetchDebugInfo } from '@/renderer/utils/switchUtils' ;
20+ import { getStopAtEntry , getFetchDebugInfo , getSwitchStatus , openDevtool , openDomTree } from '@/renderer/utils/switchUtils' ;
21+
22+ let notificationKey = '' ;
23+
24+ interface SwitchNotificationContentProps {
25+ devtoolSwitch : boolean ;
26+ domTreeSwitch : boolean ;
27+ close : ( ) => void ;
28+ }
29+
30+ function SwitchNotificationContent ( { devtoolSwitch, domTreeSwitch, close } : SwitchNotificationContentProps ) {
31+ const handleEnableAll = async ( ) => {
32+ const results = await Promise . all ( [
33+ ! devtoolSwitch ? openDevtool ( true ) : Promise . resolve ( true ) ,
34+ ! domTreeSwitch ? openDomTree ( true ) : Promise . resolve ( true )
35+ ] ) ;
36+ if ( results . every ( Boolean ) ) {
37+ close ( ) ;
38+ }
39+ } ;
40+
41+ return (
42+ < div >
43+ < p style = { { marginBottom : 8 } } >
44+ The following switches need to be enabled for DevTool to work properly:
45+ </ p >
46+ < ul style = { { marginBottom : 12 , paddingLeft : 20 } } >
47+ { ! devtoolSwitch && < li > enable_devtool</ li > }
48+ { ! domTreeSwitch && < li > enable_dom_tree</ li > }
49+ </ ul >
50+ < Button type = "primary" size = "small" onClick = { handleEnableAll } >
51+ Enable All
52+ </ Button >
53+ </ div >
54+ ) ;
55+ }
2156
2257export default function DeviceSelect ( ) {
2358 const { deviceList, selectedDevice, setSelectedDevice } = useConnection ( ) ;
2459 const { selectedDevice : currentDevice , setCurrentDevice } = useldtConnection ( ) ;
2560
2661 useEffect ( ( ) => {
2762 setCurrentDevice ( xdbDriver . getCurrentDevice ( ) ) ;
63+ checkDevtoolSwitch ( ) ;
2864 getStopAtEntry ( 'DEFAULT' ) ;
2965 getStopAtEntry ( 'MTS' ) ;
3066 getFetchDebugInfo ( 'MTS' ) ;
3167 } , [ selectedDevice ] ) ;
3268
69+ const checkDevtoolSwitch = async ( ) => {
70+ const devtoolSwitch = await getSwitchStatus ( 'enable_devtool' ) ;
71+ const domTreeSwitch = await getSwitchStatus ( 'enable_dom_tree' ) ;
72+ const currentClientId = debugDriver . getSelectClientId ( ) ;
73+ if ( ( ! devtoolSwitch || ! domTreeSwitch ) && currentClientId === selectedDevice ?. clientId ) {
74+ if ( notificationKey !== '' ) {
75+ notification . destroy ( notificationKey ) ;
76+ }
77+ notificationKey = `devtool-switch-${ Date . now ( ) } ` ;
78+ notification . warning ( {
79+ key : notificationKey ,
80+ message : 'DevTool Switch Required' ,
81+ description : (
82+ < SwitchNotificationContent
83+ devtoolSwitch = { devtoolSwitch }
84+ domTreeSwitch = { domTreeSwitch }
85+ close = { closeNotification }
86+ />
87+ ) ,
88+ duration : 0
89+ } ) ;
90+ }
91+ } ;
92+
93+ const closeNotification = ( ) => {
94+ if ( notificationKey !== '' ) {
95+ notification . destroy ( notificationKey ) ;
96+ notificationKey = '' ;
97+ }
98+ } ;
99+
33100 function combieDevices ( groupKey : 'App' | 'deviceModel' = 'App' ) : IDevice [ ] {
34101 const sortList = deviceList
35102 . filter ( ( item ) => item . clientId && item . info ?. deviceType !== 'simulator' )
0 commit comments