Skip to content

Commit

Permalink
Image support
Browse files Browse the repository at this point in the history
  • Loading branch information
BobVul committed Jun 9, 2016
1 parent df594f4 commit 51c7d5b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
8 changes: 5 additions & 3 deletions Bread/ImageJsonConverter.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Text;

Expand All @@ -19,14 +21,14 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
Image img = (Image)value;
using (MemoryStream ms = new MemoryStream())
{
img.Save(ms, img.RawFormat);
writer.WriteValue(Convert.ToBase64String(ms.ToArray()));
img.Save(ms, ImageFormat.Png);
(new JValue(Convert.ToBase64String(ms.ToArray()))).WriteTo(writer);
}
}

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
using (MemoryStream ms = new MemoryStream(Convert.FromBase64String((string)existingValue)))
using (MemoryStream ms = new MemoryStream(Convert.FromBase64String((string)reader.Value)))
{
return Image.FromStream(ms);
}
Expand Down
2 changes: 0 additions & 2 deletions Growler/Growler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ protected override void HandleNotification(Notification notification, string dis
Silent = this.GetSettingOrDefault<bool>(GrowlerSetting.Silent, false),
Image = notification.Image
};
string title = notification.Title;
string message = notification.Description;

LaunchToaster(bread);
}
Expand Down
12 changes: 10 additions & 2 deletions Toaster/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using NotificationsExtensions.Toasts;
using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -16,7 +18,7 @@ static class Program
private const string APP_ID = "GrowlToToast";

static void Main()
{
{
Message bread = JsonConvert.DeserializeObject<Message>(Console.ReadLine());
switch (bread.Action)
{
Expand All @@ -28,7 +30,9 @@ static void Main()
ToastNotificationManager.History.Remove(ToastNotificationManager.History.GetHistory().Last().Tag);
break;

case ActionType.Show:
case ActionType.Show:
string imagePath = Path.ChangeExtension(Path.GetTempFileName(), "png");
bread.Image.Save(imagePath, ImageFormat.Png);
ToastContent content = new ToastContent()
{
Visual = new ToastVisual()
Expand All @@ -40,6 +44,10 @@ static void Main()
BodyTextLine1 = new ToastText()
{
Text = bread.Body
},
AppLogoOverride = new ToastAppLogo
{
Source = new ToastImageSource("file:///" + imagePath)
}
}
};
Expand Down

0 comments on commit 51c7d5b

Please sign in to comment.