Files
Dave Friedel c60453ea31 Fix incomplete functionality, nullable warnings, and async issues
Incomplete functionality fixes:
- SkiaEditor: Wire up Completed event to fire on focus lost
- X11InputMethodService: Remove unused _commitCallback field
- SkiaWebView: Set _isProperlyReparented when reparenting succeeds,
  use _lastMainX/_lastMainY to track main window position,
  add _isEmbedded guard to prevent double embedding

Nullable reference fixes:
- Easing: Reorder BounceOut before BounceIn (static init order)
- GestureManager: Use local command variable instead of re-accessing
- SkiaShell: Handle null Title with ?? operator
- GLibNative: Use null! for closure pattern
- LinuxProgramHost: Default title if null
- SkiaWebView.LoadHtml: Add null/empty check for html
- SystemThemeService: Initialize Colors with default values
- DeviceDisplayService/AppInfoService: Use var for nullable env vars
- EmailService: Add null check for message parameter

Async fixes:
- SkiaImage: Use _ = for fire-and-forget async calls
- SystemTrayService: Convert async method without await to sync Task

Reduces warnings from 156 to 133 (remaining are P/Invoke structs
and obsolete MAUI API usage)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 17:20:11 -05:00

112 lines
3.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace Microsoft.Maui.Platform.Linux.Native;
public static class GLibNative
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate bool GSourceFunc(IntPtr userData);
private const string Lib = "libglib-2.0.so.0";
private static readonly List<GSourceFunc> _callbacks = new List<GSourceFunc>();
private static readonly object _callbackLock = new object();
[DllImport("libglib-2.0.so.0", EntryPoint = "g_idle_add")]
private static extern uint g_idle_add_native(GSourceFunc function, IntPtr data);
[DllImport("libglib-2.0.so.0", EntryPoint = "g_timeout_add")]
private static extern uint g_timeout_add_native(uint interval, GSourceFunc function, IntPtr data);
[DllImport("libglib-2.0.so.0", EntryPoint = "g_source_remove")]
public static extern bool SourceRemove(uint sourceId);
[DllImport("libglib-2.0.so.0", EntryPoint = "g_get_monotonic_time")]
public static extern long GetMonotonicTime();
public static uint IdleAdd(Func<bool> callback)
{
GSourceFunc wrapper = null!;
wrapper = delegate
{
bool flag = false;
try
{
flag = callback();
}
catch (Exception ex)
{
Console.WriteLine("[GLibNative] Error in idle callback: " + ex.Message);
}
if (!flag)
{
lock (_callbackLock)
{
_callbacks.Remove(wrapper);
}
}
return flag;
};
lock (_callbackLock)
{
_callbacks.Add(wrapper);
}
return g_idle_add_native(wrapper, IntPtr.Zero);
}
public static uint TimeoutAdd(uint intervalMs, Func<bool> callback)
{
GSourceFunc wrapper = null!;
wrapper = delegate
{
bool flag = false;
try
{
flag = callback();
}
catch (Exception ex)
{
Console.WriteLine("[GLibNative] Error in timeout callback: " + ex.Message);
}
if (!flag)
{
lock (_callbackLock)
{
_callbacks.Remove(wrapper);
}
}
return flag;
};
lock (_callbackLock)
{
_callbacks.Add(wrapper);
}
return g_timeout_add_native(intervalMs, wrapper, IntPtr.Zero);
}
public static void ClearCallbacks()
{
lock (_callbackLock)
{
_callbacks.Clear();
}
}
public static uint g_idle_add(GSourceFunc func, IntPtr data)
{
return g_idle_add_native(func, data);
}
public static uint g_timeout_add(uint intervalMs, GSourceFunc func, IntPtr data)
{
return g_timeout_add_native(intervalMs, func, data);
}
public static bool g_source_remove(uint tag)
{
return SourceRemove(tag);
}
}