解决了打开文件时有黑框的bug

This commit is contained in:
2024-10-12 16:00:32 +08:00
parent 7a6f815597
commit 88439dfb81
3 changed files with 14 additions and 17 deletions
+6
View File
@@ -1,6 +1,7 @@
package utils
import (
"fmt"
"io"
"os"
"os/exec"
@@ -93,3 +94,8 @@ func (*FileUtils) WinOpenFolder(folderPath string) error {
//_, err = Exec.Command(fmt.Sprintf("explorer %s", f), dir)
//return err
}
func (*FileUtils) WinOpenFile(dir string, fileName string) error {
_, err := Exec.Command(fmt.Sprintf("cmd /c start %s", fileName), dir)
return err
}
+4 -9
View File
@@ -8,11 +8,11 @@ import (
"fyne.io/fyne/v2/widget"
dialogWin "github.com/sqweek/dialog"
"log"
"os/exec"
"path/filepath"
"time"
"work_cation/global"
"work_cation/models"
"work_cation/pkg/utils"
"work_cation/repo"
"work_cation/service"
)
@@ -67,17 +67,12 @@ func CreateExecFile(w fyne.Window) fyne.CanvasObject {
dialog.ShowInformation("测试失败", "未填写执行命令", w)
return
}
ex := exec.Command("cmd", "/c", "start", info.Cmd)
ex.Dir = filepath.Join(chooseDir, info.Pwd)
if err := ex.Start(); err != nil {
dir := filepath.Join(chooseDir, info.Pwd)
err := utils.File.WinOpenFile(dir, info.Cmd)
if err != nil {
dialog.ShowInformation("测试失败", err.Error(), w)
return
}
go func() {
if err := ex.Wait(); err != nil {
dialog.ShowInformation("测试失败", err.Error(), w)
}
}()
})
return container.NewBorder(container.NewHBox(widget.NewLabel("新建"), widget.NewSeparator()),
+4 -8
View File
@@ -11,6 +11,7 @@ import (
"path/filepath"
"work_cation/cfg"
"work_cation/models"
"work_cation/pkg/utils"
)
func ExecFileCardView(w fyne.Window, data *models.BaseCard) (fyne.CanvasObject, error) {
@@ -34,17 +35,12 @@ func runExecFile(data *models.BaseCard, w fyne.Window) {
dialog.ShowInformation("测试失败", err.Error(), w)
return
}
ex := exec.Command("cmd", "/c", "start", info.Cmd)
ex.Dir = filepath.Join(cfg.T.CardDir, data.UUID, info.Pwd)
if err := ex.Start(); err != nil {
dir := filepath.Join(cfg.T.CardDir, data.UUID, info.Pwd)
err = utils.File.WinOpenFile(dir, info.Cmd)
if err != nil {
dialog.ShowInformation("测试失败", err.Error(), w)
return
}
go func() {
if err := ex.Wait(); err != nil {
dialog.ShowInformation("测试失败", err.Error(), w)
}
}()
}
func openDir(data *models.BaseCard, w fyne.Window) {