feat: transfer tab state to popout window and close tab in main window

- Restore transfer-tab-data IPC for transferring tab state
- Create usePopOutTab hook to receive tab data in new window
- Update handlePopOut to transfer data and close tab in main window
- Add PopOutTabData interface for type safety
This commit is contained in:
2026-03-21 23:52:02 +08:00
parent c37e6ab4f2
commit aa5895873b
7 changed files with 106 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ export { useDialogState, useErrorDialogState } from './useDialogState'
export { useNoteBrowser, type UseNoteBrowserReturn } from './useNoteBrowser'
export { useNoteContent } from './useNoteContent'
export { useAutoLoadTabContent } from './useAutoLoadTabContent'
export { usePopOutTab } from './usePopOutTab'
export { useFileSystemController } from './useFileSystemController'
export { useFileTabs } from './useFileTabs'

View File

@@ -0,0 +1,58 @@
import { useEffect } from 'react'
import { useTabStore, TabState } from '@/stores'
export interface PopOutTabData {
file: {
name: string
path: string
type: 'file' | 'dir'
size: number
modified: string
}
content: string
unsavedContent: string
isEditing: boolean
loading: boolean
loaded: boolean
}
export function usePopOutTab() {
const { selectFile } = useTabStore()
useEffect(() => {
const unsubscribe = window.electronAPI?.onTabDataReceived((tabData: PopOutTabData) => {
console.log('[PopOut] Received tab data:', tabData)
if (!tabData?.file?.path) {
console.error('[PopOut] Invalid tab data received')
return
}
const { file, content, unsavedContent, isEditing, loading, loaded } = tabData
const newTab: TabState = {
file: file as any,
content: content || '',
unsavedContent: unsavedContent || content || '',
isEditing: isEditing || false,
loading: loading || false,
loaded: loaded !== undefined ? loaded : true,
}
useTabStore.setState((state) => {
const newTabs = new Map(state.tabs)
newTabs.set(file.path, newTab)
return {
tabs: newTabs,
activeTabId: file.path,
}
})
selectFile(file as any)
})
return () => {
unsubscribe?.()
}
}, [selectFile])
}