Notification counter on desktop.

This commit is contained in:
Michael 2017-02-25 10:03:36 -05:00
parent ea18e37bff
commit 910a1c455e
5 changed files with 62 additions and 32 deletions

View file

@ -47,6 +47,7 @@
// fllist
//
this.fllist.Dock = System.Windows.Forms.DockStyle.Fill;
this.fllist.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;
this.fllist.Location = new System.Drawing.Point(0, 33);
this.fllist.Name = "fllist";
this.fllist.Size = new System.Drawing.Size(437, 487);

View file

@ -36,32 +36,41 @@ namespace ShiftOS.WinForms.Applications
{
if (note.Read == false)
{
showNoNotes = false;
var headerLabel = new Label();
headerLabel.Tag = "header2";
ControlManager.SetupControl(headerLabel);
headerLabel.Text = ParseNotification(note);
headerLabel.Width = fllist.Width - 4;
fllist.Controls.Add(headerLabel);
headerLabel.Show();
var markButton = new Button();
ControlManager.SetupControl(markButton);
markButton.Text = "Mark as read";
markButton.Click += (o, a) =>
try
{
NotificationDaemon.MarkRead(new List<Notification>(NotificationDaemon.GetAllFromFile()).IndexOf(note));
SetupUI();
};
fllist.Controls.Add(markButton);
markButton.Show();
showNoNotes = false;
var headerLabel = new Label();
headerLabel.Tag = "header2";
ControlManager.SetupControl(headerLabel);
headerLabel.Text = ParseNotification(note);
headerLabel.Width = fllist.Width - 4;
fllist.Controls.Add(headerLabel);
headerLabel.Show();
var dataLabel = new Label();
dataLabel.Text = ParseNotificationData(note);
dataLabel.MaximumSize = new Size(fllist.Width - 4, 0);
dataLabel.AutoSize = true;
fllist.Controls.Add(dataLabel);
dataLabel.Show();
var markButton = new Button();
ControlManager.SetupControl(markButton);
markButton.Text = "Mark as read";
markButton.AutoSize = true;
markButton.AutoSizeMode = AutoSizeMode.GrowAndShrink;
markButton.Click += (o, a) =>
{
NotificationDaemon.MarkRead(new List<Notification>(NotificationDaemon.GetAllFromFile()).IndexOf(note));
SetupUI();
};
fllist.Controls.Add(markButton);
markButton.Show();
var dataLabel = new Label();
dataLabel.Text = ParseNotificationData(note);
dataLabel.MaximumSize = new Size(fllist.Width - 4, 0);
dataLabel.AutoSize = true;
fllist.Controls.Add(dataLabel);
dataLabel.Show();
}
catch
{
}
}
}

View file

@ -60,6 +60,14 @@ namespace ShiftOS.WinForms
{
InitializeComponent();
this.TopMost = false;
NotificationDaemon.NotificationMade += (note) =>
{
//Soon this will pop a balloon note.
btnnotifications.Text = "Notifications (" + NotificationDaemon.GetUnreadCount().ToString() + ")";
};
this.LocationChanged += (o, a) =>
{
if (this.Left != 0)
@ -80,6 +88,10 @@ namespace ShiftOS.WinForms
{
if(this.Visible == true)
this.Invoke(new Action(() => SetupDesktop()));
this.Invoke(new Action(() =>
{
btnnotifications.Text = "Notifications (" + NotificationDaemon.GetUnreadCount().ToString() + ")";
}));
};
Shiftorium.Installed += () =>
{

View file

@ -45,6 +45,15 @@ namespace ShiftOS.Engine
notes[note].Read = true;
WriteNotes(notes);
}
public static int GetUnreadCount()
{
int c = 0;
foreach (var note in GetAllFromFile())
if (note.Read == false)
c++; //gahh I hate that programming language.
return c;
}
}
public struct Notification
@ -57,13 +66,13 @@ namespace ShiftOS.Engine
Timestamp = DateTime.Now;
}
public bool Read { get; internal set; }
public NotificationType Type { get; private set; }
public object Data { get; private set; }
public DateTime Timestamp { get; private set; }
public bool Read { get; set; }
public NotificationType Type { get; set; }
public object Data { get; set; }
public DateTime Timestamp { get; set; }
}
public enum NotificationType : byte
public enum NotificationType
{
Generic = 0x00,
MemoReceived = 0x10,

View file

@ -209,8 +209,7 @@ namespace ShiftOS.Engine
public static void TransferCodepointsToVoid(int amount)
{
CurrentSave.Codepoints -= amount;
if(!Shiftorium.Silent)
Console.WriteLine($"{{SHIFTORIUM_TRANSFERRED_TO}}: {amount} -> sys");
NotificationDaemon.AddNotification(NotificationType.CodepointsSent, amount);
}
public static void Restart()
@ -302,7 +301,7 @@ namespace ShiftOS.Engine
public static void TransferCodepointsFrom(string who, int amount)
{
Console.WriteLine($"{{SHIFTORIUM_TRANSFERRED_FROM}}: {amount} <- {who}");
NotificationDaemon.AddNotification(NotificationType.CodepointsReceived, amount);
CurrentSave.Codepoints += amount;
}
}