ソースを参照

V1.0.14 修复内置浏览器卡死问题

liuq 1 ヶ月 前
コミット
06f2763ea5
2 ファイル変更1 行追加53 行削除
  1. 0 18
      src/main/index.ts
  2. 1 35
      src/renderer/src/BrowserWindow.tsx

+ 0 - 18
src/main/index.ts

@@ -320,21 +320,6 @@ class ViewManager {
     this.activeTabId = id
   }
 
-  closeTab(id: string) {
-    const tab = this.tabs.get(id)
-    if (!tab) return
-
-    if (this.activeTabId === id) {
-      this.window.contentView.removeChildView(tab.view)
-      this.activeTabId = null
-    } else {
-      this.window.contentView.removeChildView(tab.view)
-    }
-
-    tab.view.webContents.close()
-    this.tabs.delete(id)
-  }
-
   setBounds(bounds: Electron.Rectangle) {
     this.bounds = bounds
     if (this.activeTabId) {
@@ -956,9 +941,6 @@ ipcMain.on('browser-action', (event, action) => {
       case 'switch-tab':
         viewManager.switchTab(action.id)
         break
-      case 'close-tab':
-        viewManager.closeTab(action.id)
-        break
       case 'go-back':
         viewManager.goBack()
         break

+ 1 - 35
src/renderer/src/BrowserWindow.tsx

@@ -1,5 +1,4 @@
 import React, { useState, useEffect, useRef, useCallback } from 'react'
-import { BsX } from 'react-icons/bs'
 
 interface Tab {
   id: string
@@ -90,29 +89,6 @@ const BrowserWindow: React.FC = () => {
       window.electron.ipcRenderer.send('browser-action', { type: 'switch-tab', id })
   }
 
-  const closeTab = (e: React.MouseEvent, tabId: string) => {
-    e.stopPropagation()
-    // 先在前端乐观更新UI,防止闪烁
-    const newTabs = tabs.filter(t => t.id !== tabId)
-    let newActiveId = activeTabId
-
-    if (activeTabId === tabId) {
-        if (newTabs.length > 0) {
-            newActiveId = newTabs[newTabs.length - 1].id
-            setActiveTabId(newActiveId)
-            window.electron.ipcRenderer.send('browser-action', { type: 'switch-tab', id: newActiveId })
-        } else {
-            setActiveTabId(null)
-            window.close() 
-        }
-    }
-    setTabs(newTabs)
-    
-    // 通知主进程关闭
-    window.electron.ipcRenderer.send('browser-action', { type: 'close-tab', id: tabId })
-  }
-
-
   return (
     <div className="browser-window" style={{ display: 'flex', flexDirection: 'column', height: '100vh', width: '100vw', backgroundColor: '#f5f5f5', overflow: 'hidden' }}>
       {/* Title Bar / Tab Bar */}
@@ -141,16 +117,9 @@ const BrowserWindow: React.FC = () => {
               title={tab.title}
             >
               {tab.isLoading && <div className="spinner" style={{width: 12, height: 12, border: '2px solid #ccc', borderTopColor: '#333', borderRadius: '50%', marginRight: 6, animation: 'spin 1s linear infinite'}}></div>}
-              <div style={{ flex: 1, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', marginRight: '5px' }}>
+              <div style={{ flex: 1, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
                 {tab.title || 'Loading...'}
               </div>
-              <div
-                onClick={(e) => closeTab(e, tab.id)}
-                style={{ cursor: 'pointer', padding: '2px', borderRadius: '50%', display: 'flex', alignItems: 'center' }}
-                className="close-btn"
-              >
-                <BsX size={14} />
-              </div>
             </div>
           ))}
         </div>
@@ -176,9 +145,6 @@ const BrowserWindow: React.FC = () => {
           0% { transform: rotate(0deg); }
           100% { transform: rotate(360deg); }
         }
-        .close-btn:hover {
-            background-color: #ddd;
-        }
       `}</style>
     </div>
   )