mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
little code cleanup
This commit is contained in:
@@ -13,20 +13,20 @@ namespace mRemoteNG.Connection.Protocol.Http
|
||||
{
|
||||
#region Private Properties
|
||||
|
||||
private Control wBrowser;
|
||||
private Control _wBrowser;
|
||||
private string _tabTitle;
|
||||
protected string httpOrS;
|
||||
protected int defaultPort;
|
||||
private string tabTitle;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
protected HTTPBase(RenderingEngine RenderingEngine)
|
||||
protected HTTPBase(RenderingEngine renderingEngine)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (RenderingEngine == RenderingEngine.EdgeChromium)
|
||||
if (renderingEngine == RenderingEngine.EdgeChromium)
|
||||
{
|
||||
Control = new WebView2()
|
||||
{
|
||||
@@ -50,26 +50,26 @@ namespace mRemoteNG.Connection.Protocol.Http
|
||||
|
||||
try
|
||||
{
|
||||
if (InterfaceControl.Parent is ConnectionTab objConnectionTab) tabTitle = objConnectionTab.TabText;
|
||||
if (InterfaceControl.Parent is ConnectionTab objConnectionTab) _tabTitle = objConnectionTab.TabText;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
tabTitle = "";
|
||||
_tabTitle = "";
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
wBrowser = Control;
|
||||
_wBrowser = Control;
|
||||
|
||||
if (InterfaceControl.Info.RenderingEngine == RenderingEngine.EdgeChromium)
|
||||
{
|
||||
var edge = (WebView2)wBrowser;
|
||||
var edge = (WebView2)_wBrowser;
|
||||
|
||||
edge.CoreWebView2InitializationCompleted += Edge_CoreWebView2InitializationCompleted;
|
||||
}
|
||||
else
|
||||
{
|
||||
var objWebBrowser = (WebBrowser)wBrowser;
|
||||
var objWebBrowser = (WebBrowser)_wBrowser;
|
||||
objWebBrowser.ScrollBarsEnabled = true;
|
||||
|
||||
// http://stackoverflow.com/questions/4655662/how-to-ignore-script-errors-in-webbrowser
|
||||
@@ -94,11 +94,11 @@ namespace mRemoteNG.Connection.Protocol.Http
|
||||
{
|
||||
if (InterfaceControl.Info.RenderingEngine == RenderingEngine.EdgeChromium)
|
||||
{
|
||||
((WebView2)wBrowser).Source = new Uri(GetURL());
|
||||
((WebView2)_wBrowser).Source = new Uri(GetUrl());
|
||||
}
|
||||
else
|
||||
{
|
||||
((WebBrowser)wBrowser).Navigate(GetURL());
|
||||
((WebBrowser)_wBrowser).Navigate(GetUrl());
|
||||
}
|
||||
|
||||
base.Connect();
|
||||
@@ -115,22 +115,12 @@ namespace mRemoteNG.Connection.Protocol.Http
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private string GetURL()
|
||||
private string GetUrl()
|
||||
{
|
||||
try
|
||||
{
|
||||
var strHost = InterfaceControl.Info.Hostname;
|
||||
/*
|
||||
* Commenting out since this codes doesn't actually do anything at this time...
|
||||
* Possibly related to MR-221 and/or MR-533 ????
|
||||
*
|
||||
string strAuth = "";
|
||||
|
||||
if (((int)Force & (int)ConnectionInfo.Force.NoCredentials) != (int)ConnectionInfo.Force.NoCredentials && !string.IsNullOrEmpty(InterfaceControl.Info.Username) && !string.IsNullOrEmpty(InterfaceControl.Info.Password))
|
||||
{
|
||||
strAuth = "Authorization: Basic " + Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(InterfaceControl.Info.Username + ":" + InterfaceControl.Info.Password)) + Environment.NewLine;
|
||||
}
|
||||
*/
|
||||
if (InterfaceControl.Info.Port != defaultPort)
|
||||
{
|
||||
if (strHost.EndsWith("/"))
|
||||
@@ -146,6 +136,7 @@ namespace mRemoteNG.Connection.Protocol.Http
|
||||
if (strHost.Contains(httpOrS + "://") == false)
|
||||
strHost = httpOrS + "://" + strHost;
|
||||
}
|
||||
|
||||
return strHost;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -163,14 +154,13 @@ namespace mRemoteNG.Connection.Protocol.Http
|
||||
{
|
||||
if (!e.IsSuccess)
|
||||
{
|
||||
//TODO: Log
|
||||
MessageBox.Show($"WebView2 creation failed with exception = {e.InitializationException}");
|
||||
Runtime.MessageCollector.AddExceptionStackTrace(Language.HttpFailedUrlBuild, e.InitializationException);
|
||||
}
|
||||
}
|
||||
|
||||
private void WBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
|
||||
{
|
||||
if (!(wBrowser is WebBrowser objWebBrowser)) return;
|
||||
if (!(_wBrowser is WebBrowser objWebBrowser)) return;
|
||||
|
||||
// This can only be set once the WebBrowser control is shown, it will throw a COM exception otherwise.
|
||||
objWebBrowser.AllowWebBrowserDrop = false;
|
||||
@@ -184,18 +174,18 @@ namespace mRemoteNG.Connection.Protocol.Http
|
||||
{
|
||||
if (!(InterfaceControl.Parent is ConnectionTab tabP)) return;
|
||||
string shortTitle;
|
||||
if (((WebBrowser)wBrowser).DocumentTitle.Length >= 15)
|
||||
if (((WebBrowser)_wBrowser).DocumentTitle.Length >= 15)
|
||||
{
|
||||
shortTitle = ((WebBrowser)wBrowser).DocumentTitle.Substring(0, 10) + "...";
|
||||
shortTitle = ((WebBrowser)_wBrowser).DocumentTitle.Substring(0, 10) + "...";
|
||||
}
|
||||
else
|
||||
{
|
||||
shortTitle = ((WebBrowser)wBrowser).DocumentTitle;
|
||||
shortTitle = ((WebBrowser)_wBrowser).DocumentTitle;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(tabTitle))
|
||||
if (!string.IsNullOrEmpty(_tabTitle))
|
||||
{
|
||||
tabP.TabText = tabTitle + @" - " + shortTitle;
|
||||
tabP.TabText = _tabTitle + @" - " + shortTitle;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -6082,6 +6082,15 @@ namespace mRemoteNG.Resources.Language {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Zeichenfolge, die WebView2 creation failed with exception ähnelt.
|
||||
/// </summary>
|
||||
internal static string WebView2InitializationFailed {
|
||||
get {
|
||||
return ResourceManager.GetString("WebView2InitializationFailed", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Zeichenfolge, die Weekly ähnelt.
|
||||
/// </summary>
|
||||
|
||||
@@ -2022,4 +2022,7 @@ Nightly umfasst Alphas, Betas und Release Candidates.</value>
|
||||
<data name="ExceptionMessage" xml:space="preserve">
|
||||
<value>Fehlermeldung</value>
|
||||
</data>
|
||||
<data name="WebView2InitializationFailed" xml:space="preserve">
|
||||
<value>WebView2-Erstellung fehlgeschlagen</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -2147,4 +2147,7 @@ Nightly Channel includes Alphas, Betas & Release Candidates.</value>
|
||||
<data name="StartProgram" xml:space="preserve">
|
||||
<value>Start Program</value>
|
||||
</data>
|
||||
<data name="WebView2InitializationFailed" xml:space="preserve">
|
||||
<value>WebView2 creation failed with exception</value>
|
||||
</data>
|
||||
</root>
|
||||
Reference in New Issue
Block a user