mirror of
https://github.com/Maassoft/ColorControl.git
synced 2026-10-22 00:22:18 -05:00
fix issues with new UI, add color profiles, add sdr brightness for AMD
This commit is contained in:
1 parent
4d2ca8a552
commit
f42a46e53f
95 files changed
+12129
-10005
No files matched your search
@@ -0,0 +1,47 @@
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace ColorControl.UI.Services;
|
||||
|
||||
public class JSHelper(IJSRuntime jsRuntime)
|
||||
{
|
||||
private IJSObjectReference? jsModule;
|
||||
|
||||
public async Task<bool> IsFormValid(string id)
|
||||
{
|
||||
return await InvokeAsync<bool>("FormValid", id);
|
||||
}
|
||||
|
||||
public async Task OpenModal(string id)
|
||||
{
|
||||
await InvokeVoidAsync("OpenModal", id);
|
||||
}
|
||||
|
||||
public async Task CloseModal(string id)
|
||||
{
|
||||
await InvokeVoidAsync("CloseModal", id);
|
||||
}
|
||||
|
||||
public async Task ShowToast(string id)
|
||||
{
|
||||
await InvokeVoidAsync("ShowToast", id);
|
||||
}
|
||||
|
||||
private async ValueTask<T> InvokeAsync<T>(string identifier, params object?[]? names) where T : struct
|
||||
{
|
||||
jsModule = await LoadModule();
|
||||
|
||||
return await jsModule.InvokeAsync<T>(identifier, names);
|
||||
}
|
||||
|
||||
private async ValueTask InvokeVoidAsync(string identifier, params object?[]? names)
|
||||
{
|
||||
jsModule = await LoadModule();
|
||||
|
||||
await jsModule.InvokeVoidAsync(identifier, names);
|
||||
}
|
||||
|
||||
private async Task<IJSObjectReference> LoadModule()
|
||||
{
|
||||
return jsModule ??= await jsRuntime.InvokeAsync<IJSObjectReference>("import", "./helper.js");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
namespace ColorControl.UI.Services;
|
||||
|
||||
public class NotificationService
|
||||
{
|
||||
public event Func<NotificationDto, Task>? OnNotification;
|
||||
|
||||
private List<NotificationDto> _scheduledNotifications = new();
|
||||
|
||||
public void SendNotification(NotificationDto notification)
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
if (notification.ScheduledAt == null || notification.ScheduledAt <= now)
|
||||
{
|
||||
OnNotification?.Invoke(notification);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(notification.ScheduledAt.Value - now);
|
||||
|
||||
OnNotification?.Invoke(notification);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using ColorControl.Shared.Common;
|
||||
using ColorControl.Shared.Contracts;
|
||||
using Newtonsoft.Json;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace ColorControl.UI.Services;
|
||||
|
||||
public class RpcUiClientOptions
|
||||
{
|
||||
public int Timeout { get; set; } = PipeUtils.DefaultTimeout;
|
||||
}
|
||||
|
||||
public class RpcUiClientService(NotificationService notificationService)
|
||||
{
|
||||
public string? LastErrorMessage { get; private set; }
|
||||
|
||||
public async Task<T> CallAsync<T>(string serviceName, string method, params object[] arguments)
|
||||
{
|
||||
var rpcMessage = new SvcRpcMessage
|
||||
{
|
||||
ServiceName = serviceName,
|
||||
MethodName = method,
|
||||
Arguments = arguments
|
||||
};
|
||||
|
||||
var timeout = Debugger.IsAttached ? 60000 : PipeUtils.DefaultTimeout;
|
||||
|
||||
return await SendRpcMessageAsync<T>(rpcMessage, timeout, pipeName: PipeUtils.MainPipe);
|
||||
}
|
||||
|
||||
public async Task<T> CallWithOptionsAsync<T>(string serviceName, string method, RpcUiClientOptions options, params object[] arguments)
|
||||
{
|
||||
var rpcMessage = new SvcRpcMessage
|
||||
{
|
||||
ServiceName = serviceName,
|
||||
MethodName = method,
|
||||
Arguments = arguments
|
||||
};
|
||||
|
||||
return await SendRpcMessageAsync<T>(rpcMessage, options.Timeout, pipeName: PipeUtils.MainPipe);
|
||||
}
|
||||
|
||||
public T Call<T>(string serviceName, string method, params object[] arguments)
|
||||
{
|
||||
var rpcMessage = new SvcRpcMessage
|
||||
{
|
||||
ServiceName = serviceName,
|
||||
MethodName = method,
|
||||
Arguments = arguments
|
||||
};
|
||||
|
||||
var timeout = Debugger.IsAttached ? 60000 : 2000;
|
||||
|
||||
return PipeUtils.SendRpcMessage<T>(rpcMessage, timeout, pipeName: PipeUtils.MainPipe);
|
||||
}
|
||||
|
||||
private async Task<T> SendRpcMessageAsync<T>(SvcRpcMessage message, int timeout = PipeUtils.DefaultTimeout, string pipeName = PipeUtils.ServicePipe)
|
||||
{
|
||||
var messageJson = JsonConvert.SerializeObject(message);
|
||||
|
||||
var resultJson = await PipeUtils.SendMessageAsync(messageJson, timeout, pipeName);
|
||||
|
||||
if (resultJson == null)
|
||||
{
|
||||
notificationService.SendNotification(new NotificationDto("Unknown communication error", Constants.Danger));
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
var resultMessage = JsonConvert.DeserializeObject<SvcResultMessage>(resultJson);
|
||||
|
||||
if (resultMessage?.Data == null)
|
||||
{
|
||||
LastErrorMessage = resultMessage?.ErrorMessage ?? "Unknown communication error";
|
||||
|
||||
notificationService.SendNotification(new NotificationDto(LastErrorMessage, Constants.Danger));
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
LastErrorMessage = null;
|
||||
|
||||
var result = JsonConvert.DeserializeObject<T>(resultMessage.Data);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user