fixed some issues, added check for updates

This commit is contained in:
Vincent Maas committed 2021-08-16 13:59:01 +02:00
1 parent 92f4ab8ef5
commit 3667243fc7
12 files changed
+193 -56

No files matched your search

+1 -1
View File
@@ -7,7 +7,7 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+4 -1
View File
@@ -27,7 +27,7 @@
<ProductName>ColorControl</ProductName>
<PublisherName>Maassoft</PublisherName>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>4.0.0.0</ApplicationVersion>
<ApplicationVersion>4.1.0.0</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
@@ -141,6 +141,9 @@
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.Formatting, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll</HintPath>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
+3
View File
@@ -8,6 +8,8 @@
public bool MinimizeToTray { get; set; }
public bool CheckForUpdates { get; set; }
public int DisplaySettingsDelay { get; set; }
public string ScreenSaverShortcut { get; set; }
@@ -26,6 +28,7 @@
FormWidth = 900;
FormHeight = 600;
MinimizeToTray = true;
CheckForUpdates = true;
}
}
}
+4 -2
View File
@@ -223,13 +223,15 @@ namespace ColorControl
{
var settings = payload.settings;
Logger.Debug($"PictureSettingsChanged: {JsonConvert.SerializeObject(settings)}");
if (settings.backlight != null)
{
PictureSettings.Backlight = int.Parse(settings.backlight.Value);
PictureSettings.Backlight = Utils.ParseInt(settings.backlight.Value, PictureSettings.Backlight);
}
if (settings.contrast != null)
{
PictureSettings.Contrast = int.Parse(settings.contrast.Value);
PictureSettings.Contrast = Utils.ParseInt(settings.contrast.Value, PictureSettings.Contrast);
}
}
+1 -1
View File
@@ -277,7 +277,7 @@ namespace ColorControl
private void SaveConfig()
{
Config.PowerOnAfterStartup = Devices.Any(d => d.PowerOnAfterStartup);
Config.PowerOnAfterStartup = Devices?.Any(d => d.PowerOnAfterStartup) ?? false;
var json = JsonConvert.SerializeObject(Config);
File.WriteAllText(_configFilename, json);
+35 -21
View File
@@ -104,6 +104,8 @@
this.lvAmdPresets = new System.Windows.Forms.ListView();
this.tabLG = new System.Windows.Forms.TabPage();
this.scLgController = new System.Windows.Forms.SplitContainer();
this.btnLgPresetEditTriggerConditions = new System.Windows.Forms.Button();
this.edtLgPresetTriggerConditions = new System.Windows.Forms.TextBox();
this.lblLgPresetExcludedProcesses = new System.Windows.Forms.Label();
this.edtLgPresetExcludedProcesses = new System.Windows.Forms.TextBox();
this.lblLgPresetIncludedProcesses = new System.Windows.Forms.Label();
@@ -191,8 +193,7 @@
this.lbPlugins = new System.Windows.Forms.ListBox();
this.label7 = new System.Windows.Forms.Label();
this.lblInfo = new System.Windows.Forms.Label();
this.edtLgPresetTriggerConditions = new System.Windows.Forms.TextBox();
this.btnLgPresetEditTriggerConditions = new System.Windows.Forms.Button();
this.chkCheckForUpdates = new System.Windows.Forms.CheckBox();
this.tcMain.SuspendLayout();
this.tabNVIDIA.SuspendLayout();
this.mnuNvPresets.SuspendLayout();
@@ -995,6 +996,27 @@
this.scLgController.SplitterDistance = 767;
this.scLgController.TabIndex = 43;
//
// btnLgPresetEditTriggerConditions
//
this.btnLgPresetEditTriggerConditions.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnLgPresetEditTriggerConditions.Location = new System.Drawing.Point(689, 317);
this.btnLgPresetEditTriggerConditions.Name = "btnLgPresetEditTriggerConditions";
this.btnLgPresetEditTriggerConditions.Size = new System.Drawing.Size(75, 23);
this.btnLgPresetEditTriggerConditions.TabIndex = 54;
this.btnLgPresetEditTriggerConditions.Text = "Edit...";
this.btnLgPresetEditTriggerConditions.UseVisualStyleBackColor = true;
this.btnLgPresetEditTriggerConditions.Click += new System.EventHandler(this.btnLgPresetEditTriggerConditions_Click);
//
// edtLgPresetTriggerConditions
//
this.edtLgPresetTriggerConditions.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.edtLgPresetTriggerConditions.Enabled = false;
this.edtLgPresetTriggerConditions.Location = new System.Drawing.Point(515, 319);
this.edtLgPresetTriggerConditions.Name = "edtLgPresetTriggerConditions";
this.edtLgPresetTriggerConditions.ReadOnly = true;
this.edtLgPresetTriggerConditions.Size = new System.Drawing.Size(167, 20);
this.edtLgPresetTriggerConditions.TabIndex = 53;
//
// lblLgPresetExcludedProcesses
//
this.lblLgPresetExcludedProcesses.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
@@ -1755,6 +1777,7 @@
//
// grpGeneralOptions
//
this.grpGeneralOptions.Controls.Add(this.chkCheckForUpdates);
this.grpGeneralOptions.Controls.Add(this.chkMinimizeToSystemTray);
this.grpGeneralOptions.Controls.Add(this.chkMinimizeOnClose);
this.grpGeneralOptions.Controls.Add(this.chkStartMinimized);
@@ -1931,26 +1954,16 @@
this.lblInfo.TabIndex = 1;
this.lblInfo.Text = "Info";
//
// edtLgPresetTriggerConditions
// chkCheckForUpdates
//
this.edtLgPresetTriggerConditions.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.edtLgPresetTriggerConditions.Enabled = false;
this.edtLgPresetTriggerConditions.Location = new System.Drawing.Point(515, 319);
this.edtLgPresetTriggerConditions.Name = "edtLgPresetTriggerConditions";
this.edtLgPresetTriggerConditions.ReadOnly = true;
this.edtLgPresetTriggerConditions.Size = new System.Drawing.Size(167, 20);
this.edtLgPresetTriggerConditions.TabIndex = 53;
//
// btnLgPresetEditTriggerConditions
//
this.btnLgPresetEditTriggerConditions.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnLgPresetEditTriggerConditions.Location = new System.Drawing.Point(689, 317);
this.btnLgPresetEditTriggerConditions.Name = "btnLgPresetEditTriggerConditions";
this.btnLgPresetEditTriggerConditions.Size = new System.Drawing.Size(75, 23);
this.btnLgPresetEditTriggerConditions.TabIndex = 54;
this.btnLgPresetEditTriggerConditions.Text = "Edit...";
this.btnLgPresetEditTriggerConditions.UseVisualStyleBackColor = true;
this.btnLgPresetEditTriggerConditions.Click += new System.EventHandler(this.btnLgPresetEditTriggerConditions_Click);
this.chkCheckForUpdates.AutoSize = true;
this.chkCheckForUpdates.Location = new System.Drawing.Point(204, 42);
this.chkCheckForUpdates.Name = "chkCheckForUpdates";
this.chkCheckForUpdates.Size = new System.Drawing.Size(177, 17);
this.chkCheckForUpdates.TabIndex = 6;
this.chkCheckForUpdates.Text = "Automatically check for updates";
this.chkCheckForUpdates.UseVisualStyleBackColor = true;
this.chkCheckForUpdates.CheckedChanged += new System.EventHandler(this.chkCheckForUpdates_CheckedChanged);
//
// MainForm
//
@@ -2172,6 +2185,7 @@
private System.Windows.Forms.TextBox edtLgPresetIncludedProcesses;
private System.Windows.Forms.Button btnLgPresetEditTriggerConditions;
private System.Windows.Forms.TextBox edtLgPresetTriggerConditions;
private System.Windows.Forms.CheckBox chkCheckForUpdates;
}
}
+88 -23
View File
@@ -53,6 +53,9 @@ namespace ColorControl
private AmdService _amdService;
private bool _skipResize;
private FileVersionInfo _currentVersionInfo;
private bool _checkedForUpdates = false;
private string _updateHtmlUrl;
public MainForm(AppContext appContext)
{
@@ -86,6 +89,7 @@ namespace ColorControl
};
_trayIcon.MouseDoubleClick += trayIcon_MouseDoubleClick;
_trayIcon.ContextMenu.Popup += trayIconContextMenu_Popup;
_trayIcon.BalloonTipClicked += trayIconBalloonTip_Clicked;
chkStartAfterLogin.Checked = Utils.TaskExists(TS_TASKNAME, true);
@@ -116,6 +120,7 @@ namespace ColorControl
{
try
{
//throw new Exception("bla");
_nvService = new NvService(_dataDir);
FillNvPresets();
@@ -194,6 +199,8 @@ namespace ColorControl
private void AfterLgServiceRefreshDevices()
{
FillLgDevices();
if (StartUpParams.ExecuteLgPreset)
{
var _ = _lgService.ApplyPreset(StartUpParams.LgPresetName);
@@ -221,7 +228,7 @@ namespace ColorControl
private void InitInfo()
{
var fileVersionInfo = FileVersionInfo.GetVersionInfo(Path.GetFileName(Application.ExecutablePath));
_currentVersionInfo = FileVersionInfo.GetVersionInfo(Path.GetFileName(Application.ExecutablePath));
if (ApplicationDeployment.IsNetworkDeployed)
{
@@ -232,7 +239,7 @@ namespace ColorControl
Text = Application.ProductName + " " + Application.ProductVersion;
}
lblInfo.Text = Text + " - " + fileVersionInfo.LegalCopyright;
lblInfo.Text = Text + " - " + _currentVersionInfo.LegalCopyright;
lbPlugins.Items.Add("lgtv.net by gr4b4z");
lbPlugins.Items.Add("Newtonsoft.Json by James Newton-King");
@@ -261,6 +268,14 @@ namespace ColorControl
WindowState = FormWindowState.Normal;
}
private void trayIconBalloonTip_Clicked(object sender, EventArgs e)
{
if (_updateHtmlUrl != null)
{
Utils.StartProcess(_updateHtmlUrl);
}
}
private void FillNvPresets()
{
Utils.InitListView(lvNvPresets, NvPreset.GetColumnNames());
@@ -611,6 +626,7 @@ namespace ColorControl
chkStartMinimized.Checked = _config.StartMinimized;
chkMinimizeOnClose.Checked = _config.MinimizeOnClose;
chkMinimizeToSystemTray.Checked = _config.MinimizeToTray;
chkCheckForUpdates.Checked = _config.CheckForUpdates;
edtDelayDisplaySettings.Value = _config.DisplaySettingsDelay;
edtBlankScreenSaverShortcut.Text = _config.ScreenSaverShortcut;
@@ -687,6 +703,9 @@ namespace ColorControl
lblLgError.Text = "Error while initializing the LG-controller. You either don't have a LG TV or it is disabled.";
lblLgError.Visible = true;
}
InitSelectedTab();
CheckForUpdates();
}
protected override void SetVisibleCore(bool value)
@@ -1271,6 +1290,11 @@ namespace ColorControl
}
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
InitSelectedTab();
}
private void InitSelectedTab()
{
if (tcMain.SelectedTab == tabLG)
{
@@ -1292,29 +1316,16 @@ namespace ColorControl
private void InitLgTab()
{
if (cbxLgDevices.Items.Count == 0 && _lgService != null)
if (scLgController.Panel2.Controls.Count == 0)
{
var devices = _lgService.Devices;
if (devices == null || !devices.Any())
{
RefreshLgDevices();
}
else
{
FillLgDevices();
}
if (scLgController.Panel2.Controls.Count == 0)
{
var rcPanel = new RemoteControlPanel(_lgService, _lgService.GetRemoteControlButtons());
rcPanel.Parent = scLgController.Panel2;
rcPanel.Dock = DockStyle.Fill;
}
chkLgRemoteControlShow.Checked = _lgService.Config.ShowRemoteControl;
scLgController.Panel2Collapsed = !_lgService.Config.ShowRemoteControl;
Utils.BuildComboBox<PresetTriggerType>(cbxLgPresetTrigger, PresetTriggerType.Resume, PresetTriggerType.Screensaver, PresetTriggerType.Shutdown, PresetTriggerType.Standby, PresetTriggerType.Startup);
var rcPanel = new RemoteControlPanel(_lgService, _lgService.GetRemoteControlButtons());
rcPanel.Parent = scLgController.Panel2;
rcPanel.Dock = DockStyle.Fill;
}
chkLgRemoteControlShow.Checked = _lgService.Config.ShowRemoteControl;
scLgController.Panel2Collapsed = !_lgService.Config.ShowRemoteControl;
Utils.BuildComboBox<PresetTriggerType>(cbxLgPresetTrigger, PresetTriggerType.Resume, PresetTriggerType.Screensaver, PresetTriggerType.Shutdown, PresetTriggerType.Standby, PresetTriggerType.Startup);
}
private void InitOptionsTab()
@@ -2039,6 +2050,52 @@ Do you want to continue?";
{
ApplyNvPresetOnStartup();
ApplyAmdPresetOnStartup();
if (_trayIcon.Visible)
{
CheckForUpdates();
}
}
private void CheckForUpdates()
{
if (!_config.CheckForUpdates || _checkedForUpdates || Debugger.IsAttached)
{
return;
}
_checkedForUpdates = true;
var _ = Utils.GetRestJsonAsync("https://api.github.com/repos/maassoft/colorcontrol/releases/latest", InitHandleCheckForUpdates);
}
private void InitHandleCheckForUpdates(dynamic latest)
{
BeginInvoke(new Action<dynamic>(HandleCheckForUpdates), new[] { latest });
}
private void HandleCheckForUpdates(dynamic latest)
{
if (latest?.tag_name == null)
{
return;
}
var currentVersion = Application.ProductVersion;
var newVersion = latest.tag_name.Value.Substring(1);
if (newVersion.CompareTo(currentVersion) > 0)
{
_updateHtmlUrl = latest.html_url.Value;
if (_trayIcon.Visible)
{
_trayIcon.ShowBalloonTip(5000, "Update available", $"Version {newVersion} is available. Click to open the GitHub page", ToolTipIcon.Info);
}
else
{
MessageForms.InfoOk($"New version {newVersion} is available. Click on the Help-button to open the GitHub page.", "Update available", "https://github.com/Maassoft/ColorControl/releases/tag/v4.0.0.0");
}
}
}
private void ApplyNvPresetOnStartup(int attempts = 5) {
@@ -2749,5 +2806,13 @@ Do you want to continue?"
edtLgPresetTriggerConditions.Tag = (PresetConditionType)values.First().Value;
edtLgPresetTriggerConditions.Text = Utils.GetDescriptions<PresetConditionType>((int)value).Join(", ");
}
private void chkCheckForUpdates_CheckedChanged(object sender, EventArgs e)
{
if (_initialized)
{
_config.CheckForUpdates = chkCheckForUpdates.Checked;
}
}
}
}
+2 -2
View File
@@ -38,9 +38,9 @@ namespace ColorControl
MessageBox.Show(text, MainForm?.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
public static void InfoOk(string text)
public static void InfoOk(string text, string title = null, string url = null)
{
MessageBox.Show(text, MainForm?.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show(text, title ?? MainForm?.Text, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, 0, url);
}
public static DialogResult QuestionYesNo(string text)
+2 -2
View File
@@ -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("4.0.0.0")]
[assembly: AssemblyFileVersion("4.0.0.0")]
[assembly: AssemblyVersion("4.1.0.0")]
[assembly: AssemblyFileVersion("4.1.0.0")]
+42 -1
View File
@@ -12,13 +12,13 @@ using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Windows;
using System.Windows.Forms;
using Windows.Devices.Enumeration;
using Windows.Devices.Enumeration.Pnp;
@@ -630,6 +630,11 @@ namespace ColorControl
public static int SetComboBoxEnumIndex(ComboBox comboBox, int value)
{
if (comboBox.Items.Count == 0)
{
return -1;
}
var index = 0;
for (var i = 0; i < comboBox.Items.Count; i++)
@@ -926,6 +931,42 @@ namespace ColorControl
}
target.AddRange(words);
}
public static int ParseInt(string value, int def = 0)
{
if (int.TryParse(value, out var result))
{
return result;
}
return def;
}
public static async Task<dynamic> GetRestJsonAsync(string url, Action<dynamic> callBack = null)
{
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.UserAgent.TryParseAdd("request");
var response = await httpClient.GetAsync(url);
if (response.IsSuccessStatusCode)
{
var result = await response.Content.ReadAsAsync<dynamic>();
if (callBack != null)
{
callBack(result);
}
return result;
}
if (callBack != null)
{
callBack(null);
}
return null;
}
}
public class EnumComboBoxItem
+10 -2
View File
@@ -205,7 +205,14 @@ namespace LgTv
if (_callbacks.TryGetValue(id, out Func<dynamic, bool> callback))
{
callback(obj.payload);
try
{
callback(obj.payload);
}
catch (Exception callbackException)
{
Logger.Error($"Connection_MessageReceived: the callback threw an exception: {callbackException.ToLogString()}");
}
}
}
}
@@ -230,8 +237,9 @@ namespace LgTv
{
try
{
if (taskCompletion.Task?.Status == TaskStatus.Running)
if (taskCompletion.Task.Status != TaskStatus.RanToCompletion)
{
Logger.Debug("taskCompletion.Task.Status: " + taskCompletion.Task.Status);
taskCompletion.SetException(new Exception(ex.Message));
}
}
+1
View File
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.7" targetFramework="net472" />
<package id="Native" version="0.1.1" targetFramework="net472" />
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net472" />
<package id="NLog" version="4.7.10" targetFramework="net472" />