refactor: replace Console.WriteLine with DiagnosticLog service
All checks were successful
CI / Build (Linux) (push) Successful in 21s

Replace 495+ Console.WriteLine debug statements across handlers, dispatching, services, views, and window components with centralized DiagnosticLog service for proper logging infrastructure. Add new DiagnosticLog.cs service with Debug/Error methods to eliminate debug logging pollution in production code.
This commit is contained in:
2026-03-06 22:06:08 -05:00
parent 08e0c4d2b9
commit e55230c441
70 changed files with 814 additions and 638 deletions

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Platform.Linux.Services;
using SkiaSharp;
namespace Microsoft.Maui.Platform;
@@ -63,10 +64,10 @@ public static class LinuxDialogService
public static void DrawDialogsOnly(SKCanvas canvas, SKRect bounds)
{
Console.WriteLine($"[LinuxDialogService] DrawDialogsOnly: {_activeDialogs.Count} dialogs, IsDarkMode={SkiaTheme.IsDarkMode}");
DiagnosticLog.Debug("LinuxDialogService", $"DrawDialogsOnly: {_activeDialogs.Count} dialogs, IsDarkMode={SkiaTheme.IsDarkMode}");
foreach (var dialog in _activeDialogs)
{
Console.WriteLine($"[LinuxDialogService] Drawing dialog: IsVisible={dialog.IsVisible}, Opacity={dialog.Opacity}");
DiagnosticLog.Debug("LinuxDialogService", $"Drawing dialog: IsVisible={dialog.IsVisible}, Opacity={dialog.Opacity}");
dialog.Measure(new Size(bounds.Width, bounds.Height));
dialog.Arrange(new Rect(bounds.Left, bounds.Top, bounds.Width, bounds.Height));
dialog.Draw(canvas);
@@ -89,7 +90,7 @@ public static class LinuxDialogService
public static void ShowContextMenu(SkiaContextMenu menu)
{
Console.WriteLine("[LinuxDialogService] ShowContextMenu called");
DiagnosticLog.Debug("LinuxDialogService", "ShowContextMenu called");
_activeContextMenu = menu;
_showPopupCallback?.Invoke();
_invalidateCallback?.Invoke();

View File

@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.Maui.Platform.Linux.Interop;
using Microsoft.Maui.Platform.Linux.Services;
using SkiaSharp;
namespace Microsoft.Maui.Platform;
@@ -111,7 +112,7 @@ public class LinuxWebView : SkiaView
_gtkWindow = WebKitGtk.gtk_window_new(0);
if (_gtkWindow == IntPtr.Zero)
{
Console.WriteLine("[LinuxWebView] Failed to create GTK window");
DiagnosticLog.Error("LinuxWebView", "Failed to create GTK window");
return;
}
@@ -123,7 +124,7 @@ public class LinuxWebView : SkiaView
_webView = WebKitGtk.webkit_web_view_new();
if (_webView == IntPtr.Zero)
{
Console.WriteLine("[LinuxWebView] Failed to create WebKit WebView");
DiagnosticLog.Error("LinuxWebView", "Failed to create WebKit WebView");
WebKitGtk.gtk_widget_destroy(_gtkWindow);
_gtkWindow = IntPtr.Zero;
return;
@@ -148,12 +149,12 @@ public class LinuxWebView : SkiaView
WebKitGtk.gtk_container_add(_gtkWindow, _webView);
_initialized = true;
Console.WriteLine("[LinuxWebView] WebKitGTK WebView initialized successfully");
DiagnosticLog.Debug("LinuxWebView", "WebKitGTK WebView initialized successfully");
}
catch (Exception ex)
{
Console.WriteLine($"[LinuxWebView] Initialization failed: {ex.Message}");
Console.WriteLine($"[LinuxWebView] Make sure WebKitGTK is installed: sudo apt install libwebkit2gtk-4.1-0");
DiagnosticLog.Error("LinuxWebView", $"Initialization failed: {ex.Message}", ex);
DiagnosticLog.Warn("LinuxWebView", "Make sure WebKitGTK is installed: sudo apt install libwebkit2gtk-4.1-0");
}
}

View File

@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.Maui.Platform.Linux.Services;
using SkiaSharp;
namespace Microsoft.Maui.Platform;
@@ -62,7 +63,7 @@ public class SkiaAlertDialog : SkiaView
protected override void OnDraw(SKCanvas canvas, SKRect bounds)
{
var app = Application.Current;
Console.WriteLine($"[SkiaAlertDialog] OnDraw: app={app != null}, UserAppTheme={app?.UserAppTheme}, RequestedTheme={app?.RequestedTheme}, IsDarkMode={SkiaTheme.IsDarkMode}, DialogBg={DialogBackground}");
DiagnosticLog.Debug("SkiaAlertDialog", $"OnDraw: app={app != null}, UserAppTheme={app?.UserAppTheme}, RequestedTheme={app?.RequestedTheme}, IsDarkMode={SkiaTheme.IsDarkMode}, DialogBg={DialogBackground}");
// Draw semi-transparent overlay covering entire screen
using var overlayPaint = new SKPaint

View File

@@ -6,6 +6,7 @@ using System.Windows.Input;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Platform.Linux.Rendering;
using Microsoft.Maui.Platform.Linux.Services;
using SkiaSharp;
namespace Microsoft.Maui.Platform;
@@ -1096,7 +1097,7 @@ public class SkiaButton : SkiaView, IButtonController
var result = new Size(Math.Max(width, 44f), Math.Max(height, 36f));
if (Text == "Round")
Console.WriteLine($"[SkiaButton.Measure] Text='Round' WReq={WidthRequest} HReq={HeightRequest} width={width:F1} height={height:F1} result={result.Width:F0}x{result.Height:F0}");
DiagnosticLog.Debug("SkiaButton", $"Measure Text='Round' WReq={WidthRequest} HReq={HeightRequest} width={width:F1} height={height:F1} result={result.Width:F0}x{result.Height:F0}");
return result;
}

View File

@@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Platform.Linux.Services;
using SkiaSharp;
namespace Microsoft.Maui.Platform;
@@ -460,7 +461,7 @@ public class SkiaCollectionView : SkiaItemsView
}
catch (Exception ex)
{
Console.WriteLine("[SkiaCollectionView.DrawItem] EXCEPTION: " + ex.Message + "\n" + ex.StackTrace);
DiagnosticLog.Error("SkiaCollectionView", "DrawItem EXCEPTION: " + ex.Message + "\n" + ex.StackTrace, ex);
return;
}
}

View File

@@ -1087,13 +1087,13 @@ public class SkiaEditor : SkiaView, IInputContext
public override void OnPointerPressed(PointerEventArgs e)
{
Console.WriteLine($"[SkiaEditor] OnPointerPressed: Button={e.Button}, IsEnabled={IsEnabled}");
DiagnosticLog.Debug("SkiaEditor", $"OnPointerPressed: Button={e.Button}, IsEnabled={IsEnabled}");
if (!IsEnabled) return;
// Handle right-click context menu
if (e.Button == PointerButton.Right)
{
Console.WriteLine("[SkiaEditor] Right-click detected, showing context menu");
DiagnosticLog.Debug("SkiaEditor", "Right-click detected, showing context menu");
ShowContextMenu(e.X, e.Y);
return;
}
@@ -1532,7 +1532,7 @@ public class SkiaEditor : SkiaView, IInputContext
private void ShowContextMenu(float x, float y)
{
Console.WriteLine($"[SkiaEditor] ShowContextMenu at ({x}, {y}), IsGtkMode={LinuxApplication.IsGtkMode}");
DiagnosticLog.Debug("SkiaEditor", $"ShowContextMenu at ({x}, {y}), IsGtkMode={LinuxApplication.IsGtkMode}");
bool hasSelection = _selectionLength != 0;
bool hasText = !string.IsNullOrEmpty(Text);
bool hasClipboard = !string.IsNullOrEmpty(SystemClipboard.GetText());

View File

@@ -1644,7 +1644,7 @@ public class SkiaEntry : SkiaView, IInputContext
private void ShowContextMenu(float x, float y)
{
Console.WriteLine($"[SkiaEntry] ShowContextMenu at ({x}, {y}), IsGtkMode={LinuxApplication.IsGtkMode}");
DiagnosticLog.Debug("SkiaEntry", $"ShowContextMenu at ({x}, {y}), IsGtkMode={LinuxApplication.IsGtkMode}");
bool hasSelection = _selectionLength != 0;
bool hasText = !string.IsNullOrEmpty(Text);
bool hasClipboard = !string.IsNullOrEmpty(SystemClipboard.GetText());

View File

@@ -11,6 +11,7 @@ using System.Threading.Tasks;
using System.Timers;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Platform.Linux.Services;
using SkiaSharp;
using Svg.Skia;
@@ -513,7 +514,7 @@ public class SkiaImage : SkiaView
_isSvg = false;
_currentFilePath = null;
_cacheKey = null;
Console.WriteLine($"[SkiaImage] File not found: {filePath}");
DiagnosticLog.Warn("SkiaImage", $"File not found: {filePath}");
ImageLoadingError?.Invoke(this, new ImageLoadingErrorEventArgs(new FileNotFoundException(filePath)));
return;
}
@@ -1210,7 +1211,7 @@ public class SkiaImage : SkiaView
var stream = assembly.GetManifestResourceStream(resourceName);
if (stream != null)
{
Console.WriteLine($"[SkiaImage] Loaded embedded resource: {resourceName}");
DiagnosticLog.Debug("SkiaImage", $"Loaded embedded resource: {resourceName}");
return (stream, requestedExt);
}
}
@@ -1227,7 +1228,7 @@ public class SkiaImage : SkiaView
var stream = assembly.GetManifestResourceStream(resourceName);
if (stream != null)
{
Console.WriteLine($"[SkiaImage] Loaded SVG as PNG substitute: {resourceName}");
DiagnosticLog.Debug("SkiaImage", $"Loaded SVG as PNG substitute: {resourceName}");
return (stream, ".svg");
}
}

View File

@@ -9,6 +9,7 @@ using System.Threading.Tasks;
using System.Windows.Input;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Platform.Linux.Services;
using SkiaSharp;
using Svg.Skia;
@@ -422,7 +423,7 @@ public class SkiaImageButton : SkiaView
{
_isLoading = true;
Invalidate();
Console.WriteLine("[SkiaImageButton] LoadFromFileAsync: " + filePath);
DiagnosticLog.Debug("SkiaImageButton", "LoadFromFileAsync: " + filePath);
try
{
@@ -450,15 +451,15 @@ public class SkiaImageButton : SkiaView
if (File.Exists(path))
{
foundPath = path;
Console.WriteLine("[SkiaImageButton] Found file at: " + path);
DiagnosticLog.Debug("SkiaImageButton", "Found file at: " + path);
break;
}
}
if (foundPath == null)
{
Console.WriteLine("[SkiaImageButton] File not found: " + filePath);
Console.WriteLine("[SkiaImageButton] Searched paths: " + string.Join(", ", searchPaths));
DiagnosticLog.Warn("SkiaImageButton", "File not found: " + filePath);
DiagnosticLog.Debug("SkiaImageButton", "Searched paths: " + string.Join(", ", searchPaths));
_isLoading = false;
ImageLoadingError?.Invoke(this, new ImageLoadingErrorEventArgs(new FileNotFoundException(filePath)));
return;
@@ -498,7 +499,7 @@ public class SkiaImageButton : SkiaView
canvas.Translate(-cullRect.Left, -cullRect.Top);
canvas.DrawPicture(svg.Picture);
Bitmap = bitmap;
Console.WriteLine($"[SkiaImageButton] Loaded SVG: {foundPath} ({width}x{height}), cullRect={cullRect}");
DiagnosticLog.Debug("SkiaImageButton", $"Loaded SVG: {foundPath} ({width}x{height}), cullRect={cullRect}");
}
}
else
@@ -508,7 +509,7 @@ public class SkiaImageButton : SkiaView
if (bitmap != null)
{
Bitmap = bitmap;
Console.WriteLine("[SkiaImageButton] Loaded image: " + foundPath);
DiagnosticLog.Debug("SkiaImageButton", "Loaded image: " + foundPath);
}
}
});

View File

@@ -5,6 +5,7 @@ using SkiaSharp;
using System.Collections;
using System.Collections.Specialized;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Platform.Linux.Services;
namespace Microsoft.Maui.Platform;
@@ -114,7 +115,7 @@ public class SkiaItemsView : SkiaView
protected virtual void RefreshItems()
{
Console.WriteLine($"[SkiaItemsView] RefreshItems called, clearing {_items.Count} items and {_itemViewCache.Count} cached views");
DiagnosticLog.Debug("SkiaItemsView", $"RefreshItems called, clearing {_items.Count} items and {_itemViewCache.Count} cached views");
_items.Clear();
_itemViewCache.Clear(); // Clear cached views when items change
_itemHeights.Clear(); // Clear cached heights
@@ -125,7 +126,7 @@ public class SkiaItemsView : SkiaView
_items.Add(item);
}
}
Console.WriteLine($"[SkiaItemsView] RefreshItems done, now have {_items.Count} items");
DiagnosticLog.Debug("SkiaItemsView", $"RefreshItems done, now have {_items.Count} items");
_scrollOffset = 0;
}
@@ -194,7 +195,7 @@ public class SkiaItemsView : SkiaView
protected override void OnDraw(SKCanvas canvas, SKRect bounds)
{
Console.WriteLine($"[SkiaItemsView] OnDraw - bounds={bounds}, items={_items.Count}, ItemViewCreator={(ItemViewCreator != null ? "set" : "null")}");
DiagnosticLog.Debug("SkiaItemsView", $"OnDraw - bounds={bounds}, items={_items.Count}, ItemViewCreator={(ItemViewCreator != null ? "set" : "null")}");
// Draw background
if (BackgroundColor != null && BackgroundColor != Colors.Transparent)
@@ -283,7 +284,7 @@ public class SkiaItemsView : SkiaView
// Try to use ItemViewCreator for templated rendering
if (ItemViewCreator != null)
{
Console.WriteLine($"[SkiaItemsView] DrawItem {index} - ItemViewCreator exists, item: {item}");
DiagnosticLog.Debug("SkiaItemsView", $"DrawItem {index} - ItemViewCreator exists, item: {item}");
// Get or create cached view for this index
if (!_itemViewCache.TryGetValue(index, out var itemView) || itemView == null)
{
@@ -322,7 +323,7 @@ public class SkiaItemsView : SkiaView
}
else
{
Console.WriteLine($"[SkiaItemsView] DrawItem {index} - ItemViewCreator is NULL, falling back to ToString");
DiagnosticLog.Debug("SkiaItemsView", $"DrawItem {index} - ItemViewCreator is NULL, falling back to ToString");
}
// Draw separator
@@ -424,7 +425,7 @@ public class SkiaItemsView : SkiaView
public override void OnPointerPressed(PointerEventArgs e)
{
Console.WriteLine($"[SkiaItemsView] OnPointerPressed - x={e.X}, y={e.Y}, Bounds={Bounds}, ScreenBounds={ScreenBounds}, ItemCount={_items.Count}");
DiagnosticLog.Debug("SkiaItemsView", $"OnPointerPressed - x={e.X}, y={e.Y}, Bounds={Bounds}, ScreenBounds={ScreenBounds}, ItemCount={_items.Count}");
if (!IsEnabled) return;
// Check if clicking on scrollbar thumb
@@ -537,7 +538,7 @@ public class SkiaItemsView : SkiaView
cumulativeY += itemH + _itemSpacing;
}
Console.WriteLine($"[SkiaItemsView] Tap at Y={e.Y}, screenBounds.Top={screenBounds.Top}, scrollOffset={_scrollOffset}, localY={localY}, index={tappedIndex}");
DiagnosticLog.Debug("SkiaItemsView", $"Tap at Y={e.Y}, screenBounds.Top={screenBounds.Top}, scrollOffset={_scrollOffset}, localY={localY}, index={tappedIndex}");
if (tappedIndex >= 0 && tappedIndex < _items.Count)
{

View File

View File

@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Platform.Linux.Services;
using SkiaSharp;
using Microsoft.Maui;
@@ -227,10 +228,10 @@ public abstract class SkiaLayoutView : SkiaView
}
if (hasCV)
{
Console.WriteLine($"[SkiaStackLayout+CV] OnDraw - bounds={bounds}, children={_children.Count}");
DiagnosticLog.Debug("SkiaLayoutView", $"[SkiaStackLayout+CV] OnDraw - bounds={bounds}, children={_children.Count}");
foreach (var c in _children)
{
Console.WriteLine($"[SkiaStackLayout+CV] Child: {c.GetType().Name}, IsVisible={c.IsVisible}, Bounds={c.Bounds}");
DiagnosticLog.Debug("SkiaLayoutView", $"[SkiaStackLayout+CV] Child: {c.GetType().Name}, IsVisible={c.IsVisible}, Bounds={c.Bounds}");
}
}
}
@@ -959,9 +960,9 @@ public class SkiaGrid : SkiaLayoutView
}
catch (Exception ex)
{
Console.WriteLine($"[SkiaGrid] EXCEPTION in ArrangeOverride: {ex.GetType().Name}: {ex.Message}");
Console.WriteLine($"[SkiaGrid] Bounds: {bounds}, RowHeights: {_rowHeights.Length}, RowDefs: {_rowDefinitions.Count}, Children: {Children.Count}");
Console.WriteLine($"[SkiaGrid] Stack trace: {ex.StackTrace}");
DiagnosticLog.Error("SkiaGrid", $"EXCEPTION in ArrangeOverride: {ex.GetType().Name}: {ex.Message}", ex);
DiagnosticLog.Error("SkiaGrid", $"Bounds: {bounds}, RowHeights: {_rowHeights.Length}, RowDefs: {_rowDefinitions.Count}, Children: {Children.Count}");
DiagnosticLog.Error("SkiaGrid", $"Stack trace: {ex.StackTrace}");
throw;
}
}

View File

@@ -7,6 +7,7 @@ using System.Linq;
using System.Threading.Tasks;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Platform.Linux;
using Microsoft.Maui.Platform.Linux.Services;
using SkiaSharp;
namespace Microsoft.Maui.Platform;
@@ -123,12 +124,12 @@ public class SkiaNavigationPage : SkiaView
}
else
{
Console.WriteLine("[SkiaNavigationPage] Push (no animation): setting _currentPage to " + page.Title);
DiagnosticLog.Debug("SkiaNavigationPage", "Push (no animation): setting _currentPage to " + page.Title);
_currentPage = page;
_currentPage.OnAppearing();
Console.WriteLine("[SkiaNavigationPage] Push: calling Invalidate");
DiagnosticLog.Debug("SkiaNavigationPage", "Push: calling Invalidate");
Invalidate();
Console.WriteLine("[SkiaNavigationPage] Push: Invalidate called, _currentPage is now " + _currentPage?.Title);
DiagnosticLog.Debug("SkiaNavigationPage", "Push: Invalidate called, _currentPage is now " + _currentPage?.Title);
}
Pushed?.Invoke(this, new NavigationEventArgs(page));
@@ -326,7 +327,7 @@ public class SkiaNavigationPage : SkiaView
else if (_currentPage != null)
{
// Draw current page normally
Console.WriteLine("[SkiaNavigationPage] OnDraw: drawing _currentPage=" + _currentPage.Title);
DiagnosticLog.Debug("SkiaNavigationPage", "OnDraw: drawing _currentPage=" + _currentPage.Title);
_currentPage.Bounds = new Rect(bounds.Left, bounds.Top, bounds.Width, bounds.Height);
_currentPage.Draw(canvas);
@@ -375,7 +376,7 @@ public class SkiaNavigationPage : SkiaView
public override void OnPointerPressed(PointerEventArgs e)
{
Console.WriteLine($"[SkiaNavigationPage] OnPointerPressed at ({e.X}, {e.Y}), _isAnimating={_isAnimating}");
DiagnosticLog.Debug("SkiaNavigationPage", $"OnPointerPressed at ({e.X}, {e.Y}), _isAnimating={_isAnimating}");
if (_isAnimating) return;
// Check for back button click
@@ -383,13 +384,13 @@ public class SkiaNavigationPage : SkiaView
{
if (e.X < 56 && e.Y < _navigationBarHeight)
{
Console.WriteLine($"[SkiaNavigationPage] Back button clicked");
DiagnosticLog.Debug("SkiaNavigationPage", "Back button clicked");
Pop();
return;
}
}
Console.WriteLine($"[SkiaNavigationPage] Forwarding to _currentPage: {_currentPage?.GetType().Name}");
DiagnosticLog.Debug("SkiaNavigationPage", $"Forwarding to _currentPage: {_currentPage?.GetType().Name}");
_currentPage?.OnPointerPressed(e);
}
@@ -454,7 +455,7 @@ public class SkiaNavigationPage : SkiaView
}
catch (Exception ex)
{
Console.WriteLine($"[SkiaNavigationPage] HitTest error: {ex.Message}");
DiagnosticLog.Error("SkiaNavigationPage", $"HitTest error: {ex.Message}", ex);
}
}

View File

@@ -3,6 +3,7 @@
using SkiaSharp;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Platform.Linux.Services;
namespace Microsoft.Maui.Platform;
@@ -204,7 +205,7 @@ public class SkiaPage : SkiaView
var availableSize = new Size(adjustedBounds.Width, adjustedBounds.Height);
_content.Measure(availableSize);
_content.Arrange(new Rect(adjustedBounds.Left, adjustedBounds.Top, adjustedBounds.Width, adjustedBounds.Height));
Console.WriteLine($"[SkiaPage] Drawing content: {_content.GetType().Name}, Bounds={_content.Bounds}, IsVisible={_content.IsVisible}");
DiagnosticLog.Debug("SkiaPage", $"Drawing content: {_content.GetType().Name}, Bounds={_content.Bounds}, IsVisible={_content.IsVisible}");
_content.Draw(canvas);
}
@@ -284,7 +285,7 @@ public class SkiaPage : SkiaView
public void OnAppearing()
{
Console.WriteLine($"[SkiaPage] OnAppearing called for: {Title}, HasListeners={Appearing != null}");
DiagnosticLog.Debug("SkiaPage", $"OnAppearing called for: {Title}, HasListeners={Appearing != null}");
Appearing?.Invoke(this, EventArgs.Empty);
}
@@ -436,7 +437,7 @@ public class SkiaContentPage : SkiaPage
private void DrawToolbarItems(SKCanvas canvas, SKRect navBarBounds)
{
var primaryItems = _toolbarItems.Where(t => t.Order == SkiaToolbarItemOrder.Primary).ToList();
Console.WriteLine($"[SkiaContentPage] DrawToolbarItems: {primaryItems.Count} primary items, navBarBounds={navBarBounds}");
DiagnosticLog.Debug("SkiaContentPage", $"DrawToolbarItems: {primaryItems.Count} primary items, navBarBounds={navBarBounds}");
if (primaryItems.Count == 0) return;
using var font = new SKFont(SKTypeface.Default, 14);
@@ -470,7 +471,7 @@ public class SkiaContentPage : SkiaPage
var destRect = new SKRect(iconX, iconY, iconX + iconSize, iconY + iconSize);
canvas.DrawBitmap(item.Icon, destRect);
Console.WriteLine($"[SkiaContentPage] Drew toolbar icon '{item.Text}' at ({iconX}, {iconY})");
DiagnosticLog.Debug("SkiaContentPage", $"Drew toolbar icon '{item.Text}' at ({iconX}, {iconY})");
}
else
{
@@ -490,33 +491,33 @@ public class SkiaContentPage : SkiaPage
canvas.DrawText(item.Text, x, y, textPaint);
}
Console.WriteLine($"[SkiaContentPage] Toolbar item '{item.Text}' HitBounds set to {item.HitBounds}");
DiagnosticLog.Debug("SkiaContentPage", $"Toolbar item '{item.Text}' HitBounds set to {item.HitBounds}");
rightEdge = itemLeft - 8; // Gap between items
}
}
public override void OnPointerPressed(PointerEventArgs e)
{
Console.WriteLine($"[SkiaContentPage] OnPointerPressed at ({e.X}, {e.Y}), ShowNavigationBar={ShowNavigationBar}, NavigationBarHeight={NavigationBarHeight}");
Console.WriteLine($"[SkiaContentPage] ToolbarItems count: {_toolbarItems.Count}");
DiagnosticLog.Debug("SkiaContentPage", $"OnPointerPressed at ({e.X}, {e.Y}), ShowNavigationBar={ShowNavigationBar}, NavigationBarHeight={NavigationBarHeight}");
DiagnosticLog.Debug("SkiaContentPage", $"ToolbarItems count: {_toolbarItems.Count}");
// Check toolbar item clicks
if (ShowNavigationBar && e.Y < NavigationBarHeight)
{
Console.WriteLine($"[SkiaContentPage] In navigation bar area, checking toolbar items");
DiagnosticLog.Debug("SkiaContentPage", "In navigation bar area, checking toolbar items");
foreach (var item in _toolbarItems.Where(t => t.Order == SkiaToolbarItemOrder.Primary))
{
var bounds = item.HitBounds;
var contains = bounds.Contains(e.X, e.Y);
Console.WriteLine($"[SkiaContentPage] Checking item '{item.Text}', HitBounds=({bounds.Left},{bounds.Top},{bounds.Right},{bounds.Bottom}), Click=({e.X},{e.Y}), Contains={contains}, Command={item.Command != null}");
DiagnosticLog.Debug("SkiaContentPage", $"Checking item '{item.Text}', HitBounds=({bounds.Left},{bounds.Top},{bounds.Right},{bounds.Bottom}), Click=({e.X},{e.Y}), Contains={contains}, Command={item.Command != null}");
if (contains)
{
Console.WriteLine($"[SkiaContentPage] Toolbar item clicked: {item.Text}");
DiagnosticLog.Debug("SkiaContentPage", $"Toolbar item clicked: {item.Text}");
item.Command?.Execute(null);
return;
}
}
Console.WriteLine($"[SkiaContentPage] No toolbar item hit");
DiagnosticLog.Debug("SkiaContentPage", "No toolbar item hit");
}
base.OnPointerPressed(e);

View File

@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Platform.Linux.Services;
using SkiaSharp;
namespace Microsoft.Maui.Platform;
@@ -428,7 +429,7 @@ public class SkiaScrollView : SkiaView
public override void OnScroll(ScrollEventArgs e)
{
Console.WriteLine($"[SkiaScrollView] OnScroll - DeltaY={e.DeltaY}, ScrollableHeight={ScrollableHeight}, ContentSize={ContentSize}, Bounds={Bounds}");
DiagnosticLog.Debug("SkiaScrollView", $"OnScroll - DeltaY={e.DeltaY}, ScrollableHeight={ScrollableHeight}, ContentSize={ContentSize}, Bounds={Bounds}");
// Handle mouse wheel scrolling
var deltaMultiplier = 40f; // Scroll speed
@@ -438,7 +439,7 @@ public class SkiaScrollView : SkiaView
{
var oldScrollY = _scrollY;
ScrollY += e.DeltaY * deltaMultiplier;
Console.WriteLine($"[SkiaScrollView] ScrollY changed: {oldScrollY} -> {_scrollY}");
DiagnosticLog.Debug("SkiaScrollView", $"ScrollY changed: {oldScrollY} -> {_scrollY}");
if (_scrollY != oldScrollY)
scrolled = true;
}
@@ -876,7 +877,7 @@ public class SkiaScrollView : SkiaView
var actualBounds = bounds;
if (double.IsInfinity(bounds.Height) || double.IsNaN(bounds.Height))
{
Console.WriteLine($"[SkiaScrollView] WARNING: Infinite/NaN height, using default viewport={DefaultViewportHeight}");
DiagnosticLog.Warn("SkiaScrollView", $"Infinite/NaN height, using default viewport={DefaultViewportHeight}");
actualBounds = new Rect(bounds.Left, bounds.Top, bounds.Width, DefaultViewportHeight);
}

View File

@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Platform.Linux.Services;
using SkiaSharp;
namespace Microsoft.Maui.Platform;
@@ -481,10 +482,10 @@ public class SkiaShell : SkiaLayoutView
/// </summary>
public void RefreshTheme()
{
Console.WriteLine("[SkiaShell] RefreshTheme called - refreshing all pages");
DiagnosticLog.Debug("SkiaShell", "RefreshTheme called - refreshing all pages");
if (MauiShell != null && ColorRefresher != null)
{
Console.WriteLine("[SkiaShell] Refreshing shell colors");
DiagnosticLog.Debug("SkiaShell", "Refreshing shell colors");
ColorRefresher(this, MauiShell);
}
if (ContentRenderer != null)
@@ -495,7 +496,7 @@ public class SkiaShell : SkiaLayoutView
{
if (item.MauiShellContent != null)
{
Console.WriteLine("[SkiaShell] Re-rendering: " + item.Title);
DiagnosticLog.Debug("SkiaShell", "Re-rendering: " + item.Title);
var skiaView = ContentRenderer(item.MauiShellContent);
if (skiaView != null)
{
@@ -775,7 +776,7 @@ public class SkiaShell : SkiaLayoutView
protected override Rect ArrangeOverride(Rect bounds)
{
Console.WriteLine($"[SkiaShell] ArrangeOverride - bounds={bounds}");
DiagnosticLog.Debug("SkiaShell", $"ArrangeOverride - bounds={bounds}");
// Arrange current content with padding
if (_currentContent != null)
@@ -787,7 +788,7 @@ public class SkiaShell : SkiaLayoutView
contentTop,
bounds.Width - ContentPadding * 2,
contentBottom - contentTop);
Console.WriteLine($"[SkiaShell] Arranging content with bounds={contentBounds}, padding={ContentPadding}");
DiagnosticLog.Debug("SkiaShell", $"Arranging content with bounds={contentBounds}, padding={ContentPadding}");
_currentContent.Arrange(contentBounds);
}

View File

@@ -1682,7 +1682,7 @@ public abstract class SkiaView : BindableObject, IDisposable, IAccessible
public virtual void OnPointerReleased(PointerEventArgs e)
{
Console.WriteLine($"[SkiaView] OnPointerReleased on {GetType().Name}, MauiView={MauiView?.GetType().Name ?? "null"}");
DiagnosticLog.Debug("SkiaView", $"OnPointerReleased on {GetType().Name}, MauiView={MauiView?.GetType().Name ?? "null"}");
if (MauiView != null)
{
GestureManager.ProcessPointerUp(MauiView, e.X, e.Y);

View File

@@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Net;
using System.Runtime.InteropServices;
using Microsoft.Maui.Platform.Linux.Services;
using SkiaSharp;
namespace Microsoft.Maui.Platform;
@@ -507,7 +508,7 @@ public class SkiaWebView : SkiaView
{
_mainDisplay = display;
_mainWindow = window;
Console.WriteLine($"[WebView] Main window set: display={display}, window={window}");
DiagnosticLog.Debug("SkiaWebView", $"Main window set: display={display}, window={window}");
}
public static void ProcessGtkEvents()
@@ -548,14 +549,14 @@ public class SkiaWebView : SkiaView
{
_useGtk4 = true;
_webkitLib = "libwebkitgtk-6.0.so.4";
Console.WriteLine("[WebView] Warning: Using GTK4 WebKitGTK - embedding may be limited");
DiagnosticLog.Warn("SkiaWebView", "Using GTK4 WebKitGTK - embedding may be limited");
}
}
}
if (_webkitHandle == IntPtr.Zero)
{
Console.WriteLine("[WebView] WebKitGTK not found. Install with: sudo apt install libwebkit2gtk-4.1-0");
DiagnosticLog.Error("SkiaWebView", "WebKitGTK not found. Install with: sudo apt install libwebkit2gtk-4.1-0");
return false;
}
@@ -579,7 +580,7 @@ public class SkiaWebView : SkiaView
_webkitGetUserAgent = LoadFunction<WebKitSettingsGetUserAgentDelegate>("webkit_settings_get_user_agent");
_webkitRunJavascript = LoadFunction<WebKitWebViewRunJavascriptDelegate>("webkit_web_view_run_javascript");
Console.WriteLine($"[WebView] Using {_webkitLib}");
DiagnosticLog.Debug("SkiaWebView", $"Using {_webkitLib}");
return _webkitWebViewNew != null;
}
@@ -593,7 +594,7 @@ public class SkiaWebView : SkiaView
{
string[] events = { "STARTED", "REDIRECTED", "COMMITTED", "FINISHED" };
string eventName = loadEvent >= 0 && loadEvent < events.Length ? events[loadEvent] : loadEvent.ToString();
Console.WriteLine($"[WebView] Load event: {eventName}");
DiagnosticLog.Debug("SkiaWebView", $"Load event: {eventName}");
if (!_webViewInstances.TryGetValue(webView, out var instance)) return;
@@ -644,11 +645,11 @@ public class SkiaWebView : SkiaView
Environment.SetEnvironmentVariable("GDK_BACKEND", "x11");
Environment.SetEnvironmentVariable("LIBGL_ALWAYS_SOFTWARE", "1");
Environment.SetEnvironmentVariable("WEBKIT_DISABLE_COMPOSITING_MODE", "1");
Console.WriteLine("[WebView] Using X11 backend with software rendering for proper positioning");
DiagnosticLog.Debug("SkiaWebView", "Using X11 backend with software rendering for proper positioning");
var waylandDisplay = Environment.GetEnvironmentVariable("WAYLAND_DISPLAY");
Console.WriteLine($"[WebView] XDG_RUNTIME_DIR: {Environment.GetEnvironmentVariable("XDG_RUNTIME_DIR")}");
Console.WriteLine($"[WebView] Forcing X11: GDK_BACKEND=x11, WAYLAND_DISPLAY={waylandDisplay}, XDG_SESSION_TYPE=x11");
DiagnosticLog.Debug("SkiaWebView", $"XDG_RUNTIME_DIR: {Environment.GetEnvironmentVariable("XDG_RUNTIME_DIR")}");
DiagnosticLog.Debug("SkiaWebView", $"Forcing X11: GDK_BACKEND=x11, WAYLAND_DISPLAY={waylandDisplay}, XDG_SESSION_TYPE=x11");
if (_useGtk4)
{
@@ -660,19 +661,19 @@ public class SkiaWebView : SkiaView
IntPtr argv = IntPtr.Zero;
if (!gtk3_init_check(ref argc, ref argv))
{
Console.WriteLine("[WebView] gtk3_init_check failed!");
DiagnosticLog.Error("SkiaWebView", "gtk3_init_check failed!");
}
}
_gtkInitialized = true;
var gdkDisplay = gdk3_display_get_default();
Console.WriteLine($"[WebView] GDK display: {gdkDisplay}");
DiagnosticLog.Debug("SkiaWebView", $"GDK display: {gdkDisplay}");
}
_webView = _webkitWebViewNew!();
if (_webView == IntPtr.Zero)
{
Console.WriteLine("[WebView] Failed to create WebKit view");
DiagnosticLog.Error("SkiaWebView", "Failed to create WebKit view");
return;
}
@@ -680,7 +681,7 @@ public class SkiaWebView : SkiaView
_loadChangedCallback = OnLoadChanged;
var callbackPtr = Marshal.GetFunctionPointerForDelegate(_loadChangedCallback);
g_signal_connect_data(_webView, "load-changed", callbackPtr, IntPtr.Zero, IntPtr.Zero, 0);
Console.WriteLine("[WebView] Connected to load-changed signal");
DiagnosticLog.Debug("SkiaWebView", "Connected to load-changed signal");
int width = Math.Max(800, (int)RequestedWidth);
int height = Math.Max(600, (int)RequestedHeight);
@@ -691,7 +692,7 @@ public class SkiaWebView : SkiaView
gtk4_window_set_title(_gtkWindow, "OpenMaui WebView");
gtk4_window_set_default_size(_gtkWindow, width, height);
gtk4_window_set_child(_gtkWindow, _webView);
Console.WriteLine($"[WebView] GTK4 window created: {width}x{height}");
DiagnosticLog.Debug("SkiaWebView", $"GTK4 window created: {width}x{height}");
}
else
{
@@ -702,7 +703,7 @@ public class SkiaWebView : SkiaView
gtk3_widget_set_vexpand(_webView, true);
gtk3_widget_set_size_request(_webView, width, height);
gtk3_container_add(_gtkWindow, _webView);
Console.WriteLine($"[WebView] GTK3 TOPLEVEL window created: {width}x{height}");
DiagnosticLog.Debug("SkiaWebView", $"GTK3 TOPLEVEL window created: {width}x{height}");
}
ConfigureWebKitSettings();
@@ -727,11 +728,11 @@ public class SkiaWebView : SkiaView
LoadHtml(_html);
}
Console.WriteLine("[WebView] Initialized successfully");
DiagnosticLog.Debug("SkiaWebView", "Initialized successfully");
}
catch (Exception ex)
{
Console.WriteLine($"[WebView] Initialization failed: {ex.Message}");
DiagnosticLog.Error("SkiaWebView", $"Initialization failed: {ex.Message}", ex);
}
}
@@ -746,31 +747,31 @@ public class SkiaWebView : SkiaView
var settings = _webkitGetSettings(_webView);
if (settings == IntPtr.Zero)
{
Console.WriteLine("[WebView] Could not get WebKit settings");
DiagnosticLog.Warn("SkiaWebView", "Could not get WebKit settings");
return;
}
if (_webkitSetHardwareAcceleration != null)
{
_webkitSetHardwareAcceleration(settings, 2); // NEVER
Console.WriteLine("[WebView] Set hardware acceleration to NEVER (software rendering)");
DiagnosticLog.Debug("SkiaWebView", "Set hardware acceleration to NEVER (software rendering)");
}
else
{
Console.WriteLine("[WebView] Warning: Could not set hardware acceleration policy");
DiagnosticLog.Warn("SkiaWebView", "Could not set hardware acceleration policy");
}
if (_webkitSetWebgl != null)
{
_webkitSetWebgl(settings, false);
Console.WriteLine("[WebView] Disabled WebGL");
DiagnosticLog.Debug("SkiaWebView", "Disabled WebGL");
}
Console.WriteLine("[WebView] WebKit settings configured successfully");
DiagnosticLog.Debug("SkiaWebView", "WebKit settings configured successfully");
}
catch (Exception ex)
{
Console.WriteLine($"[WebView] Failed to configure settings: {ex.Message}");
DiagnosticLog.Error("SkiaWebView", $"Failed to configure settings: {ex.Message}", ex);
}
}
@@ -808,28 +809,28 @@ public class SkiaWebView : SkiaView
{
Navigating?.Invoke(this, new WebNavigatingEventArgs(url));
_webkitLoadUri(_webView, url);
Console.WriteLine($"[WebView] URL loaded: {url}");
DiagnosticLog.Debug("SkiaWebView", $"URL loaded: {url}");
ShowNativeWindow();
}
}
public void LoadHtml(string html, string? baseUrl = null)
{
Console.WriteLine($"[WebView] LoadHtml called, html length: {html?.Length ?? 0}");
DiagnosticLog.Debug("SkiaWebView", $"LoadHtml called, html length: {html?.Length ?? 0}");
if (string.IsNullOrEmpty(html))
{
Console.WriteLine("[WebView] Cannot load HTML - html is null or empty");
DiagnosticLog.Warn("SkiaWebView", "Cannot load HTML - html is null or empty");
return;
}
if (!_isInitialized) Initialize();
if (_webView == IntPtr.Zero || _webkitLoadHtml == null)
{
Console.WriteLine("[WebView] Cannot load HTML - not initialized or no webkit function");
DiagnosticLog.Warn("SkiaWebView", "Cannot load HTML - not initialized or no webkit function");
return;
}
Console.WriteLine("[WebView] Calling webkit_web_view_load_html...");
DiagnosticLog.Debug("SkiaWebView", "Calling webkit_web_view_load_html...");
_webkitLoadHtml(_webView, html, baseUrl);
Console.WriteLine("[WebView] HTML loaded to WebKit");
DiagnosticLog.Debug("SkiaWebView", "HTML loaded to WebKit");
ShowNativeWindow();
}
@@ -919,13 +920,13 @@ public class SkiaWebView : SkiaView
{
if (_mainDisplay == IntPtr.Zero || _mainWindow == IntPtr.Zero)
{
Console.WriteLine("[WebView] Cannot create X11 container - main window not set");
DiagnosticLog.Warn("SkiaWebView", "Cannot create X11 container - main window not set");
return false;
}
if (_x11Container != IntPtr.Zero)
{
Console.WriteLine("[WebView] X11 container already exists");
DiagnosticLog.Debug("SkiaWebView", "X11 container already exists");
return true;
}
@@ -939,23 +940,23 @@ public class SkiaWebView : SkiaView
if (width < 100) width = 780;
if (height < 100) height = 300;
Console.WriteLine($"[WebView] Creating X11 container at ({x}, {y}), size ({width}x{height})");
DiagnosticLog.Debug("SkiaWebView", $"Creating X11 container at ({x}, {y}), size ({width}x{height})");
_x11Container = XCreateSimpleWindow(_mainDisplay, _mainWindow, x, y, width, height, 0, 0, 0xFFFFFF);
if (_x11Container == IntPtr.Zero)
{
Console.WriteLine("[WebView] Failed to create X11 container window");
DiagnosticLog.Error("SkiaWebView", "Failed to create X11 container window");
return false;
}
Console.WriteLine($"[WebView] Created X11 container: {_x11Container.ToInt64()}");
DiagnosticLog.Debug("SkiaWebView", $"Created X11 container: {_x11Container.ToInt64()}");
XMapWindow(_mainDisplay, _x11Container);
XFlush(_mainDisplay);
return true;
}
catch (Exception ex)
{
Console.WriteLine($"[WebView] Error creating X11 container: {ex.Message}");
DiagnosticLog.Error("SkiaWebView", $"Error creating X11 container: {ex.Message}", ex);
return false;
}
}
@@ -966,7 +967,7 @@ public class SkiaWebView : SkiaView
if (!_isInitialized) Initialize();
if (_gtkWindow == IntPtr.Zero) return;
Console.WriteLine("[WebView] Showing native GTK window...");
DiagnosticLog.Debug("SkiaWebView", "Showing native GTK window...");
if (!_useGtk4)
{
@@ -997,14 +998,14 @@ public class SkiaWebView : SkiaView
TryReparentIntoMainWindow();
_isEmbedded = true;
Console.WriteLine("[WebView] Native window shown");
DiagnosticLog.Debug("SkiaWebView", "Native window shown");
}
private void TryReparentIntoMainWindow()
{
if (_mainDisplay == IntPtr.Zero || _mainWindow == IntPtr.Zero)
{
Console.WriteLine("[WebView] Cannot setup - main window not set");
DiagnosticLog.Warn("SkiaWebView", "Cannot setup - main window not set");
return;
}
@@ -1015,11 +1016,11 @@ public class SkiaWebView : SkiaView
if (_gtkX11Window != IntPtr.Zero)
{
_isProperlyReparented = true;
Console.WriteLine($"[WebView] GTK X11 window: {_gtkX11Window} (reparented successfully)");
DiagnosticLog.Debug("SkiaWebView", $"GTK X11 window: {_gtkX11Window} (reparented successfully)");
}
else
{
Console.WriteLine($"[WebView] GTK X11 window: failed to get XID");
DiagnosticLog.Warn("SkiaWebView", "GTK X11 window: failed to get XID");
}
}
@@ -1047,7 +1048,7 @@ public class SkiaWebView : SkiaView
int width = Math.Max(100, (int)Bounds.Width);
int height = Math.Max(100, (int)Bounds.Height);
Console.WriteLine($"[WebView] Position: screen=({screenX}, {screenY}), size ({width}x{height}), bounds=({Bounds.Left},{Bounds.Top})");
DiagnosticLog.Debug("SkiaWebView", $"Position: screen=({screenX}, {screenY}), size ({width}x{height}), bounds=({Bounds.Left},{Bounds.Top})");
if (!_useGtk4)
{
@@ -1126,11 +1127,11 @@ public class SkiaWebView : SkiaView
gtk3_window_set_skip_pager_hint(_gtkWindow, true);
gtk3_window_set_keep_above(_gtkWindow, true);
gtk3_window_set_decorated(_gtkWindow, false);
Console.WriteLine("[WebView] Overlay mode enabled with UTILITY hint");
DiagnosticLog.Debug("SkiaWebView", "Overlay mode enabled with UTILITY hint");
}
catch (Exception ex)
{
Console.WriteLine($"[WebView] Failed to enable overlay mode: {ex.Message}");
DiagnosticLog.Error("SkiaWebView", $"Failed to enable overlay mode: {ex.Message}", ex);
}
}
@@ -1138,7 +1139,7 @@ public class SkiaWebView : SkiaView
{
if (_mainDisplay == IntPtr.Zero || _mainWindow == IntPtr.Zero)
{
Console.WriteLine("[WebView] Cannot setup embedding - main window not set");
DiagnosticLog.Warn("SkiaWebView", "Cannot setup embedding - main window not set");
return;
}
@@ -1148,7 +1149,7 @@ public class SkiaWebView : SkiaView
int width = Math.Max(100, (int)Bounds.Width);
int height = Math.Max(100, (int)Bounds.Height);
Console.WriteLine($"[WebView] Initial position: ({screenX}, {screenY}), size ({width}x{height})");
DiagnosticLog.Debug("SkiaWebView", $"Initial position: ({screenX}, {screenY}), size ({width}x{height})");
if (!_useGtk4)
{
@@ -1191,7 +1192,7 @@ public class SkiaWebView : SkiaView
if (mainWindowMoved || Math.Abs(screenX - _lastPosX) > 2 || Math.Abs(screenY - _lastPosY) > 2 ||
Math.Abs(width - _lastWidth) > 2 || Math.Abs(height - _lastHeight) > 2)
{
Console.WriteLine($"[WebView] Move to ({screenX}, {screenY}), size ({width}x{height}), mainWin=({destX},{destY}), bounds=({Bounds.Left},{Bounds.Top})");
DiagnosticLog.Debug("SkiaWebView", $"Move to ({screenX}, {screenY}), size ({width}x{height}), mainWin=({destX},{destY}), bounds=({Bounds.Left},{Bounds.Top})");
_lastPosX = screenX;
_lastPosY = screenY;
_lastWidth = width;
@@ -1266,12 +1267,12 @@ public class SkiaWebView : SkiaView
var root = XDefaultRootWindow(display);
if (XTranslateCoordinates(display, window, root, 0, 0, out x, out y, out _))
{
Console.WriteLine($"[WebView] Main window at screen ({x}, {y})");
DiagnosticLog.Debug("SkiaWebView", $"Main window at screen ({x}, {y})");
}
}
catch (Exception ex)
{
Console.WriteLine($"[WebView] Failed to get window position: {ex.Message}");
DiagnosticLog.Error("SkiaWebView", $"Failed to get window position: {ex.Message}", ex);
}
}
@@ -1295,13 +1296,13 @@ public class SkiaWebView : SkiaView
if (_isProperlyReparented && _gtkX11Window != IntPtr.Zero)
{
Console.WriteLine($"[WebView] UpdateEmbedded (reparented): ({x}, {y}), size ({width}x{height})");
DiagnosticLog.Debug("SkiaWebView", $"UpdateEmbedded (reparented): ({x}, {y}), size ({width}x{height})");
XMoveResizeWindow(_mainDisplay, _gtkX11Window, x, y, width, height);
XFlush(_mainDisplay);
}
else if (_x11Container != IntPtr.Zero)
{
Console.WriteLine($"[WebView] UpdateEmbedded (container): ({x}, {y}), size ({width}x{height})");
DiagnosticLog.Debug("SkiaWebView", $"UpdateEmbedded (container): ({x}, {y}), size ({width}x{height})");
XMoveResizeWindow(_mainDisplay, _x11Container, x, y, width, height);
if (_gtkX11Window != IntPtr.Zero && _isProperlyReparented)
{