Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<OutputPath>bin\$(Configuration)\</OutputPath>

<!-- Version info visible in Windows File Properties -->
<Version>1.0.0</Version>
<AssemblyVersion>1.0.0</AssemblyVersion>
<FileVersion>1.0.0</FileVersion>
<Version>1.1.0</Version>
<AssemblyVersion>1.1.0</AssemblyVersion>
<FileVersion>1.1.0</FileVersion>

<!-- File properties metadata -->
<Product>Zaparoo LaunchBox Plugin</Product>
Expand Down
61 changes: 46 additions & 15 deletions scripts/windows/launchbox-plugin/ZaparooPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class ZaparooPlugin : ISystemEventsPlugin, IGameLaunchingPlugin, IGameMen
private static readonly object _pipeLock = new();
private static bool _isShuttingDown;
private static bool _isBigBoxRunning;
private static System.Windows.Threading.Dispatcher? _uiDispatcher;

// Instance-specific state
private IGame? _currentGame;
Expand All @@ -69,14 +70,20 @@ public ZaparooPlugin()

public void OnEventRaised(string eventType)
{
if (eventType == SystemEventTypes.LaunchBoxStartupCompleted)
if (eventType == SystemEventTypes.PluginInitialized)
{
_uiDispatcher ??= System.Windows.Threading.Dispatcher.CurrentDispatcher;
}
Comment thread
wizzomafizzo marked this conversation as resolved.
else if (eventType == SystemEventTypes.LaunchBoxStartupCompleted)
{
_uiDispatcher ??= System.Windows.Threading.Dispatcher.CurrentDispatcher;
_isBigBoxRunning = false;
_isShuttingDown = false;
StartConnectionTask();
}
else if (eventType == SystemEventTypes.BigBoxStartupCompleted)
{
_uiDispatcher ??= System.Windows.Threading.Dispatcher.CurrentDispatcher;
_isBigBoxRunning = true;
_isShuttingDown = false;
StartConnectionTask();
Expand Down Expand Up @@ -453,29 +460,40 @@ private void LaunchGameById(string gameId)
var game = PluginHelper.DataManager.GetGameById(gameId);
if (game != null)
{
if (_isBigBoxRunning)
{
PluginHelper.BigBoxMainViewModel.PlayGame(game, null, null, null);
}
else
InvokeOnUiThread(() =>
{
PluginHelper.LaunchBoxMainViewModel.PlayGame(game, null, null, null);
}
if (_isBigBoxRunning)
{
// ShowGame navigates BigBox UI to the game, which fires
// LEDBlinky Event 9 (game selection). Without this, LEDBlinky
// shows controls for whichever game was highlighted in the menu.
PluginHelper.BigBoxMainViewModel?.ShowGame(game, FilterType.None);
PluginHelper.BigBoxMainViewModel?.PlayGame(game, null, null, null);
}
else
{
PluginHelper.LaunchBoxMainViewModel?.PlayGame(game, null, null, null);
}
});
return;
}

// Try to find as an additional application (merged games, secondary discs)
var (parentGame, additionalApp) = FindAdditionalApplicationById(gameId);
if (additionalApp != null && parentGame != null)
{
if (_isBigBoxRunning)
InvokeOnUiThread(() =>
{
PluginHelper.BigBoxMainViewModel.PlayGame(parentGame, additionalApp, null, null);
}
else
{
PluginHelper.LaunchBoxMainViewModel.PlayGame(parentGame, additionalApp, null, null);
}
if (_isBigBoxRunning)
{
PluginHelper.BigBoxMainViewModel?.ShowGame(parentGame, FilterType.None);
PluginHelper.BigBoxMainViewModel?.PlayGame(parentGame, additionalApp, null, null);
}
else
{
PluginHelper.LaunchBoxMainViewModel?.PlayGame(parentGame, additionalApp, null, null);
}
});
return;
}

Expand All @@ -487,6 +505,19 @@ private void LaunchGameById(string gameId)
}
}

private static void InvokeOnUiThread(Action action)
{
var dispatcher = _uiDispatcher ?? System.Windows.Application.Current?.Dispatcher;
if (dispatcher != null && !dispatcher.CheckAccess())
{
dispatcher.Invoke(action);
}
else
{
action();
}
}

private (IGame?, IAdditionalApplication?) FindAdditionalApplicationById(string id)
{
foreach (var game in PluginHelper.DataManager.GetAllGames())
Expand Down