mirror of
https://github.com/greenshot/greenshot
synced 2025-07-16 10:03:44 -07:00
First step in moving towards replaceable notification messages, extracted the logic to do so into it's own module. [skip ci]
This commit is contained in:
parent
87b7905457
commit
d0846b0f09
4 changed files with 168 additions and 65 deletions
|
@ -46,7 +46,6 @@ using System.Threading.Tasks;
|
||||||
using GreenshotPlugin.IniFile;
|
using GreenshotPlugin.IniFile;
|
||||||
using GreenshotPlugin.Interfaces;
|
using GreenshotPlugin.Interfaces;
|
||||||
using GreenshotPlugin.Interfaces.Plugin;
|
using GreenshotPlugin.Interfaces.Plugin;
|
||||||
using GreenshotPlugin.UnmanagedHelpers.Enums;
|
|
||||||
|
|
||||||
namespace Greenshot {
|
namespace Greenshot {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -350,6 +349,12 @@ namespace Greenshot {
|
||||||
// Make the notify icon available
|
// Make the notify icon available
|
||||||
SimpleServiceProvider.Current.AddService(notifyIcon);
|
SimpleServiceProvider.Current.AddService(notifyIcon);
|
||||||
|
|
||||||
|
// TODO: Enable check if the Windows 10 notification service is available
|
||||||
|
//if (WindowsVersion.IsBeforeWindows10)
|
||||||
|
//{
|
||||||
|
SimpleServiceProvider.Current.AddService(new NotifyIconNotificationService());
|
||||||
|
//}
|
||||||
|
|
||||||
// Disable access to the settings, for feature #3521446
|
// Disable access to the settings, for feature #3521446
|
||||||
contextmenu_settings.Visible = !_conf.DisableSettings;
|
contextmenu_settings.Visible = !_conf.DisableSettings;
|
||||||
|
|
||||||
|
@ -428,20 +433,7 @@ namespace Greenshot {
|
||||||
HandleDataTransport(dataTransport);
|
HandleDataTransport(dataTransport);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void BalloonTipClicked(object sender, EventArgs e) {
|
private void HandleDataTransport(CopyDataTransport dataTransport) {
|
||||||
try {
|
|
||||||
ShowSetting();
|
|
||||||
} finally {
|
|
||||||
BalloonTipClosed(sender, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void BalloonTipClosed(object sender, EventArgs e) {
|
|
||||||
notifyIcon.BalloonTipClicked -= BalloonTipClicked;
|
|
||||||
notifyIcon.BalloonTipClosed -= BalloonTipClosed;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void HandleDataTransport(CopyDataTransport dataTransport) {
|
|
||||||
foreach(KeyValuePair<CommandEnum, string> command in dataTransport.Commands) {
|
foreach(KeyValuePair<CommandEnum, string> command in dataTransport.Commands) {
|
||||||
LOG.Debug("Data received, Command = " + command.Key + ", Data: " + command.Value);
|
LOG.Debug("Data received, Command = " + command.Key + ", Data: " + command.Value);
|
||||||
switch(command.Key) {
|
switch(command.Key) {
|
||||||
|
@ -451,14 +443,9 @@ namespace Greenshot {
|
||||||
break;
|
break;
|
||||||
case CommandEnum.FirstLaunch:
|
case CommandEnum.FirstLaunch:
|
||||||
LOG.Info("FirstLaunch: Created new configuration, showing balloon.");
|
LOG.Info("FirstLaunch: Created new configuration, showing balloon.");
|
||||||
try {
|
var notifyIconClassicMessageHandler = SimpleServiceProvider.Current.GetInstance<NotifyIconNotificationService>();
|
||||||
notifyIcon.BalloonTipClicked += BalloonTipClicked;
|
notifyIconClassicMessageHandler.ShowInfoMessage(Language.GetFormattedString(LangKey.tooltip_firststart, HotkeyControl.GetLocalizedHotkeyStringFromString(_conf.RegionHotkey)), 2000, ShowSetting);
|
||||||
notifyIcon.BalloonTipClosed += BalloonTipClosed;
|
break;
|
||||||
notifyIcon.ShowBalloonTip(2000, "Greenshot", Language.GetFormattedString(LangKey.tooltip_firststart, HotkeyControl.GetLocalizedHotkeyStringFromString(_conf.RegionHotkey)), ToolTipIcon.Info);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
LOG.Warn("Exception while showing first launch: ", ex);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CommandEnum.ReloadConfig:
|
case CommandEnum.ReloadConfig:
|
||||||
LOG.Info("Reload requested");
|
LOG.Info("Reload requested");
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
/*
|
/*
|
||||||
* Greenshot - a free and open source screenshot tool
|
* Greenshot - a free and open source screenshot tool
|
||||||
* Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom
|
* Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom
|
||||||
*
|
*
|
||||||
* For more information see: http://getgreenshot.org/
|
* For more information see: http://getgreenshot.org/
|
||||||
* The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
|
* The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 1 of the License, or
|
* the Free Software Foundation, either version 1 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
@ -41,7 +41,7 @@ using GreenshotPlugin.UnmanagedHelpers.Enums;
|
||||||
|
|
||||||
namespace Greenshot.Helpers {
|
namespace Greenshot.Helpers {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// CaptureHelper contains all the capture logic
|
/// CaptureHelper contains all the capture logic
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CaptureHelper : IDisposable {
|
public class CaptureHelper : IDisposable {
|
||||||
private static readonly ILog Log = LogManager.GetLogger(typeof(CaptureHelper));
|
private static readonly ILog Log = LogManager.GetLogger(typeof(CaptureHelper));
|
||||||
|
@ -177,7 +177,7 @@ namespace Greenshot.Helpers {
|
||||||
|
|
||||||
public CaptureHelper(CaptureMode captureMode) {
|
public CaptureHelper(CaptureMode captureMode) {
|
||||||
_captureMode = captureMode;
|
_captureMode = captureMode;
|
||||||
_capture = new Capture();
|
_capture = new Capture();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CaptureHelper(CaptureMode captureMode, bool captureMouseCursor) : this(captureMode) {
|
public CaptureHelper(CaptureMode captureMode, bool captureMouseCursor) : this(captureMode) {
|
||||||
|
@ -192,7 +192,7 @@ namespace Greenshot.Helpers {
|
||||||
public CaptureHelper(CaptureMode captureMode, bool captureMouseCursor, IDestination destination) : this(captureMode, captureMouseCursor) {
|
public CaptureHelper(CaptureMode captureMode, bool captureMouseCursor, IDestination destination) : this(captureMode, captureMouseCursor) {
|
||||||
_capture.CaptureDetails.AddDestination(destination);
|
_capture.CaptureDetails.AddDestination(destination);
|
||||||
}
|
}
|
||||||
|
|
||||||
public WindowDetails SelectedCaptureWindow {
|
public WindowDetails SelectedCaptureWindow {
|
||||||
get {
|
get {
|
||||||
return _selectedCaptureWindow;
|
return _selectedCaptureWindow;
|
||||||
|
@ -201,7 +201,7 @@ namespace Greenshot.Helpers {
|
||||||
_selectedCaptureWindow = value;
|
_selectedCaptureWindow = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DoCaptureFeedback() {
|
private void DoCaptureFeedback() {
|
||||||
if (CoreConfig.PlayCameraSound) {
|
if (CoreConfig.PlayCameraSound) {
|
||||||
SoundHelper.Play();
|
SoundHelper.Play();
|
||||||
|
@ -459,13 +459,13 @@ namespace Greenshot.Helpers {
|
||||||
_capture.Dispose();
|
_capture.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Pre-Initialization for CaptureWithFeedback, this will get all the windows before we change anything
|
/// Pre-Initialization for CaptureWithFeedback, this will get all the windows before we change anything
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private Thread PrepareForCaptureWithFeedback() {
|
private Thread PrepareForCaptureWithFeedback() {
|
||||||
_windows = new List<WindowDetails>();
|
_windows = new List<WindowDetails>();
|
||||||
|
|
||||||
// If the App Launcher is visisble, no other windows are active
|
// If the App Launcher is visisble, no other windows are active
|
||||||
WindowDetails appLauncherWindow = WindowDetails.GetAppLauncher();
|
WindowDetails appLauncherWindow = WindowDetails.GetAppLauncher();
|
||||||
if (appLauncherWindow != null && appLauncherWindow.Visible) {
|
if (appLauncherWindow != null && appLauncherWindow.Visible) {
|
||||||
|
@ -514,14 +514,12 @@ namespace Greenshot.Helpers {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If a balloon tip is show for a taken capture, this handles the click on it
|
/// If a balloon tip is show for a taken capture, this handles the click on it
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="e">SurfaceMessageEventArgs</param>
|
||||||
/// <param name="e"></param>
|
private void OpenCaptureOnClick(SurfaceMessageEventArgs e) {
|
||||||
private void OpenCaptureOnClick(object sender, EventArgs e) {
|
|
||||||
var notifyIcon = SimpleServiceProvider.Current.GetInstance<NotifyIcon>();
|
var notifyIcon = SimpleServiceProvider.Current.GetInstance<NotifyIcon>();
|
||||||
if (!(notifyIcon.Tag is SurfaceMessageEventArgs eventArgs)) {
|
if (!(notifyIcon.Tag is SurfaceMessageEventArgs eventArgs)) {
|
||||||
Log.Warn("OpenCaptureOnClick called without SurfaceMessageEventArgs");
|
Log.Warn("OpenCaptureOnClick called without SurfaceMessageEventArgs");
|
||||||
RemoveEventHandler(sender, e);
|
return;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
ISurface surface = eventArgs.Surface;
|
ISurface surface = eventArgs.Surface;
|
||||||
if (surface != null)
|
if (surface != null)
|
||||||
|
@ -537,17 +535,9 @@ namespace Greenshot.Helpers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.DebugFormat("Deregistering the BalloonTipClicked");
|
Log.DebugFormat("Deregistering the BalloonTipClicked");
|
||||||
RemoveEventHandler(sender, e);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void RemoveEventHandler(object sender, EventArgs e) {
|
/// <summary>
|
||||||
var notifyIcon = SimpleServiceProvider.Current.GetInstance<NotifyIcon>();
|
|
||||||
notifyIcon.BalloonTipClicked -= OpenCaptureOnClick;
|
|
||||||
notifyIcon.BalloonTipClosed -= RemoveEventHandler;
|
|
||||||
notifyIcon.Tag = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// This is the SurfaceMessageEvent receiver
|
/// This is the SurfaceMessageEvent receiver
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender">object</param>
|
/// <param name="sender">object</param>
|
||||||
|
@ -556,27 +546,22 @@ namespace Greenshot.Helpers {
|
||||||
if (string.IsNullOrEmpty(eventArgs?.Message)) {
|
if (string.IsNullOrEmpty(eventArgs?.Message)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var notifyIcon = SimpleServiceProvider.Current.GetInstance<NotifyIcon>();
|
var notifyIconClassicMessageHandler = SimpleServiceProvider.Current.GetInstance<NotifyIconNotificationService>();
|
||||||
switch (eventArgs.MessageType) {
|
switch (eventArgs.MessageType) {
|
||||||
case SurfaceMessageTyp.Error:
|
case SurfaceMessageTyp.Error:
|
||||||
notifyIcon.ShowBalloonTip(10000, "Greenshot", eventArgs.Message, ToolTipIcon.Error);
|
notifyIconClassicMessageHandler.ShowErrorMessage(eventArgs.Message, 10000);
|
||||||
break;
|
break;
|
||||||
case SurfaceMessageTyp.Info:
|
case SurfaceMessageTyp.Info:
|
||||||
notifyIcon.ShowBalloonTip(10000, "Greenshot", eventArgs.Message, ToolTipIcon.Info);
|
notifyIconClassicMessageHandler.ShowInfoMessage(eventArgs.Message, 10000);
|
||||||
break;
|
break;
|
||||||
case SurfaceMessageTyp.FileSaved:
|
case SurfaceMessageTyp.FileSaved:
|
||||||
case SurfaceMessageTyp.UploadedUri:
|
case SurfaceMessageTyp.UploadedUri:
|
||||||
// Show a balloon and register an event handler to open the "capture" for if someone clicks the balloon.
|
// Show a balloon and register an event handler to open the "capture" for if someone clicks the balloon.
|
||||||
notifyIcon.BalloonTipClicked += OpenCaptureOnClick;
|
notifyIconClassicMessageHandler.ShowInfoMessage(eventArgs.Message, 10000, () => OpenCaptureOnClick(eventArgs));
|
||||||
notifyIcon.BalloonTipClosed += RemoveEventHandler;
|
|
||||||
// Store for later usage
|
|
||||||
notifyIcon.Tag = eventArgs;
|
|
||||||
notifyIcon.ShowBalloonTip(10000, "Greenshot", eventArgs.Message, ToolTipIcon.Info);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void HandleCapture() {
|
private void HandleCapture() {
|
||||||
// Flag to see if the image was "exported" so the FileEditor doesn't
|
// Flag to see if the image was "exported" so the FileEditor doesn't
|
||||||
// ask to save the file as long as nothing is done.
|
// ask to save the file as long as nothing is done.
|
||||||
|
@ -587,7 +572,7 @@ namespace Greenshot.Helpers {
|
||||||
var selectionRectangle = new Rectangle(Point.Empty, _capture.Image.Size);
|
var selectionRectangle = new Rectangle(Point.Empty, _capture.Image.Size);
|
||||||
var ocrInfo = _capture.CaptureDetails.OcrInformation;
|
var ocrInfo = _capture.CaptureDetails.OcrInformation;
|
||||||
if (ocrInfo != null)
|
if (ocrInfo != null)
|
||||||
{
|
{
|
||||||
var textResult = new StringBuilder();
|
var textResult = new StringBuilder();
|
||||||
foreach (var line in ocrInfo.Lines)
|
foreach (var line in ocrInfo.Lines)
|
||||||
{
|
{
|
||||||
|
@ -666,10 +651,10 @@ namespace Greenshot.Helpers {
|
||||||
Modified = !outputMade
|
Modified = !outputMade
|
||||||
};
|
};
|
||||||
|
|
||||||
// Register notify events if this is wanted
|
// Register notify events if this is wanted
|
||||||
if (CoreConfig.ShowTrayNotification && !CoreConfig.HideTrayicon) {
|
if (CoreConfig.ShowTrayNotification && !CoreConfig.HideTrayicon) {
|
||||||
surface.SurfaceMessage += SurfaceMessageReceived;
|
surface.SurfaceMessage += SurfaceMessageReceived;
|
||||||
|
|
||||||
}
|
}
|
||||||
// Let the processors do their job
|
// Let the processors do their job
|
||||||
foreach(var processor in SimpleServiceProvider.Current.GetAllInstances<IProcessor>()) {
|
foreach(var processor in SimpleServiceProvider.Current.GetAllInstances<IProcessor>()) {
|
||||||
|
@ -677,7 +662,7 @@ namespace Greenshot.Helpers {
|
||||||
Log.InfoFormat("Calling processor {0}", processor.Description);
|
Log.InfoFormat("Calling processor {0}", processor.Description);
|
||||||
processor.ProcessCapture(surface, _capture.CaptureDetails);
|
processor.ProcessCapture(surface, _capture.CaptureDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
// As the surfaces copies the reference to the image, make sure the image is not being disposed (a trick to save memory)
|
// As the surfaces copies the reference to the image, make sure the image is not being disposed (a trick to save memory)
|
||||||
_capture.Image = null;
|
_capture.Image = null;
|
||||||
|
|
||||||
|
@ -749,7 +734,7 @@ namespace Greenshot.Helpers {
|
||||||
// Nothing to capture, code up in the stack will capture the full screen
|
// Nothing to capture, code up in the stack will capture the full screen
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Fix for Bug #3430560
|
// Fix for Bug #3430560
|
||||||
CoreConfig.LastCapturedRegion = _selectedCaptureWindow.WindowRectangle;
|
CoreConfig.LastCapturedRegion = _selectedCaptureWindow.WindowRectangle;
|
||||||
bool returnValue = CaptureWindow(_selectedCaptureWindow, _capture, CoreConfig.WindowCaptureMode) != null;
|
bool returnValue = CaptureWindow(_selectedCaptureWindow, _capture, CoreConfig.WindowCaptureMode) != null;
|
||||||
return returnValue;
|
return returnValue;
|
||||||
|
@ -775,7 +760,7 @@ namespace Greenshot.Helpers {
|
||||||
}
|
}
|
||||||
return windowToCapture;
|
return windowToCapture;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check if Process uses PresentationFramework.dll -> meaning it uses WPF
|
/// Check if Process uses PresentationFramework.dll -> meaning it uses WPF
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -992,9 +977,9 @@ namespace Greenshot.Helpers {
|
||||||
|
|
||||||
private void CaptureWithFeedback()
|
private void CaptureWithFeedback()
|
||||||
{
|
{
|
||||||
// The following, to be precise the HideApp, causes the app to close as described in BUG-1620
|
// The following, to be precise the HideApp, causes the app to close as described in BUG-1620
|
||||||
// Added check for metro (Modern UI) apps, which might be maximized and cover the screen.
|
// Added check for metro (Modern UI) apps, which might be maximized and cover the screen.
|
||||||
|
|
||||||
//foreach(WindowDetails app in WindowDetails.GetMetroApps()) {
|
//foreach(WindowDetails app in WindowDetails.GetMetroApps()) {
|
||||||
// if (app.Maximised) {
|
// if (app.Maximised) {
|
||||||
// app.HideApp();
|
// app.HideApp();
|
||||||
|
|
125
Greenshot/Helpers/NotifyIconNotificationService.cs
Normal file
125
Greenshot/Helpers/NotifyIconNotificationService.cs
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom
|
||||||
|
*
|
||||||
|
* For more information see: http://getgreenshot.org/
|
||||||
|
* The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 1 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using GreenshotPlugin.Core;
|
||||||
|
using log4net;
|
||||||
|
|
||||||
|
namespace Greenshot.Helpers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Notify the user with messages via the NotifyIcon
|
||||||
|
/// </summary>
|
||||||
|
public class NotifyIconNotificationService
|
||||||
|
{
|
||||||
|
private static readonly ILog Log = LogManager.GetLogger(typeof(NotifyIconNotificationService));
|
||||||
|
private readonly NotifyIcon _notifyIcon;
|
||||||
|
|
||||||
|
public NotifyIconNotificationService()
|
||||||
|
{
|
||||||
|
_notifyIcon = SimpleServiceProvider.Current.GetInstance<NotifyIcon>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This will show a warning message to the user
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">string</param>
|
||||||
|
/// <param name="timeout"></param>
|
||||||
|
/// <param name="onClickAction">Action called if the user clicks the notification</param>
|
||||||
|
/// <param name="onClosedAction">Action</param>
|
||||||
|
public void ShowWarningMessage(string message, int timeout, Action onClickAction = null, Action onClosedAction = null)
|
||||||
|
{
|
||||||
|
ShowMessage(message, timeout, ToolTipIcon.Warning, onClickAction, onClosedAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This will show an error message to the user
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">string</param>
|
||||||
|
/// <param name="timeout"></param>
|
||||||
|
/// <param name="onClickAction">Action called if the user clicks the notification</param>
|
||||||
|
/// <param name="onClosedAction">Action</param>
|
||||||
|
public void ShowErrorMessage(string message, int timeout, Action onClickAction = null, Action onClosedAction = null)
|
||||||
|
{
|
||||||
|
ShowMessage(message, timeout, ToolTipIcon.Error, onClickAction, onClosedAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This will show an info message to the user
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">string</param>
|
||||||
|
/// <param name="timeout">int</param>
|
||||||
|
/// <param name="onClickAction">Action called if the user clicks the notification</param>
|
||||||
|
/// <param name="onClosedAction">Action</param>
|
||||||
|
public void ShowInfoMessage(string message, int timeout, Action onClickAction = null, Action onClosedAction = null)
|
||||||
|
{
|
||||||
|
ShowMessage(message, timeout, ToolTipIcon.Info, onClickAction, onClosedAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This will show a message to the user
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">string</param>
|
||||||
|
/// <param name="timeout">int</param>
|
||||||
|
/// <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) {
|
||||||
|
void BalloonClickedHandler(object s, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
onClickAction?.Invoke();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Warn("Exception while handling the onclick action: ", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
_notifyIcon.BalloonTipClicked -= BalloonClickedHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (onClickAction != null)
|
||||||
|
{
|
||||||
|
_notifyIcon.BalloonTipClicked += BalloonClickedHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BalloonClosedHandler(object s, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
onClosedAction?.Invoke();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Warn("Exception while handling the onClosed action: ", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
_notifyIcon.BalloonTipClosed -= BalloonClosedHandler;
|
||||||
|
// Remove the other handler too
|
||||||
|
_notifyIcon.BalloonTipClicked -= BalloonClickedHandler;
|
||||||
|
}
|
||||||
|
_notifyIcon.BalloonTipClosed += BalloonClosedHandler;
|
||||||
|
_notifyIcon.ShowBalloonTip(timeout, @"Greenshot", message, level);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,6 +21,12 @@ namespace GreenshotPlugin.Core
|
||||||
/// <returns>true if we are running on Windows 10</returns>
|
/// <returns>true if we are running on Windows 10</returns>
|
||||||
public static bool IsWindows10 { get; } = WinVersion.Major == 10;
|
public static bool IsWindows10 { get; } = WinVersion.Major == 10;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test if the current OS is before Windows 10
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>true if we are running on Windows before 10</returns>
|
||||||
|
public static bool IsBeforeWindows10 { get; } = WinVersion.Major < 10;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test if the current OS is Windows 10 or later
|
/// Test if the current OS is Windows 10 or later
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue