diff --git a/cmd/WiiUDownloader/mainwindow.go b/cmd/WiiUDownloader/mainwindow.go index 30a7aad..08c5ace 100644 --- a/cmd/WiiUDownloader/mainwindow.go +++ b/cmd/WiiUDownloader/mainwindow.go @@ -489,9 +489,11 @@ func (mw *MainWindow) onCategoryToggled(button *gtk.ToggleButton) { func (mw *MainWindow) onDecryptContentsMenuItemClicked(selectedPath string) error { err := wiiudownloader.DecryptContents(selectedPath, &mw.progressWindow, false) - if mw.progressWindow.Window.IsVisible() { - mw.progressWindow.Window.Close() - } + glib.IdleAdd(func() { + if mw.progressWindow.Window.IsVisible() { + mw.progressWindow.Window.Close() + } + }) return err } @@ -778,9 +780,11 @@ queueProcessingLoop: } mw.titleQueue = []wiiudownloader.TitleEntry{} // Clear the queue - if mw.progressWindow.Window.IsVisible() { - mw.progressWindow.Window.Close() - } + glib.IdleAdd(func() { + if mw.progressWindow.Window.IsVisible() { + mw.progressWindow.Window.Close() + } + }) mw.updateTitlesInQueue() mw.onSelectionChanged() diff --git a/decryption.go b/decryption.go index 4a56a6c..4497117 100644 --- a/decryption.go +++ b/decryption.go @@ -18,6 +18,7 @@ import ( "time" "unsafe" + "github.com/gotk3/gotk3/glib" "github.com/gotk3/gotk3/gtk" ) @@ -35,11 +36,15 @@ func DecryptContents(path string, progress *ProgressWindow, deleteEncryptedConte go runDecryption(path, errorChan, deleteEncryptedContents) - progress.bar.SetText("Decrypting...") + glib.IdleAdd(func() { + progress.bar.SetText("Decrypting...") + }) for progressInt := range progressChan { if progressInt > 0 { - progress.bar.SetFraction(float64(progressInt) / 100) + glib.IdleAdd(func() { + progress.bar.SetFraction(float64(progressInt) / 100) + }) for gtk.EventsPending() { gtk.MainIteration() } diff --git a/downloader.go b/downloader.go index 2f9b2b9..d83079f 100644 --- a/downloader.go +++ b/downloader.go @@ -98,8 +98,10 @@ func downloadFile(progressWindow *ProgressWindow, client *grab.Client, downloadU req.BufferSize = bufferSize resp := client.Do(req) - progressWindow.bar.SetFraction(resp.Progress()) - progressWindow.bar.SetText(fmt.Sprintf("Downloading %s (%s/%s) (%s/s)", filePath, humanize.Bytes(uint64(resp.BytesComplete())), humanize.Bytes(uint64(resp.Size())), humanize.Bytes(uint64(resp.BytesPerSecond())))) + glib.IdleAdd(func() { + progressWindow.bar.SetFraction(resp.Progress()) + progressWindow.bar.SetText(fmt.Sprintf("Downloading %s (%s/%s) (%s/s)", filePath, humanize.Bytes(uint64(resp.BytesComplete())), humanize.Bytes(uint64(resp.Size())), humanize.Bytes(uint64(resp.BytesPerSecond())))) + }) for gtk.EventsPending() { gtk.MainIteration() } @@ -148,7 +150,9 @@ func DownloadTitle(titleID string, outputDirectory string, doDecryption bool, pr titleEntry := getTitleEntryFromTid(titleID) - progressWindow.gameLabel.SetText(titleEntry.Name) + glib.IdleAdd(func() { + progressWindow.gameLabel.SetText(titleEntry.Name) + }) outputDir := strings.TrimRight(outputDirectory, "/\\") baseURL := fmt.Sprintf("http://ccs.cdn.c.shop.nintendowifi.net/ccs/download/%s", titleID) titleIDBytes, err := hex.DecodeString(titleID)