Skip to content

Desktop MessageDialog: extended button support and non-blocking macOS sheets #64

Done

Description

@glatiuden

Environment

  • Package / Binding: nativeapi-core (via Dart / Flutter nativeapi / cnativeapi)
  • Version: 0.6.2 / main
  • OS: macOS, Windows, Linux

Summary

While integrating MessageDialog into a Flutter desktop app, I noticed two limitations in the desktop implementations:

1. Custom buttons aren't supported on any of the three desktop backends.

message_dialog_extensions.inc already defines SetButtons(primary, secondary, close), SetDefaultButton, and SetParentWindow. However, MessageDialog::IsExtendedSupported() currently returns false on macOS, Windows (Win32), and Linux.

As a result, each platform falls back to a single OK button (NSAlert default, MB_OK | MB_ICONINFORMATION, and GTK_BUTTONS_OK respectively).

2. macOS MessageDialog blocks the calling thread.

message_dialog_macos.mm uses [ns_alert runModal] for all modalities. In apps where UI and script execution share the main thread (such as Flutter), this blocks rendering until the user dismisses the alert. Close() also can't currently dismiss an open dialog programmatically.

(I also noticed that ios/message_dialog_ios.mm appears to be a stub. Happy to look into that separately after the desktop changes.)

Proposed Plan

If these are areas the project is open to improving, I'd be happy to contribute PRs for both.

1. Add extended button support to desktop backends (IsExtendedSupported() = true)

This would use the existing state in message_dialog_extensions.inc, without requiring changes to the C ABI or codegen.

  • Windows (Win32): Use TaskDialogIndirect with TASKDIALOG_BUTTON entries and nDefaultButton.
  • macOS: Add buttons using addButtonWithTitle: and configure the key equivalent for the default button.
  • Linux: Use GTK_BUTTONS_NONE, add each configured button with gtk_dialog_add_button, and set the default response with gtk_dialog_set_default_response on the current GTK 3 backend. This can be updated to GtkAlertDialog when libnativeapi/nativeapi-core#103 lands.
  • Add a multi-button example under examples/ to test button labels, Return/Escape handling, and returned results across all three platforms.

2. Make macOS sheet dialogs non-blocking

  • When a parent window is provided, present the alert using beginSheetModalForWindow:completionHandler: and return the result through the completion handler.
  • Implement Close() using [parentWindow endSheet:].
  • Keep runModal for cases where no parent window is provided, as documented.

Activity

  1. lijy91 commented on Nov 30, 2026

    @lijy91
    Member

    Implemented and merged in libnativeapi/nativeapi-core#108:

    • Desktop extended MessageDialog support (IsExtendedSupported() == true) across macOS, Windows (Win32), and Linux (GTK 3) without changing the C ABI:
      • macOS (NSAlert): fresh NSAlert per Open(), custom primary / secondary / close buttons, Return (default) and Escape (close) key equivalents configured after [alert layout], result mapping, plus checkbox, text input, and live-updating progress bar.
      • macOS non-blocking sheets & Close(): uses beginSheetModalForWindow:completionHandler: when SetParentWindow is set, updates IsOpen() / GetResult() in the completion handler, and dismisses via endSheet:returnCode: (keeping runModal when no parent window is set).
      • Windows (Win32): dynamically loads TaskDialogIndirect (with a ComCtl32 v6 activation context fallback for manifest-less hosts, falling back to MessageBoxW if unavailable) with custom TASKDIALOG_BUTTONs, nDefaultButton, hwndParent, checkbox, progress bar, and programmatic Close().
      • Linux (GTK 3): uses GTK_BUTTONS_NONE + gtk_dialog_add_button + gtk_dialog_set_default_response, parent window support, result mapping, and optional input/checkbox/progress controls.
    • Verified on macOS, Windows 11, Ubuntu GNOME, and Arch Hyprland (plus all 10 CI targets in nativeapi-core).

    Feel free to open a separate issue or PR if you'd like to follow up on iOS (message_dialog_ios.mm). Thanks for the detailed report and design!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions