mirror of
https://github.com/Maassoft/ColorControl.git
synced 2026-10-21 08:09:49 -05:00
fixed some issues
This commit is contained in:
1 parent
fc134b146a
commit
fa63d8dc4f
11 files changed
+160
-43
No files matched your search
@@ -27,7 +27,7 @@
|
||||
<ProductName>ColorControl</ProductName>
|
||||
<PublisherName>Maassoft</PublisherName>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>3.2.1.0</ApplicationVersion>
|
||||
<ApplicationVersion>3.2.2.0</ApplicationVersion>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<PublishWizardCompleted>true</PublishWizardCompleted>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using NvAPIWrapper.Display;
|
||||
using NvAPIWrapper.Native.Display;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Script.Serialization;
|
||||
@@ -22,33 +21,7 @@ namespace ColorControl
|
||||
|
||||
public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
|
||||
{
|
||||
var format = ColorDataFormat.RGB;
|
||||
var dynamicRange = ColorDataDynamicRange.VESA;
|
||||
var colorDepth = ColorDataDepth.BPC8;
|
||||
var colorimetry = ColorDataColorimetry.Auto;
|
||||
var selectionPolicy = ColorDataSelectionPolicy.User;
|
||||
object value;
|
||||
if (dictionary.TryGetValue("ColorFormat", out value))
|
||||
{
|
||||
format = (ColorDataFormat)Enum.ToObject(typeof(ColorDataFormat), value);
|
||||
}
|
||||
if (dictionary.TryGetValue("ColorDepth", out value))
|
||||
{
|
||||
colorDepth = (ColorDataDepth)Enum.ToObject(typeof(ColorDataDepth), value);
|
||||
}
|
||||
if (dictionary.TryGetValue("Colorimetry", out value))
|
||||
{
|
||||
colorimetry = (ColorDataColorimetry)Enum.ToObject(typeof(ColorDataColorimetry), value);
|
||||
}
|
||||
if (dictionary.TryGetValue("DynamicRange", out value))
|
||||
{
|
||||
dynamicRange = (ColorDataDynamicRange)Enum.ToObject(typeof(ColorDataDynamicRange), value);
|
||||
}
|
||||
if (dictionary.TryGetValue("SelectionPolicy", out value))
|
||||
{
|
||||
selectionPolicy = (ColorDataSelectionPolicy)Enum.ToObject(typeof(ColorDataSelectionPolicy), value);
|
||||
}
|
||||
return new ColorData(format, dynamicRange: dynamicRange, colorimetry: colorimetry, colorDepth: colorDepth, colorSelectionPolicy: selectionPolicy, desktopColorDepth: ColorDataDesktopDepth.Default);
|
||||
return NvPreset.GenerateColorData(dictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,22 @@ namespace ColorControl
|
||||
public decimal MaxValue { get; set; }
|
||||
}
|
||||
|
||||
public enum PowerState
|
||||
{
|
||||
Unknown,
|
||||
Active,
|
||||
Power_Off,
|
||||
Suspend,
|
||||
Active_Standby
|
||||
}
|
||||
|
||||
public enum PowerOffSource
|
||||
{
|
||||
Unknown,
|
||||
App,
|
||||
Manually
|
||||
}
|
||||
|
||||
protected static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
public string Name { get; private set; }
|
||||
@@ -35,10 +51,17 @@ namespace ColorControl
|
||||
public bool PowerOffOnStandby { get; set; }
|
||||
public bool PowerSwitchOnScreenSaver { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public PowerState CurrentState { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
private LgTvApi _lgTvApi;
|
||||
[JsonIgnore]
|
||||
private bool _justWokeUp;
|
||||
[JsonIgnore]
|
||||
public PowerOffSource PoweredOffBy { get; private set; }
|
||||
|
||||
public bool PoweredOffViaApp { get; private set; }
|
||||
|
||||
[JsonIgnore]
|
||||
private List<InvokableAction> _invokableActions = new List<InvokableAction>();
|
||||
@@ -87,7 +110,9 @@ namespace ColorControl
|
||||
{
|
||||
Name = name,
|
||||
Function = new Func<Dictionary<string, string>, bool>(GenericPictureAction),
|
||||
EnumType = type
|
||||
EnumType = type,
|
||||
MinValue = minValue,
|
||||
MaxValue = maxValue
|
||||
};
|
||||
|
||||
_invokableActions.Add(action);
|
||||
@@ -95,7 +120,8 @@ namespace ColorControl
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return (IsDummy ? string.Empty : (IsCustom ? "Custom: " : "Auto detect: ")) + $"{Name}" + (!string.IsNullOrEmpty(IpAddress) ? $" ({IpAddress})" : string.Empty);
|
||||
//return (IsDummy ? string.Empty : (IsCustom ? "Custom: " : "Auto detect: ")) + $"{Name}" + (!string.IsNullOrEmpty(IpAddress) ? $" ({IpAddress})" : string.Empty);
|
||||
return $"{(IsDummy ? string.Empty : (IsCustom ? "Custom: " : "Auto detect: "))}{Name}{(!string.IsNullOrEmpty(IpAddress) ? ", " + IpAddress : string.Empty)}";
|
||||
}
|
||||
|
||||
public async Task<bool> Connect(int retries = 3)
|
||||
@@ -114,6 +140,14 @@ namespace ColorControl
|
||||
{
|
||||
ModelName = info.modelName;
|
||||
}
|
||||
|
||||
//await _lgTvApi.SubscribeVolume(VolumeChanged);
|
||||
await _lgTvApi.SubscribePowerState(PowerStateChanged);
|
||||
|
||||
//await _lgTvApi.SetInput("HDMI_1");
|
||||
//await Task.Delay(2000);
|
||||
//await _lgTvApi.SetConfig("com.palm.app.settings.enableHdmiPcLabel", true);
|
||||
//await _lgTvApi.SetInput("HDMI_2");
|
||||
}
|
||||
return _lgTvApi != null;
|
||||
}
|
||||
@@ -125,6 +159,40 @@ namespace ColorControl
|
||||
}
|
||||
}
|
||||
|
||||
public bool VolumeChanged(dynamic payload)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public bool PowerStateChanged(dynamic payload)
|
||||
{
|
||||
Logger.Debug($"[{Name}] Power state change: " + JsonConvert.SerializeObject(payload));
|
||||
|
||||
var state = ((string)payload.state).Replace(' ', '_');
|
||||
|
||||
PowerState newState;
|
||||
if (Enum.TryParse(state, out newState))
|
||||
{
|
||||
CurrentState = newState;
|
||||
|
||||
if (CurrentState == PowerState.Active)
|
||||
{
|
||||
if (payload.processing == null)
|
||||
{
|
||||
PoweredOffViaApp = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PoweredOffBy = PoweredOffViaApp ? PowerOffSource.App : PowerOffSource.Manually;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentState = PowerState.Unknown;
|
||||
Logger.Warn($"Unknown power state: {state}");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool IsConnected()
|
||||
{
|
||||
return !_lgTvApi?.ConnectionClosed ?? false;
|
||||
@@ -303,7 +371,10 @@ namespace ColorControl
|
||||
return false;
|
||||
}
|
||||
|
||||
PoweredOffViaApp = true;
|
||||
|
||||
await _lgTvApi.TurnOff();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -429,6 +429,12 @@ namespace ColorControl
|
||||
state == PowerOnOffState.ScreenSaver && d.PowerSwitchOnScreenSaver);
|
||||
foreach (var device in wakeDevices)
|
||||
{
|
||||
if (device.PoweredOffBy == LgDevice.PowerOffSource.Manually)
|
||||
{
|
||||
Logger.Debug($"[{device.Name}]: device was manually powered off by user, not powering on");
|
||||
continue;
|
||||
}
|
||||
|
||||
device.DisposeConnection();
|
||||
var _ = device.WakeAndConnectWithRetries(Config.PowerOnRetries);
|
||||
}
|
||||
|
||||
Generated
+2
-1
@@ -994,7 +994,7 @@
|
||||
this.miLgExpertSeparator1,
|
||||
this.mnuLgExpertBacklight});
|
||||
this.mnuLgExpert.Name = "mnuLgButtons";
|
||||
this.mnuLgExpert.Size = new System.Drawing.Size(321, 76);
|
||||
this.mnuLgExpert.Size = new System.Drawing.Size(321, 54);
|
||||
this.mnuLgExpert.Opening += new System.ComponentModel.CancelEventHandler(this.mnuLgExpert_Opening);
|
||||
//
|
||||
// mnuLgOLEDMotionPro
|
||||
@@ -1056,6 +1056,7 @@
|
||||
// cbxLgDevices
|
||||
//
|
||||
this.cbxLgDevices.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.cbxLgDevices.DropDownWidth = 400;
|
||||
this.cbxLgDevices.FormattingEnabled = true;
|
||||
this.cbxLgDevices.Location = new System.Drawing.Point(86, 8);
|
||||
this.cbxLgDevices.Name = "cbxLgDevices";
|
||||
|
||||
@@ -52,6 +52,7 @@ namespace ColorControl
|
||||
private StartUpParams StartUpParams { get; }
|
||||
|
||||
private AmdService _amdService;
|
||||
private bool _skipResize;
|
||||
|
||||
public MainForm(AppContext appContext)
|
||||
{
|
||||
@@ -541,6 +542,11 @@ namespace ColorControl
|
||||
|
||||
private void MainForm_Resize(object sender, EventArgs e)
|
||||
{
|
||||
if (_skipResize)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (WindowState == FormWindowState.Minimized)
|
||||
{
|
||||
if (_config.MinimizeToTray)
|
||||
@@ -578,8 +584,16 @@ namespace ColorControl
|
||||
Utils.RegisterShortcut(Handle, SHORTCUTID_SCREENSAVER, _config.ScreenSaverShortcut);
|
||||
}
|
||||
|
||||
Width = _config.FormWidth;
|
||||
Height = _config.FormHeight;
|
||||
_skipResize = true;
|
||||
try
|
||||
{
|
||||
Width = _config.FormWidth;
|
||||
Height = _config.FormHeight;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_skipResize = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveConfig()
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace ColorControl
|
||||
displayName = preset.displayName;
|
||||
|
||||
var colorData = preset.colorData;
|
||||
this.colorData = new ColorData(colorData.ColorFormat, dynamicRange: colorData.DynamicRange, colorDepth: colorData.ColorDepth, colorSelectionPolicy: colorData.SelectionPolicy);
|
||||
this.colorData = new ColorData(colorData.ColorFormat, dynamicRange: colorData.DynamicRange, colorDepth: colorData.ColorDepth, colorSelectionPolicy: ColorDataSelectionPolicy.User);
|
||||
applyColorData = preset.applyColorData;
|
||||
|
||||
applyHDR = preset.applyHDR;
|
||||
@@ -206,11 +206,16 @@ namespace ColorControl
|
||||
{
|
||||
dynamicRange = (ColorDataDynamicRange)Enum.ToObject(typeof(ColorDataDynamicRange), value);
|
||||
}
|
||||
if (dictionary.TryGetValue("SelectionPolicy", out value))
|
||||
if (dictionary.TryGetValue("SelectionPolicy", out _))
|
||||
{
|
||||
selectionPolicy = (ColorDataSelectionPolicy)Enum.ToObject(typeof(ColorDataSelectionPolicy), value);
|
||||
selectionPolicy =
|
||||
colorDepth == ColorDataDepth.Default &&
|
||||
format >= ColorDataFormat.Default &&
|
||||
colorimetry >= ColorDataColorimetry.Default &&
|
||||
dynamicRange == ColorDataDynamicRange.Auto ?
|
||||
ColorDataSelectionPolicy.BestQuality : selectionPolicy;
|
||||
}
|
||||
return new ColorData(format, dynamicRange: dynamicRange, colorimetry: colorimetry, colorDepth: colorDepth, colorSelectionPolicy: selectionPolicy);
|
||||
return new ColorData(format, dynamicRange: dynamicRange, colorimetry: colorimetry, colorDepth: colorDepth, colorSelectionPolicy: selectionPolicy, desktopColorDepth: ColorDataDesktopDepth.Default);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("3.2.1.0")]
|
||||
[assembly: AssemblyFileVersion("3.2.1.0")]
|
||||
[assembly: AssemblyVersion("3.2.2.0")]
|
||||
[assembly: AssemblyFileVersion("3.2.2.0")]
|
||||
@@ -307,7 +307,7 @@ namespace LgTv
|
||||
}
|
||||
public async Task<IEnumerable<ExternalInput>> GetInputList()
|
||||
{
|
||||
var requestMessage = new RequestMessage("input","ssap://tv/getExternalInputList");
|
||||
var requestMessage = new RequestMessage("input","ssap://tv/getExternalInputList");
|
||||
var results = await _connection.SendCommandAsync(requestMessage);
|
||||
var l = new List<ExternalInput>();
|
||||
foreach (var result in results)
|
||||
@@ -326,6 +326,20 @@ namespace LgTv
|
||||
await _connection.SendCommandAsync(requestMessage);
|
||||
}
|
||||
|
||||
public async Task SubscribeVolume(Func<dynamic, bool> callback, dynamic payload = null)
|
||||
{
|
||||
var requestMessage = new RequestMessage("ssap://audio/getVolume", null, "subscribe");
|
||||
|
||||
await _connection.SubscribeAsync(requestMessage, callback);
|
||||
}
|
||||
|
||||
public async Task SubscribePowerState(Func<dynamic, bool> callback, dynamic payload = null)
|
||||
{
|
||||
var requestMessage = new RequestMessage("ssap://com.webos.service.tvpower/power/getPowerState", null, "subscribe");
|
||||
|
||||
await _connection.SubscribeAsync(requestMessage, callback);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<App>> GetLaunchPoints()
|
||||
{
|
||||
_appList = new List<App>();
|
||||
@@ -436,6 +450,15 @@ namespace LgTv
|
||||
await ExecuteRequest(lunauri, @params);
|
||||
}
|
||||
|
||||
public async Task SetConfig(string key, bool value)
|
||||
{
|
||||
var lunauri = "luna://com.webos.service.config/setConfigs";
|
||||
|
||||
var @params = JObject.Parse(@"{ ""configs"": { """ + key + @""": " + value.ToString().ToLowerInvariant() + @" } }");
|
||||
|
||||
await ExecuteRequest(lunauri, @params);
|
||||
}
|
||||
|
||||
private async Task ExecuteRequest(string lunauri, object @params)
|
||||
{
|
||||
var buttons = new[]
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace LgTv
|
||||
|
||||
public event IsConnectedDelegate IsConnected;
|
||||
private readonly ConcurrentDictionary<string, TaskCompletionSource<dynamic>> _tokens = new ConcurrentDictionary<string, TaskCompletionSource<dynamic>>();
|
||||
private readonly ConcurrentDictionary<string, Func<dynamic, bool>> _callbacks = new ConcurrentDictionary<string, Func<dynamic, bool>>();
|
||||
|
||||
private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
@@ -135,6 +136,20 @@ namespace LgTv
|
||||
return SendCommandAsync(rawMessage.Id, serialized);
|
||||
}
|
||||
|
||||
public Task<dynamic> SubscribeAsync(RequestMessage message, Func<dynamic, bool> callback)
|
||||
{
|
||||
var rawMessage = new RawRequestMessage(message, ++_commandCount);
|
||||
var serialized = JsonConvert.SerializeObject(rawMessage, new JsonSerializerSettings()
|
||||
{
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||
});
|
||||
|
||||
_callbacks.TryAdd(rawMessage.Id, callback);
|
||||
|
||||
return SendCommandAsync(rawMessage.Id, serialized);
|
||||
}
|
||||
|
||||
private void Connection_Closed(IWebSocket sender, WebSocketClosedEventArgs args)
|
||||
{
|
||||
MessageWebSocket webSocket = Interlocked.Exchange(ref _connection, null);
|
||||
@@ -177,6 +192,11 @@ namespace LgTv
|
||||
// taskSource.SetCanceled();
|
||||
//}
|
||||
taskCompletion.TrySetResult(obj.payload);
|
||||
|
||||
if (_callbacks.TryGetValue(id, out Func<dynamic, bool> callback))
|
||||
{
|
||||
callback(obj.payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,14 @@ namespace LgTv
|
||||
Prefix = prefix;
|
||||
Uri = uri;
|
||||
}
|
||||
public RequestMessage(string uri,object payload)
|
||||
public RequestMessage(string uri, object payload, string type = "request")
|
||||
{
|
||||
Uri = uri;
|
||||
Payload = JsonConvert.SerializeObject(payload);
|
||||
if (payload != null)
|
||||
{
|
||||
Payload = JsonConvert.SerializeObject(payload);
|
||||
}
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public string Prefix { get; set; }
|
||||
|
||||
Reference in new issue
Block a user