Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix WPF message boxes rarely appearing in the background #1068

Merged
merged 2 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions TwitchDownloaderWPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,16 @@ private async void Window_Loaded(object sender, RoutedEventArgs e)
}
catch (Exception ex)
{
if (MessageBox.Show(string.Format(Translations.Strings.UnableToDownloadFfmpegFull, "https://ffmpeg.org/download.html", Path.Combine(Environment.CurrentDirectory, "ffmpeg.exe")),
Translations.Strings.UnableToDownloadFfmpeg, MessageBoxButton.OKCancel, MessageBoxImage.Information) == MessageBoxResult.OK)
var messageBoxResult = MessageBox.Show(this, string.Format(Translations.Strings.UnableToDownloadFfmpegFull, "https://ffmpeg.org/download.html", Path.Combine(Environment.CurrentDirectory, "ffmpeg.exe")),
Translations.Strings.UnableToDownloadFfmpeg, MessageBoxButton.OKCancel, MessageBoxImage.Information);
if (messageBoxResult == MessageBoxResult.OK)
{
Process.Start(new ProcessStartInfo("https://ffmpeg.org/download.html") { UseShellExecute = true });
}

if (Settings.Default.VerboseErrors)
{
MessageBox.Show(ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(this, ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
}
}

Expand Down
8 changes: 4 additions & 4 deletions TwitchDownloaderWPF/PageChatDownload.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private async Task GetVideoInfo()
string id = ValidateUrl(textUrl.Text.Trim());
if (string.IsNullOrWhiteSpace(id))
{
MessageBox.Show(Translations.Strings.UnableToParseLinkMessage, Translations.Strings.UnableToParseLink, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Application.Current.MainWindow!, Translations.Strings.UnableToParseLinkMessage, Translations.Strings.UnableToParseLink, MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
btnGetInfo.IsEnabled = false;
Expand Down Expand Up @@ -188,12 +188,12 @@ private async Task GetVideoInfo()
}
catch (Exception ex)
{
MessageBox.Show(Translations.Strings.UnableToGetInfoMessage, Translations.Strings.UnableToGetInfo, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Application.Current.MainWindow!, Translations.Strings.UnableToGetInfoMessage, Translations.Strings.UnableToGetInfo, MessageBoxButton.OK, MessageBoxImage.Error);
AppendLog(Translations.Strings.ErrorLog + ex.Message);
btnGetInfo.IsEnabled = true;
if (Settings.Default.VerboseErrors)
{
MessageBox.Show(ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Application.Current.MainWindow!, ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
Expand Down Expand Up @@ -547,7 +547,7 @@ private async void SplitBtnDownload_Click(object sender, RoutedEventArgs e)
AppendLog(Translations.Strings.ErrorLog + ex.Message);
if (Settings.Default.VerboseErrors)
{
MessageBox.Show(ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Application.Current.MainWindow!, ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
btnGetInfo.IsEnabled = true;
Expand Down
12 changes: 6 additions & 6 deletions TwitchDownloaderWPF/PageChatRender.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ private bool ValidateInputs()
{
if (!File.Exists(fileName))
{
AppendLog(Translations.Strings.ErrorLog + Translations.Strings.FileNotFound + ' ' + Path.GetFileName(fileName));
AppendLog(Translations.Strings.ErrorLog + Translations.Strings.FileNotFound + Path.GetFileName(fileName));
return false;
}
}
Expand Down Expand Up @@ -579,7 +579,7 @@ private async void SplitBtnRender_Click(object sender, RoutedEventArgs e)
{
if (!ValidateInputs())
{
MessageBox.Show(Translations.Strings.UnableToParseInputsMessage, Translations.Strings.UnableToParseInputs, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Application.Current.MainWindow!, Translations.Strings.UnableToParseInputsMessage, Translations.Strings.UnableToParseInputs, MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

Expand Down Expand Up @@ -609,7 +609,7 @@ private async void SplitBtnRender_Click(object sender, RoutedEventArgs e)
AppendLog(Translations.Strings.ErrorLog + ex.Message);
if (Settings.Default.VerboseErrors)
{
MessageBox.Show(ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Application.Current.MainWindow!, ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
}
return;
}
Expand Down Expand Up @@ -664,11 +664,11 @@ private async void SplitBtnRender_Click(object sender, RoutedEventArgs e)
if (ex.Message.Contains("The pipe has been ended"))
{
string errorLog = String.Join('\n', ffmpegLog.TakeLast(20).ToArray());
MessageBox.Show(errorLog, Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Application.Current.MainWindow!, errorLog, Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
}
else
{
MessageBox.Show(ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Application.Current.MainWindow!, ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
Expand Down Expand Up @@ -709,7 +709,7 @@ private void MenuItemEnqueue_Click(object sender, RoutedEventArgs e)
}
else
{
MessageBox.Show(Translations.Strings.UnableToParseInputsMessage, Translations.Strings.UnableToParseInputs, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Application.Current.MainWindow!, Translations.Strings.UnableToParseInputsMessage, Translations.Strings.UnableToParseInputs, MessageBoxButton.OK, MessageBoxImage.Error);
}
}

Expand Down
12 changes: 6 additions & 6 deletions TwitchDownloaderWPF/PageChatUpdate.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private async void btnBrowse_Click(object sender, RoutedEventArgs e)
AppendLog(Translations.Strings.ErrorLog + ex.Message);
if (Settings.Default.VerboseErrors)
{
MessageBox.Show(ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Application.Current.MainWindow!, ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
}

return;
Expand Down Expand Up @@ -181,11 +181,11 @@ private async void btnBrowse_Click(object sender, RoutedEventArgs e)
}
catch (Exception ex)
{
MessageBox.Show(Translations.Strings.UnableToGetInfoMessage, Translations.Strings.UnableToGetInfo, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Application.Current.MainWindow!, Translations.Strings.UnableToGetInfoMessage, Translations.Strings.UnableToGetInfo, MessageBoxButton.OK, MessageBoxImage.Error);
AppendLog(Translations.Strings.ErrorLog + ex.Message);
if (Settings.Default.VerboseErrors)
{
MessageBox.Show(ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Application.Current.MainWindow!, ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
Expand Down Expand Up @@ -534,7 +534,7 @@ private async void SplitBtnUpdate_Click(object sender, RoutedEventArgs e)
AppendLog(Translations.Strings.ErrorLog + ex.Message);
if (Settings.Default.VerboseErrors)
{
MessageBox.Show(ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Application.Current.MainWindow!, ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
}
return;
}
Expand Down Expand Up @@ -566,7 +566,7 @@ private async void SplitBtnUpdate_Click(object sender, RoutedEventArgs e)
AppendLog(Translations.Strings.ErrorLog + ex.Message);
if (Settings.Default.VerboseErrors)
{
MessageBox.Show(ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Application.Current.MainWindow!, ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
btnBrowse.IsEnabled = true;
Expand All @@ -582,7 +582,7 @@ private async void SplitBtnUpdate_Click(object sender, RoutedEventArgs e)
AppendLog(Translations.Strings.ErrorLog + ex.Message);
if (Settings.Default.VerboseErrors)
{
MessageBox.Show(ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Application.Current.MainWindow!, ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions TwitchDownloaderWPF/PageClipDownload.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private async Task GetClipInfo()
clipId = ValidateUrl(textUrl.Text.Trim());
if (string.IsNullOrWhiteSpace(clipId))
{
MessageBox.Show(Translations.Strings.InvalidClipLinkIdMessage.Replace(@"\n", Environment.NewLine), Translations.Strings.InvalidClipLinkId, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Application.Current.MainWindow!, Translations.Strings.InvalidClipLinkIdMessage.Replace(@"\n", Environment.NewLine), Translations.Strings.InvalidClipLinkId, MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

Expand Down Expand Up @@ -90,11 +90,11 @@ private async Task GetClipInfo()
}
catch (Exception ex)
{
MessageBox.Show(Translations.Strings.UnableToGetClipInfo, Translations.Strings.UnableToGetInfo, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Application.Current.MainWindow!, Translations.Strings.UnableToGetClipInfo, Translations.Strings.UnableToGetInfo, MessageBoxButton.OK, MessageBoxImage.Error);
AppendLog(Translations.Strings.ErrorLog + ex);
if (Settings.Default.VerboseErrors)
{
MessageBox.Show(ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Application.Current.MainWindow!, ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
btnGetInfo.IsEnabled = true;
Expand Down Expand Up @@ -238,7 +238,7 @@ private async void SplitBtnDownload_Click(object sender, RoutedEventArgs e)
AppendLog(Translations.Strings.ErrorLog + ex.Message);
if (Settings.Default.VerboseErrors)
{
MessageBox.Show(ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Application.Current.MainWindow!, ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
btnGetInfo.IsEnabled = true;
Expand Down
6 changes: 3 additions & 3 deletions TwitchDownloaderWPF/PageQueue.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ private static void ShowTaskException(ITwitchTask task)
errorMessage = taskException.Exception.ToString();
}

MessageBox.Show(errorMessage, Translations.Strings.MessageBoxTitleError, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Application.Current.MainWindow!, errorMessage, Translations.Strings.MessageBoxTitleError, MessageBoxButton.OK, MessageBoxImage.Error);
}

private void BtnRemoveTask_Click(object sender, RoutedEventArgs e)
Expand All @@ -291,13 +291,13 @@ private static void RemoveTask(ITwitchTask task)
{
if (task.CanRun() || task.Status is TwitchTaskStatus.Running or TwitchTaskStatus.Waiting)
{
MessageBox.Show(Translations.Strings.CancelTaskBeforeRemoving, Translations.Strings.TaskCouldNotBeRemoved, MessageBoxButton.OK, MessageBoxImage.Information);
MessageBox.Show(Application.Current.MainWindow!, Translations.Strings.CancelTaskBeforeRemoving, Translations.Strings.TaskCouldNotBeRemoved, MessageBoxButton.OK, MessageBoxImage.Information);
return;
}

if (!taskList.Remove(task))
{
MessageBox.Show(Translations.Strings.TaskCouldNotBeRemoved, Translations.Strings.UnknownErrorOccurred, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Application.Current.MainWindow!, Translations.Strings.TaskCouldNotBeRemoved, Translations.Strings.UnknownErrorOccurred, MessageBoxButton.OK, MessageBoxImage.Error);
}
}

Expand Down
8 changes: 4 additions & 4 deletions TwitchDownloaderWPF/PageVodDownload.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private async Task GetVideoInfo()
long videoId = ValidateUrl(textUrl.Text.Trim());
if (videoId <= 0)
{
MessageBox.Show(Translations.Strings.InvalidVideoLinkIdMessage.Replace(@"\n", Environment.NewLine), Translations.Strings.InvalidVideoLinkId, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Application.Current.MainWindow!, Translations.Strings.InvalidVideoLinkIdMessage.Replace(@"\n", Environment.NewLine), Translations.Strings.InvalidVideoLinkId, MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

Expand Down Expand Up @@ -173,10 +173,10 @@ private async Task GetVideoInfo()
{
btnGetInfo.IsEnabled = true;
AppendLog(Translations.Strings.ErrorLog + ex.Message);
MessageBox.Show(Translations.Strings.UnableToGetVideoInfo, Translations.Strings.UnableToGetInfo, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Application.Current.MainWindow!, Translations.Strings.UnableToGetVideoInfo, Translations.Strings.UnableToGetInfo, MessageBoxButton.OK, MessageBoxImage.Error);
if (Settings.Default.VerboseErrors)
{
MessageBox.Show(ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Application.Current.MainWindow!, ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
Expand Down Expand Up @@ -450,7 +450,7 @@ private async void SplitBtnDownloader_Click(object sender, RoutedEventArgs e)
AppendLog(Translations.Strings.ErrorLog + ex.Message);
if (Settings.Default.VerboseErrors)
{
MessageBox.Show(ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Application.Current.MainWindow!, ex.ToString(), Translations.Strings.VerboseErrorOutput, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
btnGetInfo.IsEnabled = true;
Expand Down
12 changes: 6 additions & 6 deletions TwitchDownloaderWPF/WindowQueueOptions.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void btnQueue_Click(object sender, RoutedEventArgs e)
string folderPath = textFolder.Text;
if (!Directory.Exists(folderPath))
{
MessageBox.Show(Translations.Strings.InvaliFolderPathMessage, Translations.Strings.InvalidFolderPath, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(this, Translations.Strings.InvaliFolderPathMessage, Translations.Strings.InvalidFolderPath, MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

Expand Down Expand Up @@ -208,7 +208,7 @@ private void btnQueue_Click(object sender, RoutedEventArgs e)
string folderPath = textFolder.Text;
if (!Directory.Exists(folderPath))
{
MessageBox.Show(Translations.Strings.InvaliFolderPathMessage, Translations.Strings.InvalidFolderPath, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(this, Translations.Strings.InvaliFolderPathMessage, Translations.Strings.InvalidFolderPath, MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

Expand Down Expand Up @@ -312,7 +312,7 @@ private void btnQueue_Click(object sender, RoutedEventArgs e)
string folderPath = textFolder.Text;
if (!Directory.Exists(folderPath))
{
MessageBox.Show(Translations.Strings.InvaliFolderPathMessage, Translations.Strings.InvalidFolderPath, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(this, Translations.Strings.InvaliFolderPathMessage, Translations.Strings.InvalidFolderPath, MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

Expand Down Expand Up @@ -370,7 +370,7 @@ private void btnQueue_Click(object sender, RoutedEventArgs e)
string folderPath = textFolder.Text;
if (!Directory.Exists(folderPath))
{
MessageBox.Show(Translations.Strings.InvaliFolderPathMessage, Translations.Strings.InvalidFolderPath, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(this, Translations.Strings.InvaliFolderPathMessage, Translations.Strings.InvalidFolderPath, MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

Expand Down Expand Up @@ -407,7 +407,7 @@ private void btnQueue_Click(object sender, RoutedEventArgs e)
{
if (!Directory.Exists(folderPath))
{
MessageBox.Show(Translations.Strings.InvaliFolderPathMessage, Translations.Strings.InvalidFolderPath, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(this, Translations.Strings.InvaliFolderPathMessage, Translations.Strings.InvalidFolderPath, MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

Expand Down Expand Up @@ -450,7 +450,7 @@ private void EnqueueDataList()
string folderPath = textFolder.Text;
if (!Directory.Exists(folderPath))
{
MessageBox.Show(Translations.Strings.InvaliFolderPathMessage, Translations.Strings.InvalidFolderPath, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(this, Translations.Strings.InvaliFolderPathMessage, Translations.Strings.InvalidFolderPath, MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

Expand Down
Loading
Loading