Skip to content

Commit

Permalink
successfully restart a game
Browse files Browse the repository at this point in the history
Delay is needed after stopping a game and before starting it.

#575
  • Loading branch information
andrew-codes committed Oct 29, 2024
1 parent cebd628 commit 562ec00
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
26 changes: 26 additions & 0 deletions apps/PlayniteWebPlugin/src/Models/Release.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@

namespace PlayniteWeb.Models
{
public enum RunState
{
Running,
Installed,
Uninstalled
}

public class Release : IIdentifiable
{
private readonly Playnite.SDK.Models.Game game;
Expand All @@ -23,6 +30,25 @@ public Release(Playnite.SDK.Models.Game game, Platform platform)
this.platform = platform;
}

[DontSerialize]
public RunState RunState
{
get
{
if (game.IsRunning)
{
return RunState.Running;
}
else if (game.IsInstalled)
{
return RunState.Installed;
}
else
{
return RunState.Uninstalled;
}
}
}
public int? ProcessId { get; set; }
public Guid Id => game.Id;
public string Name => game.Name;
Expand Down
11 changes: 10 additions & 1 deletion apps/PlayniteWebPlugin/src/PlayniteWeb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public override void OnApplicationStopped(OnApplicationStoppedEventArgs args)
private void Subscriber_OnRestartRelease(object sender, Release e)
{
this.Subscriber_OnStopRelease(sender, e);
this.Subscriber_OnStartRelease(sender, e);
Task.Delay(3000).ContinueWith(t => this.Subscriber_OnStartRelease(sender, e));
}

private void Subscriber_OnStopRelease(object sender, Release e)
Expand All @@ -295,6 +295,11 @@ private void Subscriber_OnStopRelease(object sender, Release e)
return;
}

if (e.RunState != RunState.Running)
{
return;
}

try
{
var gameProcess = Process.GetProcessById(e.ProcessId.Value);
Expand Down Expand Up @@ -392,7 +397,11 @@ private void Subscriber_OnStartRelease(object sender, Release release)
if (!isPcPlatform(release.Platform))
{
return;
}

if (release.RunState == RunState.Running)
{
return;
}

if (!release.IsInstalled)
Expand Down

0 comments on commit 562ec00

Please sign in to comment.