@@ -66,6 +66,25 @@ async function _getTauriWindowLabel(prefix) {
6666 throw new Error ( "Could not get a free window label to create tauri window" ) ;
6767}
6868
69+ /**
70+ * Opens a URL in a new Phoenix window. Works across all platforms (Tauri, Electron, browser).
71+ *
72+ * @param {string } url - The URL to open in the new window
73+ * @param {Object } [options] - Window configuration options
74+ * @param {string } [options.windowTitle] - Title for the window (defaults to label or URL)
75+ * @param {boolean } [options.fullscreen] - Whether to open in fullscreen mode
76+ * @param {boolean } [options.resizable=true] - Whether the window is resizable
77+ * @param {number } [options.height=900] - Window height in pixels
78+ * @param {number } [options.minHeight=600] - Minimum window height in pixels
79+ * @param {number } [options.width=1366] - Window width in pixels
80+ * @param {number } [options.minWidth=800] - Minimum window width in pixels
81+ * @param {boolean } [options.acceptFirstMouse=true] - (Tauri only) Accept first mouse click
82+ * @param {boolean } [options.preferTabs] - (Browser only) Prefer opening in a new tab
83+ * @param {string } [options._prefixPvt] - Internal: window label prefix
84+ * @returns {Promise<{label: string, isNativeWindow: boolean}> } Window object with `label` and `isNativeWindow` properties.
85+ * - In Tauri/Electron: `{ label: string, isNativeWindow: true }` (Tauri returns WebviewWindow instance with these props)
86+ * - In browser: Returns window.open() result with `isNativeWindow: false`
87+ */
6988async function openURLInPhoenixWindow ( url , {
7089 windowTitle, fullscreen, resizable,
7190 height, minHeight, width, minWidth, acceptFirstMouse, preferTabs, _prefixPvt = PHOENIX_EXTENSION_WINDOW_PREFIX
@@ -242,6 +261,27 @@ Phoenix.app = {
242261 return window . electronAPI . focusWindow ( ) ;
243262 }
244263 } ,
264+ /**
265+ * Closes a window by its label. Returns true if window was found and closed, false otherwise.
266+ * @param {string } label - The window label to close
267+ * @return {Promise<boolean> }
268+ */
269+ closeWindowByLabel : async function ( label ) {
270+ if ( ! Phoenix . isNativeApp ) {
271+ throw new Error ( "closeWindowByLabel is not supported in browsers" ) ;
272+ }
273+ if ( window . __TAURI__ ) {
274+ const win = window . __TAURI__ . window . WebviewWindow . getByLabel ( label ) ;
275+ if ( win ) {
276+ await win . close ( ) ;
277+ return true ;
278+ }
279+ return false ;
280+ } else if ( window . __ELECTRON__ ) {
281+ return window . electronAPI . closeWindowByLabel ( label ) ;
282+ }
283+ return false ;
284+ } ,
245285 /**
246286 * Gets the commandline argument in desktop builds and null in browser builds.
247287 * Will always return CLI of the current process only.
0 commit comments