Repository navigation
Consider adding Windows plugin API to post tasks to main thread #79213
Copy link
Copy link
Closed
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projecta: desktopRunning on desktopRunning on desktopa: pluginsSupport for writing, building, and running plugin packagesSupport for writing, building, and running plugin packagesc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterengineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.platform-windowsBuilding on or for Windows specificallyBuilding on or for Windows specificallyteam-windowsOwned by the Windows platform teamOwned by the Windows platform teamtriaged-windowsTriaged by the Windows platform teamTriaged by the Windows platform team
Description
There are plugin APIs that can only be called from the main thread, but there's not a particularly good way for Windows plugins to move calls to that thread AFAIK. Options include:
- Each plugin doing the hidden-window message loop implementation themselves.
- Using the top-level window proc override registration to send themselves a custom message and hope nobody else uses it in a way that interferes.
This came up in the Texture PR and the solution there was to make most of it thread-safe; applying that more broadly is another option (e.g., to event streams). But a generic way to move things to the main thread would avoid needing to make lots of thread-safe APIs.
Proposed API:
class FlutterEngine : public PluginRegistry {
// ...
// Schedule a callback to be called on the platform thread.
//
// This may be called on any thread. The callback is executed only
// once on the platform thread.
void PostPlatformThreadTask(std::function<void()> callback);
}// Schedule a callback to be invoked on the engine's platform thread.
//
// This may be called on any thread. The callback is executed only
// once on the platform thread.
FLUTTER_EXPORT void FlutterDesktopEnginePostPlatformThreadTask(
FlutterDesktopEngineRef engine,
VoidCallback callback,
void* user_data);/cc @cbracken
(We would only do one of #134346 and this.)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projecta: desktopRunning on desktopRunning on desktopa: pluginsSupport for writing, building, and running plugin packagesSupport for writing, building, and running plugin packagesc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterengineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.platform-windowsBuilding on or for Windows specificallyBuilding on or for Windows specificallyteam-windowsOwned by the Windows platform teamOwned by the Windows platform teamtriaged-windowsTriaged by the Windows platform teamTriaged by the Windows platform team
Activity
Sunbreak commentedon Mar 28, 2021
hidden-window message loop implementation for further reference: flutter-team-archive/engine#24232
[-]Consider adding Windows plugin API to post talks to main thread[/-][+]Consider adding Windows plugin API to post tasks to main thread[/+]sebastianhaberey commentedon Sep 9, 2023
Just dropping in to say this would be immensely helpful for an issue I am currently facing with my plugin. Until then, would you advise me to use the linked commit as a template for a hidden message loop within the plugin?
stuartmorgan-g commentedon Sep 9, 2023
As discussed in flutter-team-archive/engine#31134, the preferred solution to the problem you describe in that issue is for the Windows embedding API to be made thread safe.
7 remaining items
flutter-triage-bot commentedon Jun 7, 2024
The
triaged-desktoplabel is irrelevant if there is noteam-desktoplabel orfyi-desktoplabel.Ae-Mc commentedon Aug 14, 2025
[Windows] Add public API to post task to platform thread (flutter#187365
loic-sharma commentedon Jun 24, 2026
Added by: #187365
[Windows] Add public API to post task to platform thread (flutter#187365
github-actions commentedon Jul 14, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.