From ea7b58952180c3aeb46a10971fdda0ab339d7f2f Mon Sep 17 00:00:00 2001 From: dfgHiatus Date: Sun, 11 Jan 2026 12:21:29 -0500 Subject: [PATCH] Swap DispatcherQueue for SynchronizationContext --- .../Library/UnifiedLibManager.cs | 5 ++++- .../ModuleProcessMain.cs | 3 +-- VRCFaceTracking.ModuleProcess/ProxyLogger.cs | 7 +++---- .../ProxyLoggerProvider.cs | 20 ++++++------------- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/VRCFaceTracking.Core/Library/UnifiedLibManager.cs b/VRCFaceTracking.Core/Library/UnifiedLibManager.cs index 79557d12..f0e2baf2 100644 --- a/VRCFaceTracking.Core/Library/UnifiedLibManager.cs +++ b/VRCFaceTracking.Core/Library/UnifiedLibManager.cs @@ -11,6 +11,7 @@ using VRCFaceTracking.Core.Models; using VRCFaceTracking.Core.Sandboxing; using VRCFaceTracking.Core.Sandboxing.IPC; +using OperatingSystem = System.OperatingSystem; namespace VRCFaceTracking.Core.Library; @@ -57,7 +58,9 @@ public UnifiedLibManager(ILoggerFactory factory, IDispatcherService dispatcherSe _moduleDataService = moduleDataService; LoadedModulesMetadata = new ObservableCollection(); - _sandboxProcessPath = Path.GetFullPath("VRCFaceTracking.ModuleProcess.exe"); + _sandboxProcessPath = Path.GetFullPath(OperatingSystem.IsWindows() ? + "VRCFaceTracking.ModuleProcess.exe" : + "VRCFaceTracking.ModuleProcess"); if ( !File.Exists(_sandboxProcessPath) ) { // @TODO: Better error handling diff --git a/VRCFaceTracking.ModuleProcess/ModuleProcessMain.cs b/VRCFaceTracking.ModuleProcess/ModuleProcessMain.cs index bcc4c6c8..b3a9a5ac 100644 --- a/VRCFaceTracking.ModuleProcess/ModuleProcessMain.cs +++ b/VRCFaceTracking.ModuleProcess/ModuleProcessMain.cs @@ -7,7 +7,6 @@ using VRCFaceTracking.Core.Params.Expressions; using VRCFaceTracking.Core.Sandboxing; using VRCFaceTracking.Core.Sandboxing.IPC; -using Windows.System; namespace VRCFaceTracking.ModuleProcess; @@ -96,7 +95,7 @@ static int VrcftMain(string modulePath, int serverPortNumber) // .AddSentry(o => // o.Dsn = // "https://444b0799dd2b670efa85d866c8c12134@o4506152235237376.ingest.us.sentry.io/4506152246575104") - .AddProvider(new ProxyLoggerProvider(DispatcherQueue.GetForCurrentThread())) + .AddProvider(new ProxyLoggerProvider(SynchronizationContext.Current)) ) .BuildServiceProvider(); diff --git a/VRCFaceTracking.ModuleProcess/ProxyLogger.cs b/VRCFaceTracking.ModuleProcess/ProxyLogger.cs index 3f79f7eb..b03de82f 100644 --- a/VRCFaceTracking.ModuleProcess/ProxyLogger.cs +++ b/VRCFaceTracking.ModuleProcess/ProxyLogger.cs @@ -1,6 +1,5 @@ using System.Collections.ObjectModel; using Microsoft.Extensions.Logging; -using Windows.System; namespace VRCFaceTracking.ModuleProcess; @@ -11,12 +10,12 @@ public class ProxyLogger : ILogger private readonly string _categoryName; // public static readonly ObservableCollection AllLogs = new(); public static OnLog OnLog; - private static DispatcherQueue? _dispatcher; + private static SynchronizationContext? _syncContext; - public ProxyLogger(string categoryName, DispatcherQueue? queue) + public ProxyLogger(string categoryName, SynchronizationContext? syncContext = null) { _categoryName = categoryName; - _dispatcher = queue; + _syncContext = syncContext ?? SynchronizationContext.Current; } public IDisposable BeginScope(TState state) where TState : notnull => default!; diff --git a/VRCFaceTracking.ModuleProcess/ProxyLoggerProvider.cs b/VRCFaceTracking.ModuleProcess/ProxyLoggerProvider.cs index 86552dfa..e268ce99 100644 --- a/VRCFaceTracking.ModuleProcess/ProxyLoggerProvider.cs +++ b/VRCFaceTracking.ModuleProcess/ProxyLoggerProvider.cs @@ -1,22 +1,14 @@ -using System.Collections.Concurrent; +using System.Threading; using Microsoft.Extensions.Logging; -using Windows.System; namespace VRCFaceTracking.ModuleProcess; -public class ProxyLoggerProvider : ILoggerProvider -{ - private readonly ConcurrentDictionary _loggers = - new(StringComparer.OrdinalIgnoreCase); - - private readonly DispatcherQueue _dispatcher; - public ProxyLoggerProvider(DispatcherQueue dispatcher) +public class ProxyLoggerProvider(SynchronizationContext? syncContext = null) : ILoggerProvider +{ + public ILogger CreateLogger(string categoryName) { - _dispatcher = dispatcher; + return new ProxyLogger(categoryName, syncContext); } - public ILogger CreateLogger(string categoryName) => - _loggers.GetOrAdd(categoryName, name => new ProxyLogger(name, _dispatcher)); - - public void Dispose() => _loggers.Clear(); + public void Dispose() { } }