Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/MauiDevFlow.Agent.Core/DevFlowAgentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,37 @@ protected virtual async Task<HttpResponse> HandleScreenshot(HttpRequest request)
var pngData = await DispatchAsync(async () =>
{
var window = GetWindow(windowIndex);
if (window?.Page is not VisualElement rootElement) return null;
if (window == null) return null;

// If a modal page is displayed, capture it instead of the underlying page
VisualElement? topModal = null;
try
{
var modalStack = window.Page?.Navigation?.ModalStack;
if (modalStack?.Count > 0 && modalStack[^1] is VisualElement ms)
topModal = ms;
}
catch { }

// Fallback: check Window's visual children for modal pages
// (on some platforms like GTK, modals appear as direct children of the Window)
if (topModal == null && window is IVisualTreeElement windowVte)
{
var children = windowVte.GetVisualChildren();
for (int i = children.Count - 1; i >= 0; i--)
{
if (children[i] is Page page && page != window.Page)
{
topModal = page;
break;
}
}
}

if (topModal != null)
return await CaptureScreenshotAsync(topModal);

if (window.Page is not VisualElement rootElement) return null;

return await CaptureScreenshotAsync(rootElement);
});
Expand Down
13 changes: 12 additions & 1 deletion src/MauiDevFlow.Agent.Gtk/GtkAgentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,18 @@ protected override bool TryNativeTap(VisualElement ve)
}
catch { }

// GTK4-specific fallback: capture via Gtk.WidgetPaintable
// GTK4-specific fallback: capture the rootElement's native widget directly
try
{
if (rootElement.Handler?.PlatformView is global::Gtk.Widget widget)
{
var pngBytes = CaptureGtkWidget(widget);
if (pngBytes != null) return pngBytes;
}
}
catch { }

// Final fallback: capture the main GTK window
try
{
var window = Application.Current?.Windows.FirstOrDefault();
Expand Down
2 changes: 1 addition & 1 deletion src/MauiDevFlow.Agent.Gtk/MauiDevFlow.Agent.Gtk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Platform.Maui.Linux.Gtk4" Version="0.2.3" />
<PackageReference Include="Platform.Maui.Linux.Gtk4" Version="0.5.0" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/MauiDevFlow.Blazor.Gtk/MauiDevFlow.Blazor.Gtk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Platform.Maui.Linux.Gtk4.BlazorWebView" Version="0.2.3" />
<PackageReference Include="Platform.Maui.Linux.Gtk4.BlazorWebView" Version="0.5.0" />
</ItemGroup>

<!-- Embed JS scripts as resources -->
Expand Down
6 changes: 3 additions & 3 deletions src/SampleMauiApp.Linux/SampleMauiApp.Linux.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Platform.Maui.Linux.Gtk4" Version="0.2.3" />
<PackageReference Include="Platform.Maui.Linux.Gtk4.BlazorWebView" Version="0.2.3" />
<PackageReference Include="Platform.Maui.Linux.Gtk4.Essentials" Version="0.2.3" />
<PackageReference Include="Platform.Maui.Linux.Gtk4" Version="0.5.0" />
<PackageReference Include="Platform.Maui.Linux.Gtk4.BlazorWebView" Version="0.5.0" />
<PackageReference Include="Platform.Maui.Linux.Gtk4.Essentials" Version="0.5.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="10.0.0" />
</ItemGroup>
Expand Down
Loading