From 232f6920f4036d912efcc8be82eeb0c2d4edbf50 Mon Sep 17 00:00:00 2001 From: Oleg Date: Mon, 16 Nov 2026 22:00:42 -0500 Subject: [PATCH 1/2] feat: flash the taskbar button for background toasts A toast shown while the main window is in the background flashes its taskbar button until the window is focused or the toast is activated. window.flash and window.stopFlash expose the same control to the page. Co-authored-by: Cursor --- src/Bermuda.Fdc3.Tests/IpcDispatchTests.cs | 10 ++ src/Bermuda.IpcContract/IpcModels.cs | 20 ++++ src/Bermuda.Web/e2e/host-api.spec.ts | 99 +++++++++++++++++++ src/Bermuda.Web/src/bridge/index.ts | 9 ++ .../src/ipc/__generated__/ipc.d.ts | 5 + src/Bermuda/HostBridge.cs | 10 +- src/Bermuda/IWindowController.cs | 12 +++ src/Bermuda/MainWindow.xaml.cs | 77 ++++++++++++++- src/Bermuda/NotificationService.cs | 4 + 9 files changed, 244 insertions(+), 2 deletions(-) diff --git a/src/Bermuda.Fdc3.Tests/IpcDispatchTests.cs b/src/Bermuda.Fdc3.Tests/IpcDispatchTests.cs index cef6337..e8b55df 100644 --- a/src/Bermuda.Fdc3.Tests/IpcDispatchTests.cs +++ b/src/Bermuda.Fdc3.Tests/IpcDispatchTests.cs @@ -15,6 +15,9 @@ public class IpcDispatchTests [Theory] [InlineData("ping", typeof(IHostCommands))] + [InlineData("window.flash", typeof(IWindowCommands))] + [InlineData("window.stopFlash", typeof(IWindowCommands))] + [InlineData("window.isFlashing", typeof(IWindowCommands))] [InlineData("fdc3.getInfo", typeof(IFdc3Commands))] [InlineData("fdc3.raiseIntent", typeof(IFdc3Commands))] // "Async" suffix dropped [InlineData("fdc3.getIntentResult", typeof(IFdc3Commands))] @@ -33,6 +36,13 @@ public void Every_fdc3_command_is_discovered() Assert.Equal(typeof(IFdc3Commands).GetMethods().Length, discovered); } + [Fact] + public void Every_window_command_is_discovered() + { + var discovered = IpcContract.IpcContract.Commands.Count(c => c.Interface == typeof(IWindowCommands)); + Assert.Equal(typeof(IWindowCommands).GetMethods().Length, discovered); + } + [Fact] public async Task CamelCase_payloads_bind_to_typed_parameters() { diff --git a/src/Bermuda.IpcContract/IpcModels.cs b/src/Bermuda.IpcContract/IpcModels.cs index ec54c20..0fd1748 100644 --- a/src/Bermuda.IpcContract/IpcModels.cs +++ b/src/Bermuda.IpcContract/IpcModels.cs @@ -24,6 +24,26 @@ public interface IHostCommands SimulateNotificationActivationResult SimulateNotificationActivation(SimulateNotificationActivationRequest request); } +/// +/// Window commands (window.flash, window.stopFlash, window.isFlashing). +/// Implemented by HostBridge, which forwards them to that window's controller. +/// +[IpcCommands("window")] +public interface IWindowCommands +{ + /// + /// Flashes the taskbar button until the window is in the foreground or window.stopFlash runs. + /// While the window is already in the foreground the call does not leave it flashing. + /// + void Flash(); + + /// Stops the taskbar button flashing. + void StopFlash(); + + /// True while the taskbar button is flashing. + bool IsFlashing(); +} + /// /// A postMessage request from the web side to HostBridge. Payload /// is deliberately untyped (its shape depends on Command). diff --git a/src/Bermuda.Web/e2e/host-api.spec.ts b/src/Bermuda.Web/e2e/host-api.spec.ts index bec14f8..1411a32 100644 --- a/src/Bermuda.Web/e2e/host-api.spec.ts +++ b/src/Bermuda.Web/e2e/host-api.spec.ts @@ -296,3 +296,102 @@ test.describe('taskbar overlay badge', () => { expect(clearAfterSet.ok).toBe(true) }) }) + +test.describe('taskbar flash', () => { + let original: Snapshot + + test.beforeEach(async ({ page }) => { + await inPage(page, "await bermudaHost.invoke('window.stopFlash')") + original = await getState(page) + }) + + // Flash tests minimize the window so it is not the foreground window. Put it back afterwards. + test.afterEach(async ({ page }) => { + await inPage( + page, + `await bermudaHost.invoke('window.stopFlash') + const c = chrome.webview.hostObjects.windowController + await c.Restore() + await c.Resize(${original.bounds.width}, ${original.bounds.height}) + await c.Move(${original.bounds.left}, ${original.bounds.top}) + ${original.isMaximized ? 'await c.Maximize()' : ''}`, + ) + }) + + const isFlashing = (page: Page) => inPage(page, "return await bermudaHost.invoke('window.isFlashing')") + + test('window.stopFlash is safe when the taskbar is not flashing', async ({ page }) => { + expect(await inPage(page, "return await bermudaHost.invoke('window.stopFlash')")).toBeNull() + expect(await isFlashing(page)).toBe(false) + }) + + test('window.flash starts flashing in the background and window.stopFlash stops it', async ({ page }) => { + await inPage(page, 'await chrome.webview.hostObjects.windowController.Minimize()') + expect(await inPage(page, 'return await chrome.webview.hostObjects.windowController.IsFocused')).toBe(false) + + expect(await inPage(page, "return await bermudaHost.invoke('window.flash')")).toBeNull() + expect(await isFlashing(page)).toBe(true) + + expect(await inPage(page, "return await bermudaHost.invoke('window.stopFlash')")).toBeNull() + expect(await isFlashing(page)).toBe(false) + }) + + test('window.flash does not leave a focused window flashing', async ({ page }) => { + await inPage(page, 'await chrome.webview.hostObjects.windowController.Restore()') + const focused = await inPage(page, 'return await chrome.webview.hostObjects.windowController.IsFocused') + test.skip(!focused, 'This session did not leave the Bermuda window in the foreground.') + + expect(await inPage(page, "return await bermudaHost.invoke('window.flash')")).toBeNull() + expect(await isFlashing(page)).toBe(false) + }) + + test('command names are matched case-insensitively', async ({ page }) => { + await inPage(page, 'await chrome.webview.hostObjects.windowController.Minimize()') + expect(await inPage(page, "return await bermudaHost.invoke('WINDOW.FLASH')")).toBeNull() + expect(await isFlashing(page)).toBe(true) + + expect(await inPage(page, "return await bermudaHost.invoke('Window.StopFlash')")).toBeNull() + expect(await isFlashing(page)).toBe(false) + }) + + test('bermudaHost.window.flash and stopFlash call the same commands', async ({ page }) => { + await inPage(page, 'await chrome.webview.hostObjects.windowController.Minimize()') + expect(await inPage(page, 'return await bermudaHost.window.flash()')).toBeNull() + expect(await inPage(page, 'return await bermudaHost.window.isFlashing()')).toBe(true) + + expect(await inPage(page, 'return await bermudaHost.window.stopFlash()')).toBeNull() + expect(await inPage(page, 'return await bermudaHost.window.isFlashing()')).toBe(false) + }) + + test('a background toast starts flashing and activation stops it', async ({ page }) => { + await inPage(page, 'await chrome.webview.hostObjects.windowController.Minimize()') + expect(await inPage(page, 'return await chrome.webview.hostObjects.windowController.IsFocused')).toBe(false) + + const shown = await inPage<{ shown: boolean; message: string }>( + page, + `return await bermudaHost.notifications.show({ id: 'e2e-flash', title: 'Bermuda e2e', body: 'Flash the taskbar', expiresInSeconds: 4 })`, + ) + expect(shown).toEqual({ shown: true, message: '' }) + expect(await isFlashing(page)).toBe(true) + + const delivered = await inPage<{ delivered: boolean; message: string }>( + page, + `return await bermudaHost.notifications.simulateActivation({ notificationId: 'e2e-flash' })`, + ) + expect(delivered).toEqual({ delivered: true, message: '' }) + expect(await isFlashing(page)).toBe(false) + }) + + test('a toast does not flash the taskbar when the window is focused', async ({ page }) => { + await inPage(page, 'await chrome.webview.hostObjects.windowController.Restore()') + const focused = await inPage(page, 'return await chrome.webview.hostObjects.windowController.IsFocused') + test.skip(!focused, 'This session did not leave the Bermuda window in the foreground.') + + const shown = await inPage<{ shown: boolean }>( + page, + `return await bermudaHost.notifications.show({ id: 'e2e-flash-focused', title: 'Bermuda e2e', body: 'Already here', expiresInSeconds: 4 })`, + ) + expect(shown.shown).toBe(true) + expect(await isFlashing(page)).toBe(false) + }) +}) diff --git a/src/Bermuda.Web/src/bridge/index.ts b/src/Bermuda.Web/src/bridge/index.ts index f81e61a..392168a 100644 --- a/src/Bermuda.Web/src/bridge/index.ts +++ b/src/Bermuda.Web/src/bridge/index.ts @@ -92,6 +92,15 @@ const windowApi = { setOverlay: (iconPng: string, description = '') => windowController().SetOverlayIcon(iconPng, description), /** Sets the taskbar progress bar's state ('none' hides it). */ setProgressState: (state: TaskbarProgressState) => windowController().SetProgressState(state), + /** + * Flashes the taskbar button until the window is in the foreground or stopFlash() runs. + * A window that is already in front is left not flashing. + */ + flash: () => invoke('window.flash'), + /** Stops taskbar flashing started by flash(). */ + stopFlash: () => invoke('window.stopFlash'), + /** True while the taskbar button is flashing. */ + isFlashing: () => invoke('window.isFlashing'), } as const export type WindowApi = typeof windowApi diff --git a/src/Bermuda.Web/src/ipc/__generated__/ipc.d.ts b/src/Bermuda.Web/src/ipc/__generated__/ipc.d.ts index ca23371..ce2488b 100644 --- a/src/Bermuda.Web/src/ipc/__generated__/ipc.d.ts +++ b/src/Bermuda.Web/src/ipc/__generated__/ipc.d.ts @@ -311,6 +311,11 @@ export interface IpcMethods { sendIntentResult: (payload: Fdc3SendIntentResultRequest, ) => Promise; unsubscribe: (payload: Fdc3ListenerIdRequest, ) => Promise; }; + window: { + flash: () => Promise; + isFlashing: () => Promise; + stopFlash: () => Promise; + }; } export interface IpcHostObjects { diff --git a/src/Bermuda/HostBridge.cs b/src/Bermuda/HostBridge.cs index 887d7d8..86bc155 100644 --- a/src/Bermuda/HostBridge.cs +++ b/src/Bermuda/HostBridge.cs @@ -17,10 +17,11 @@ namespace Bermuda; /// This window's current FDC3 connection, read per call because a page reload /// reconnects as a new instance (see MainWindow.OnContentLoading). /// +/// This window, for window.* commands. /// Enables dev/test-only commands (MainWindow: when CDP_PORT is set). [ClassInterface(ClassInterfaceType.AutoDual)] [ComVisible(true)] -public class HostBridge(Func fdc3, bool testHooks = false) : IHostCommands +public class HostBridge(Func fdc3, IWindowController window, bool testHooks = false) : IHostCommands, IWindowCommands { /// Web preset (camelCase, case-insensitive) with enums as camelCase strings, matching the generated TS unions. public static JsonSerializerOptions PayloadJson { get; } = new(JsonSerializerDefaults.Web) @@ -52,6 +53,12 @@ public Task ShowNotificationAsync(ShowNotificationReques public SimulateNotificationActivationResult SimulateNotificationActivation(SimulateNotificationActivationRequest request) => NotificationService.Simulate(request); + public void Flash() => window.Flash(); + + public void StopFlash() => window.StopFlash(); + + public bool IsFlashing() => window.IsFlashing; + public async Task HandleAsync(string command, object? payload) { if (IpcContract.IpcContract.Find(command) is not { } ipcCommand) @@ -87,5 +94,6 @@ public SimulateNotificationActivationResult SimulateNotificationActivation(Simul private object TargetFor(Type commands) => commands == typeof(IFdc3Commands) ? fdc3() : commands == typeof(IHostCommands) ? this + : commands == typeof(IWindowCommands) ? this : throw new InvalidOperationException($"No handler for {commands.Name}."); } diff --git a/src/Bermuda/IWindowController.cs b/src/Bermuda/IWindowController.cs index 56acb07..abdd7b5 100644 --- a/src/Bermuda/IWindowController.cs +++ b/src/Bermuda/IWindowController.cs @@ -59,4 +59,16 @@ public interface IWindowController /// Sets the taskbar progress value. Clamped to 0.0–1.0; ignored while the state is "none" or "indeterminate". void SetProgressValue(double value); + + /// + /// Flashes the taskbar button until the window comes to the foreground or is called. + /// A window that is already in the foreground is left not flashing. + /// + void Flash(); + + /// Stops taskbar flashing started by . + void StopFlash(); + + /// True while the taskbar button is flashing. + bool IsFlashing { get; } } diff --git a/src/Bermuda/MainWindow.xaml.cs b/src/Bermuda/MainWindow.xaml.cs index 8adcf38..f1eeee6 100644 --- a/src/Bermuda/MainWindow.xaml.cs +++ b/src/Bermuda/MainWindow.xaml.cs @@ -56,6 +56,10 @@ public partial class MainWindow : Window, IWindowController, IFdc3AppSink // is disposed, so every continuation checks this before touching it. private bool _closed; + // True after Flash() until StopFlash(), or until the window comes to the foreground + // (FLASHW_TIMERNOFG). Read from the WebView thread; written on the UI thread. + private volatile bool _flashing; + /// The App Directory appId this window's page runs as. /// Set when FDC3 launched this window; the agent is waiting on this id. /// Overrides WEB_URL (FDC3-launched windows load their App Directory URL). @@ -70,6 +74,7 @@ public MainWindow(IConfiguration configuration, DesktopAgent fdc3, string fdc3Ap // A remote debugging port already means "dev/test run"; test-only commands ride on that. _bridge = new HostBridge( () => _fdc3Connection ?? throw new InvalidOperationException("FDC3 not connected yet."), + this, testHooks: _cdpPort > 0); // TITLE_BAR=client (default) lets the web app draw the title bar; TITLE_BAR=native @@ -82,8 +87,11 @@ public MainWindow(IConfiguration configuration, DesktopAgent fdc3, string fdc3Ap Loaded += OnLoaded; StateChanged += OnStateChanged; + // FLASHW_TIMERNOFG stops on its own once this window is in front; keep our flag in step. + Activated += OnWindowActivated; // A toast (or one of its buttons) was clicked: surface the window and tell the web app. + NotificationService.ToastShown += OnNotificationShown; NotificationService.Activated += OnNotificationActivated; WindowRegistry.Add(this); // With the tray icon on, closing the main window only hides it; the tray's Quit is the way out. @@ -96,6 +104,8 @@ public MainWindow(IConfiguration configuration, DesktopAgent fdc3, string fdc3Ap Closed += (_, _) => { _closed = true; + StopFlash(); + NotificationService.ToastShown -= OnNotificationShown; NotificationService.Activated -= OnNotificationActivated; _fdc3Connection?.Dispose(); _fdc3Connection = null; @@ -108,17 +118,31 @@ public MainWindow(IConfiguration configuration, DesktopAgent fdc3, string fdc3Ap }; } - // Only the app's main window reacts to toast clicks (every window is subscribed to the static event). + // Only the app's main window reacts to toasts (every window is subscribed to the static events). + private void OnNotificationShown() => Dispatcher.Invoke(() => + { + if (_closed || WindowRegistry.Main != this) return; + if (!((IWindowController)this).IsFocused) + Flash(); + }); + private void OnNotificationActivated(NotificationActivation activation) => Dispatcher.Invoke(() => { if (_closed || WindowRegistry.Main != this) return; + StopFlash(); ShowWindow(); Activate(); if (_webView.CoreWebView2 is not null) PushEvent(activation); }); + private void OnWindowActivated(object? sender, EventArgs e) + { + if (_closed || !_flashing) return; + StopFlash(); + } + private Task GetEnvironmentAsync() { if (_environment is not null) return _environment; @@ -430,6 +454,57 @@ public void SetProgressValue(double value) }); } + public void Flash() => ApplyWindowAction(() => + { + // TIMERNOFG does not keep flashing a window that is already in front. + var foreground = IsWindowForeground(); + FlashWindow(foreground ? FLASHW_STOP : (FLASHW_TRAY | FLASHW_TIMERNOFG)); + _flashing = NativeWindowHandle != IntPtr.Zero && !foreground; + }); + + public void StopFlash() => ApplyWindowAction(() => + { + FlashWindow(FLASHW_STOP); + _flashing = false; + }); + + public bool IsFlashing => _flashing; + + // FLASHW_TRAY | FLASHW_TIMERNOFG flashes the taskbar button until this window is in + // the foreground or FLASHW_STOP. dwTimeout 0 uses the caret blink rate. + private const uint FLASHW_STOP = 0; + private const uint FLASHW_TRAY = 0x00000002; + private const uint FLASHW_TIMERNOFG = 0x0000000C; + + [StructLayout(LayoutKind.Sequential)] + private struct FLASHWINFO + { + public uint cbSize; + public IntPtr hwnd; + public uint dwFlags; + public uint uCount; + public uint dwTimeout; + } + + [DllImport("user32.dll")] + private static extern bool FlashWindowEx(ref FLASHWINFO pwfi); + + private void FlashWindow(uint flags) + { + var hwnd = NativeWindowHandle; + if (hwnd == IntPtr.Zero) return; + + var info = new FLASHWINFO + { + cbSize = (uint)Marshal.SizeOf(), + hwnd = hwnd, + dwFlags = flags, + uCount = flags == FLASHW_STOP ? 0u : uint.MaxValue, + dwTimeout = 0, + }; + FlashWindowEx(ref info); + } + [DllImport("user32.dll", EntryPoint = "GetForegroundWindow")] private static extern IntPtr NativeGetForegroundWindow(); diff --git a/src/Bermuda/NotificationService.cs b/src/Bermuda/NotificationService.cs index 5af0970..9060887 100644 --- a/src/Bermuda/NotificationService.cs +++ b/src/Bermuda/NotificationService.cs @@ -27,6 +27,9 @@ internal static class NotificationService /// Raised (on a background thread) when a toast or one of its buttons is clicked. public static event Action? Activated; + /// Raised (possibly off the UI thread) after a toast has been shown. + public static event Action? ToastShown; + public static void Initialize() { var manager = AppNotificationManager.Default; @@ -181,6 +184,7 @@ public static async Task ShowAsync(ShowNotificationReque AppNotificationManager.Default.Show(notification); Shown[id] = new ShownToast(bodyArguments, buttonArguments, hasReply); + ToastShown?.Invoke(); return new(true, ""); } catch (Exception ex) From f9e3d7906f9effe4fcf56fe4ff88b3de59e6e8cb Mon Sep 17 00:00:00 2001 From: Oleg Date: Mon, 16 Nov 2026 22:59:22 -0500 Subject: [PATCH 2/2] fix: drive taskbar flash through windowController Co-authored-by: Cursor --- src/Bermuda.Fdc3.Tests/IpcDispatchTests.cs | 10 ------ src/Bermuda.IpcContract/IpcModels.cs | 20 ------------ src/Bermuda.Web/e2e/host-api.spec.ts | 32 +++++++------------ src/Bermuda.Web/src/bridge/index.ts | 6 ++-- .../src/ipc/__generated__/ipc.d.ts | 8 ++--- src/Bermuda/HostBridge.cs | 10 +----- src/Bermuda/MainWindow.xaml.cs | 1 - src/Bermuda/WindowScriptHost.cs | 4 +++ 8 files changed, 23 insertions(+), 68 deletions(-) diff --git a/src/Bermuda.Fdc3.Tests/IpcDispatchTests.cs b/src/Bermuda.Fdc3.Tests/IpcDispatchTests.cs index e8b55df..cef6337 100644 --- a/src/Bermuda.Fdc3.Tests/IpcDispatchTests.cs +++ b/src/Bermuda.Fdc3.Tests/IpcDispatchTests.cs @@ -15,9 +15,6 @@ public class IpcDispatchTests [Theory] [InlineData("ping", typeof(IHostCommands))] - [InlineData("window.flash", typeof(IWindowCommands))] - [InlineData("window.stopFlash", typeof(IWindowCommands))] - [InlineData("window.isFlashing", typeof(IWindowCommands))] [InlineData("fdc3.getInfo", typeof(IFdc3Commands))] [InlineData("fdc3.raiseIntent", typeof(IFdc3Commands))] // "Async" suffix dropped [InlineData("fdc3.getIntentResult", typeof(IFdc3Commands))] @@ -36,13 +33,6 @@ public void Every_fdc3_command_is_discovered() Assert.Equal(typeof(IFdc3Commands).GetMethods().Length, discovered); } - [Fact] - public void Every_window_command_is_discovered() - { - var discovered = IpcContract.IpcContract.Commands.Count(c => c.Interface == typeof(IWindowCommands)); - Assert.Equal(typeof(IWindowCommands).GetMethods().Length, discovered); - } - [Fact] public async Task CamelCase_payloads_bind_to_typed_parameters() { diff --git a/src/Bermuda.IpcContract/IpcModels.cs b/src/Bermuda.IpcContract/IpcModels.cs index 0fd1748..ec54c20 100644 --- a/src/Bermuda.IpcContract/IpcModels.cs +++ b/src/Bermuda.IpcContract/IpcModels.cs @@ -24,26 +24,6 @@ public interface IHostCommands SimulateNotificationActivationResult SimulateNotificationActivation(SimulateNotificationActivationRequest request); } -/// -/// Window commands (window.flash, window.stopFlash, window.isFlashing). -/// Implemented by HostBridge, which forwards them to that window's controller. -/// -[IpcCommands("window")] -public interface IWindowCommands -{ - /// - /// Flashes the taskbar button until the window is in the foreground or window.stopFlash runs. - /// While the window is already in the foreground the call does not leave it flashing. - /// - void Flash(); - - /// Stops the taskbar button flashing. - void StopFlash(); - - /// True while the taskbar button is flashing. - bool IsFlashing(); -} - /// /// A postMessage request from the web side to HostBridge. Payload /// is deliberately untyped (its shape depends on Command). diff --git a/src/Bermuda.Web/e2e/host-api.spec.ts b/src/Bermuda.Web/e2e/host-api.spec.ts index 1411a32..13ef7f3 100644 --- a/src/Bermuda.Web/e2e/host-api.spec.ts +++ b/src/Bermuda.Web/e2e/host-api.spec.ts @@ -301,7 +301,7 @@ test.describe('taskbar flash', () => { let original: Snapshot test.beforeEach(async ({ page }) => { - await inPage(page, "await bermudaHost.invoke('window.stopFlash')") + await inPage(page, 'await chrome.webview.hostObjects.windowController.StopFlash()') original = await getState(page) }) @@ -309,8 +309,8 @@ test.describe('taskbar flash', () => { test.afterEach(async ({ page }) => { await inPage( page, - `await bermudaHost.invoke('window.stopFlash') - const c = chrome.webview.hostObjects.windowController + `const c = chrome.webview.hostObjects.windowController + await c.StopFlash() await c.Restore() await c.Resize(${original.bounds.width}, ${original.bounds.height}) await c.Move(${original.bounds.left}, ${original.bounds.top}) @@ -318,10 +318,11 @@ test.describe('taskbar flash', () => { ) }) - const isFlashing = (page: Page) => inPage(page, "return await bermudaHost.invoke('window.isFlashing')") + const isFlashing = (page: Page) => + inPage(page, 'return await chrome.webview.hostObjects.windowController.IsFlashing') test('window.stopFlash is safe when the taskbar is not flashing', async ({ page }) => { - expect(await inPage(page, "return await bermudaHost.invoke('window.stopFlash')")).toBeNull() + await inPage(page, 'await chrome.webview.hostObjects.windowController.StopFlash()') expect(await isFlashing(page)).toBe(false) }) @@ -329,10 +330,10 @@ test.describe('taskbar flash', () => { await inPage(page, 'await chrome.webview.hostObjects.windowController.Minimize()') expect(await inPage(page, 'return await chrome.webview.hostObjects.windowController.IsFocused')).toBe(false) - expect(await inPage(page, "return await bermudaHost.invoke('window.flash')")).toBeNull() + await inPage(page, 'await chrome.webview.hostObjects.windowController.Flash()') expect(await isFlashing(page)).toBe(true) - expect(await inPage(page, "return await bermudaHost.invoke('window.stopFlash')")).toBeNull() + await inPage(page, 'await chrome.webview.hostObjects.windowController.StopFlash()') expect(await isFlashing(page)).toBe(false) }) @@ -341,25 +342,16 @@ test.describe('taskbar flash', () => { const focused = await inPage(page, 'return await chrome.webview.hostObjects.windowController.IsFocused') test.skip(!focused, 'This session did not leave the Bermuda window in the foreground.') - expect(await inPage(page, "return await bermudaHost.invoke('window.flash')")).toBeNull() - expect(await isFlashing(page)).toBe(false) - }) - - test('command names are matched case-insensitively', async ({ page }) => { - await inPage(page, 'await chrome.webview.hostObjects.windowController.Minimize()') - expect(await inPage(page, "return await bermudaHost.invoke('WINDOW.FLASH')")).toBeNull() - expect(await isFlashing(page)).toBe(true) - - expect(await inPage(page, "return await bermudaHost.invoke('Window.StopFlash')")).toBeNull() + await inPage(page, 'await chrome.webview.hostObjects.windowController.Flash()') expect(await isFlashing(page)).toBe(false) }) - test('bermudaHost.window.flash and stopFlash call the same commands', async ({ page }) => { + test('bermudaHost.window.flash and stopFlash call the host object', async ({ page }) => { await inPage(page, 'await chrome.webview.hostObjects.windowController.Minimize()') - expect(await inPage(page, 'return await bermudaHost.window.flash()')).toBeNull() + await inPage(page, 'await bermudaHost.window.flash()') expect(await inPage(page, 'return await bermudaHost.window.isFlashing()')).toBe(true) - expect(await inPage(page, 'return await bermudaHost.window.stopFlash()')).toBeNull() + await inPage(page, 'await bermudaHost.window.stopFlash()') expect(await inPage(page, 'return await bermudaHost.window.isFlashing()')).toBe(false) }) diff --git a/src/Bermuda.Web/src/bridge/index.ts b/src/Bermuda.Web/src/bridge/index.ts index 392168a..e084239 100644 --- a/src/Bermuda.Web/src/bridge/index.ts +++ b/src/Bermuda.Web/src/bridge/index.ts @@ -96,11 +96,11 @@ const windowApi = { * Flashes the taskbar button until the window is in the foreground or stopFlash() runs. * A window that is already in front is left not flashing. */ - flash: () => invoke('window.flash'), + flash: () => windowController().Flash(), /** Stops taskbar flashing started by flash(). */ - stopFlash: () => invoke('window.stopFlash'), + stopFlash: () => windowController().StopFlash(), /** True while the taskbar button is flashing. */ - isFlashing: () => invoke('window.isFlashing'), + isFlashing: () => windowController().IsFlashing, } as const export type WindowApi = typeof windowApi diff --git a/src/Bermuda.Web/src/ipc/__generated__/ipc.d.ts b/src/Bermuda.Web/src/ipc/__generated__/ipc.d.ts index ce2488b..3a9717f 100644 --- a/src/Bermuda.Web/src/ipc/__generated__/ipc.d.ts +++ b/src/Bermuda.Web/src/ipc/__generated__/ipc.d.ts @@ -264,6 +264,7 @@ export interface WindowControllerHostObject { readonly Top: Promise; readonly Width: Promise; readonly Height: Promise; + readonly IsFlashing: Promise; Minimize(): Promise; Maximize(): Promise; Restore(): Promise; @@ -277,6 +278,8 @@ export interface WindowControllerHostObject { ClearOverlayIcon(): Promise; SetProgressState(state: string): Promise; SetProgressValue(value: number): Promise; + Flash(): Promise; + StopFlash(): Promise; } export interface IpcMethods { @@ -311,11 +314,6 @@ export interface IpcMethods { sendIntentResult: (payload: Fdc3SendIntentResultRequest, ) => Promise; unsubscribe: (payload: Fdc3ListenerIdRequest, ) => Promise; }; - window: { - flash: () => Promise; - isFlashing: () => Promise; - stopFlash: () => Promise; - }; } export interface IpcHostObjects { diff --git a/src/Bermuda/HostBridge.cs b/src/Bermuda/HostBridge.cs index 86bc155..887d7d8 100644 --- a/src/Bermuda/HostBridge.cs +++ b/src/Bermuda/HostBridge.cs @@ -17,11 +17,10 @@ namespace Bermuda; /// This window's current FDC3 connection, read per call because a page reload /// reconnects as a new instance (see MainWindow.OnContentLoading). /// -/// This window, for window.* commands. /// Enables dev/test-only commands (MainWindow: when CDP_PORT is set). [ClassInterface(ClassInterfaceType.AutoDual)] [ComVisible(true)] -public class HostBridge(Func fdc3, IWindowController window, bool testHooks = false) : IHostCommands, IWindowCommands +public class HostBridge(Func fdc3, bool testHooks = false) : IHostCommands { /// Web preset (camelCase, case-insensitive) with enums as camelCase strings, matching the generated TS unions. public static JsonSerializerOptions PayloadJson { get; } = new(JsonSerializerDefaults.Web) @@ -53,12 +52,6 @@ public Task ShowNotificationAsync(ShowNotificationReques public SimulateNotificationActivationResult SimulateNotificationActivation(SimulateNotificationActivationRequest request) => NotificationService.Simulate(request); - public void Flash() => window.Flash(); - - public void StopFlash() => window.StopFlash(); - - public bool IsFlashing() => window.IsFlashing; - public async Task HandleAsync(string command, object? payload) { if (IpcContract.IpcContract.Find(command) is not { } ipcCommand) @@ -94,6 +87,5 @@ public SimulateNotificationActivationResult SimulateNotificationActivation(Simul private object TargetFor(Type commands) => commands == typeof(IFdc3Commands) ? fdc3() : commands == typeof(IHostCommands) ? this - : commands == typeof(IWindowCommands) ? this : throw new InvalidOperationException($"No handler for {commands.Name}."); } diff --git a/src/Bermuda/MainWindow.xaml.cs b/src/Bermuda/MainWindow.xaml.cs index f1eeee6..f9849ad 100644 --- a/src/Bermuda/MainWindow.xaml.cs +++ b/src/Bermuda/MainWindow.xaml.cs @@ -74,7 +74,6 @@ public MainWindow(IConfiguration configuration, DesktopAgent fdc3, string fdc3Ap // A remote debugging port already means "dev/test run"; test-only commands ride on that. _bridge = new HostBridge( () => _fdc3Connection ?? throw new InvalidOperationException("FDC3 not connected yet."), - this, testHooks: _cdpPort > 0); // TITLE_BAR=client (default) lets the web app draw the title bar; TITLE_BAR=native diff --git a/src/Bermuda/WindowScriptHost.cs b/src/Bermuda/WindowScriptHost.cs index 8ef3f41..b54096b 100644 --- a/src/Bermuda/WindowScriptHost.cs +++ b/src/Bermuda/WindowScriptHost.cs @@ -57,4 +57,8 @@ public void ToggleMaximize() public void SetProgressState(string state) => _window.SetProgressState(state); public void SetProgressValue(double value) => _window.SetProgressValue(value); + + public void Flash() => _window.Flash(); + public void StopFlash() => _window.StopFlash(); + public bool IsFlashing => _window.IsFlashing; }