-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2209 from Nexus-Mods/disable-apply-if-not-running-2
Improved: Edge Cases around the Apply & Launch Button
- Loading branch information
Showing
27 changed files
with
417 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/Abstractions/NexusMods.Abstractions.Loadouts/Exceptions/ExecutableInUseException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Runtime.Serialization; | ||
namespace NexusMods.Abstractions.Loadouts.Exceptions; | ||
|
||
/// <summary> | ||
/// Exception thrown when an executable is in use | ||
/// </summary> | ||
public class ExecutableInUseException : Exception | ||
{ | ||
/// <inheritdoc /> | ||
public ExecutableInUseException() { } | ||
/// <inheritdoc /> | ||
public ExecutableInUseException(string? message) : base(message) { } | ||
/// <inheritdoc /> | ||
public ExecutableInUseException(string? message, Exception? innerException) : base(message, innerException) { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/Abstractions/NexusMods.Abstractions.Loadouts/NexusMods.Abstractions.Loadouts.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Reactive.Linq; | ||
using DynamicData; | ||
using NexusMods.Abstractions.Games; | ||
using NexusMods.Abstractions.Jobs; | ||
namespace NexusMods.App.UI; | ||
|
||
/// <summary> | ||
/// This class helps us efficiently identify whether a game is currently running. | ||
/// </summary> | ||
/// <remarks> | ||
/// There are multiple places in the App where it's necessary to determine if | ||
/// there is already a game running; however the necessary calculation for this | ||
/// can be prohibitively expensive. Therefore we re-use the logic inside this class. | ||
/// </remarks> | ||
public class GameRunningTracker | ||
{ | ||
private readonly IObservable<bool> _observable; | ||
|
||
/// <summary> | ||
/// Retrieves the current state of the game running tracker, | ||
/// with the current state being immediately emitted as the first item. | ||
/// </summary> | ||
public IObservable<bool> GetWithCurrentStateAsStarting() => _observable; | ||
|
||
public GameRunningTracker(IJobMonitor monitor) | ||
{ | ||
// Note(sewer): Yes, this technically can lead to a race condition; | ||
// however it's not possible to start a game before activating GameRunningTracker | ||
// singleton for an end user. | ||
var numRunning = monitor.Jobs.Count(x => x is { Definition: IRunGameTool } && x.Status.IsActive()); | ||
_observable = monitor.GetObservableChangeSet<IRunGameTool>() | ||
.TransformOnObservable(job => job.ObservableStatus) | ||
.QueryWhenChanged(query => query.Items.Any(x => x.IsActive())) | ||
.StartWith(numRunning > 0) | ||
.Replay(1) | ||
.RefCount(); | ||
} | ||
} |
Oops, something went wrong.