From 08a59c29be49c957af08ef5f82e6d8232966b859 Mon Sep 17 00:00:00 2001 From: Jaex Date: Thu, 1 Oct 2020 02:39:49 +0300 Subject: [PATCH] Show screen record encoding progress in tray icon --- ShareX/Forms/ScreenRecordForm.cs | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/ShareX/Forms/ScreenRecordForm.cs b/ShareX/Forms/ScreenRecordForm.cs index 4a5986255..d95f9ed43 100644 --- a/ShareX/Forms/ScreenRecordForm.cs +++ b/ShareX/Forms/ScreenRecordForm.cs @@ -52,6 +52,7 @@ public partial class ScreenRecordForm : Form private Rectangle borderRectangle0Based; private bool activateWindow; private float duration; + private static int lastIconStatus = -1; public ScreenRecordForm(Rectangle regionRectangle, TaskSettings taskSettings, bool activateWindow = true, float duration = 0) { @@ -306,6 +307,38 @@ public void ChangeState(ScreenRecordState state) public void ChangeStateProgress(int progress) { niTray.Text = $"ShareX - {Resources.ScreenRecordForm_StartRecording_Encoding___} {progress}%"; + + if (niTray.Visible && lastIconStatus != progress) + { + Icon icon; + + if (progress >= 0) + { + try + { + icon = TaskHelpers.GetProgressIcon(progress); + } + catch (Exception e) + { + DebugHelper.WriteException(e); + progress = -1; + if (lastIconStatus == progress) return; + icon = Resources.camcorder_pencil.ToIcon(); + } + } + else + { + icon = Resources.camcorder_pencil.ToIcon(); + } + + using (Icon oldIcon = niTray.Icon) + { + niTray.Icon = icon; + oldIcon.DisposeHandle(); + } + + lastIconStatus = progress; + } } } } \ No newline at end of file