|
|
@@ -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>
|
|
|
)
|