Skip to content

Commit

Permalink
Squash my 5 commits into one new, the more easily merge into 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
denisabt committed Oct 30, 2024
1 parent e08c937 commit 090c2c2
Show file tree
Hide file tree
Showing 8 changed files with 383 additions and 295 deletions.

Large diffs are not rendered by default.

44 changes: 40 additions & 4 deletions src/HASS.Agent/HASS.Agent/Controls/Configuration/ConfigTrayIcon.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using System.Diagnostics;
using HASS.Agent.Functions;
using HASS.Agent.Functions;
using HASS.Agent.Models.Internal;
using System.Diagnostics;
using Syncfusion.Windows.Forms.Tools;

namespace HASS.Agent.Controls.Configuration
{
public partial class ConfigTrayIcon : UserControl
{
internal int SelectedScreen { get; set; }

public ConfigTrayIcon()
{
InitializeComponent();
Expand All @@ -14,6 +17,34 @@ public ConfigTrayIcon()
private void ConfigTrayIcon_Load(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(TbWebViewUrl.Text)) TbWebViewUrl.Text = Variables.AppSettings.HassUri;
InitMultiScreenConfig(Variables.AppSettings.TrayIconWebViewScreen);
}

private void InitMultiScreenConfig(int selectedScreenIndex = 0)
{
var displays = Screen.AllScreens;
int ix = 0;

if (Screen.AllScreens.Length == 1)
{
NumWebViewScreen.Visible = false;
selectedScreenIndex = 0;
}

// Add screens to updownControl
foreach (var display in displays)
{
string label = display.DeviceName;
if (display.Primary)
{
label += " (Primary)";
}
NumWebViewScreen.Items.Add(label);
ix++;
}

NumWebViewScreen.SelectedIndex = selectedScreenIndex;
SelectedScreen = selectedScreenIndex;
}

private void CbDefaultMenu_CheckedChanged(object sender, EventArgs e)
Expand Down Expand Up @@ -45,14 +76,19 @@ private void BtnShowWebViewPreview_Click(object sender, EventArgs e)
IsTrayIconWebView = true,
IsTrayIconPreview = true
};

HelperFunctions.LaunchTrayIconWebView(webView);
Debug.WriteLine("X-Coordinate " + webView.X);
HelperFunctions.LaunchTrayIconWebView(webView, NumWebViewScreen.SelectedIndex);
}

private void BtnWebViewReset_Click(object sender, EventArgs e)
{
NumWebViewWidth.Value = 700;
NumWebViewHeight.Value = 560;
}

private void domainUpDown1_SelectedItemChanged(object sender, EventArgs e)
{
SelectedScreen = ((ComboBoxAdv) sender).SelectedIndex;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,64 @@
<root>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
Expand Down
2 changes: 2 additions & 0 deletions src/HASS.Agent/HASS.Agent/Forms/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ private void LoadSettings()
_trayIcon.CbShowWebView.CheckState = Variables.AppSettings.TrayIconShowWebView ? CheckState.Checked : CheckState.Unchecked;
_trayIcon.NumWebViewWidth.Value = Variables.AppSettings.TrayIconWebViewWidth;
_trayIcon.NumWebViewHeight.Value = Variables.AppSettings.TrayIconWebViewHeight;
_trayIcon.SelectedScreen = Variables.AppSettings.TrayIconWebViewScreen;
_trayIcon.TbWebViewUrl.Text = Variables.AppSettings.TrayIconWebViewUrl;
_trayIcon.CbWebViewKeepLoaded.CheckState = Variables.AppSettings.TrayIconWebViewBackgroundLoading ? CheckState.Checked : CheckState.Unchecked;
_trayIcon.CbWebViewShowMenuOnLeftClick.CheckState = Variables.AppSettings.TrayIconWebViewShowMenuOnLeftClick ? CheckState.Checked : CheckState.Unchecked;
Expand Down Expand Up @@ -460,6 +461,7 @@ private async Task StoreSettingsAsync()
Variables.AppSettings.TrayIconShowWebView = _trayIcon.CbShowWebView.CheckState == CheckState.Checked;
Variables.AppSettings.TrayIconWebViewWidth = (int)_trayIcon.NumWebViewWidth.Value;
Variables.AppSettings.TrayIconWebViewHeight = (int)_trayIcon.NumWebViewHeight.Value;
Variables.AppSettings.TrayIconWebViewScreen = _trayIcon.NumWebViewScreen.SelectedIndex;
Variables.AppSettings.TrayIconWebViewUrl = _trayIcon.TbWebViewUrl.Text;
Variables.AppSettings.TrayIconWebViewBackgroundLoading = _trayIcon.CbWebViewKeepLoaded.CheckState == CheckState.Checked;
Variables.AppSettings.TrayIconWebViewShowMenuOnLeftClick = _trayIcon.CbWebViewShowMenuOnLeftClick.CheckState == CheckState.Checked;
Expand Down
2 changes: 1 addition & 1 deletion src/HASS.Agent/HASS.Agent/Forms/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ private void NotifyIcon_MouseClick(object sender, MouseEventArgs e)
};

// show it
HelperFunctions.LaunchTrayIconWebView(webView);
HelperFunctions.LaunchTrayIconWebView(webView, Variables.AppSettings.TrayIconWebViewScreen);
}

private async void PbDonate_Click(object sender, EventArgs e)
Expand Down
22 changes: 11 additions & 11 deletions src/HASS.Agent/HASS.Agent/Functions/HelperFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ internal static void LaunchWebView(WebViewInfo webViewInfo, string url = "")
/// <summary>
/// Prepares and loads the tray icon's webview
/// </summary>
internal static void PrepareTrayIconWebView()
internal static void PrepareTrayIconWebView(int screenIndex = 0)
{
// prepare the webview info
var webViewInfo = new WebViewInfo
Expand All @@ -435,8 +435,8 @@ internal static void PrepareTrayIconWebView()
IsTrayIconWebView = true
};

var x = Screen.PrimaryScreen.WorkingArea.Width - webViewInfo.Width;
var y = Screen.PrimaryScreen.WorkingArea.Height - webViewInfo.Height;
var x = Screen.AllScreens[screenIndex].Bounds.Right - webViewInfo.Width;
var y = Screen.AllScreens[screenIndex].Bounds.Bottom - webViewInfo.Height;

webViewInfo.X = x;
webViewInfo.Y = y;
Expand All @@ -463,13 +463,13 @@ internal static void PrepareTrayIconWebView()
/// Shows a new webview form near the tray icon
/// </summary>
/// <param name="webViewInfo"></param>
internal static void LaunchTrayIconWebView(WebViewInfo webViewInfo)
internal static void LaunchTrayIconWebView(WebViewInfo webViewInfo, int screenIndex = 0)
{
// are we previewing?
if (webViewInfo.IsTrayIconPreview)
{
// yep, show as configured
LaunchTrayIconCustomWebView(webViewInfo);
LaunchTrayIconCustomWebView(webViewInfo, screenIndex);

// done
return;
Expand All @@ -479,17 +479,17 @@ internal static void LaunchTrayIconWebView(WebViewInfo webViewInfo)
if (Variables.AppSettings.TrayIconWebViewBackgroundLoading)
{
// yep
LaunchTrayIconBackgroundLoadedWebView();
LaunchTrayIconBackgroundLoadedWebView(screenIndex);

// done
return;
}

// show a new webview from within the UI thread
LaunchTrayIconCustomWebView(webViewInfo);
LaunchTrayIconCustomWebView(webViewInfo, screenIndex);
}

private static void LaunchTrayIconBackgroundLoadedWebView()
private static void LaunchTrayIconBackgroundLoadedWebView(int screenIndex)
{
Variables.MainForm.Invoke(new MethodInvoker(delegate
{
Expand All @@ -501,12 +501,12 @@ private static void LaunchTrayIconBackgroundLoadedWebView()
}));
}

private static void LaunchTrayIconCustomWebView(WebViewInfo webViewInfo)
private static void LaunchTrayIconCustomWebView(WebViewInfo webViewInfo, int screenIndex = 0)
{
Variables.MainForm.Invoke(new MethodInvoker(delegate
{
var x = Screen.PrimaryScreen.WorkingArea.Width - webViewInfo.Width;
var y = Screen.PrimaryScreen.WorkingArea.Height - webViewInfo.Height;
var x = Screen.AllScreens[screenIndex].Bounds.Right - webViewInfo.Width;
var y = Screen.AllScreens[screenIndex].Bounds.Bottom - webViewInfo.Height;

webViewInfo.X = x;
webViewInfo.Y = y;
Expand Down
1 change: 1 addition & 0 deletions src/HASS.Agent/HASS.Agent/Models/Config/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public AppSettings()
public bool TrayIconShowWebView { get; set; } = false;
public int TrayIconWebViewWidth { get; set; } = 700;
public int TrayIconWebViewHeight { get; set; } = 560;
public int TrayIconWebViewScreen { get; set; } = 0;
public string TrayIconWebViewUrl { get; set; } = string.Empty;
public bool TrayIconWebViewBackgroundLoading { get; set; } = false;
public bool TrayIconWebViewShowMenuOnLeftClick { get; set; } = false;
Expand Down
21 changes: 8 additions & 13 deletions src/HASS.Agent/HASS.Agent/Variables.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
extern alias WV2;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Net.Http;
using System.Reflection;
using Windows.Media.Playback;
using CoreAudio;
using Grapevine;
using HASS.Agent.Forms;
using HASS.Agent.Functions;
using HASS.Agent.Managers;
using HASS.Agent.Models.Config;
using HASS.Agent.Models.Internal;
using HASS.Agent.MQTT;
using HASS.Agent.Service;
using HASS.Agent.Settings;
using HASS.Agent.Shared.HomeAssistant;
using HASS.Agent.Shared.HomeAssistant.Commands;
using HASS.Agent.Shared.HomeAssistant.Sensors;
using HASS.Agent.Shared.Models.HomeAssistant;
using HASS.Agent.Shared.Mqtt;
using WV2::Microsoft.Web.WebView2.Core;
using Microsoft.Win32;
using MQTTnet;
using WK.Libraries.HotkeyListenerNS;
using Serilog.Core;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Net.Http;
using System.Reflection;
using Windows.Media.Playback;
using WK.Libraries.HotkeyListenerNS;
using WV2::Microsoft.Web.WebView2.Core;

namespace HASS.Agent
{
Expand Down

0 comments on commit 090c2c2

Please sign in to comment.