@@ -20,7 +20,7 @@ import Quota, { getPercent } from './components/Quota'
20
20
import { runCode } from './tools/runCode'
21
21
import { loader } from "@monaco-editor/react" ;
22
22
import { sendRequestLog } from './tools/sendRequest'
23
- import { ActiveGroupId , BootLogKey , DarkFieldKey , HiddenFieldsFieldKey , ActiveIdFieldKey , RulesFieldKey , SelectedRowFieldKeys , UpdateMsgKey , WatchFilterKey , ConfigInfoFieldKey , PopupMsgKey } from './tools/constants'
23
+ import { ActiveGroupId , HiddenFieldsFieldKey , ActiveIdFieldKey , RulesFieldKey , SelectedRowFieldKeys , UpdateMsgKey , WatchFilterKey , ConfigInfoFieldKey , PopupMsgKey } from './tools/constants'
24
24
import useTranslate from './hooks/useTranslate'
25
25
import getStorage from './tools/getStorage'
26
26
import { ConfigProvider , theme } from 'antd'
@@ -74,6 +74,8 @@ export interface ConfigInfoType {
74
74
action : string
75
75
banType : BanType
76
76
bootLog : boolean
77
+ allFrames : boolean
78
+ dark : boolean
77
79
}
78
80
79
81
const defaultConfigInfo : ConfigInfoType = {
@@ -84,22 +86,22 @@ const defaultConfigInfo: ConfigInfoType = {
84
86
runAtTrigger : '**' ,
85
87
action : 'close' ,
86
88
banType : 'none' ,
87
- bootLog : false ,
89
+ bootLog : true ,
90
+ allFrames : false ,
91
+ dark : isDarkTheme ,
88
92
}
89
93
90
94
export default function App ( ) {
91
- const [ dark , setDark ] = useStorage ( DarkFieldKey , isDarkTheme )
95
+ const [ configInfo , setConfigInfo ] = useStorage < ConfigInfoType > ( ConfigInfoFieldKey , defaultConfigInfo )
92
96
const [ activeGroupId , setActiveGroupId ] = useStorage ( ActiveGroupId , 'default' )
93
97
const [ watchFilter , setWatchFilter ] = useStorage ( WatchFilterKey , '' )
94
- const [ configInfo , setConfigInfo ] = useStorage < ConfigInfoType > ( ConfigInfoFieldKey , defaultConfigInfo )
95
98
const [ rules , setRules ] = useStorage < MatchRule [ ] > ( RulesFieldKey , [ ] )
96
99
const [ selectedRowKeys , setSelectedRowKeys ] = useStorage ( SelectedRowFieldKeys , [ ] )
97
100
const [ loading , setLoading ] = useState ( false )
98
101
const [ activeId , setActiveId ] = useStorage < string > ( ActiveIdFieldKey , null )
99
102
const [ invalid , setInvalid ] = useState ( false )
100
103
const [ visible , setVisible ] = useState ( false )
101
104
const [ hiddenFields , setHiddenFields ] = useStorage < string [ ] > ( HiddenFieldsFieldKey , [ ] )
102
- const [ bootLog , setBootLog ] = useStorage ( BootLogKey , true )
103
105
const [ percent , setPercent ] = useState ( 0 )
104
106
const originRef = useRef ( '' )
105
107
const editorRef = useRef ( )
@@ -120,11 +122,9 @@ export default function App() {
120
122
[ ConfigInfoFieldKey ] : setConfigInfo ,
121
123
[ RulesFieldKey ] : setRules ,
122
124
[ SelectedRowFieldKeys ] : setSelectedRowKeys ,
123
- [ DarkFieldKey ] : setDark ,
124
125
[ ActiveIdFieldKey ] : setActiveId ,
125
126
[ HiddenFieldsFieldKey ] : setHiddenFields ,
126
127
[ WatchFilterKey ] : setWatchFilter ,
127
- [ BootLogKey ] : setBootLog ,
128
128
[ ActiveGroupId ] : setActiveGroupId ,
129
129
}
130
130
@@ -427,8 +427,6 @@ export default function App() {
427
427
[ ]
428
428
)
429
429
430
- // 数据改变后通知background,并保存chrome.storage
431
-
432
430
useEffect (
433
431
( ) => {
434
432
if ( ! __DEV__ ) {
@@ -438,6 +436,15 @@ export default function App() {
438
436
payload : configInfo ,
439
437
} )
440
438
}
439
+
440
+ const html = document . querySelector ( 'html' )
441
+ const cls = 'theme--dark'
442
+ if ( configInfo . dark && ! html . classList . contains ( cls ) ) {
443
+ html . classList . add ( cls )
444
+ } else {
445
+ html . classList . remove ( cls )
446
+ document . head . querySelector ( 'link[dark]' ) ?. remove ( )
447
+ }
441
448
} ,
442
449
[ configInfo ]
443
450
)
@@ -453,20 +460,6 @@ export default function App() {
453
460
} ,
454
461
[ workspaceRules ]
455
462
)
456
- useEffect (
457
- ( ) => {
458
- const html = document . querySelector ( 'html' )
459
- const cls = 'theme--dark'
460
- if ( dark && ! html . classList . contains ( cls ) ) {
461
- html . classList . add ( cls )
462
- } else {
463
- html . classList . remove ( cls )
464
- document . head . querySelector ( 'link[dark]' ) ?. remove ( )
465
- }
466
- } ,
467
- [ dark ]
468
- )
469
-
470
463
useEffect (
471
464
( ) => {
472
465
getPercent ( sizeof ( rules ) ) . then ( setPercent )
@@ -476,7 +469,7 @@ export default function App() {
476
469
477
470
return (
478
471
< ConfigProvider theme = { {
479
- algorithm : dark ? theme . darkAlgorithm : undefined ,
472
+ algorithm : configInfo . dark ? theme . darkAlgorithm : undefined ,
480
473
components : {
481
474
Table : {
482
475
headerBorderRadius : 0 ,
@@ -676,19 +669,21 @@ export default function App() {
676
669
< >
677
670
< Divider orientation = 'left' plain >
678
671
< Button size = 'small' type = 'primary' onClick = { ( ) => {
679
- setDark ( false )
680
- setBootLog ( true )
681
- setConfigInfo ( info => ( { ...info , fakedLog : true } ) )
672
+ setConfigInfo ( info => ( { ...info , fakedLog : true , bootLog : true , dark : false , allFrames : false } ) )
682
673
} } > { t ( 'action_reset' ) } </ Button >
683
674
</ Divider >
684
675
< Space size = { 'large' } >
676
+ < div style = { { display : 'flex' } } >
677
+ < span style = { { marginRight : 8 } } > { t ( 'action_all_frames' ) } </ span >
678
+ < Switch checked = { configInfo . allFrames } onClick = { ( ) => setConfigInfo ( info => ( { ...info , allFrames : ! info . allFrames } ) ) } > </ Switch >
679
+ </ div >
685
680
< div style = { { display : 'flex' } } >
686
681
< span style = { { marginRight : 8 } } > { t ( 'action_theme' ) } </ span >
687
- < Switch checked = { dark } onClick = { ( ) => setDark ( dark => ! dark ) } > </ Switch >
682
+ < Switch checked = { configInfo . dark } onClick = { ( ) => setConfigInfo ( info => ( { ... info , dark : ! info . dark } ) ) } > </ Switch >
688
683
</ div >
689
684
< div style = { { display : 'flex' } } >
690
685
< span style = { { marginRight : 8 } } > { t ( 'action_boot_log' ) } </ span >
691
- < Switch checked = { bootLog } onClick = { ( ) => setBootLog ( bootLog => ! bootLog ) } > </ Switch >
686
+ < Switch checked = { configInfo . bootLog } onClick = { ( ) => setConfigInfo ( info => ( { ... info , bootLog : ! info . bootLog } ) ) } > </ Switch >
692
687
</ div >
693
688
< div style = { { display : 'flex' } } >
694
689
< span style = { { marginRight : 8 } } > { t ( 'action_faked_log' ) } </ span >
@@ -729,7 +724,11 @@ export default function App() {
729
724
< Popover trigger = { [ 'click' ] } placement = 'top' showArrow = { false } content = { (
730
725
< >
731
726
< Segmented value = { configInfo . runAt } onChange = { ( runAt : string ) => {
732
- setConfigInfo ( info => ( { ...info , runAt } ) )
727
+ setConfigInfo ( info => ( {
728
+ ...info ,
729
+ runAt,
730
+ action : ( runAt === 'override' && info . action === 'close' ) ? 'intercept' : info . action ,
731
+ } ) )
733
732
} } options = { [
734
733
{
735
734
label : t ( 'run_at_start' ) ,
@@ -806,7 +805,7 @@ export default function App() {
806
805
editable && (
807
806
< div className = 'app__editor' >
808
807
< MainEditor
809
- isDark = { dark }
808
+ isDark = { configInfo . dark }
810
809
ref = { editorRef }
811
810
index = { activeIndex }
812
811
rule = { rules [ activeIndex ] }
0 commit comments