From a872d21355660a7538db3115bf30c0bf5a4b4f33 Mon Sep 17 00:00:00 2001 From: Rylan/wowmom98 Date: Thu, 18 May 2017 16:32:49 -0400 Subject: documentation of NotificationDaemon --- ShiftOS_TheReturn/NotificationDaemon.cs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'ShiftOS_TheReturn/NotificationDaemon.cs') diff --git a/ShiftOS_TheReturn/NotificationDaemon.cs b/ShiftOS_TheReturn/NotificationDaemon.cs index 77a31fc..a90510a 100644 --- a/ShiftOS_TheReturn/NotificationDaemon.cs +++ b/ShiftOS_TheReturn/NotificationDaemon.cs @@ -34,6 +34,7 @@ namespace ShiftOS.Engine { public static class NotificationDaemon { + //if the notifications file already exists then get them public static Notification[] GetAllFromFile() { Notification[] notes = { }; @@ -44,23 +45,25 @@ namespace ShiftOS.Engine return notes; } + //tells the computer how it likes it to be written in the file internal static void WriteNotes(Notification[] notes) { - Utils.WriteAllText(Paths.GetPath("notifications.dat"), JsonConvert.SerializeObject(notes, Formatting.Indented)); + Utils.WriteAllText(Paths.GetPath("notifications.dat"), JsonConvert.SerializeObject(notes, Formatting.Indented)); //"write it in there indented pls" } - public static event Action NotificationMade; - + public static event Action NotificationMade; //use this if you want to know when a notification has been made + public static void AddNotification(NotificationType note, object data) { - var lst = new List(GetAllFromFile()); - lst.Add(new Engine.Notification(note, data)); + var lst = new List(GetAllFromFile()); //grabs all current notifications + lst.Add(new Engine.Notification(note, data)); //then adds the new one to the list WriteNotes(lst.ToArray()); - NotificationMade?.Invoke(lst[lst.Count - 1]); + NotificationMade?.Invoke(lst[lst.Count - 1]); //says to the program that a notification has indeed been made } public static event Action NotificationRead; + //for every notification that there is, mark them as read public static void MarkAllRead() { var notes = GetAllFromFile(); @@ -68,30 +71,33 @@ namespace ShiftOS.Engine MarkRead(i); } + //grabs list of notifcations and if the notification you want to mark as read actually exsists, then it assigns it as read public static void MarkRead(int note) { var notes = GetAllFromFile(); if (note >= notes.Length || note < 0) throw new ArgumentOutOfRangeException("note", new Exception("You cannot mark a notification that does not exist as read.")); - notes[note].Read = true; + notes[note].Read = true; //assigns the specific notification as read WriteNotes(notes); NotificationRead?.Invoke(); } - public static int GetUnreadCount() + public static int GetUnreadCount() //use this if you want the unread notification count, but i think you probably already knew that { int c = 0; foreach (var note in GetAllFromFile()) if (note.Read == false) - c++; //gahh I hate that programming language. + c++; //gahh I hate that programming language. //dont we all return c; } } + //actually gives the proper data for the notification public struct Notification { + //defaults for all notificaions public Notification(NotificationType t, object data) { Type = t; @@ -106,9 +112,10 @@ namespace ShiftOS.Engine public DateTime Timestamp { get; set; } } + //defines all the possible notificaions that can happen public enum NotificationType { - Generic = 0x00, + Generic = 0x00, //lets get generic MemoReceived = 0x10, MemoSent = 0x11, DownloadStarted = 0x20, -- cgit v1.2.3 From c63117276194d18890f14c75b8864749fbd33a0e Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 31 May 2017 09:03:19 -0400 Subject: modular notifications --- ShiftOS.WinForms/WinformsDesktop.cs | 44 +++++++++++++++++++++++++++++++++ ShiftOS_TheReturn/IStatusIcon.cs | 14 +++++++++++ ShiftOS_TheReturn/NotificationDaemon.cs | 30 ++++++++++++++++++++++ ShiftOS_TheReturn/ShiftOS.Engine.csproj | 1 + 4 files changed, 89 insertions(+) create mode 100644 ShiftOS_TheReturn/IStatusIcon.cs (limited to 'ShiftOS_TheReturn/NotificationDaemon.cs') diff --git a/ShiftOS.WinForms/WinformsDesktop.cs b/ShiftOS.WinForms/WinformsDesktop.cs index 643c02a..0cfd667 100644 --- a/ShiftOS.WinForms/WinformsDesktop.cs +++ b/ShiftOS.WinForms/WinformsDesktop.cs @@ -70,6 +70,46 @@ namespace ShiftOS.WinForms private int millisecondsUntilScreensaver = 300000; + public void LoadIcons() + { + //That shot me back to 0.0.x with that name. Whatever. + flnotifications.Controls.Clear(); //Clear the status tray + + foreach(var itype in NotificationDaemon.GetAllStatusIcons()) + { + //We have the types. No need for shiftorium calls or anything. + //First create the icon control... + + var ic = new PictureBox(); + //We can use the type name, in lowercase, for the icon tag. + ic.Tag = itype.Name.ToLower(); + //Next get the icon data if any. + + var iconattrib = itype.GetCustomAttributes(false).FirstOrDefault(x => x is DefaultIconAttribute) as DefaultIconAttribute; + if(iconattrib != null) + { + //We can use this attribute's ID in the skin engine to get an icon. + var img = GetIcon(iconattrib.ID); + //Make it transparent. + (img as Bitmap).MakeTransparent(LoadedSkin.SystemKey); + //Assign it to the control + ic.Image = img; + //Set the sizing mode + ic.SizeMode = PictureBoxSizeMode.StretchImage; + } + else + { + ic.BackColor = Color.White; //TODO: Make it skinnable. + } + ic.Size = new Size(20, 20); //TODO: make it skinnable + //add to the notification tray + flnotifications.Controls.Add(ic); + ic.Show(); + + //TODO: Settings pane on click. + } + } + public void PushNotification(string app, string title, string msg) { lbnotemsg.Text = msg; @@ -134,6 +174,8 @@ namespace ShiftOS.WinForms widget.OnUpgrade(); } + LoadIcons(); + //Only if the DevX Legions story hasn't been experienced yet. if (!Shiftorium.UpgradeInstalled("devx_legions")) { @@ -180,6 +222,7 @@ namespace ShiftOS.WinForms SaveSystem.GameReady += () => { + this.Invoke(new Action(LoadIcons)); if (this.Visible == true) this.Invoke(new Action(() => SetupDesktop())); }; @@ -208,6 +251,7 @@ namespace ShiftOS.WinForms }; SkinEngine.SkinLoaded += () => { + LoadIcons(); foreach (var widget in Widgets) { widget.OnSkinLoad(); diff --git a/ShiftOS_TheReturn/IStatusIcon.cs b/ShiftOS_TheReturn/IStatusIcon.cs new file mode 100644 index 0000000..f32d1c1 --- /dev/null +++ b/ShiftOS_TheReturn/IStatusIcon.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShiftOS.Engine +{ + public interface IStatusIcon + { + void Setup(); + + } +} diff --git a/ShiftOS_TheReturn/NotificationDaemon.cs b/ShiftOS_TheReturn/NotificationDaemon.cs index a90510a..0725782 100644 --- a/ShiftOS_TheReturn/NotificationDaemon.cs +++ b/ShiftOS_TheReturn/NotificationDaemon.cs @@ -25,6 +25,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; @@ -34,6 +35,35 @@ namespace ShiftOS.Engine { public static class NotificationDaemon { + /// + /// Gets a list of all objects that meet their Shiftorium dependencies. + /// + /// An array of s containing the found objects. + public static Type[] GetAllStatusIcons() + { + List lst = new List(); + foreach(var exec in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) + { + if(exec.ToLower().EndsWith(".exe") || exec.ToLower().EndsWith(".dll")) + { + try + { + var asm = Assembly.LoadFile(exec); + foreach(var type in asm.GetTypes().Where(x => x.GetInterfaces().Contains(typeof(IStatusIcon)))) + { + if (Shiftorium.UpgradeAttributesUnlocked(type)) + { + lst.Add(type); + } + } + } + catch { } + } + } + return lst.ToArray(); + } + + //if the notifications file already exists then get them public static Notification[] GetAllFromFile() { diff --git a/ShiftOS_TheReturn/ShiftOS.Engine.csproj b/ShiftOS_TheReturn/ShiftOS.Engine.csproj index 4cbce72..f70c41e 100644 --- a/ShiftOS_TheReturn/ShiftOS.Engine.csproj +++ b/ShiftOS_TheReturn/ShiftOS.Engine.csproj @@ -109,6 +109,7 @@ + -- cgit v1.2.3