-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
178 additions
and
173 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
41 changes: 41 additions & 0 deletions
41
src/Networking/NexusMods.Networking.NexusWebApi/HandlerRegistration.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,41 @@ | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using NexusMods.CrossPlatform.ProtocolRegistration; | ||
|
||
namespace NexusMods.Networking.NexusWebApi; | ||
|
||
internal class HandlerRegistration : IHostedService | ||
{ | ||
private readonly ILogger _logger; | ||
private readonly IProtocolRegistration _protocolRegistration; | ||
|
||
public HandlerRegistration( | ||
ILogger<HandlerRegistration> logger, | ||
IProtocolRegistration protocolRegistration) | ||
{ | ||
_logger = logger; | ||
_protocolRegistration = protocolRegistration; | ||
} | ||
|
||
public Task StartAsync(CancellationToken cancellationToken) | ||
{ | ||
_ = Task.Run(async () => | ||
{ | ||
try | ||
{ | ||
await _protocolRegistration.RegisterHandler(uriScheme: "nxm", cancellationToken: cancellationToken); | ||
} | ||
catch (Exception e) | ||
{ | ||
_logger.LogError(e, "Exception while registering handler for nxm links"); | ||
} | ||
}, cancellationToken); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
public Task StopAsync(CancellationToken cancellationToken) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
} |
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
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
34 changes: 3 additions & 31 deletions
34
src/NexusMods.CrossPlatform/ProtocolRegistration/IProtocolRegistration.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 |
---|---|---|
@@ -1,40 +1,12 @@ | ||
using NexusMods.Paths; | ||
|
||
namespace NexusMods.CrossPlatform.ProtocolRegistration; | ||
|
||
/// <summary> | ||
/// deals with protocol registration, that is: setting up this application system wide | ||
/// as the default handler for a custom protocol (e.g. nxm://...) | ||
/// For the actual code to be invoked when such a url is received, see NexusMods.Cli.ProtocolInvokation | ||
/// | ||
/// This is platform dependent functionality | ||
/// Abstracts OS-specific protocol registration logic. | ||
/// </summary> | ||
public interface IProtocolRegistration | ||
{ | ||
/// <summary> | ||
/// register this application as a handler for a protocol (e.g. nxm://...). | ||
/// This should be called every time the application runs for every protocol it handles | ||
/// </summary> | ||
/// <param name="protocol">The protocol to register for</param> | ||
/// <returns>the previous handler, if any</returns> | ||
Task<string?> RegisterSelf(string protocol); | ||
|
||
/// <summary> | ||
/// register an arbitrary command line as the handler for a protocol. | ||
/// The primary usecase for this is to unregister the current application, potentially | ||
/// restoring a previous handler | ||
/// </summary> | ||
/// <param name="protocol">The protocol to register for</param> | ||
/// <param name="friendlyName">Arbitrary friendly name for the protocol</param> | ||
/// <param name="workingDirectory">The directory inside which the program is executed</param> | ||
/// <param name="commandLine">The full commandline</param> | ||
/// <returns>the previous handler, if any</returns> | ||
Task<string?> Register(string protocol, string friendlyName, string workingDirectory, string commandLine); | ||
|
||
/// <summary> | ||
/// determine if this application is the handler for a protocol. This is based on the full url | ||
/// of the calling process so another installation of the same application would _not_ count | ||
/// Registers the App as a protocol handler for <paramref name="uriScheme"/>. | ||
/// </summary> | ||
/// <param name="protocol">The protocol to check for</param> | ||
Task<bool> IsSelfHandler(string protocol); | ||
Task RegisterHandler(string uriScheme, bool setAsDefaultHandler = true, CancellationToken cancellationToken = default); | ||
} |
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
20 changes: 3 additions & 17 deletions
20
src/NexusMods.CrossPlatform/ProtocolRegistration/ProtocolRegistrationOSX.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
Oops, something went wrong.