1- /* eslint-disable prettier/prettier */
21import { Discord , DocumentationSite , ExtVersion } from "@App/app/const" ;
32import { Alert , Badge , Button , Card , Collapse , Dropdown , Menu , Switch } from "@arco-design/web-react" ;
43import {
@@ -32,6 +31,7 @@ const iconStyle = {
3231} ;
3332
3433function App ( ) {
34+ const [ loading , setLoading ] = useState ( true ) ;
3535 const [ scriptList , setScriptList ] = useState < ScriptMenu [ ] > ( [ ] ) ;
3636 const [ backScriptList , setBackScriptList ] = useState < ScriptMenu [ ] > ( [ ] ) ;
3737 const [ showAlert , setShowAlert ] = useState ( false ) ;
@@ -43,6 +43,7 @@ function App() {
4343 const [ currentUrl , setCurrentUrl ] = useState ( "" ) ;
4444 const [ isEnableScript , setIsEnableScript ] = useState ( true ) ;
4545 const [ isBlacklist , setIsBlacklist ] = useState ( false ) ;
46+ const [ collapseActiveKey , setCollapseActiveKey ] = useState < string [ ] > ( [ "script" ] ) ;
4647 const { t } = useTranslation ( ) ;
4748
4849 let url : URL | undefined ;
@@ -83,6 +84,9 @@ function App() {
8384 setBackScriptList ( resp . backScriptList || [ ] ) ;
8485 setIsBlacklist ( resp . isBlacklist || false ) ;
8586 checkScriptEnableAndUpdate ( ) ;
87+ if ( resp . backScriptList . length > 0 ) {
88+ setCollapseActiveKey ( [ "script" , "background" ] ) ;
89+ }
8690 } )
8791 . catch ( ( error ) => {
8892 console . error ( "Failed to get popup data:" , error ) ;
@@ -91,6 +95,10 @@ function App() {
9195 setScriptList ( [ ] ) ;
9296 setBackScriptList ( [ ] ) ;
9397 setIsBlacklist ( false ) ;
98+ } )
99+ . finally ( ( ) => {
100+ if ( ! isMounted ) return ;
101+ setLoading ( false ) ;
94102 } ) ;
95103 } ;
96104
@@ -199,8 +207,7 @@ function App() {
199207 const dropdown = dropdowns [ 0 ] as HTMLElement ;
200208 console . log ( dropdowns , dropdown . style . top ) ;
201209 // 如果top是负数修改为0
202- if ( parseInt ( dropdown
203- . style . top ) < 0 ) {
210+ if ( parseInt ( dropdown . style . top ) < 0 ) {
204211 dropdown . style . top = "0px" ;
205212 }
206213 }
@@ -265,7 +272,10 @@ function App() {
265272 />
266273 < Collapse
267274 bordered = { false }
268- defaultActiveKey = { [ "script" , ...( backScriptList . length > 0 ? [ "background" ] : [ ] ) ] }
275+ activeKey = { collapseActiveKey }
276+ onChange = { ( _ , keys ) => {
277+ setCollapseActiveKey ( keys ) ;
278+ } }
269279 style = { { maxWidth : 640 , maxHeight : 500 , overflow : "auto" } }
270280 >
271281 < CollapseItem
@@ -280,7 +290,11 @@ function App() {
280290 < CollapseItem
281291 header = { t ( "enabled_background_scripts" ) }
282292 name = "background"
283- style = { { padding : "0" } }
293+ style = { {
294+ padding : "0" ,
295+ // 未加载完成前不采用动画,避免collapseActiveKey变化时闪现
296+ ...( loading ? { transform : "none" } : { transform : "height 0.2s cubic-bezier(0.34, 0.69, 0.1, 1)" } ) ,
297+ } }
284298 contentStyle = { { padding : "0" } }
285299 >
286300 < ScriptMenuList script = { backScriptList } isBackscript = { true } currentUrl = { currentUrl } />
0 commit comments