Skip to content

Commit

Permalink
Add similar code to Notification Center
Browse files Browse the repository at this point in the history
  • Loading branch information
QilongTang committed Jun 11, 2024
1 parent c1f3d72 commit 6e4b782
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions src/Notifications/NotificationCenterController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,27 @@ private void WebView_NewWindowRequested(object sender, Microsoft.Web.WebView2.Co
e.Handled = true;
}

/// <summary>
/// Convenience method for logging to Dynamo Console.
/// </summary>
/// <param name="meessage"></param>
internal void LogToDynamoConsole(string message)
{
this.dynamoViewModel?.Model?.Logger?.Log(message);
}

private void WebView_CoreWebView2InitializationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs e)
{
if (!e.IsSuccess)
{
if (e.InitializationException != null)
{
LogToDynamoConsole(e.InitializationException.Message);
}
LogToDynamoConsole("NotificationCenter CoreWebView2 initialization failed.");
return;
}

var assembly = Assembly.GetExecutingAssembly();
string htmlString = string.Empty;

Expand All @@ -241,15 +260,22 @@ private void WebView_CoreWebView2InitializationCompleted(object sender, Microsof
// More initialization options
// Context menu disabled
notificationUIPopup.webView.CoreWebView2.Settings.AreDefaultContextMenusEnabled = true;
notificationUIPopup.webView.CoreWebView2.Settings.IsZoomControlEnabled = false;
notificationUIPopup.webView.CoreWebView2.Settings.IsStatusBarEnabled = false;
// Opening hyper-links using default system browser instead of WebView2 tab window
notificationUIPopup.webView.CoreWebView2.NewWindowRequested += WebView_NewWindowRequested;
notificationUIPopup.webView.CoreWebView2.NavigateToString(htmlString);
// Hosts an object that will expose the properties and methods to be called from the javascript side
notificationUIPopup.webView.CoreWebView2.AddHostObjectToScript("scriptObject",
new ScriptObject(OnMarkAllAsRead, OnNotificationPopupUpdated));

notificationUIPopup.webView.CoreWebView2.Settings.IsZoomControlEnabled = false;
notificationUIPopup.webView.CoreWebView2.Settings.IsStatusBarEnabled = false;
try
{
notificationUIPopup.webView.CoreWebView2.NavigateToString(htmlString);
// Hosts an object that will expose the properties and methods to be called from the javascript side
notificationUIPopup.webView.CoreWebView2.AddHostObjectToScript("scriptObject",
new ScriptObject(OnMarkAllAsRead, OnNotificationPopupUpdated));
}
catch (Exception ex)
{
LogToDynamoConsole("NotificationCenter CoreWebView2 initialization failed: " + ex.Message);
}
}
}

Expand Down

0 comments on commit 6e4b782

Please sign in to comment.