@@ -259,7 +259,6 @@ class MenuBar extends React.Component {
259259 "handleDocumentMouseUp" ,
260260 "handleMenubarClickSuppress" ,
261261 ] ) ;
262- this . overlay = navigator ?. windowControlsOverlay || { } ;
263262 this . menubar = React . createRef ( ) ;
264263 this . _menubarPressing = false ;
265264 this . _menubarDragMode = false ;
@@ -277,10 +276,6 @@ class MenuBar extends React.Component {
277276 this . updateMaximizedState ( ) ;
278277 // 监听窗口大小变化
279278 window . addEventListener ( "resize" , this . handleResize ) ;
280- // 监听 title bar overlay 区域变化(Window Controls Overlay API)
281- if ( navigator ?. windowControlsOverlay ) {
282- navigator . windowControlsOverlay . addEventListener ( "geometrychange" , this . handleResize ) ;
283- }
284279 }
285280 componentDidUpdate ( prevProps ) {
286281 // 当 isMaximize 首次可用时更新状态
@@ -304,22 +299,18 @@ class MenuBar extends React.Component {
304299 componentWillUnmount ( ) {
305300 document . removeEventListener ( "keydown" , this . handleKeyPress ) ;
306301 window . removeEventListener ( "resize" , this . handleResize ) ;
307- if ( navigator ?. windowControlsOverlay ) {
308- navigator . windowControlsOverlay . removeEventListener ( "geometrychange" , this . handleResize ) ;
309- }
310- clearTimeout ( this . _menubarDragTimer ) ;
311- this . exitDragMode ( ) ;
312302 if ( this . props . setWindowMaximizeStateHandler ) {
313303 this . props . setWindowMaximizeStateHandler ( null ) ;
314304 }
305+ clearTimeout ( this . _menubarDragTimer ) ;
306+ this . exitDragMode ( ) ;
315307 }
316308 handleWindowMaximizeStateChange ( isMaximized ) {
317309 this . setState ( { isMaximized : Boolean ( isMaximized ) } ) ;
318310 }
319311 handleResize ( ) {
320312 // 窗口大小变化时更新最大化状态
321313 this . updateMaximizedState ( ) ;
322- this . overlay = navigator ?. windowControlsOverlay || { } ;
323314 }
324315 async updateMaximizedState ( ) {
325316 if ( this . props . isMaximize ) {
@@ -332,6 +323,63 @@ class MenuBar extends React.Component {
332323 // 延迟更新状态,等待 Electron 完成窗口状态变化
333324 setTimeout ( ( ) => this . updateMaximizedState ( ) , 100 ) ;
334325 }
326+ clickMainMenu ( e ) {
327+ if ( this . _menubarDragMode ) return ;
328+ clearTimeout ( this . _menubarDragTimer ) ;
329+ this . _menubarPressing = true ;
330+ this . _menubarDragTimer = setTimeout ( ( ) => {
331+ if ( this . _menubarPressing && ! this . _menubarDragMode ) {
332+ this . enterDragMode ( ) ;
333+ }
334+ } , 600 ) ;
335+ }
336+ overClickMainMenu ( ) {
337+ clearTimeout ( this . _menubarDragTimer ) ;
338+ this . _menubarPressing = false ;
339+ }
340+ enterDragMode ( ) {
341+ this . _menubarDragMode = true ;
342+ this . _menubarDragActivated = true ;
343+ const bar = this . menubar . current ;
344+ if ( bar ) {
345+ bar . classList . add ( styles . dragMode ) ;
346+ bar . addEventListener ( "click" , this . handleMenubarClickSuppress , true ) ;
347+ }
348+ document . addEventListener ( "mousedown" , this . handleDocumentMouseDown , true ) ;
349+ document . addEventListener ( "mouseup" , this . handleDocumentMouseUp , true ) ;
350+ }
351+ exitDragMode ( ) {
352+ if ( ! this . _menubarDragMode ) return ;
353+ this . _menubarDragMode = false ;
354+ this . _menubarDragActivated = false ;
355+ clearTimeout ( this . _menubarDragTimer ) ;
356+ const bar = this . menubar . current ;
357+ if ( bar ) {
358+ bar . classList . remove ( styles . dragMode ) ;
359+ bar . removeEventListener ( "click" , this . handleMenubarClickSuppress , true ) ;
360+ }
361+ document . removeEventListener ( "mousedown" , this . handleDocumentMouseDown , true ) ;
362+ document . removeEventListener ( "mouseup" , this . handleDocumentMouseUp , true ) ;
363+ }
364+ handleDocumentMouseDown ( e ) {
365+ if ( ! this . _menubarDragMode ) return ;
366+ const bar = this . menubar . current ;
367+ if ( ! bar || ! bar . contains ( e . target ) ) {
368+ this . exitDragMode ( ) ;
369+ }
370+ }
371+ handleDocumentMouseUp ( ) {
372+ if ( ! this . _menubarDragMode ) return ;
373+ if ( this . _menubarDragActivated ) {
374+ this . _menubarDragActivated = false ;
375+ return ;
376+ }
377+ this . exitDragMode ( ) ;
378+ }
379+ handleMenubarClickSuppress ( e ) {
380+ e . stopPropagation ( ) ;
381+ e . preventDefault ( ) ;
382+ }
335383 handleClickNew ( ) {
336384 // if the project is dirty, and user owns the project, we will autosave.
337385 // but if they are not logged in and can't save, user should consider
@@ -605,74 +653,6 @@ class MenuBar extends React.Component {
605653 this . props . onRequestCloseAbout ( ) ;
606654 } ;
607655 }
608- clickMainMenu ( e ) {
609- // 非桌面端不启用拖拽
610- if ( ! window . EditorPreload ) return ;
611- // 已处于拖拽模式时不再重新计时,交给 Electron 处理拖拽
612- if ( this . _menubarDragMode ) return ;
613- // 仅检测 menubar 顶部条:忽略输入框与多级下拉菜单内的长按
614- if ( e . target . closest ( `input, textarea, [contenteditable], .${ styles . menuBarMenu } ` ) ) return ;
615- this . _menubarPressing = true ;
616- clearTimeout ( this . _menubarDragTimer ) ;
617- this . _menubarDragTimer = setTimeout ( ( ) => {
618- if ( this . _menubarPressing && ! this . _menubarDragMode ) {
619- this . enterDragMode ( ) ;
620- }
621- } , 600 ) ;
622- }
623- overClickMainMenu ( ) {
624- this . _menubarPressing = false ;
625- clearTimeout ( this . _menubarDragTimer ) ;
626- }
627- enterDragMode ( ) {
628- this . _menubarDragMode = true ;
629- // 标记此次为长按激活,等待用户松开后再按下才会真正拖拽
630- this . _menubarDragActivated = true ;
631- const bar = this . menubar . current ;
632- if ( bar ) {
633- bar . classList . add ( styles . dragMode ) ;
634- // 拖拽模式下吞掉 menubar 内的点击,避免触发按钮行为
635- bar . addEventListener ( "click" , this . handleMenubarClickSuppress , true ) ;
636- }
637- document . addEventListener ( "mousedown" , this . handleDocumentMouseDown , true ) ;
638- document . addEventListener ( "mouseup" , this . handleDocumentMouseUp , true ) ;
639- }
640- exitDragMode ( ) {
641- if ( ! this . _menubarDragMode ) return ;
642- this . _menubarDragMode = false ;
643- this . _menubarDragActivated = false ;
644- this . _menubarPressing = false ;
645- clearTimeout ( this . _menubarDragTimer ) ;
646- const bar = this . menubar . current ;
647- if ( bar ) {
648- bar . classList . remove ( styles . dragMode ) ;
649- bar . removeEventListener ( "click" , this . handleMenubarClickSuppress , true ) ;
650- }
651- document . removeEventListener ( "mousedown" , this . handleDocumentMouseDown , true ) ;
652- document . removeEventListener ( "mouseup" , this . handleDocumentMouseUp , true ) ;
653- }
654- handleDocumentMouseDown ( e ) {
655- if ( ! this . _menubarDragMode ) return ;
656- const bar = this . menubar . current ;
657- // 按下时未碰到 menubar:退出拖拽模式;碰到了则交给 Electron 拖拽
658- if ( bar && ! bar . contains ( e . target ) ) {
659- this . exitDragMode ( ) ;
660- }
661- }
662- handleDocumentMouseUp ( ) {
663- if ( ! this . _menubarDragMode ) return ;
664- if ( this . _menubarDragActivated ) {
665- // 长按激活后的首次松开:保持拖拽模式,等待用户再次按下拖拽
666- this . _menubarDragActivated = false ;
667- return ;
668- }
669- // 拖拽结束(松开鼠标):恢复 menubar
670- this . exitDragMode ( ) ;
671- }
672- handleMenubarClickSuppress ( e ) {
673- e . stopPropagation ( ) ;
674- e . preventDefault ( ) ;
675- }
676656 render ( ) {
677657 const saveNowMessage = (
678658 < FormattedMessage
@@ -714,15 +694,8 @@ class MenuBar extends React.Component {
714694 ) ;
715695 // Show the About button only if we have a handler for it (like in the desktop app)
716696 const aboutButton = this . buildAboutMenu ( this . props . onClickAbout ) ;
717- const isMac = window . EditorPreload ?. platform === 'darwin' ;
718697 const menuBar = (
719- < Box className = { classNames ( this . props . className , styles . menuBar , { [ styles . macos ] : isMac } ) } style = {
720- this . overlay . visible ? {
721- width : `${ Math . max ( this . overlay . getTitlebarAreaRect ( ) . width , window . innerWidth ) } px` ,
722- // 如果是阿拉伯那种从右往左的,改一下位置
723- marginRight : `${ this . props . isRtl ? window . innerWidth - this . overlay . getTitlebarAreaRect ( ) . width : '0' } px`
724- }
725- : { } } >
698+ < Box className = { classNames ( this . props . className , styles . menuBar ) } >
726699 < div className = { styles . mainMenu } >
727700 < div
728701 className = { styles . menuGroup }
@@ -1678,7 +1651,6 @@ MenuBar.propTypes = {
16781651 onShare : PropTypes . func ,
16791652 onStartSelectingFileUpload : PropTypes . func ,
16801653 onToggleLoginOpen : PropTypes . func ,
1681- setWindowControlsStyle : PropTypes . func ,
16821654 projectId : PropTypes . string ,
16831655 projectTitle : PropTypes . string ,
16841656 renderLogin : PropTypes . func ,
0 commit comments