Skip to content

Commit

Permalink
Slowly removing unnecessary code #8
Browse files Browse the repository at this point in the history
  • Loading branch information
megastary committed Aug 29, 2021
1 parent 80dd119 commit 1ccea74
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace HoubyStudio.LazyAdmin.DesktopApp
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using Microsoft.Extensions.Configuration;
Expand Down Expand Up @@ -62,7 +63,9 @@ private async void Application_Exit(object sender, ExitEventArgs e)
{
using (this.host)
{
await this.host.StopAsync();
var timeoutCts = new CancellationTokenSource(1000);

await this.host.RunAsync(timeoutCts.Token);
}

this.OnExit(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private void Output_DataAdded(object sender, DataAddedEventArgs e)
_ = System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
// LazyAdminWebView.ShowMessage("Results obtained");
MainWindow.ShowMessageFromThread(Guid.NewGuid(), "Running");
//MainWindow.ShowMessageFromThread(Guid.NewGuid(), "Running");
}));
// LazyAdminWebView.ShowMessage("Result mate");
// dispatcher.Invoke((Action)(() => MockPowerShell.Text = result + "`r`n"));
Expand All @@ -210,7 +210,7 @@ private void Powershell_InvocationStateChanged(object sender, PSInvocationStateC
_ = System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
LazyAdminWebView.ShowMessage("Finished");
MainWindow.ShowMessageFromThread(Guid.NewGuid(), "Completed");
//MainWindow.ShowMessageFromThread(Guid.NewGuid(), "Completed");
}));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,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 += MainWindow.GetLazyAdminPwsh().ReceiveMessage;
//_webView.CoreWebView2.WebMessageReceived += MainWindow.GetLazyAdminPwsh().ReceiveMessage;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public partial class MainWindow : Window
// public static void SetWebView(WebView2 value) => webView1 = value;
private readonly IWebViewService webViewService;

private static LazyAdminPowerShell lazyAdminPwsh = new();
//private static LazyAdminPowerShell lazyAdminPwsh = new();

/// <summary>
/// Initializes a new instance of the <see cref="MainWindow"/> class.
Expand All @@ -41,70 +41,71 @@ public MainWindow(IWebViewService webViewService)
// LazyAdminWebView.WebView = this.webView;
// SetWebView(this.webView);
this.webViewService = webViewService;
this.webViewService.EnsureCoreWebView2Async(this.webView);

GetLazyAdminPwsh().MockPowerShell = this.PowerShell;
//GetLazyAdminPwsh().MockPowerShell = this.PowerShell;
}

/// <summary>
/// Gets LazyAdminPowerShell object.
/// </summary>
/// <returns>LazyAdminPowerShell.</returns>
public static LazyAdminPowerShell GetLazyAdminPwsh()
{
return lazyAdminPwsh;
}
///// <summary>
///// Gets LazyAdminPowerShell object.
///// </summary>
///// <returns>LazyAdminPowerShell.</returns>
//public static LazyAdminPowerShell GetLazyAdminPwsh()
//{
// return lazyAdminPwsh;
//}

/// <summary>
/// Sets LazyAdminPowerShell object.
/// </summary>
public static void SetLazyAdminPwsh(LazyAdminPowerShell value)
{
lazyAdminPwsh = value;
}
///// <summary>
///// Sets LazyAdminPowerShell object.
///// </summary>
//public static void SetLazyAdminPwsh(LazyAdminPowerShell value)
//{
// lazyAdminPwsh = value;
//}

/// <summary>
/// Displays Message.
/// </summary>
/// <param name="uid">Uid.</param>
/// <param name="status">Status.</param>
/// <param name="message">Message.</param>
public static void ShowMessageFromThread(Guid uid, string status, string message)
{
LazyAdminWebView.PostRunspaceStatus(uid, status, message);
}
///// <summary>
///// Displays Message.
///// </summary>
///// <param name="uid">Uid.</param>
///// <param name="status">Status.</param>
///// <param name="message">Message.</param>
//public static void ShowMessageFromThread(Guid uid, string status, string message)
//{
// LazyAdminWebView.PostRunspaceStatus(uid, status, message);
//}

/// <summary>
/// Displays Message.
/// </summary>
/// <param name="uid">Uid.</param>
/// <param name="status">Status.</param>
public static void ShowMessageFromThread(Guid uid, string status)
{
LazyAdminWebView.PostRunspaceStatus(uid, status);
}
///// <summary>
///// Displays Message.
///// </summary>
///// <param name="uid">Uid.</param>
///// <param name="status">Status.</param>
//public static void ShowMessageFromThread(Guid uid, string status)
//{
// LazyAdminWebView.PostRunspaceStatus(uid, status);
//}

protected override void OnContentRendered(EventArgs e)
{
base.OnContentRendered(e);
//protected override void OnContentRendered(EventArgs e)
//{
// base.OnContentRendered(e);

try
{
// Let WebView to initialize itself
LazyAdminWebView.InitializeWebView();
}
catch (Exception)
{
// TODO: String to resource for translation
this.Shutdown("An error occurred when starting the browser. Browser window will close.", "Error Occurred");
}
}
// try
// {
// // Let WebView to initialize itself
// LazyAdminWebView.InitializeWebView();
// }
// catch (Exception)
// {
// // TODO: String to resource for translation
// this.Shutdown("An error occurred when starting the browser. Browser window will close.", "Error Occurred");
// }
//}

// TODO: String to resource for translation
private void Shutdown(string message, string caption = "Information")
{
_ = MessageBox.Show(this, message, caption);
Application.Current.Shutdown();
}
//private void Shutdown(string message, string caption = "Information")
//{
// _ = MessageBox.Show(this, message, caption);
// Application.Current.Shutdown();
//}

private async void Execute_Click(object sender, RoutedEventArgs e)
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ public virtual async Task<bool> EnsureCoreWebView2Async(WebView2 webView)
await Task.Run(() =>
{
// TODO: Ensure WebView is present with all the settings.
result = webView.EnsureCoreWebView2Async().IsCompleted;
_ = System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
result = webView.EnsureCoreWebView2Async().IsCompleted;
}));
});

return result;
Expand Down

This file was deleted.

0 comments on commit 1ccea74

Please sign in to comment.