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
2 changes: 2 additions & 0 deletions PlayniteBoot/Localization/en_US.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@
<sys:String x:Key="LOCPlayniteBootCheckWaitForVideoEnd">Wait for the video to finish before revealing Playnite</sys:String>
<sys:String x:Key="LOCPlayniteBootCheckLoopVideo">Loop the video</sys:String>
<sys:String x:Key="LOCPlayniteBootCheckHideCursor">Hide the mouse cursor</sys:String>
<sys:String x:Key="LOCPlayniteBootCheckDesktopFullscreenSwitch">Show the boot screen when switching from Desktop to Fullscreen</sys:String>
<sys:String x:Key="LOCPlayniteBootCheckMute">Mute video audio</sys:String>
<sys:String x:Key="LOCPlayniteBootCheckEnableLog">Enable runtime logging</sys:String>
<sys:String x:Key="LOCPlayniteBootCheckStreamingEnabled">Enable streaming preload integration</sys:String>

<sys:String x:Key="LOCPlayniteBootTipDesktopFullscreenSwitch">Covers Playnite's built-in Desktop to Fullscreen transition with the configured boot video.</sys:String>
<sys:String x:Key="LOCPlayniteBootTipWaitForVideoEnd">Playnite starts in the background immediately, but the overlay fades only after Playnite is ready and the video reaches its natural end.</sys:String>
<sys:String x:Key="LOCPlayniteBootTipLoopVideo">Looping is unavailable while waiting for the natural end of the video.</sys:String>
<sys:String x:Key="LOCPlayniteBootTipMinimumDuration">Ignored while waiting for the complete video.</sys:String>
Expand Down
2 changes: 2 additions & 0 deletions PlayniteBoot/Localization/it_IT.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@
<sys:String x:Key="LOCPlayniteBootCheckWaitForVideoEnd">Attendi la fine del video prima di mostrare Playnite</sys:String>
<sys:String x:Key="LOCPlayniteBootCheckLoopVideo">Ripeti il video</sys:String>
<sys:String x:Key="LOCPlayniteBootCheckHideCursor">Nascondi il cursore del mouse</sys:String>
<sys:String x:Key="LOCPlayniteBootCheckDesktopFullscreenSwitch">Mostra la schermata di avvio quando passi da Desktop a Fullscreen</sys:String>
<sys:String x:Key="LOCPlayniteBootCheckMute">Disattiva l'audio del video</sys:String>
<sys:String x:Key="LOCPlayniteBootCheckEnableLog">Abilita log del runtime</sys:String>
<sys:String x:Key="LOCPlayniteBootCheckStreamingEnabled">Abilita integrazione preload streaming</sys:String>

<sys:String x:Key="LOCPlayniteBootTipDesktopFullscreenSwitch">Copre la transizione integrata di Playnite da Desktop a Fullscreen con il video di avvio configurato.</sys:String>
<sys:String x:Key="LOCPlayniteBootTipWaitForVideoEnd">Playnite parte subito in background, ma l'overlay sfuma solo quando Playnite è pronta e il video raggiunge la fine naturale.</sys:String>
<sys:String x:Key="LOCPlayniteBootTipLoopVideo">La ripetizione non è disponibile quando si attende la fine naturale del video.</sys:String>
<sys:String x:Key="LOCPlayniteBootTipMinimumDuration">Ignorata quando si attende il video completo.</sys:String>
Expand Down
4 changes: 3 additions & 1 deletion PlayniteBoot/Models/PlayniteBootSettingsData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace PlayniteBoot.Models
{
public class PlayniteBootSettingsData : ObservableObject
{
public const int CurrentSettingsVersion = 2;
public const int CurrentSettingsVersion = 3;

private int settingsVersion;
private string playniteExecutable = "auto";
Expand All @@ -27,6 +27,7 @@ public class PlayniteBootSettingsData : ObservableObject
private int fadeInMilliseconds = 80;
private int fadeOutMilliseconds = 400;
private bool hideMouseCursor = true;
private bool enableDesktopFullscreenSwitch = true;
private bool logEnabled = true;
private string shortcutName = "Playnite Fullscreen";
private StreamingSettings streaming = new StreamingSettings();
Expand Down Expand Up @@ -81,6 +82,7 @@ public double Volume
public int FadeInMilliseconds { get => fadeInMilliseconds; set => SetValue(ref fadeInMilliseconds, value); }
public int FadeOutMilliseconds { get => fadeOutMilliseconds; set => SetValue(ref fadeOutMilliseconds, value); }
public bool HideMouseCursor { get => hideMouseCursor; set => SetValue(ref hideMouseCursor, value); }
public bool EnableDesktopFullscreenSwitch { get => enableDesktopFullscreenSwitch; set => SetValue(ref enableDesktopFullscreenSwitch, value); }
public bool LogEnabled { get => logEnabled; set => SetValue(ref logEnabled, value); }
public string ShortcutName { get => shortcutName; set => SetValue(ref shortcutName, value); }
public StreamingSettings Streaming { get => streaming; set => SetValue(ref streaming, value); }
Expand Down
1 change: 1 addition & 0 deletions PlayniteBoot/PlayniteBoot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<Compile Include="Services\VideoLibraryService.cs" />
<Compile Include="Services\ShellService.cs" />
<Compile Include="Services\ShortcutService.cs" />
<Compile Include="Services\DesktopFullscreenSwitchService.cs" />
<Compile Include="Services\WindowsPowerShell.cs" />
</ItemGroup>

Expand Down
25 changes: 25 additions & 0 deletions PlayniteBoot/PlayniteBootPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class PlayniteBootPlugin : GenericPlugin
private readonly RuntimeInstaller runtimeInstaller;
private readonly RuntimeConfigWriter configWriter;
private readonly ShortcutService shortcutService;
private readonly DesktopFullscreenSwitchService desktopFullscreenSwitchService;
private readonly object runtimeOperationLock = new object();

public override Guid Id { get; } = Guid.Parse("71b5c099-3c25-4fe7-b26f-1262c7f0e138");
Expand All @@ -34,6 +35,9 @@ public PlayniteBootPlugin(IPlayniteAPI api) : base(api)
configWriter = new RuntimeConfigWriter(Paths, PlayniteApi.Paths.ConfigurationPath);
shortcutService = new ShortcutService(Paths);
SettingsViewModel = new PlayniteBootSettingsViewModel(this);
desktopFullscreenSwitchService = new DesktopFullscreenSwitchService(
Paths,
() => SettingsViewModel.Settings.EnableDesktopFullscreenSwitch);

Properties = new GenericPluginProperties
{
Expand All @@ -53,6 +57,22 @@ public override UserControl GetSettingsView(bool firstRunSettings)

public override void OnApplicationStarted(OnApplicationStartedEventArgs args)
{
if (PlayniteApi.ApplicationInfo.Mode == ApplicationMode.Desktop)
{
try
{
var appWindow = PlayniteApi.Dialogs.GetCurrentAppWindow();
if (!desktopFullscreenSwitchService.Attach(appWindow))
{
logger.Warn(ProductName + " could not attach Desktop-to-Fullscreen switch handling to the Playnite window.");
}
}
catch (Exception exception)
{
logger.Error(exception, ProductName + " failed to attach Desktop-to-Fullscreen switch handling.");
}
}

// Take a snapshot on Playnite's UI thread, then perform disk work in
// the background. All runtime mutations are serialized by the lock.
var settingsSnapshot = Serialization.GetClone(SettingsViewModel.Settings);
Expand All @@ -69,6 +89,11 @@ public override void OnApplicationStarted(OnApplicationStartedEventArgs args)
});
}

public override void OnApplicationStopped(OnApplicationStoppedEventArgs args)
{
desktopFullscreenSwitchService.Detach();
}

public RuntimeInstallResult PrepareRuntime(PlayniteBootSettingsData settings, bool forceUpdate)
{
lock (runtimeOperationLock)
Expand Down
7 changes: 7 additions & 0 deletions PlayniteBoot/PlayniteBootSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,12 @@ private void EnsureDefaultsAndMigrate()
// Follow Playnite is selected later.
settings.MonitorFallback = settings.Monitor;
}
if (settings.SettingsVersion < 3)
{
// The Desktop -> Fullscreen boot transition is enabled by default
// for both new and existing installations.
settings.EnableDesktopFullscreenSwitch = true;
}

settings.SettingsVersion = PlayniteBootSettingsData.CurrentSettingsVersion;

Expand Down Expand Up @@ -753,6 +759,7 @@ private string BuildDiagnostics()
b.AppendLine("Config version: " + RuntimeConfigWriter.CurrentConfigVersion);
b.AppendLine("Mode: " + (Settings.WaitForVideoEnd ? "waitForVideoEnd" : "readyAndMinimumDuration"));
b.AppendLine("Streaming preload: " + (Settings.Streaming != null && Settings.Streaming.Enabled ? "enabled" : "disabled"));
b.AppendLine("Desktop -> Fullscreen boot: " + (Settings.EnableDesktopFullscreenSwitch ? "enabled" : "disabled"));
b.AppendLine("Runtime installed: " + YesNo(File.Exists(plugin.Paths.ScriptPath) && File.Exists(plugin.Paths.ConfigPath)));
b.AppendLine("Video exists: " + YesNo(videoExists));
b.AppendLine("Desktop shortcut: " + YesNo(plugin.ShortcutExists(Settings, ShortcutLocation.Desktop)));
Expand Down
5 changes: 5 additions & 0 deletions PlayniteBoot/PlayniteBootSettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<TextBlock Grid.Row="0" Text="{DynamicResource LOCPlayniteBootLabelVideoFile}"
Expand Down Expand Up @@ -73,6 +74,10 @@
<CheckBox Grid.Row="5" Grid.Column="1"
Content="{DynamicResource LOCPlayniteBootCheckHideCursor}"
IsChecked="{Binding Settings.HideMouseCursor}" Margin="6,5" />
<CheckBox Grid.Row="6" Grid.Column="1"
Content="{DynamicResource LOCPlayniteBootCheckDesktopFullscreenSwitch}"
IsChecked="{Binding Settings.EnableDesktopFullscreenSwitch}" Margin="6,5"
ToolTip="{DynamicResource LOCPlayniteBootTipDesktopFullscreenSwitch}" />
</Grid>
</GroupBox>

Expand Down
101 changes: 96 additions & 5 deletions PlayniteBoot/RuntimeTemplate/PlayniteBoot.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,19 @@ param(
[string]$ConfigPath,

[Parameter(Mandatory = $false)]
[ValidateSet('Standalone', 'Preload', 'Continue', 'Host')]
[string]$Mode = 'Standalone'
[ValidateSet('Standalone', 'Preload', 'Continue', 'Host', 'Switch')]
[string]$Mode = 'Standalone',

# Switch is an internal mode used by the Playnite Desktop plugin hook.
# Playnite Desktop owns the transition; the bootstrap and this runtime only
# cover it until the Fullscreen window is ready.
[Parameter(Mandatory = $false)]
[long]$SwitchStartUtcTicks = 0,

# Set only by the lightweight SwitchBootstrap.ps1 path. The bootstrap
# already owns a rendered black cover and has released Playnite Desktop.
[Parameter(Mandatory = $false)]
[switch]$SwitchBootstrapActive
)

Set-StrictMode -Version 2.0
Expand Down Expand Up @@ -241,6 +252,21 @@ function Find-PlayniteFullscreenExecutable {

function Get-RunningFullscreenProcess {
$processes = @(Get-Process -Name 'Playnite.FullscreenApp' -ErrorAction SilentlyContinue)

# During Desktop -> Fullscreen switching, ignore stale/orphaned Fullscreen
# processes that predate the Closing callback which armed this overlay.
if ($Mode -eq 'Switch' -and $SwitchStartUtcTicks -gt 0 -and $processes.Count -gt 0) {
$minimumStartTicks = $SwitchStartUtcTicks - (250 * [TimeSpan]::TicksPerMillisecond)
$processes = @($processes | Where-Object {
try {
$_.StartTime.ToUniversalTime().Ticks -ge $minimumStartTicks
}
catch {
$false
}
})
}

if ($processes.Count -eq 0) {
return $null
}
Expand Down Expand Up @@ -1266,12 +1292,16 @@ public static class PlayniteBootNative
}

$existingProcess = Get-RunningFullscreenProcess
if ($null -ne $existingProcess) {
if ($null -ne $existingProcess -and $Mode -ne 'Switch') {
Write-Log 'Playnite Fullscreen is already running. No new boot overlay will be shown.'
Activate-PlayniteWindow -Process $existingProcess
exit 0
}

if ($Mode -eq 'Switch' -and $null -ne $existingProcess) {
Write-Log "Switch bootstrap found Playnite Fullscreen PID $($existingProcess.Id) already starting. It will be adopted by the readiness tracker."
}

# Parametri generali. I valori e i limiti sono gli stessi della baseline.
$settings = [PSCustomObject]@{
PlayniteExecutable = [string](Get-ConfigValue -Config $config -Name 'playniteExecutable' -DefaultValue 'auto')
Expand Down Expand Up @@ -1303,7 +1333,12 @@ public static class PlayniteBootNative
throw 'Invalid configuration: loopVideo and waitForVideoEnd cannot both be enabled.'
}

$playniteExecutable = Find-PlayniteFullscreenExecutable -ConfiguredPath $settings.PlayniteExecutable -BaseDirectory $baseDirectory
$playniteExecutable = $null
if ($Mode -ne 'Switch') {
# Switch mode never starts Playnite itself. Skipping executable discovery
# also avoids unnecessary registry probing on the critical switch path.
$playniteExecutable = Find-PlayniteFullscreenExecutable -ConfiguredPath $settings.PlayniteExecutable -BaseDirectory $baseDirectory
}

Add-Type -AssemblyName PresentationFramework
Add-Type -AssemblyName PresentationCore
Expand Down Expand Up @@ -1529,7 +1564,7 @@ public static class PlayniteBootNative
# Stato condiviso dagli handler WPF. Le chiavi sono inizializzate in un
# unico punto per rendere esplicito il ciclo di vita dell'overlay.
$state = @{
Process = $null
Process = $(if ($Mode -eq 'Switch') { $existingProcess } else { $null })
ReadySince = $null
ReadyProcessId = $null
ReadyWindowHandle = [IntPtr]::Zero
Expand Down Expand Up @@ -1629,6 +1664,31 @@ public static class PlayniteBootNative
Write-Log 'Preload-ready signal sent: the video is visible and advancing.'
}

$closeSwitchBootstrapOverlay = {
if ($Mode -ne 'Switch' -or -not $SwitchBootstrapActive) {
return
}

try {
$bootstrapVariable = Get-Variable -Name 'PlayniteBootSwitchBootstrapForm' -Scope Global -ErrorAction SilentlyContinue
if ($null -eq $bootstrapVariable -or $null -eq $bootstrapVariable.Value) {
return
}

$bootstrapForm = $bootstrapVariable.Value
if (-not $bootstrapForm.IsDisposed) {
$bootstrapForm.Hide()
$bootstrapForm.Close()
$bootstrapForm.Dispose()
}
$global:PlayniteBootSwitchBootstrapForm = $null
Write-Log 'Switch bootstrap cover released after the main WPF overlay rendered.'
}
catch {
Write-Log "Could not release the switch bootstrap cover: $($_.Exception.Message)" 'WARN'
}
}

$revealVideo = {
if ($state.VideoRevealed -or -not $videoExists -or $state.Closing) {
return
Expand Down Expand Up @@ -2264,6 +2324,10 @@ public static class PlayniteBootNative

$window.Add_ContentRendered({
try {
# The lightweight bootstrap is already covering the target display.
# Replace it only after this normal WPF overlay has rendered black.
& $closeSwitchBootstrapOverlay

if ($settings.HideMouseCursor) {
[System.Windows.Forms.Cursor]::Hide()
$script:cursorHidden = $true
Expand All @@ -2284,6 +2348,17 @@ public static class PlayniteBootNative
$state.PreloadWatch.Restart()
Write-Log "Preload overlay displayed. Waiting for video-ready and then Continue for up to $($streamingSettings.PreloadAbandonTimeoutMilliseconds) ms."
}
elseif ($Mode -eq 'Switch') {
# Playnite Desktop owns the transition and launches Fullscreen
# after the Closing handler returns. The bootstrap cover has
# already released Desktop, so this runtime only tracks readiness.
$state.LaunchStarted = $true
$state.StartWatch.Restart()
Write-Log 'Desktop-to-Fullscreen switch overlay displayed. Waiting for Playnite Desktop to launch Fullscreen behind it.'
if ($SwitchBootstrapActive) {
Write-Log 'Desktop was already released by the switch bootstrap cover.'
}
}
else {
& $startPlaynite
}
Expand Down Expand Up @@ -2344,6 +2419,22 @@ finally {
try { [System.Windows.Forms.Cursor]::Show() } catch {}
}

if ($Mode -eq 'Switch' -and $SwitchBootstrapActive) {
try {
$bootstrapVariable = Get-Variable -Name 'PlayniteBootSwitchBootstrapForm' -Scope Global -ErrorAction SilentlyContinue
if ($null -ne $bootstrapVariable -and $null -ne $bootstrapVariable.Value) {
$bootstrapForm = $bootstrapVariable.Value
if (-not $bootstrapForm.IsDisposed) {
$bootstrapForm.Close()
$bootstrapForm.Dispose()
}
$global:PlayniteBootSwitchBootstrapForm = $null
}
}
catch {
}
}

if ($launcherMutexAcquired -and $null -ne $launcherMutex) {
try { $launcherMutex.ReleaseMutex() } catch {}
}
Expand Down
Loading