From 1725de6ace0fb1650ac51fb47cca28121f90a6f7 Mon Sep 17 00:00:00 2001
From: mappu <mappu04@gmail.com>
Date: Fri, 18 Apr 2025 12:13:56 +1200
Subject: [PATCH] import/export: use background thread

---
 mainwindow.go | 33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/mainwindow.go b/mainwindow.go
index 5c24f1c..65a5885 100644
--- a/mainwindow.go
+++ b/mainwindow.go
@@ -7,6 +7,7 @@ import (
 	"strings"
 
 	qt "github.com/mappu/miqt/qt6"
+	"github.com/mappu/miqt/qt6/mainthread"
 	bolt "go.etcd.io/bbolt"
 )
 
@@ -186,13 +187,17 @@ func (this *MainWindow) onactionExport_database_as_zip_triggered() {
 		return
 	}
 
-	err := Bolt_ExportDatabaseToZip(dbPath, zipPath)
-	if err != nil {
-		this.alert(fmt.Sprintf("Error exporting database as zip: %s", err.Error()))
-		return
-	}
+	go func() {
+		err := Bolt_ExportDatabaseToZip(dbPath, zipPath)
+		mainthread.Start(func() {
+			if err != nil {
+				this.alert(fmt.Sprintf("Error exporting database as zip: %s", err.Error()))
+				return
+			}
 
-	this.alert("Exported as zip successfully.")
+			this.alert("Exported as zip successfully.")
+		})
+	}()
 }
 
 func (this *MainWindow) onactionCreate_database_from_zip_triggered() {
@@ -214,13 +219,17 @@ func (this *MainWindow) onactionCreate_database_from_zip_triggered() {
 		return
 	}
 
-	err := Bolt_ImportZipToDatabase(dbPath, zipPath)
-	if err != nil {
-		this.alert(fmt.Sprintf("Error importing database from zip %q: %s", zipPath, err.Error()))
-		return
-	}
+	go func() {
+		err := Bolt_ImportZipToDatabase(dbPath, zipPath)
+		mainthread.Start(func() {
+			if err != nil {
+				this.alert(fmt.Sprintf("Error importing database from zip %q: %s", zipPath, err.Error()))
+				return
+			}
 
-	this.alert("Imported zip to database successfully.")
+			this.alert("Imported zip to database successfully.")
+		})
+	}()
 }
 
 func (this *MainWindow) refreshBucketTree(itm *qt.QTreeWidgetItem) {