forked from superset-sh/superset
-
Notifications
You must be signed in to change notification settings - Fork 1
feat(desktop): ペインのポップアウト(別ウィンドウ分離)機能 #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8d37a1f
feat(desktop): ペインのポップアウト(別ウィンドウ分離)機能を実装
MocA-Love 7c31e76
feat(desktop): ポップアウトウィンドウのUI調整
MocA-Love f6e152c
feat(desktop): ポップアウトウィンドウのドラッグ領域をタブバー右側に移動
MocA-Love 09b6e73
fix(desktop): ポップアウトウィンドウclose時の全タブ返却と重複防止
MocA-Love b38002f
fix(desktop): ティアオフウィンドウのWindowIdを"main"から"tearoff"に変更
MocA-Love 2767350
fix(desktop): tearoffレビュー指摘3件を修正
MocA-Love 042d2ce
docs: README にタブポップアウト機能を追記
MocA-Love File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { z } from "zod"; | ||
| import type { WindowManager } from "main/lib/window-manager"; | ||
| import { publicProcedure, router } from ".."; | ||
|
|
||
| export const createTabTearoffRouter = (wm: WindowManager) => { | ||
| return router({ | ||
| create: publicProcedure | ||
| .input( | ||
| z.object({ | ||
| tab: z.unknown(), | ||
| panes: z.record(z.string(), z.unknown()), | ||
| workspaceId: z.string(), | ||
| screenX: z.number(), | ||
| screenY: z.number(), | ||
| }), | ||
| ) | ||
| .mutation(({ input }) => { | ||
| const windowId = `tearoff-${Date.now()}`; | ||
|
|
||
| // Store data FIRST so it's available when preload requests it | ||
| wm.setPendingTearoffData(windowId, { | ||
| tab: input.tab, | ||
| panes: input.panes, | ||
| workspaceId: input.workspaceId, | ||
| }); | ||
|
|
||
| wm.createTearoffWindow({ | ||
| windowId, | ||
| screenX: input.screenX, | ||
| screenY: input.screenY, | ||
| }); | ||
|
|
||
| return { windowId }; | ||
| }), | ||
| }); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| import { join } from "node:path"; | ||
| import { BrowserWindow, ipcMain, nativeTheme } from "electron"; | ||
| import { createWindow } from "lib/electron-app/factories/windows/create"; | ||
|
|
||
| interface TearoffWindowOptions { | ||
| windowId: string; | ||
| screenX: number; | ||
| screenY: number; | ||
| width?: number; | ||
| height?: number; | ||
| } | ||
|
|
||
| interface TearoffTabData { | ||
| tab: unknown; | ||
| panes: Record<string, unknown>; | ||
| workspaceId: string; | ||
| } | ||
|
|
||
| type IpcHandler = { | ||
| attachWindow: (window: BrowserWindow) => void; | ||
| detachWindow: (window: BrowserWindow) => void; | ||
| }; | ||
|
|
||
| export class WindowManager { | ||
| private windows = new Map<string, BrowserWindow>(); | ||
| private ipcHandler: IpcHandler | null = null; | ||
| private ipcRegistered = false; | ||
| private pendingTearoffData = new Map<string, TearoffTabData>(); | ||
|
|
||
| setIpcHandler(handler: IpcHandler): void { | ||
| this.ipcHandler = handler; | ||
| this.registerIpcHandlers(); | ||
| } | ||
|
|
||
| private registerIpcHandlers(): void { | ||
| if (this.ipcRegistered) return; | ||
| this.ipcRegistered = true; | ||
|
|
||
| // Synchronous IPC: preload fetches tearoff data before React starts | ||
| ipcMain.on("get-tearoff-data", (event, windowId: string) => { | ||
| const data = this.pendingTearoffData.get(windowId); | ||
| if (data) this.pendingTearoffData.delete(windowId); | ||
| event.returnValue = data ?? null; | ||
|
MocA-Love marked this conversation as resolved.
|
||
| }); | ||
|
|
||
| // Tearoff window closing: return all tabs to main window (single message) | ||
| ipcMain.on( | ||
| "tearoff-return-tabs", | ||
| ( | ||
| _event, | ||
| data: Array<{ tab: unknown; panes: Record<string, unknown> }>, | ||
| ) => { | ||
| const mainWindow = this.getMain(); | ||
| if (mainWindow && !mainWindow.isDestroyed()) { | ||
| mainWindow.webContents.send("tearoff-tab-returned", data); | ||
| } else { | ||
| console.warn( | ||
| "[window-manager] Main window unavailable; returned tabs lost:", | ||
| data.length, | ||
| ); | ||
| } | ||
|
MocA-Love marked this conversation as resolved.
|
||
| }, | ||
| ); | ||
|
MocA-Love marked this conversation as resolved.
|
||
| } | ||
|
|
||
| setPendingTearoffData(windowId: string, data: TearoffTabData): void { | ||
| this.pendingTearoffData.set(windowId, data); | ||
| setTimeout(() => this.pendingTearoffData.delete(windowId), 30_000); | ||
| } | ||
|
|
||
| register(windowId: string, window: BrowserWindow): void { | ||
| this.windows.set(windowId, window); | ||
| } | ||
|
|
||
| unregister(windowId: string): void { | ||
| this.windows.delete(windowId); | ||
| } | ||
|
|
||
| get(windowId: string): BrowserWindow | null { | ||
| return this.windows.get(windowId) ?? null; | ||
| } | ||
|
|
||
| getMain(): BrowserWindow | null { | ||
| return this.windows.get("main") ?? null; | ||
| } | ||
|
|
||
| getAll(): Map<string, BrowserWindow> { | ||
| return new Map(this.windows); | ||
| } | ||
|
|
||
| createTearoffWindow(options: TearoffWindowOptions): { | ||
| windowId: string; | ||
| window: BrowserWindow; | ||
| } { | ||
| const { windowId } = options; | ||
|
|
||
| const window = createWindow({ | ||
| id: "tearoff", | ||
| title: "Superset", | ||
| width: options.width ?? 900, | ||
| height: options.height ?? 600, | ||
| x: Math.round(options.screenX - 100), | ||
| y: Math.round(options.screenY - 20), | ||
| minWidth: 400, | ||
| minHeight: 400, | ||
| show: false, | ||
| backgroundColor: nativeTheme.shouldUseDarkColors ? "#252525" : "#ffffff", | ||
| frame: false, | ||
| titleBarStyle: "hidden", | ||
| trafficLightPosition: { x: 16, y: 16 }, | ||
| webPreferences: { | ||
| preload: join(__dirname, "../preload/index.js"), | ||
| webviewTag: true, | ||
| partition: "persist:superset", | ||
| additionalArguments: [`--tearoff-window-id=${windowId}`], | ||
| }, | ||
| }); | ||
|
|
||
| this.register(windowId, window); | ||
| this.ipcHandler?.attachWindow(window); | ||
|
|
||
| // Detach IPC BEFORE window is destroyed (close fires before closed) | ||
| window.on("close", () => { | ||
| this.ipcHandler?.detachWindow(window); | ||
| }); | ||
| window.on("closed", () => { | ||
| this.windows.delete(windowId); | ||
| }); | ||
|
|
||
| window.webContents.once("did-finish-load", () => { | ||
| window.show(); | ||
| }); | ||
|
|
||
| return { windowId, window }; | ||
| } | ||
|
|
||
| broadcast(channel: string, ...args: unknown[]): void { | ||
| for (const window of this.windows.values()) { | ||
| if (!window.isDestroyed()) { | ||
| window.webContents.send(channel, ...args); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export const windowManager = new WindowManager(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| export { | ||
| useTearoffInit, | ||
| useReturnedTabListener, | ||
| getTearoffWindowId, | ||
| isTearoffWindow, | ||
| } from "./useTearoffInit"; |
81 changes: 81 additions & 0 deletions
81
apps/desktop/src/renderer/hooks/useTearoffInit/useTearoffInit.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import { useEffect, useRef } from "react"; | ||
| import { useNavigate } from "@tanstack/react-router"; | ||
| import { useTabsStore } from "renderer/stores/tabs/store"; | ||
| import type { Tab } from "renderer/stores/tabs/types"; | ||
| import type { Pane } from "shared/tabs-types"; | ||
|
|
||
| // Cached at module load from preload-injected data | ||
| const _cachedWindowId: string | null = | ||
| typeof window !== "undefined" ? window.App?.tearoffWindowId ?? null : null; | ||
|
|
||
| export function getTearoffWindowId(): string | null { | ||
| return _cachedWindowId; | ||
| } | ||
|
|
||
| export function isTearoffWindow(): boolean { | ||
| return _cachedWindowId !== null; | ||
| } | ||
|
|
||
| export function useTearoffInit() { | ||
| const initialized = useRef(false); | ||
| const navigate = useNavigate(); | ||
| const tabs = useTabsStore((s) => s.tabs); | ||
|
|
||
| // Navigate to the workspace for the tearoff tab | ||
| useEffect(() => { | ||
| if (!_cachedWindowId || initialized.current || tabs.length === 0) return; | ||
| initialized.current = true; | ||
| const tab = tabs[0]; | ||
| navigate({ to: `/workspace/${tab.workspaceId}`, replace: true }); | ||
| }, [tabs, navigate]); | ||
|
|
||
| // Return ALL tabs to main window when this tearoff window closes | ||
| useEffect(() => { | ||
| if (!_cachedWindowId) return; | ||
| const handleBeforeUnload = () => { | ||
| const state = useTabsStore.getState(); | ||
| if (state.tabs.length === 0) return; | ||
|
|
||
| // Collect all tabs + their panes into a single message | ||
| const tabsWithPanes = state.tabs.map((tab) => { | ||
| const panes: Record<string, Pane> = {}; | ||
| for (const [id, pane] of Object.entries(state.panes)) { | ||
| if (pane.tabId === tab.id) { | ||
| panes[id] = pane; | ||
| } | ||
| } | ||
| return { tab, panes }; | ||
| }); | ||
|
MocA-Love marked this conversation as resolved.
|
||
|
|
||
| // Send as ONE message to avoid race conditions | ||
| window.ipcRenderer.send("tearoff-return-tabs", tabsWithPanes); | ||
| }; | ||
| window.addEventListener("beforeunload", handleBeforeUnload); | ||
| return () => window.removeEventListener("beforeunload", handleBeforeUnload); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }, []); | ||
| } | ||
|
|
||
| export function useReturnedTabListener() { | ||
| useEffect(() => { | ||
| if (isTearoffWindow()) return; | ||
| const handler = ( | ||
| entries: Array<{ tab: unknown; panes: Record<string, unknown> }>, | ||
| ) => { | ||
| const store = useTabsStore.getState(); | ||
| const existingTabIds = new Set(store.tabs.map((t) => t.id)); | ||
|
|
||
| for (const entry of entries) { | ||
| const tab = entry.tab as Tab; | ||
| // Skip if tab already exists (prevent duplicates) | ||
| if (existingTabIds.has(tab.id)) continue; | ||
| const panes = entry.panes as Record<string, Pane>; | ||
| store.hydrateReturnedTab(tab, panes); | ||
| existingTabIds.add(tab.id); | ||
| } | ||
| }; | ||
| window.ipcRenderer.on("tearoff-tab-returned", handler); | ||
| return () => { | ||
| window.ipcRenderer.off("tearoff-tab-returned", handler); | ||
| }; | ||
| }, []); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.