Skip to content

Commit b8fe0ce

Browse files
committed
Replaces Update links with a single Notification - unfinished
1 parent 06b8a9e commit b8fe0ce

File tree

3 files changed

+210
-65
lines changed

3 files changed

+210
-65
lines changed

Source/Menu/MainForm.cs

Lines changed: 119 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
using System.Resources;
3333
using System.Runtime.InteropServices;
3434
using System.Threading;
35+
using System.Threading.Tasks;
3536
using System.Windows.Forms;
3637
using static ORTS.Notification;
3738
using Path = ORTS.Menu.Path;
@@ -320,18 +321,24 @@ void CheckForUpdate()
320321
{
321322
if (UpdateManager.LastCheckError != null)
322323
linkLabelUpdate.Text = catalog.GetString("Update check failed");
323-
else if (UpdateManager.LastUpdate != null && UpdateManager.LastUpdate.Version != VersionInfo.Version)
324-
linkLabelUpdate.Text = catalog.GetStringFmt("Update to {0}", UpdateManager.LastUpdate.Version);
325-
else
326-
linkLabelUpdate.Text = "";
327-
linkLabelUpdate.Enabled = true;
328-
linkLabelUpdate.Visible = linkLabelUpdate.Text.Length > 0;
329-
// Update link's elevation icon and size/position.
330-
if (UpdateManager.LastCheckError == null && UpdateManager.LastUpdate != null && UpdateManager.LastUpdate.Version != VersionInfo.Version && UpdateManager.UpdaterNeedsElevation)
331-
linkLabelUpdate.Image = ElevationIcon;
332-
else
333-
linkLabelUpdate.Image = null;
324+
//else if (UpdateManager.LastUpdate != null && UpdateManager.LastUpdate.Version != VersionInfo.Version)
325+
// linkLabelUpdate.Text = catalog.GetStringFmt("Update to {0}", UpdateManager.LastUpdate.Version);
326+
//else
327+
// linkLabelUpdate.Text = "";
328+
//linkLabelUpdate.Enabled = true;
329+
//linkLabelUpdate.Visible = linkLabelUpdate.Text.Length > 0;
330+
//// Update link's elevation icon and size/position.
331+
//if (UpdateManager.LastCheckError == null && UpdateManager.LastUpdate != null && UpdateManager.LastUpdate.Version != VersionInfo.Version && UpdateManager.UpdaterNeedsElevation)
332+
// linkLabelUpdate.Image = ElevationIcon;
333+
//else
334+
// linkLabelUpdate.Image = null;
335+
336+
if (UpdateManager.LastUpdate != null)
337+
{
338+
SetUpdateNotification();
339+
}
334340
});
341+
335342
}
336343

337344
void LoadLanguage()
@@ -1471,6 +1478,9 @@ void comboBoxTimetable_EnabledChanged(object sender, EventArgs e)
14711478
// Will probably move this region and the Details region into separate files.
14721479

14731480
bool AreNotificationsVisible = false;
1481+
// New notifications are those with a date after the NotificationsReadDate.
1482+
// Notifications are listed in reverse date order, with the newest one at the front.
1483+
// We don't track the reading of each notification but set the NewNotificationCount = 0 after the last of the new ones has been read.
14741484
int NewNotificationCount = 1;
14751485
int LastNotificationViewed = 0;
14761486

@@ -1506,6 +1516,11 @@ private void ToggleNotifications()
15061516
private void FiddleNewNotificationCount()
15071517
{
15081518
LastNotificationViewed = 1;
1519+
UpdateNotificationAlert();
1520+
}
1521+
1522+
private void UpdateNotificationAlert()
1523+
{
15091524
if (LastNotificationViewed >= NewNotificationCount)
15101525
{
15111526
pbNotificationsSome.Visible = false;
@@ -1528,28 +1543,47 @@ void ShowNotifications()
15281543
/// </summary>
15291544
private void PopulateNotificationList()
15301545
{
1531-
NotificationList.Clear();
1532-
if (NotificationList.Count == 0)
1533-
{
1534-
var newNotification = new Notification();
1535-
NotificationList.Add(newNotification);
1536-
new NHeadingControl(panelDetails, "This is a dummy notification", Color.OrangeRed).Add(newNotification);
1537-
new NTitleControl(panelDetails, DateTime.Now, "Update is available").Add(newNotification);
1538-
new NRecordControl(panelDetails, "Update mode", 140, "Stable").Add(newNotification);
1539-
new NRecordControl(panelDetails, "Installed version", 140, "1.3.1").Add(newNotification);
1540-
new NRecordControl(panelDetails, "New version available", 140, "1.4").Add(newNotification);
1541-
new NButtonControl(panelDetails, "What's new", 90, "Find out on-line what's new in this version.").Add(newNotification);
1542-
new NButtonControl(panelDetails, "Install", 90, "Install the new version.").Add(newNotification);
1543-
new NHeadingControl(panelDetails, "Warning", Color.OrangeRed).Add(newNotification);
1544-
new NTextControl(panelDetails, "The update from your current version may affect the behaviour of some of your content.").Add(newNotification);
1545-
new NButtonControl(panelDetails, "Issue details", 90, "More details about this issue are available on-line.").Add(newNotification);
1546-
}
1547-
else
1548-
{
1549-
}
1546+
//NotificationList.Clear();
1547+
//if (NotificationList.Count == 0)
1548+
//{
1549+
// var newNotification = new Notification();
1550+
// NotificationList.Add(newNotification);
1551+
//new NHeadingControl(panelDetails, "This is a dummy notification", Color.OrangeRed).Add(newNotification);
1552+
//new NTitleControl(panelDetails, DateTime.Now, "Update is available").Add(newNotification);
1553+
//new NRecordControl(panelDetails, "Update mode", 140, "Stable").Add(newNotification);
1554+
//new NRecordControl(panelDetails, "Installed version", 140, "1.3.1").Add(newNotification);
1555+
//new NRecordControl(panelDetails, "New version available", 140, "1.4").Add(newNotification);
1556+
//new NButtonControl(panelDetails, "What's new", 90, "Find out on-line what's new in this version.").Add(newNotification);
1557+
//new NButtonControl(panelDetails, "Install", 90, "Install the new version.").Add(newNotification);
1558+
//new NHeadingControl(panelDetails, "Warning", Color.OrangeRed).Add(newNotification);
1559+
//new NTextControl(panelDetails, "The update from your current version may affect the behaviour of some of your content.").Add(newNotification);
1560+
//new NButtonControl(panelDetails, "Issue details", 90, "More details about this issue are available on-line.").Add(newNotification);
1561+
1562+
//new NTitleControl(panelDetails, new DateTime(2024, 8, 31, 0, 0, 0), "Update is available").Add(newNotification);
1563+
//new NRecordControl(panelDetails, "Update mode", 140, "Stable").Add(newNotification);
1564+
//new NRecordControl(panelDetails, "Installed version", 140, "1.6").Add(newNotification);
1565+
//new NRecordControl(panelDetails, "New version available", 140, "1.7").Add(newNotification);
1566+
//new NButtonControl(panelDetails, "What's new", 90, "Find out on-line what's new in this version.").Add(newNotification);
1567+
//new NHeadingControl(panelDetails, "Install Not Available", Color.OrangeRed).Add(newNotification);
1568+
//new NTextControl(panelDetails, "V1.7 cannot be installed on your system until the graphics card is upgraded.").Add(newNotification);
1569+
//new NButtonControl(panelDetails, "Graphics card", 90, "Find out on-line about graphics hardware needed.").Add(newNotification);
1570+
//new NHeadingControl(panelDetails, "More Realism", Color.Blue).Add(newNotification);
1571+
//new NTextControl(panelDetails, "This update supports graphics which are significantly more realistic.").Add(newNotification);
1572+
//new NButtonControl(panelDetails, "Enhancement", 90, "More details about this enhancement are available on-line.").Add(newNotification);
1573+
1574+
//}
1575+
//else
1576+
//{
1577+
//}
1578+
//var notification = NotificationList.LastOrDefault();
1579+
//new NTextControl(panelDetails, "").Add(notification);
1580+
//new NTextControl(panelDetails, "(Toggle icon to hide notifications.)").Add(notification);
1581+
1582+
SetUpdateNotification();
1583+
15501584
var notification = NotificationList.LastOrDefault();
1551-
new NTextControl(panelDetails, "").Add(notification);
1552-
new NTextControl(panelDetails, "(Toggle icon to hide notifications.)").Add(notification);
1585+
new NTextControl(notification, "").Add();
1586+
new NTextControl(notification, "(Toggle icon to hide notifications.)").Add();
15531587
}
15541588

15551589
/// <summary>
@@ -1561,6 +1595,59 @@ Notification GetCurrentNotification()
15611595
return NotificationList[0];
15621596
}
15631597

1598+
/// <summary>
1599+
/// Ultimately there will be a list of notifications downloaded for openrails/content.
1600+
/// Until then, there is a single notification announcing either that a new update is available or the installation is up to date.
1601+
/// </summary>
1602+
void SetUpdateNotification()
1603+
{
1604+
NewNotificationCount = (IsUpdateAvailable()) ? 1 : 0;
1605+
UpdateNotificationAlert();
1606+
NotificationList.Clear();
1607+
var newNotification = new Notification(panelDetails);
1608+
if (IsUpdateAvailable())
1609+
{
1610+
NewNotificationCount = 1;
1611+
new NTitleControl(newNotification, UpdateManager.LastUpdate.Date, "Update is available").Add();
1612+
new NRecordControl(newNotification, "Update mode", 140, UpdateManager.ChannelName).Add();
1613+
new NRecordControl(newNotification, "Installed version", 140, VersionInfo.VersionOrBuild).Add();
1614+
new NRecordControl(newNotification, "New version available", 140, UpdateManager.LastUpdate.Version).Add();
1615+
new NLinkControl(newNotification, "What's new", 90, "Find out on-line what's new in this version.", this, UpdateManager.ChangeLogLink).Add();
1616+
new NUpdateControl(newNotification, "Install", 90, "Install the new version.", this).Add();
1617+
1618+
}
1619+
else
1620+
{
1621+
NewNotificationCount = 0;
1622+
var channelName = UpdateManager.ChannelName == "" ? "None" : UpdateManager.ChannelName;
1623+
new NTitleControl(newNotification, DateTime.Now, "Installation is up to date").Add();
1624+
new NRecordControl(newNotification, "Update mode", 140, channelName).Add();
1625+
new NRecordControl(newNotification, "Installed version", 140, VersionInfo.VersionOrBuild).Add();
1626+
new NRecordControl(newNotification, "New version available", 140, "none").Add();
1627+
}
1628+
NotificationList.Add(newNotification);
1629+
}
1630+
1631+
bool IsUpdateAvailable()
1632+
{
1633+
return UpdateManager.LastUpdate != null
1634+
&& UpdateManager.LastUpdate.Version != VersionInfo.Version
1635+
&& DateTime.Now >= UpdateManager.State.NextCheck;
1636+
}
1637+
1638+
// 3 should be enough, but is there a way to get unlimited buttons?
1639+
public void Button0_Click(object sender, EventArgs e)
1640+
{
1641+
GetCurrentNotification().DoButton(UpdateManager, 0);
1642+
}
1643+
public void Button1_Click(object sender, EventArgs e)
1644+
{
1645+
GetCurrentNotification().DoButton(UpdateManager, 1);
1646+
}
1647+
public void Button2_Click(object sender, EventArgs e)
1648+
{
1649+
GetCurrentNotification().DoButton(UpdateManager, 2);
1650+
}
15641651
#endregion Notifications
15651652
}
15661653
}

0 commit comments

Comments
 (0)