Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/10-Core/Wtq/Services/Stubs/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.Extensions.DependencyInjection;

namespace Wtq.Services.Stubs;

public static class ServiceCollectionExtensions
{
public static IServiceCollection AddStubs(this IServiceCollection services)
{
Guard.Against.Null(services);

return services
.AddSingleton<IWtqWindowService, StubWtqWindowService>()
.AddSingleton<IWtqScreenInfoProvider, StubWtqScreenInfoProvider>();
}
}
19 changes: 19 additions & 0 deletions src/10-Core/Wtq/Services/Stubs/StubWtqScreenInfoProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Wtq.Services.Stubs;

public class StubWtqScreenInfoProvider : IWtqScreenInfoProvider
{
public Task<Rectangle> GetPrimaryScreenRectAsync()
{
return Task.FromResult(new Rectangle(0, 0, 1920, 1080));
}

public Task<Rectangle[]> GetScreenRectsAsync()
{
return Task.FromResult<Rectangle[]>([new Rectangle(0, 0, 1920, 1080)]);
}

public Task<Rectangle> GetScreenWithCursorAsync()
{
return Task.FromResult(new Rectangle(0, 0, 1920, 1080));
}
}
29 changes: 29 additions & 0 deletions src/10-Core/Wtq/Services/Stubs/StubWtqWindowService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Wtq.Services.Stubs;

public class StubWtqWindowService : IWtqWindowService
{
public Task CreateAsync(WtqAppOptions opts, CancellationToken cancellationToken)
{
return Task.CompletedTask;
}

public Task<ICollection<WtqWindow>> FindWindowsAsync(WtqAppOptions opts, CancellationToken cancellationToken)
{
return Task.FromResult<ICollection<WtqWindow>>([]);
}

public Task<WtqWindow?> GetForegroundWindowAsync(CancellationToken cancellationToken)
{
return Task.FromResult<WtqWindow?>(null);
}

public List<WtqWindowProperty> GetWindowProperties()
{
return [];
}

public Task<ICollection<WtqWindow>> GetWindowsAsync(CancellationToken cancellationToken)
{
return Task.FromResult<ICollection<WtqWindow>>([]);
}
}
2 changes: 1 addition & 1 deletion src/10-Core/Wtq/Utils/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static void Configure(string pathToLogsDir)
restrictedToMinimumLevel: LogLevel)

// In-app.
.WriteTo.Sink(InAppLogSink.Instance)
// .WriteTo.Sink(InAppLogSink.Instance)

// Plain text.
.WriteTo.File(
Expand Down
62 changes: 61 additions & 1 deletion src/20-Services/Wtq.Services.UI/WtqUIHostBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@ namespace Wtq.Services.UI;

public static class WtqUIHostBuilder
{
public static void Run(Action<IServiceCollection> services)
public static void Run(Action<IServiceCollection> services, bool gui)
{
if (gui)
{
RunGui(services);
}
else
{
RunHeadless(services);
}
}

public static void RunGui(Action<IServiceCollection> services)
{
Guard.Against.Null(services);

Expand Down Expand Up @@ -60,4 +72,52 @@ public static void Run(Action<IServiceCollection> services)

app.Run();
}

public static void RunHeadless(Action<IServiceCollection> services)
{
Guard.Against.Null(services);

var s = new ServiceCollection();

using var invoker = new WtqUIInvoker();

s
.AddLogging()
.AddSingleton<IHostApplicationLifetime, ApplicationLifetime>()
.AddSingleton<IWtqUIService>(_ => invoker)
;

services(s);

var p = s.BuildServiceProvider();

var lifetime = (ApplicationLifetime)p.GetRequiredService<IHostApplicationLifetime>();

// Note that this handler needs to be called pretty early, otherwise other handles may be run first, like the AspNetCore one (if the API is enabled).
// Note that we shouldn't ignore the return value, as it can get optimized out in "Release" mode, causing the entire handler to not work (as it gets finalized immediately).
using var reg = PosixSignalRegistration.Create(
PosixSignal.SIGINT,
ctx =>
{
ctx.Cancel = true;

lifetime.StopApplication(); // "Stopping"
});

invoker.Action = a => a();

_ = new WtqHost(
lifetime,
p.GetRequiredService<IEnumerable<IHostedService>>(),
p.GetRequiredService<IPlatformService>(),
() => {});

lifetime.NotifyStarted();

var exit = new TaskCompletionSource();

lifetime.ApplicationStopped.Register(() => exit.SetResult());

exit.Task.GetAwaiter().GetResult();
}
}
2 changes: 1 addition & 1 deletion src/30-Host/Wtq.Host.Base/ConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private static IConfiguration CreateConfigurationRoot(IPlatformService platform,
var pathToWtqConf = platform.PathToWtqConf;

// Write wtq.schema.json.
WtqSchema.WriteFor(pathToWtqConf);
WtqSchema.WriteFor(pathToWtqConf); // ~40MB

// Load config file.
var config = new ConfigurationBuilder()
Expand Down
7 changes: 4 additions & 3 deletions src/30-Host/Wtq.Host.Base/WtqHostBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public async Task RunAsync(string[] args)
var platform = CreatePlatformService();

// Setup logging ASAP, so we can log stuff if initialization goes awry.
Log.Configure(platform.PathToLogsDir);
Log.Configure(platform.PathToLogsDir); // ~25MB

if (args.Length == 0)
{
Expand Down Expand Up @@ -75,10 +75,11 @@ private void RunApp(IPlatformService platform, string[] args)
.AddConfiguration(platform, args)
.AddApi()
.AddUI()
.AddWtqCore();
.AddWtqCore()
;

ConfigureServices(s);
});
}, gui: false);
}
catch (Exception ex)
{
Expand Down
5 changes: 4 additions & 1 deletion src/30-Host/Wtq.Host.Linux/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"environmentVariables": {
"WEBKIT_DISABLE_DMABUF_RENDERER": "1",

"__WTQ_LOG_LEVEL": "VERBOSE"
"__WTQ_LOG_LEVEL": "VERBOSE",
"__DOTNET_DefaultStackSize": "100000",
"__DOTNET_GCHeapHardLimit": "0x10000000",
"__DOTNET_GCHeapCount": "2"
}
},
"Config From User Home": {
Expand Down
2 changes: 2 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>

<InvariantGlobalization>true</InvariantGlobalization>

<!-- Some features we use require a documentation file, like analyzers, and the docs manifest generation -->
<GenerateDocumentationFile>true</GenerateDocumentationFile>

Expand Down