Skip to content

Commit

Permalink
Added System.Management.Automation to work on #5
Browse files Browse the repository at this point in the history
Broke debugging communication between C# and WebView
  • Loading branch information
megastary committed Aug 23, 2021
1 parent 4fe023d commit fc10a15
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
Expand All @@ -11,26 +13,28 @@ namespace HoubyStudio.LazyAdmin.DesktopApp
/// <summary>
/// Handles postMessage events received from EdgeView2 control.
/// </summary>
public static class LazyAdminPowerShell
public class LazyAdminPowerShell
{

// Mock PowerShell
private static TextBox _powerShell;

public static TextBox PowerShell
{
set => _powerShell = value;
}
private PowerShell _powerShell;
private RunspacePool runespacePool = RunspaceFactory.CreateRunspacePool();

public static void ReceiveMessage(object sender, CoreWebView2WebMessageReceivedEventArgs args)
//public static TextBox PowerShell
//{
// set => _powerShell = value;
//}

public void ReceiveMessage(object sender, CoreWebView2WebMessageReceivedEventArgs args)
{
try
{
// TODO: Replace with args.WebMessageAsJson and handle data accordingly
_powerShell.Text = args.TryGetWebMessageAsString();
} catch
//_powerShell = args.TryGetWebMessageAsString();
}
catch
{
_powerShell.Text = "";
//_powerShell = "";
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static async void InitializeWebView()
//await _webView.CoreWebView2.AddScriptToExecuteOnDocumentCreatedAsync("window.chrome.webview.addEventListener(\'message\', event => alert(event.data));");

// Register event listener for PowerShell handler
_webView.CoreWebView2.WebMessageReceived += LazyAdminPowerShell.ReceiveMessage;
//_webView.CoreWebView2.WebMessageReceived += LazyAdminPowerShell.ReceiveMessage;
}
}
}

0 comments on commit fc10a15

Please sign in to comment.