Skip to content

Commit

Permalink
Disable Network Traffice When Notification Center Disabled (#13286)
Browse files Browse the repository at this point in the history
* update

* Remain public
  • Loading branch information
QilongTang committed Sep 2, 2022
1 parent 1616453 commit 56b0938
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/Notifications/NotificationCenterController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net;
Expand All @@ -11,7 +9,6 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using Dynamo.Configuration;
using Dynamo.Controls;
using Dynamo.Logging;
using Dynamo.Notifications.View;
Expand All @@ -23,11 +20,11 @@ namespace Dynamo.Notifications
{
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
public class scriptObject
public class ScriptObject
{
Action<object[]> onMarkAllAsRead;

internal scriptObject(Action<object []> onMarkAllAsRead)
internal ScriptObject(Action<object []> onMarkAllAsRead)
{
this.onMarkAllAsRead = onMarkAllAsRead;
}
Expand All @@ -53,7 +50,7 @@ public class NotificationCenterController
private static readonly string jsEmbeddedFile = "Dynamo.Notifications.node_modules._dynamods.notifications_center.build.index.bundle.js";
private static readonly string NotificationCenterButtonName = "notificationsButton";

private DynamoLogger logger;
private readonly DynamoLogger logger;
private string jsonStringFile;
private NotificationsModel notificationsModel;

Expand All @@ -78,8 +75,12 @@ internal NotificationCenterController(DynamoView view, DynamoLogger dynLogger)
notificationUIPopup.webView.EnsureCoreWebView2Async();
notificationUIPopup.webView.CoreWebView2InitializationCompleted += WebView_CoreWebView2InitializationCompleted;
logger = dynLogger;

RequestNotifications();
// If user turns on the feature, they will need to restart Dynamo to see the count
// This ensures no network traffic when Notification center feature is turned off
if (dynamoViewModel.PreferenceSettings.EnableNotificationCenter)
{
RequestNotifications();
}
}

private void WebView_NavigationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e)
Expand Down Expand Up @@ -177,7 +178,7 @@ private void WebView_CoreWebView2InitializationCompleted(object sender, Microsof
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));
new ScriptObject(OnMarkAllAsRead));
}
}

Expand Down

0 comments on commit 56b0938

Please sign in to comment.