-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
14 changed files
with
289 additions
and
171 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using CommandLine; | ||
|
||
namespace OpenShock.ShockOsc.Cli; | ||
|
||
public sealed class CliOptions | ||
{ | ||
[Option('h', "headless", Required = false, Default = false, HelpText = "Run the application in headless mode.")] | ||
public bool Headless { get; set; } | ||
} |
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,24 @@ | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace OpenShock.ShockOsc; | ||
|
||
public static class HeadlessProgram | ||
{ | ||
public static IHost SetupHeadlessHost() | ||
{ | ||
var builder = Host.CreateDefaultBuilder(); | ||
builder.ConfigureServices(services => | ||
{ | ||
services.AddShockOscServices(); | ||
#if WINDOWS | ||
services.AddWindowsServices(); | ||
#endif | ||
}); | ||
|
||
var app = builder.Build(); | ||
app.Services.StartShockOscServices(true); | ||
|
||
return app; | ||
} | ||
} |
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
4 changes: 2 additions & 2 deletions
4
ShockOsc/Platforms/Linux/LinuxApp.cs → ShockOsc/Platforms/Linux/LinuxEntryPoint.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
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,56 @@ | ||
#if WINDOWS | ||
using System.Runtime.InteropServices; | ||
using CommandLine; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.UI.Dispatching; | ||
using OpenShock.ShockOsc.Cli; | ||
using OpenShock.ShockOsc.Services; | ||
using OpenShock.ShockOsc.Utils; | ||
using WinRT; | ||
using Application = Microsoft.UI.Xaml.Application; | ||
|
||
namespace OpenShock.ShockOsc.Platforms.Windows; | ||
|
||
public static class WindowsEntryPoint | ||
{ | ||
[DefaultDllImportSearchPaths(DllImportSearchPath.SafeDirectories)] | ||
[DllImport("Microsoft.ui.xaml.dll")] | ||
private static extern void XamlCheckProcessRequirements(); | ||
|
||
[STAThread] | ||
private static void Main(string[] args) | ||
{ | ||
var parsed = Parser.Default.ParseArguments<CliOptions>(args); | ||
parsed.WithParsed(Start); | ||
parsed.WithNotParsed(errors => | ||
{ | ||
errors.Output(); | ||
Environment.Exit(1); | ||
}); | ||
} | ||
|
||
private static void Start(CliOptions config) | ||
{ | ||
if (config.Headless) | ||
{ | ||
Console.WriteLine("Running in headless mode."); | ||
|
||
var host = HeadlessProgram.SetupHeadlessHost(); | ||
OsTask.Run(host.Services.GetRequiredService<AuthService>().Authenticate); | ||
host.Run(); | ||
|
||
return; | ||
} | ||
|
||
XamlCheckProcessRequirements(); | ||
ComWrappersSupport.InitializeComWrappers(); | ||
Application.Start(delegate | ||
{ | ||
var context = new DispatcherQueueSynchronizationContext(DispatcherQueue.GetForCurrentThread()); | ||
SynchronizationContext.SetSynchronizationContext(context); | ||
// ReSharper disable once ObjectCreationAsStatement | ||
new App(); | ||
}); | ||
} | ||
} | ||
#endif |
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,13 @@ | ||
#if WINDOWS | ||
using OpenShock.ShockOsc.Services; | ||
|
||
namespace OpenShock.ShockOsc; | ||
|
||
public static class WindowsServices | ||
{ | ||
public static void AddWindowsServices(this IServiceCollection services) | ||
{ | ||
services.AddSingleton<ITrayService, WindowsTrayService>(); | ||
} | ||
} | ||
#endif |
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 |
---|---|---|
@@ -1,8 +1,13 @@ | ||
{ | ||
"profiles": { | ||
"Windows Machine": { | ||
"ShockOsc": { | ||
"commandName": "Project", | ||
"nativeDebugging": false | ||
}, | ||
"ShockOscHeadless": { | ||
"commandName": "Project", | ||
"nativeDebugging": false, | ||
"commandLineArgs": "--headless" | ||
} | ||
} | ||
} |
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,36 @@ | ||
using Microsoft.Extensions.Logging; | ||
using OpenShock.SDK.CSharp.Hub; | ||
using OpenShock.ShockOsc.Backend; | ||
|
||
namespace OpenShock.ShockOsc.Services; | ||
|
||
public sealed class AuthService | ||
{ | ||
private readonly ILogger<AuthService> _logger; | ||
private readonly BackendHubManager _backendHubManager; | ||
private readonly OpenShockHubClient _hubClient; | ||
private readonly LiveControlManager _liveControlManager; | ||
private readonly OpenShockApi _apiClient; | ||
|
||
public AuthService(ILogger<AuthService> logger, BackendHubManager backendHubManager, OpenShockHubClient hubClient, LiveControlManager liveControlManager, OpenShockApi apiClient) | ||
{ | ||
_logger = logger; | ||
_backendHubManager = backendHubManager; | ||
_hubClient = hubClient; | ||
_liveControlManager = liveControlManager; | ||
_apiClient = apiClient; | ||
} | ||
|
||
public async Task Authenticate() | ||
{ | ||
_logger.LogInformation("Setting up live client"); | ||
await _backendHubManager.SetupLiveClient(); | ||
_logger.LogInformation("Starting live client"); | ||
await _hubClient.StartAsync(); | ||
|
||
_logger.LogInformation("Refreshing shockers"); | ||
await _apiClient.RefreshShockers(); | ||
|
||
await _liveControlManager.RefreshConnections(); | ||
} | ||
} |
Oops, something went wrong.