解决了打开文件时有黑框的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 package utils
import ( import (
"fmt"
"io" "io"
"os" "os"
"os/exec" "os/exec"
@@ -93,3 +94,8 @@ func (*FileUtils) WinOpenFolder(folderPath string) error {
//_, err = Exec.Command(fmt.Sprintf("explorer %s", f), dir) //_, err = Exec.Command(fmt.Sprintf("explorer %s", f), dir)
//return err //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" "fyne.io/fyne/v2/widget"
dialogWin "github.com/sqweek/dialog" dialogWin "github.com/sqweek/dialog"
"log" "log"
"os/exec"
"path/filepath" "path/filepath"
"time" "time"
"work_cation/global" "work_cation/global"
"work_cation/models" "work_cation/models"
"work_cation/pkg/utils"
"work_cation/repo" "work_cation/repo"
"work_cation/service" "work_cation/service"
) )
@@ -67,17 +67,12 @@ func CreateExecFile(w fyne.Window) fyne.CanvasObject {
dialog.ShowInformation("测试失败", "未填写执行命令", w) dialog.ShowInformation("测试失败", "未填写执行命令", w)
return return
} }
ex := exec.Command("cmd", "/c", "start", info.Cmd) dir := filepath.Join(chooseDir, info.Pwd)
ex.Dir = filepath.Join(chooseDir, info.Pwd) err := utils.File.WinOpenFile(dir, info.Cmd)
if err := ex.Start(); err != nil { if err != nil {
dialog.ShowInformation("测试失败", err.Error(), w) dialog.ShowInformation("测试失败", err.Error(), w)
return return
} }
go func() {
if err := ex.Wait(); err != nil {
dialog.ShowInformation("测试失败", err.Error(), w)
}
}()
}) })
return container.NewBorder(container.NewHBox(widget.NewLabel("新建"), widget.NewSeparator()), return container.NewBorder(container.NewHBox(widget.NewLabel("新建"), widget.NewSeparator()),
+4 -8
View File
@@ -11,6 +11,7 @@ import (
"path/filepath" "path/filepath"
"work_cation/cfg" "work_cation/cfg"
"work_cation/models" "work_cation/models"
"work_cation/pkg/utils"
) )
func ExecFileCardView(w fyne.Window, data *models.BaseCard) (fyne.CanvasObject, error) { 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) dialog.ShowInformation("测试失败", err.Error(), w)
return return
} }
ex := exec.Command("cmd", "/c", "start", info.Cmd) dir := filepath.Join(cfg.T.CardDir, data.UUID, info.Pwd)
ex.Dir = filepath.Join(cfg.T.CardDir, data.UUID, info.Pwd) err = utils.File.WinOpenFile(dir, info.Cmd)
if err := ex.Start(); err != nil { if err != nil {
dialog.ShowInformation("测试失败", err.Error(), w) dialog.ShowInformation("测试失败", err.Error(), w)
return return
} }
go func() {
if err := ex.Wait(); err != nil {
dialog.ShowInformation("测试失败", err.Error(), w)
}
}()
} }
func openDir(data *models.BaseCard, w fyne.Window) { func openDir(data *models.BaseCard, w fyne.Window) {