Show screen record encoding progress in tray icon

This commit is contained in:
Jaex 2020-10-01 02:39:49 +03:00
parent e9e2385aaa
commit 08a59c29be

View file

@ -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;
}
}
}
}