Only continue countdown if window is active

This commit is contained in:
Jaex 2021-06-17 20:10:38 +03:00
parent 138e7f25b3
commit 24e581403c
5 changed files with 23 additions and 16 deletions

View file

@ -364,6 +364,11 @@ public static bool IsWindowCloaked(IntPtr handle)
return false;
}
public static bool IsActive(IntPtr handle)
{
return GetForegroundWindow() == handle;
}
public static void RestoreWindow(IntPtr handle)
{
WINDOWPLACEMENT wp = new WINDOWPLACEMENT();

View file

@ -92,7 +92,7 @@ public int ProcessId
public bool IsCloaked => NativeMethods.IsWindowCloaked(Handle);
public bool IsActive => NativeMethods.GetForegroundWindow() == Handle;
public bool IsActive => NativeMethods.IsActive(Handle);
public WindowInfo(IntPtr handle)
{

View file

@ -44,6 +44,7 @@ private void InitializeComponent()
//
// btnYes
//
this.btnYes.DialogResult = System.Windows.Forms.DialogResult.Yes;
resources.ApplyResources(this.btnYes, "btnYes");
this.btnYes.Name = "btnYes";
this.btnYes.UseVisualStyleBackColor = true;
@ -51,6 +52,7 @@ private void InitializeComponent()
//
// btnNo
//
this.btnNo.DialogResult = System.Windows.Forms.DialogResult.No;
resources.ApplyResources(this.btnNo, "btnNo");
this.btnNo.Name = "btnNo";
this.btnNo.UseVisualStyleBackColor = true;

View file

@ -49,19 +49,16 @@ public FirstTimeUploadForm()
private void UpdateCountdown()
{
if (!IsDisposed)
if (countdown < 1)
{
if (countdown < 1)
{
btnYes.Text = textYes;
btnYes.Enabled = true;
tCountdown.Stop();
}
else
{
btnYes.Text = textYes + " (" + countdown + ")";
countdown--;
}
btnYes.Text = textYes;
btnYes.Enabled = true;
tCountdown.Stop();
}
else
{
btnYes.Text = textYes + " (" + countdown + ")";
countdown--;
}
}
@ -72,7 +69,10 @@ private void FirstTimeUploadForm_Shown(object sender, System.EventArgs e)
private void tCountdown_Tick(object sender, System.EventArgs e)
{
UpdateCountdown();
if (!IsDisposed && NativeMethods.IsActive(Handle))
{
UpdateCountdown();
}
}
private void btnYes_Click(object sender, System.EventArgs e)

View file

@ -132,7 +132,7 @@
<value>1</value>
</data>
<data name="lblInfo.Text" xml:space="preserve">
<value>Are you sure you want to upload screenshots?
<value>Do you want ShareX to upload screenshots?
Press "No" to cancel the current upload and disable screenshot auto uploading.</value>
</data>
@ -218,7 +218,7 @@ Press "No" to cancel the current upload and disable screenshot auto uploading.</
<value>0</value>
</data>
<data name="lblHeader.Text" xml:space="preserve">
<value>Important!</value>
<value>Attention!</value>
</data>
<data name="lblHeader.TextAlign" type="System.Drawing.ContentAlignment, System.Drawing">
<value>MiddleCenter</value>