public NotificationForm(int duration, ContentAlignment placement, Size size, NotificationFormConfig config) { InitializeComponent(); ToastConfig = config; textFont = new Font("Arial", 10); if (config.Image != null) { config.Image = ImageHelpers.ResizeImageLimit(config.Image, size); config.Image = ImageHelpers.DrawCheckers(config.Image); size = new Size(config.Image.Width + 2, config.Image.Height + 2); } else if (!string.IsNullOrEmpty(config.Text)) { textRenderSize = Helpers.MeasureText(config.Text, textFont, size.Width - textPadding * 2); size = new Size(textRenderSize.Width + textPadding * 2, textRenderSize.Height + textPadding * 2 + 2); } SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); Size = size; Point position = Helpers.GetPosition(placement, new Point(windowOffset, windowOffset), Screen.PrimaryScreen.WorkingArea.Size, Size); Location = new Point(Screen.PrimaryScreen.WorkingArea.X + position.X, Screen.PrimaryScreen.WorkingArea.Y + position.Y); tDuration.Interval = duration; tDuration.Start(); }
public static void Show(NotificationFormConfig config) { if (config.IsValid) { if (config.Image == null) { config.Image = ImageHelpers.LoadImage(config.FilePath); } if (config.Image != null || !string.IsNullOrEmpty(config.Text)) { if (instance == null || instance.IsDisposed) { instance = new NotificationForm(); instance.LoadConfig(config); NativeMethods.ShowWindow(instance.Handle, (int)WindowShowStyle.ShowNoActivate); } else { instance.LoadConfig(config); } } } }
public NotificationForm(int duration, ContentAlignment placement, Size size, NotificationFormConfig config) { InitializeComponent(); SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); ToastConfig = config; textFont = new Font("Arial", 10); if (config.Image != null) { config.Image = ImageHelpers.ResizeImageLimit(config.Image, size); config.Image = ImageHelpers.DrawCheckers(config.Image); size = new Size(config.Image.Width + 2, config.Image.Height + 2); } else if (!string.IsNullOrEmpty(config.Text)) { textRenderSize = Helpers.MeasureText(config.Text, textFont, size.Width - textPadding * 2); size = new Size(textRenderSize.Width + textPadding * 2, textRenderSize.Height + textPadding * 2 + 2); } Point position = Helpers.GetPosition(placement, new Point(windowOffset, windowOffset), Screen.PrimaryScreen.WorkingArea.Size, size); NativeMethods.SetWindowPos(Handle, (IntPtr)SpecialWindowHandles.HWND_TOPMOST, position.X + Screen.PrimaryScreen.WorkingArea.X, position.Y + Screen.PrimaryScreen.WorkingArea.Y, size.Width, size.Height, SetWindowPosFlags.SWP_NOACTIVATE); if (duration <= 0) { DurationEnd(); } else { tDuration.Interval = duration; tDuration.Start(); } }
public void LoadConfig(NotificationFormConfig config) { Config?.Dispose(); buffer?.Dispose(); gBuffer?.Dispose(); Config = config; opacityDecrement = (float)fadeInterval / Config.FadeDuration * 255; if (Config.Image != null) { Config.Image = ImageHelpers.ResizeImageLimit(Config.Image, Config.Size); Config.Size = new Size(Config.Image.Width + 2, Config.Image.Height + 2); } else if (!string.IsNullOrEmpty(Config.Text)) { Size size = Config.Size.Offset(-Config.TextPadding * 2); textRenderSize = TextRenderer.MeasureText(Config.Text, Config.TextFont, size, TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl | TextFormatFlags.EndEllipsis); textRenderSize = new Size(textRenderSize.Width, Math.Min(textRenderSize.Height, size.Height)); totalRenderSize = textRenderSize; if (!string.IsNullOrEmpty(Config.Title)) { titleRenderSize = TextRenderer.MeasureText(Config.Title, Config.TitleFont, Config.Size.Offset(-Config.TextPadding * 2), TextFormatFlags.Left | TextFormatFlags.EndEllipsis); totalRenderSize = new Size(Math.Max(textRenderSize.Width, titleRenderSize.Width), titleRenderSize.Height + titleSpace + textRenderSize.Height); } Config.Size = new Size(totalRenderSize.Width + (Config.TextPadding * 2), totalRenderSize.Height + (Config.TextPadding * 2) + 2); } buffer = new Bitmap(Config.Size.Width, Config.Size.Height); gBuffer = Graphics.FromImage(buffer); Point position = Helpers.GetPosition(Config.Placement, Config.Offset, Screen.PrimaryScreen.WorkingArea.Size, Config.Size); NativeMethods.SetWindowPos(Handle, (IntPtr)SpecialWindowHandles.HWND_TOPMOST, position.X + Screen.PrimaryScreen.WorkingArea.X, position.Y + Screen.PrimaryScreen.WorkingArea.Y, Config.Size.Width, Config.Size.Height, SetWindowPosFlags.SWP_NOACTIVATE); tDuration.Stop(); tOpacity.Stop(); opacity = 255; Render(true); if (Config.Duration <= 0) { DurationEnd(); } else { tDuration.Interval = Config.Duration; tDuration.Start(); } }
public static void Show(int duration, ContentAlignment placement, Size size, NotificationFormConfig config) { if (size.Width > 0 && size.Height > 0) { config.Image = ImageHelpers.LoadImage(config.FilePath); if (config.Image != null || !string.IsNullOrEmpty(config.Text)) { NotificationForm form = new NotificationForm(duration, placement, size, config); NativeMethods.ShowWindow(form.Handle, (int)WindowShowStyle.ShowNoActivate); } } }
public static void Show(int duration, ContentAlignment placement, Size size, NotificationFormConfig config) { if (duration > 0 && size.Width > 0 && size.Height > 0) { config.Image = ImageHelpers.LoadImage(config.FilePath); if (config.Image != null || !string.IsNullOrEmpty(config.Text)) { NotificationForm form = new NotificationForm(duration, placement, size, config); NativeMethods.ShowWindow(form.Handle, (int)WindowShowStyle.ShowNoActivate); NativeMethods.SetWindowPos(form.Handle, (IntPtr)SpecialWindowHandles.HWND_TOPMOST, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE); } } }
public static void Show(NotificationFormConfig config) { if (config.IsValid) { if (config.Image == null) { config.Image = ImageHelpers.LoadImage(config.FilePath); } if (config.Image != null || !string.IsNullOrEmpty(config.Text)) { NotificationForm form = new NotificationForm(config); NativeMethods.ShowWindow(form.Handle, (int)WindowShowStyle.ShowNoActivate); } } }
private NotificationForm(NotificationFormConfig config) { InitializeComponent(); Icon = ShareXResources.Icon; SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); Config = config; opacityDecrement = (float)fadeInterval / Config.FadeDuration; if (Config.Image != null) { Config.Image = ImageHelpers.ResizeImageLimit(Config.Image, Config.Size); Config.Size = new Size(Config.Image.Width + 2, Config.Image.Height + 2); } else if (!string.IsNullOrEmpty(Config.Text)) { Size size = Config.Size.Offset(-Config.TextPadding * 2); textRenderSize = TextRenderer.MeasureText(Config.Text, Config.TextFont, size, TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl | TextFormatFlags.EndEllipsis); textRenderSize = new Size(textRenderSize.Width, Math.Min(textRenderSize.Height, size.Height)); totalRenderSize = textRenderSize; if (!string.IsNullOrEmpty(Config.Title)) { titleRenderSize = TextRenderer.MeasureText(Config.Title, Config.TitleFont, Config.Size.Offset(-Config.TextPadding * 2), TextFormatFlags.Left | TextFormatFlags.EndEllipsis); totalRenderSize = new Size(Math.Max(textRenderSize.Width, titleRenderSize.Width), titleRenderSize.Height + titleSpace + textRenderSize.Height); } Config.Size = new Size(totalRenderSize.Width + (Config.TextPadding * 2), totalRenderSize.Height + (Config.TextPadding * 2) + 2); } Point position = Helpers.GetPosition(Config.Placement, Config.Offset, Screen.PrimaryScreen.WorkingArea.Size, Config.Size); NativeMethods.SetWindowPos(Handle, (IntPtr)SpecialWindowHandles.HWND_TOPMOST, position.X + Screen.PrimaryScreen.WorkingArea.X, position.Y + Screen.PrimaryScreen.WorkingArea.Y, Config.Size.Width, Config.Size.Height, SetWindowPosFlags.SWP_NOACTIVATE); if (Config.Duration <= 0) { DurationEnd(); } else { tDuration.Interval = Config.Duration; tDuration.Start(); } }
public NotificationForm(int duration, int fadeDuration, ContentAlignment placement, Size size, NotificationFormConfig config) { InitializeComponent(); Icon = ShareXResources.Icon; SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); Duration = duration; FadeDuration = fadeDuration; opacityDecrement = (float)fadeInterval / FadeDuration; ToastConfig = config; textFont = new Font("Arial", 10); if (config.Image != null) { config.Image = ImageHelpers.ResizeImageLimit(config.Image, size); Color backgroundColor = ShareXResources.UseCustomTheme ? ShareXResources.Theme.BackgroundColor : SystemColors.Window; config.Image = ImageHelpers.FillBackground(config.Image, backgroundColor); size = new Size(config.Image.Width + 2, config.Image.Height + 2); } else if (!string.IsNullOrEmpty(config.Text)) { textRenderSize = TextRenderer.MeasureText(config.Text, textFont, size.Offset(-textPadding * 2), TextFormatFlags.Left | TextFormatFlags.EndEllipsis); size = new Size(textRenderSize.Width + (textPadding * 2), textRenderSize.Height + (textPadding * 2) + 2); } Point position = Helpers.GetPosition(placement, new Point(windowOffset, windowOffset), Screen.PrimaryScreen.WorkingArea.Size, size); NativeMethods.SetWindowPos(Handle, (IntPtr)SpecialWindowHandles.HWND_TOPMOST, position.X + Screen.PrimaryScreen.WorkingArea.X, position.Y + Screen.PrimaryScreen.WorkingArea.Y, size.Width, size.Height, SetWindowPosFlags.SWP_NOACTIVATE); if (Duration <= 0) { DurationEnd(); } else { tDuration.Interval = Duration; tDuration.Start(); } }
public static void ShowResultNotifications(string notificationText, TaskSettings taskSettings, string filePath) { if (!taskSettings.AdvancedSettings.DisableNotifications) { if (!string.IsNullOrEmpty(notificationText)) { switch (taskSettings.GeneralSettings.PopUpNotification) { case PopUpNotificationType.BalloonTip: if (Program.MainForm.niTray.Visible) { Program.MainForm.niTray.Tag = notificationText; Program.MainForm.niTray.ShowBalloonTip(5000, "ShareX - Task completed", notificationText, ToolTipIcon.Info); } break; case PopUpNotificationType.ToastNotification: NotificationFormConfig toastConfig = new NotificationFormConfig() { Action = taskSettings.AdvancedSettings.ToastWindowClickAction, FilePath = filePath, Text = "ShareX - Task completed\r\n" + notificationText, URL = notificationText }; NotificationForm.Show((int)(taskSettings.AdvancedSettings.ToastWindowDuration * 1000), taskSettings.AdvancedSettings.ToastWindowPlacement, taskSettings.AdvancedSettings.ToastWindowSize, toastConfig); break; } } if (taskSettings.GeneralSettings.PlaySoundAfterUpload) { SystemSounds.Exclamation.Play(); } } }
private static void task_TaskCompleted(WorkerTask task) { try { if (ListViewControl != null && task != null) { if (task.RequestSettingUpdate) { Program.MainForm.UpdateCheckStates(); } TaskInfo info = task.Info; if (info != null && info.Result != null) { ListViewItem lvi = FindListViewItem(task); if (task.Status == TaskStatus.Stopped) { DebugHelper.WriteLine($"Task stopped. Filename: {info.FileName}"); if (lvi != null) { lvi.Text = info.FileName; lvi.SubItems[1].Text = info.Status; lvi.ImageIndex = 2; } } else if (task.Status == TaskStatus.Failed) { string errors = string.Join("\r\n\r\n", info.Result.Errors.ToArray()); DebugHelper.WriteLine($"Task failed. Filename: {info.FileName}, Errors:\r\n{errors}"); if (lvi != null) { lvi.SubItems[1].Text = info.Status; lvi.SubItems[6].Text = ""; lvi.ImageIndex = 1; } if (!info.TaskSettings.AdvancedSettings.DisableNotifications) { if (info.TaskSettings.GeneralSettings.PlaySoundAfterUpload) { TaskHelpers.PlayErrorSound(info.TaskSettings); } if (info.TaskSettings.GeneralSettings.PopUpNotification != PopUpNotificationType.None && Program.MainForm.niTray.Visible && !string.IsNullOrEmpty(errors)) { Program.MainForm.niTray.Tag = null; Program.MainForm.niTray.ShowBalloonTip(5000, "ShareX - " + Resources.TaskManager_task_UploadCompleted_Error, errors, ToolTipIcon.Error); } } } else { DebugHelper.WriteLine($"Task completed. Filename: {info.FileName}, Duration: {(long)info.TaskDuration.TotalMilliseconds} ms"); string result = info.Result.ToString(); if (string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(info.FilePath)) { result = info.FilePath; } if (lvi != null) { lvi.Text = info.FileName; lvi.SubItems[1].Text = info.Status; lvi.ImageIndex = 2; if (!string.IsNullOrEmpty(result)) { lvi.SubItems[6].Text = result; } } if (!task.StopRequested && !string.IsNullOrEmpty(result)) { if (Program.Settings.HistorySaveTasks && (!Program.Settings.HistoryCheckURL || (!string.IsNullOrEmpty(info.Result.URL) || !string.IsNullOrEmpty(info.Result.ShortenedURL)))) { HistoryItem historyItem = info.GetHistoryItem(); AppendHistoryItemAsync(historyItem); } RecentManager.Add(task); if (!info.TaskSettings.AdvancedSettings.DisableNotifications && info.Job != TaskJob.ShareURL) { if (info.TaskSettings.GeneralSettings.PlaySoundAfterUpload) { TaskHelpers.PlayTaskCompleteSound(info.TaskSettings); } if (!string.IsNullOrEmpty(info.TaskSettings.AdvancedSettings.BalloonTipContentFormat)) { result = new UploadInfoParser().Parse(info, info.TaskSettings.AdvancedSettings.BalloonTipContentFormat); } if (!string.IsNullOrEmpty(result)) { switch (info.TaskSettings.GeneralSettings.PopUpNotification) { case PopUpNotificationType.BalloonTip: if (Program.MainForm.niTray.Visible) { Program.MainForm.niTray.Tag = result; Program.MainForm.niTray.ShowBalloonTip(5000, "ShareX - " + Resources.TaskManager_task_UploadCompleted_ShareX___Task_completed, result, ToolTipIcon.Info); } break; case PopUpNotificationType.ToastNotification: NotificationFormConfig toastConfig = new NotificationFormConfig() { Action = info.TaskSettings.AdvancedSettings.ToastWindowClickAction, FilePath = info.FilePath, Text = "ShareX - " + Resources.TaskManager_task_UploadCompleted_ShareX___Task_completed + "\r\n" + result, URL = result }; NotificationForm.Show((int)(info.TaskSettings.AdvancedSettings.ToastWindowDuration * 1000), (int)(info.TaskSettings.AdvancedSettings.ToastWindowFadeDuration * 1000), info.TaskSettings.AdvancedSettings.ToastWindowPlacement, info.TaskSettings.AdvancedSettings.ToastWindowSize, toastConfig); break; } if (info.TaskSettings.AfterUploadJob.HasFlag(AfterUploadTasks.ShowAfterUploadWindow) && info.IsUploadJob) { AfterUploadForm dlg = new AfterUploadForm(info); NativeMethods.ShowWindow(dlg.Handle, (int)WindowShowStyle.ShowNoActivate); } } } } } if (lvi != null) { lvi.EnsureVisible(); } } } } finally { if (!IsBusy && Program.CLI.IsCommandExist("AutoClose")) { Application.Exit(); } else { StartTasks(); UpdateProgressUI(); if (Program.Settings.SaveSettingsAfterTaskCompleted && !IsBusy) { SettingManager.SaveAllSettingsAsync(); } } } }
private static void Task_TaskCompleted(WorkerTask task) { try { if (task != null) { task.KeepImage = false; if (task.RequestSettingUpdate) { Program.MainForm.UpdateCheckStates(); } TaskInfo info = task.Info; if (info != null && info.Result != null) { TaskThumbnailPanel panel = TaskThumbnailView.FindPanel(task); if (panel != null) { panel.UpdateStatus(); panel.ProgressVisible = false; } ListViewItem lvi = TaskListView.FindItem(task); if (task.Status == TaskStatus.Stopped) { DebugHelper.WriteLine($"Task stopped. Filename: {info.FileName}"); if (lvi != null) { lvi.Text = info.FileName; lvi.SubItems[1].Text = info.Status; lvi.ImageIndex = 2; } } else if (task.Status == TaskStatus.Failed) { string errors = string.Join("\r\n\r\n", info.Result.Errors.ToArray()); DebugHelper.WriteLine($"Task failed. Filename: {info.FileName}, Errors:\r\n{errors}"); if (lvi != null) { lvi.SubItems[1].Text = info.Status; lvi.SubItems[6].Text = ""; lvi.ImageIndex = 1; } if (!info.TaskSettings.GeneralSettings.DisableNotifications) { if (info.TaskSettings.GeneralSettings.PlaySoundAfterUpload) { TaskHelpers.PlayErrorSound(info.TaskSettings); } if (info.Result.Errors.Count > 0) { string errorMessage = info.Result.Errors[0]; if (info.TaskSettings.GeneralSettings.ShowToastNotificationAfterTaskCompleted && !string.IsNullOrEmpty(errorMessage) && (!info.TaskSettings.GeneralSettings.DisableNotificationsOnFullscreen || !CaptureHelpers.IsActiveWindowFullscreen())) { TaskHelpers.ShowNotificationTip(errorMessage, "ShareX - " + Resources.TaskManager_task_UploadCompleted_Error, 5000); } } } } else { DebugHelper.WriteLine($"Task completed. Filename: {info.FileName}, Duration: {(long)info.TaskDuration.TotalMilliseconds} ms"); string result = info.ToString(); if (lvi != null) { lvi.Text = info.FileName; lvi.SubItems[1].Text = info.Status; lvi.ImageIndex = 2; if (!string.IsNullOrEmpty(result)) { lvi.SubItems[6].Text = result; } } if (!task.StopRequested && !string.IsNullOrEmpty(result)) { if (Program.Settings.HistorySaveTasks && (!Program.Settings.HistoryCheckURL || (!string.IsNullOrEmpty(info.Result.URL) || !string.IsNullOrEmpty(info.Result.ShortenedURL)))) { HistoryItem historyItem = info.GetHistoryItem(); AppendHistoryItemAsync(historyItem); } RecentManager.Add(task); if (!info.TaskSettings.GeneralSettings.DisableNotifications && info.Job != TaskJob.ShareURL) { if (info.TaskSettings.GeneralSettings.PlaySoundAfterUpload) { TaskHelpers.PlayTaskCompleteSound(info.TaskSettings); } if (!string.IsNullOrEmpty(info.TaskSettings.AdvancedSettings.BalloonTipContentFormat)) { result = new UploadInfoParser().Parse(info, info.TaskSettings.AdvancedSettings.BalloonTipContentFormat); } if (info.TaskSettings.GeneralSettings.ShowToastNotificationAfterTaskCompleted && !string.IsNullOrEmpty(result) && (!info.TaskSettings.GeneralSettings.DisableNotificationsOnFullscreen || !CaptureHelpers.IsActiveWindowFullscreen())) { task.KeepImage = true; NotificationFormConfig toastConfig = new NotificationFormConfig() { Duration = (int)(info.TaskSettings.GeneralSettings.ToastWindowDuration * 1000), FadeDuration = (int)(info.TaskSettings.GeneralSettings.ToastWindowFadeDuration * 1000), Placement = info.TaskSettings.GeneralSettings.ToastWindowPlacement, Size = info.TaskSettings.GeneralSettings.ToastWindowSize, LeftClickAction = info.TaskSettings.GeneralSettings.ToastWindowLeftClickAction, RightClickAction = info.TaskSettings.GeneralSettings.ToastWindowRightClickAction, MiddleClickAction = info.TaskSettings.GeneralSettings.ToastWindowMiddleClickAction, FilePath = info.FilePath, Image = task.Image, Title = "ShareX - " + Resources.TaskManager_task_UploadCompleted_ShareX___Task_completed, Text = result, URL = result }; NotificationForm.Show(toastConfig); if (info.TaskSettings.AfterUploadJob.HasFlag(AfterUploadTasks.ShowAfterUploadWindow) && info.IsUploadJob) { AfterUploadForm dlg = new AfterUploadForm(info); NativeMethods.ShowWindow(dlg.Handle, (int)WindowShowStyle.ShowNoActivate); } } } } } if (lvi != null) { lvi.EnsureVisible(); if (Program.Settings.AutoSelectLastCompletedTask) { TaskListView.ListViewControl.SelectSingle(lvi); } } } } } finally { if (!IsBusy && Program.CLI.IsCommandExist("AutoClose")) { Application.Exit(); } else { StartTasks(); UpdateProgressUI(); if (Program.Settings.SaveSettingsAfterTaskCompleted && !IsBusy) { SettingManager.SaveAllSettingsAsync(); } } } }
private static void task_UploadCompleted(UploadTask task) { try { if (ListViewControl != null && task != null) { if (task.RequestSettingUpdate) { Program.MainForm.UpdateMainFormSettings(); } TaskInfo info = task.Info; if (info != null && info.Result != null) { ListViewItem lvi = FindListViewItem(task); if (info.Result.IsError) { string errors = string.Join("\r\n\r\n", info.Result.Errors.ToArray()); DebugHelper.WriteLine("Task failed. Filename: {0}, Errors:\r\n{1}", info.FileName, errors); if (lvi != null) { lvi.SubItems[1].Text = "Error"; lvi.SubItems[6].Text = string.Empty; lvi.ImageIndex = 1; } if (task.Info.TaskSettings.GeneralSettings.PlaySoundAfterUpload) { Helpers.PlaySoundAsync(Resources.ErrorSound); } } else { DebugHelper.WriteLine("Task completed. Filename: {0}, URL: {1}, Duration: {2} ms", info.FileName, info.Result.ToString(), (int)info.UploadDuration.TotalMilliseconds); string result = info.Result.ToString(); if (string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(info.FilePath)) { result = info.FilePath; } if (lvi != null) { lvi.Text = info.FileName; lvi.SubItems[1].Text = info.Status; lvi.ImageIndex = 2; if (!string.IsNullOrEmpty(result)) { lvi.SubItems[6].Text = result; } } if (!task.StopRequested && !string.IsNullOrEmpty(result)) { if (task.Info.TaskSettings.GeneralSettings.SaveHistory) { HistoryManager.AddHistoryItemAsync(Program.HistoryFilePath, info.GetHistoryItem()); } if (!info.TaskSettings.AdvancedSettings.DisableNotifications && info.Job != TaskJob.ShareURL) { if (task.Info.TaskSettings.GeneralSettings.PlaySoundAfterUpload) { Helpers.PlaySoundAsync(Resources.TaskCompletedSound); } if (!string.IsNullOrEmpty(info.TaskSettings.AdvancedSettings.BalloonTipContentFormat)) { result = new UploadInfoParser().Parse(info, info.TaskSettings.AdvancedSettings.BalloonTipContentFormat); } if (!string.IsNullOrEmpty(result)) { switch (info.TaskSettings.GeneralSettings.PopUpNotification) { case PopUpNotificationType.BalloonTip: if (Program.MainForm.niTray.Visible) { Program.MainForm.niTray.Tag = result; Program.MainForm.niTray.ShowBalloonTip(5000, "ShareX - Task completed", result, ToolTipIcon.Info); } break; case PopUpNotificationType.ToastNotification: NotificationFormConfig toastConfig = new NotificationFormConfig() { Action = info.TaskSettings.AdvancedSettings.ToastWindowClickAction, FilePath = info.FilePath, Text = "ShareX - Task completed\r\n" + result, URL = result }; NotificationForm.Show((int)(info.TaskSettings.AdvancedSettings.ToastWindowDuration * 1000), info.TaskSettings.AdvancedSettings.ToastWindowPlacement, info.TaskSettings.AdvancedSettings.ToastWindowSize, toastConfig); break; } } if (info.TaskSettings.GeneralSettings.ShowAfterUploadForm) { AfterUploadForm dlg = new AfterUploadForm(info); NativeMethods.ShowWindow(dlg.Handle, (int)WindowShowStyle.ShowNoActivate); } } } } if (lvi != null) { lvi.EnsureVisible(); } } } } finally { StartTasks(); UpdateProgressUI(); } }
private static void task_UploadCompleted(WorkerTask task) { try { if (ListViewControl != null && task != null) { if (task.RequestSettingUpdate) { Program.MainForm.UpdateMainFormSettings(); } TaskInfo info = task.Info; if (info != null && info.Result != null) { ListViewItem lvi = FindListViewItem(task); if (info.Result.IsError) { string errors = string.Join("\r\n\r\n", info.Result.Errors.ToArray()); DebugHelper.WriteLine("Task failed. Filename: {0}, Errors:\r\n{1}", info.FileName, errors); if (lvi != null) { lvi.SubItems[1].Text = Resources.TaskManager_task_UploadCompleted_Error; lvi.SubItems[6].Text = string.Empty; lvi.ImageIndex = 1; } if (!info.TaskSettings.AdvancedSettings.DisableNotifications) { if (info.TaskSettings.GeneralSettings.PlaySoundAfterUpload) { TaskHelpers.PlayErrorSound(info.TaskSettings); } if (info.TaskSettings.GeneralSettings.PopUpNotification != PopUpNotificationType.None && Program.MainForm.niTray.Visible && !string.IsNullOrEmpty(errors)) { Program.MainForm.niTray.Tag = null; Program.MainForm.niTray.ShowBalloonTip(5000, "sharexl - " + Resources.TaskManager_task_UploadCompleted_Error, errors, ToolTipIcon.Error); } } } else { DebugHelper.WriteLine("Task completed. Filename: {0}, URL: {1}, Duration: {2} ms", info.FileName, info.Result.ToString(), (int)info.UploadDuration.TotalMilliseconds); string result = info.Result.ToString(); if (string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(info.FilePath)) { result = info.FilePath; } if (lvi != null) { lvi.Text = info.FileName; lvi.SubItems[1].Text = info.Status; lvi.ImageIndex = 2; if (!string.IsNullOrEmpty(result)) { lvi.SubItems[6].Text = result; } } if (!task.StopRequested && !string.IsNullOrEmpty(result)) { if (info.TaskSettings.GeneralSettings.SaveHistory && (!info.TaskSettings.AdvancedSettings.HistorySaveOnlyURL || (!string.IsNullOrEmpty(info.Result.URL) || !string.IsNullOrEmpty(info.Result.ShortenedURL)))) { HistoryManager.AddHistoryItemAsync(Program.HistoryFilePath, info.GetHistoryItem()); } RecentManager.Add(result); if (Program.Settings.RecentLinksRemember) { Program.Settings.RecentLinks = RecentManager.Items.ToArray(); } else { Program.Settings.RecentLinks = null; } if (!info.TaskSettings.AdvancedSettings.DisableNotifications && info.Job != TaskJob.ShareURL) { if (info.TaskSettings.GeneralSettings.PlaySoundAfterUpload) { TaskHelpers.PlayTaskCompleteSound(info.TaskSettings); } if (!string.IsNullOrEmpty(info.TaskSettings.AdvancedSettings.BalloonTipContentFormat)) { result = new UploadInfoParser().Parse(info, info.TaskSettings.AdvancedSettings.BalloonTipContentFormat); } if (!string.IsNullOrEmpty(result)) { switch (info.TaskSettings.GeneralSettings.PopUpNotification) { case PopUpNotificationType.BalloonTip: if (Program.MainForm.niTray.Visible) { Program.MainForm.niTray.Tag = result; Program.MainForm.niTray.ShowBalloonTip(5000, "sharexl - " + Resources.TaskManager_task_UploadCompleted_ShareX___Task_completed, result, ToolTipIcon.Info); } break; case PopUpNotificationType.ToastNotification: NotificationFormConfig toastConfig = new NotificationFormConfig() { Action = info.TaskSettings.AdvancedSettings.ToastWindowClickAction, FilePath = info.FilePath, Text = "sharexl - " + Resources.TaskManager_task_UploadCompleted_ShareX___Task_completed + "\r\n" + result, URL = result }; NotificationForm.Show((int)(info.TaskSettings.AdvancedSettings.ToastWindowDuration * 1000), info.TaskSettings.AdvancedSettings.ToastWindowPlacement, info.TaskSettings.AdvancedSettings.ToastWindowSize, toastConfig); break; } } if (info.TaskSettings.GeneralSettings.ShowAfterUploadForm) { AfterUploadForm dlg = new AfterUploadForm(info); NativeMethods.ShowWindow(dlg.Handle, (int)WindowShowStyle.ShowNoActivate); } } } } if (lvi != null) { lvi.EnsureVisible(); } } } } finally { if (!IsBusy && Program.CLI.IsCommandExist("AutoClose")) { Application.Exit(); } else { StartTasks(); UpdateProgressUI(); } } }