-
Notifications
You must be signed in to change notification settings - Fork 635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DYN-5189 update notifications number #13232
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Dynamo.ViewModels; | ||
|
||
namespace Dynamo.Wpf.ViewModels.Core | ||
{ | ||
internal class ShortcutToolbarViewModel : ViewModelBase | ||
{ | ||
public ShortcutToolbarViewModel() | ||
{ | ||
NotificationsNumber = 0; | ||
} | ||
|
||
/// <summary> | ||
/// This property represents the number of new notifications | ||
/// </summary> | ||
public int NotificationsNumber { get; set; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Reflection; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
|
@@ -9,6 +13,8 @@ | |
using Dynamo.Logging; | ||
using Dynamo.Notifications.View; | ||
using Dynamo.ViewModels; | ||
using Dynamo.Wpf.ViewModels.Core; | ||
using Newtonsoft.Json; | ||
|
||
namespace Dynamo.Notifications | ||
{ | ||
|
@@ -26,7 +32,11 @@ 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 readonly DynamoLogger logger; | ||
private DynamoLogger logger; | ||
private static readonly DateTime notificationsCenterCreatedTime = DateTime.UtcNow; | ||
private static System.Timers.Timer timer; | ||
private string jsonStringFile; | ||
private NotificationsModel notificationsModel; | ||
|
||
internal NotificationCenterController(DynamoView view, DynamoLogger dynLogger) | ||
{ | ||
|
@@ -46,9 +56,45 @@ internal NotificationCenterController(DynamoView view, DynamoLogger dynLogger) | |
HorizontalOffset = notificationPopupHorizontalOffset, | ||
VerticalOffset = notificationPopupVerticalOffset | ||
}; | ||
|
||
notificationUIPopup.webView.EnsureCoreWebView2Async(); | ||
notificationUIPopup.webView.CoreWebView2InitializationCompleted += WebView_CoreWebView2InitializationCompleted; | ||
logger = dynLogger; | ||
|
||
RequestNotifications(); | ||
} | ||
|
||
private void WebView_NavigationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e) | ||
{ | ||
AddNotifications(notificationsModel.Notifications); | ||
} | ||
|
||
private void AddNotifications(List<NotificationItemModel> notifications) | ||
{ | ||
var notificationsList = JsonConvert.SerializeObject(notifications); | ||
InvokeJS($"window.setNotifications({notificationsList});"); | ||
} | ||
|
||
private void RequestNotifications() | ||
{ | ||
var uri = DynamoUtilities.PathHelper.getServiceBackendAddress(this, "notificationAddress"); | ||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); | ||
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; | ||
|
||
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) | ||
using (Stream stream = response.GetResponseStream()) | ||
using (StreamReader reader = new StreamReader(stream)) | ||
{ | ||
jsonStringFile = reader.ReadToEnd(); | ||
notificationsModel = JsonConvert.DeserializeObject<NotificationsModel>(jsonStringFile); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setting the notifications to a defined model |
||
|
||
var notificationsNumber = notificationsModel.Notifications.Count(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is counting all the notifications, but we may add a comparison between the read notification and the new ones. |
||
|
||
var shortcutToolbarViewModel = (ShortcutToolbarViewModel)dynamoView.ShortcutBar.DataContext; | ||
shortcutToolbarViewModel.NotificationsNumber = notificationsNumber; | ||
} | ||
|
||
notificationUIPopup.webView.NavigationCompleted += WebView_NavigationCompleted; | ||
} | ||
|
||
// Handler for new Webview2 tab window request | ||
|
@@ -84,7 +130,6 @@ private void WebView_CoreWebView2InitializationCompleted(object sender, Microsof | |
// Opening hyper-links using default system browser instead of WebView2 tab window | ||
notificationUIPopup.webView.CoreWebView2.NewWindowRequested += WebView_NewWindowRequested; | ||
notificationUIPopup.webView.CoreWebView2.NavigateToString(htmlString); | ||
RefreshNotifications(); | ||
} | ||
} | ||
|
||
|
@@ -98,6 +143,7 @@ internal void Dispose() | |
dynamoView.SizeChanged -= DynamoView_SizeChanged; | ||
dynamoView.LocationChanged -= DynamoView_LocationChanged; | ||
notificationsButton.Click -= NotificationsButton_Click; | ||
notificationUIPopup.webView.NavigationCompleted -= WebView_NavigationCompleted; | ||
} | ||
|
||
private void DynamoView_LocationChanged(object sender, EventArgs e) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.Serialization; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Dynamo.Notifications | ||
{ | ||
[DataContract] | ||
internal class NotificationsModel | ||
{ | ||
[DataMember(Name = "version")] | ||
internal string Version { get; set; } | ||
|
||
[DataMember(Name = "last_update_timestamp")] | ||
internal DateTime LastUpdate { get; set; } | ||
|
||
[DataMember(Name = "notifications")] | ||
internal List<NotificationItemModel> Notifications { get; set; } | ||
} | ||
|
||
[DataContract] | ||
internal class NotificationItemModel | ||
{ | ||
[DataMember(Name = "id")] | ||
internal string Id { get; set; } | ||
|
||
[DataMember(Name = "title")] | ||
internal string Title { get; set; } | ||
|
||
[DataMember(Name = "link")] | ||
internal string Link { get; set; } | ||
|
||
[DataMember(Name = "linkTitle")] | ||
internal string LinkTitle { get; set; } | ||
|
||
[DataMember(Name = "longDescription")] | ||
internal string LongDescription { get; set; } | ||
|
||
[DataMember(Name = "created")] | ||
internal DateTime Created { get; set; } | ||
|
||
[DataMember(Name = "thumbnail")] | ||
internal string Thumbnail { get; set; } | ||
|
||
[DataMember(Name = "priority")] | ||
internal string Priority { get; set; } | ||
|
||
[DataMember(Name = "type")] | ||
internal string Type { get; set; } | ||
|
||
[DataMember(Name = "scope")] | ||
internal string Scope { get; set; } | ||
|
||
[DataMember(Name = "source")] | ||
internal string Source { get; set; } | ||
|
||
[DataMember(Name = "status")] | ||
internal string Status { get; set; } | ||
|
||
[DataMember(Name = "isPinned")] | ||
internal bool IsPinned { get; set; } | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We make sure navigation is completed before calling the js function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this because otherwise the js function may not exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the navigation completed subscription makes sure the page content is loaded.