1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 03:42:57 +08:00

Implement IPC channel for osu:// scheme links

This commit is contained in:
Bartłomiej Dach 2022-06-20 20:08:36 +02:00
parent 34f1c80b7c
commit 92011124d1
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497

View File

@ -0,0 +1,49 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Diagnostics;
using System.Threading.Tasks;
using osu.Framework.Platform;
using osu.Game.Online;
namespace osu.Game.IPC
{
public class OsuSchemeLinkIPCChannel : IpcChannel<OsuSchemeLinkMessage>
{
private readonly ILinkHandler? linkHandler;
public OsuSchemeLinkIPCChannel(IIpcHost host, ILinkHandler? linkHandler = null)
: base(host)
{
this.linkHandler = linkHandler;
MessageReceived += msg =>
{
Debug.Assert(linkHandler != null);
linkHandler.HandleLink(msg.Link);
return null;
};
}
public async Task HandleLinkAsync(string url)
{
if (linkHandler == null)
{
await SendMessageAsync(new OsuSchemeLinkMessage(url)).ConfigureAwait(false);
return;
}
linkHandler.HandleLink(url);
}
}
public class OsuSchemeLinkMessage
{
public string Link { get; }
public OsuSchemeLinkMessage(string link)
{
Link = link;
}
}
}