Updates for the notification service, now an icon is shown and it now follows the configuration settings. [skip ci]

This commit is contained in:
Robin Krom 2020-03-10 22:06:47 +01:00
parent 1ba0bf9b10
commit 7e96c99b3d
23 changed files with 90 additions and 43 deletions

View file

@ -58,7 +58,7 @@ namespace Greenshot.Destinations {
public override Image DisplayIcon {
get {
return GreenshotResources.getImage("Clipboard.Image");
return GreenshotResources.GetImage("Clipboard.Image");
}
}

View file

@ -37,7 +37,7 @@ namespace Greenshot.Destinations {
private static readonly EditorConfiguration editorConfiguration = IniConfig.GetIniSection<EditorConfiguration>();
public const string DESIGNATION = "Editor";
private readonly IImageEditor editor;
private static readonly Image greenshotIcon = GreenshotResources.getGreenshotIcon().ToBitmap();
private static readonly Image greenshotIcon = GreenshotResources.GetGreenshotIcon().ToBitmap();
public EditorDestination() {
}

View file

@ -32,7 +32,7 @@ namespace Greenshot.Destinations {
/// Description of EmailDestination.
/// </summary>
public class EmailDestination : AbstractDestination {
private static readonly Image MailIcon = GreenshotResources.getImage("Email.Image");
private static readonly Image MailIcon = GreenshotResources.GetImage("Email.Image");
private static bool _isActiveFlag;
private static string _mapiClient;
public const string DESIGNATION = "EMail";

View file

@ -48,7 +48,7 @@ namespace Greenshot.Destinations {
public override Keys EditorShortcutKeys => Keys.Control | Keys.S;
public override Image DisplayIcon => GreenshotResources.getImage("Save.Image");
public override Image DisplayIcon => GreenshotResources.GetImage("Save.Image");
public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
ExportInformation exportInformation = new ExportInformation(Designation, Description);

View file

@ -61,7 +61,7 @@ namespace Greenshot.Destinations {
public override Image DisplayIcon {
get {
return GreenshotResources.getImage("Save.Image");
return GreenshotResources.GetImage("Save.Image");
}
}

View file

@ -59,7 +59,7 @@ namespace Greenshot.Destinations {
public override Keys EditorShortcutKeys => Keys.Control | Keys.P;
public override Image DisplayIcon => GreenshotResources.getImage("Printer.Image");
public override Image DisplayIcon => GreenshotResources.GetImage("Printer.Image");
public override bool IsDynamic => true;

View file

@ -59,7 +59,7 @@ namespace Greenshot.Forms {
/// Initialize the background brush
/// </summary>
static CaptureForm() {
Image backgroundForTransparency = GreenshotResources.getImage("Checkerboard.Image");
Image backgroundForTransparency = GreenshotResources.GetImage("Checkerboard.Image");
BackgroundBrush = new TextureBrush(backgroundForTransparency, WrapMode.Tile);
}

View file

@ -175,7 +175,7 @@ namespace Greenshot {
{
panel1.Controls.Add(_surface);
}
Image backgroundForTransparency = GreenshotResources.getImage("Checkerboard.Image");
Image backgroundForTransparency = GreenshotResources.GetImage("Checkerboard.Image");
if (_surface != null)
{
_surface.TransparencyBackgroundBrush = new TextureBrush(backgroundForTransparency, WrapMode.Tile);

View file

@ -38,7 +38,7 @@ namespace Greenshot.Forms {
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
Icon = GreenshotResources.getGreenshotIcon();
Icon = GreenshotResources.GetGreenshotIcon();
Load += FormLoad;
FormClosing += PreventFormClose;
}

View file

@ -231,7 +231,7 @@ namespace Greenshot {
// A dirty fix to make sure the message box is visible as a Greenshot window on the taskbar
using Form dummyForm = new Form
{
Icon = GreenshotResources.getGreenshotIcon(),
Icon = GreenshotResources.GetGreenshotIcon(),
ShowInTaskbar = true,
FormBorderStyle = FormBorderStyle.None,
Location = new Point(int.MinValue, int.MinValue)
@ -345,7 +345,7 @@ namespace Greenshot {
// Make the main menu available
SimpleServiceProvider.Current.AddService(contextMenu);
notifyIcon.Icon = GreenshotResources.getGreenshotIcon();
notifyIcon.Icon = GreenshotResources.GetGreenshotIcon();
// Make the notify icon available
SimpleServiceProvider.Current.AddService(notifyIcon);
@ -371,6 +371,7 @@ namespace Greenshot {
// Check to see if there is already another INotificationService
if (SimpleServiceProvider.Current.GetInstance<INotificationService>() == null)
{
// If not we add the internal NotifyIcon notification service
SimpleServiceProvider.Current.AddService<INotificationService>(new NotifyIconNotificationService());
}

View file

@ -22,6 +22,8 @@
using System;
using System.Windows.Forms;
using GreenshotPlugin.Core;
using GreenshotPlugin.IniFile;
using GreenshotPlugin.Interfaces;
using log4net;
namespace Greenshot.Helpers
@ -32,6 +34,7 @@ namespace Greenshot.Helpers
public class NotifyIconNotificationService : INotificationService
{
private static readonly ILog Log = LogManager.GetLogger(typeof(NotifyIconNotificationService));
private static readonly CoreConfiguration CoreConfiguration = IniConfig.GetIniSection<CoreConfiguration>();
private readonly NotifyIcon _notifyIcon;
public NotifyIconNotificationService()
@ -83,7 +86,13 @@ namespace Greenshot.Helpers
/// <param name="level">ToolTipIcon</param>
/// <param name="onClickAction">Action</param>
/// <param name="onClosedAction">Action</param>
public void ShowMessage(string message, int timeout, ToolTipIcon level, Action onClickAction = null, Action onClosedAction = null) {
private void ShowMessage(string message, int timeout, ToolTipIcon level, Action onClickAction = null, Action onClosedAction = null) {
// Do not inform the user if this is disabled
if (!CoreConfiguration.ShowTrayNotification)
{
return;
}
void BalloonClickedHandler(object s, EventArgs e)
{
try

View file

@ -40,7 +40,7 @@ namespace GreenshotJiraPlugin.Forms {
public JiraForm(JiraConnector jiraConnector) {
InitializeComponent();
Icon = GreenshotResources.getGreenshotIcon();
Icon = GreenshotResources.GetGreenshotIcon();
AcceptButton = uploadButton;
CancelButton = cancelButton;

View file

@ -40,7 +40,7 @@ namespace GreenshotOfficePlugin.Destinations {
private const int IconApplication = 0;
private const int IconMeeting = 2;
private static readonly Image MailIcon = GreenshotResources.getImage("Email.Image");
private static readonly Image MailIcon = GreenshotResources.GetImage("Email.Image");
private static readonly OfficeConfiguration OfficeConfig = IniConfig.GetIniSection<OfficeConfiguration>();
private static readonly string ExePath;
private static readonly bool IsActiveFlag;

View file

@ -51,7 +51,7 @@ namespace GreenshotPlugin.Controls {
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
Icon = GreenshotResources.getGreenshotIcon();
Icon = GreenshotResources.GetGreenshotIcon();
_shouldClose = false;
Text = title;
label_pleasewait.Text = text;

View file

@ -146,7 +146,7 @@ namespace GreenshotPlugin.Controls {
protected override void OnLoad(EventArgs e) {
// Every GreenshotForm should have it's default icon
// And it might not ne needed for a Tool Window, but still for the task manager / switcher it's important
Icon = GreenshotResources.getGreenshotIcon();
Icon = GreenshotResources.GetGreenshotIcon();
if (!DesignMode) {
if (!_applyLanguageManually) {
ApplyLanguage();

View file

@ -50,7 +50,7 @@ namespace GreenshotPlugin.Controls {
}
InitializeComponent();
ClientSize = size;
Icon = GreenshotResources.getGreenshotIcon();
Icon = GreenshotResources.GetGreenshotIcon();
Text = browserTitle;
_addressTextBox.Text = authorizationLink;

View file

@ -37,7 +37,7 @@ namespace GreenshotPlugin.Controls {
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
Icon = GreenshotResources.getGreenshotIcon();
Icon = GreenshotResources.GetGreenshotIcon();
}
/// <summary>

View file

@ -234,7 +234,7 @@ namespace GreenshotPlugin.Core {
menu.Items.Add(new ToolStripSeparator());
ToolStripMenuItem closeItem = new ToolStripMenuItem(Language.GetString("editor_close"))
{
Image = GreenshotResources.getImage("Close.Image")
Image = GreenshotResources.GetImage("Close.Image")
};
closeItem.Click += delegate {
// This menu entry is the close itself, we can dispose the surface

View file

@ -26,21 +26,18 @@ namespace GreenshotPlugin.Core {
/// Centralized storage of the icons & bitmaps
/// </summary>
public static class GreenshotResources {
private static readonly ComponentResourceManager greenshotResources = new ComponentResourceManager(typeof(GreenshotResources));
private static readonly ComponentResourceManager GreenshotResourceManager = new ComponentResourceManager(typeof(GreenshotResources));
public static Image getImage(string imageName) {
return (Image)greenshotResources.GetObject(imageName);
public static Image GetImage(string imageName) {
return (Image)GreenshotResourceManager.GetObject(imageName);
}
public static Icon getIcon(string imageName) {
return (Icon)greenshotResources.GetObject(imageName);
public static Icon GetIcon(string imageName) {
return (Icon)GreenshotResourceManager.GetObject(imageName);
}
public static Icon getGreenshotIcon() {
return getIcon("Greenshot.Icon");
public static Icon GetGreenshotIcon() {
return GetIcon("Greenshot.Icon");
}
public static Image getGreenshotImage() {
return getImage("Greenshot.Image");
}
}
}

View file

@ -21,8 +21,11 @@
using System;
namespace Greenshot.Helpers
namespace GreenshotPlugin.Interfaces
{
/// <summary>
/// This is the interface for the different notification service implementations
/// </summary>
public interface INotificationService
{
/// <summary>

View file

@ -167,7 +167,7 @@ namespace GreenshotWin10Plugin.Destinations
// Create logo
RandomAccessStreamReference logoRandomAccessStreamReference;
using (var logo = GreenshotResources.getGreenshotIcon().ToBitmap())
using (var logo = GreenshotResources.GetGreenshotIcon().ToBitmap())
using (var logoThumbnail = ImageHelper.CreateThumbnail(logo, 30, 30))
{
ImageOutput.SaveToStream(logoThumbnail, null, logoStream, outputSettings);

View file

@ -20,20 +20,51 @@
*/
using System;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using Windows.UI.Notifications;
using Greenshot.Helpers;
using GreenshotPlugin.Core;
using GreenshotPlugin.IniFile;
using GreenshotPlugin.Interfaces;
using log4net;
namespace GreenshotWin10Plugin
{
/// <summary>
/// This service provides a way to inform (notify) the user.
/// </summary>
public class ToastNotificationService : INotificationService
{
private static readonly ILog Log = LogManager.GetLogger(typeof(ToastNotificationService));
private static readonly CoreConfiguration CoreConfiguration = IniConfig.GetIniSection<CoreConfiguration>();
private readonly string _imageFilePath;
public ToastNotificationService()
{
var localAppData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Greenshot");
if (!Directory.Exists(localAppData))
{
Directory.CreateDirectory(localAppData);
}
_imageFilePath = Path.Combine(localAppData, "greenshot.png");
if (File.Exists(_imageFilePath))
{
return;
}
using var greenshotImage = GreenshotResources.GetGreenshotIcon().ToBitmap();
greenshotImage.Save(_imageFilePath, ImageFormat.Png);
}
private void ShowMessage(string message, Action onClickAction, Action onClosedAction)
{
// Do not inform the user if this is disabled
if (!CoreConfiguration.ShowTrayNotification)
{
return;
}
// Get a toast XML template
var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText01);
@ -41,10 +72,17 @@ namespace GreenshotWin10Plugin
var stringElement = toastXml.GetElementsByTagName("text").First();
stringElement.AppendChild(toastXml.CreateTextNode(message));
if (_imageFilePath != null && File.Exists(_imageFilePath))
{
// Specify the absolute path to an image
//string imagePath = "file:///" + Path.GetFullPath("toastImageAndText.png");
//var imageElement = toastXml.GetElementsByTagName("image").First();
//imageElement.Attributes.GetNamedItem("src").NodeValue = imagePath;
var imageElement = toastXml.GetElementsByTagName("image").First();
var imageSrcNode = imageElement.Attributes.GetNamedItem("src");
if (imageSrcNode != null)
{
imageSrcNode.NodeValue = _imageFilePath;
}
}
// Create the toast and attach event listeners
var toast = new ToastNotification(toastXml);

View file

@ -20,7 +20,6 @@
*/
using System;
using Greenshot.Helpers;
using GreenshotPlugin.Core;
using GreenshotPlugin.Interfaces;
using GreenshotPlugin.Interfaces.Ocr;