Threadsafe please
This commit is contained in:
27
log.go
27
log.go
@@ -4,22 +4,23 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Logger struct {
|
type Logger struct {
|
||||||
logText *widget.Entry
|
logText *widget.Entry
|
||||||
logBuffer []string
|
logBuffer []string
|
||||||
logMaxLines int
|
logMaxLines int
|
||||||
}
|
}
|
||||||
|
|
||||||
var globalLogger *Logger;
|
var globalLogger *Logger
|
||||||
|
|
||||||
func InitLogger(text *widget.Entry, maxLines int) {
|
func InitLogger(text *widget.Entry, maxLines int) {
|
||||||
globalLogger = &Logger{
|
globalLogger = &Logger{
|
||||||
logText: text,
|
logText: text,
|
||||||
logMaxLines: maxLines,
|
logMaxLines: maxLines,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Log(line string) {
|
func Log(line string) {
|
||||||
@@ -32,9 +33,11 @@ func Log(line string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *Logger) log(line string) {
|
func (l *Logger) log(line string) {
|
||||||
l.logBuffer = append(l.logBuffer, line)
|
fyne.Do(func() {
|
||||||
if len(l.logBuffer) > l.logMaxLines {
|
l.logBuffer = append(l.logBuffer, line)
|
||||||
l.logBuffer = l.logBuffer[1:]
|
if len(l.logBuffer) > l.logMaxLines {
|
||||||
}
|
l.logBuffer = l.logBuffer[1:]
|
||||||
l.logText.SetText(strings.Join(l.logBuffer, "\n"))
|
}
|
||||||
|
l.logText.SetText(strings.Join(l.logBuffer, "\n"))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
32
utils.go
32
utils.go
@@ -85,14 +85,13 @@ func GenerateUnrealSolution(project Project) {
|
|||||||
cmd = exec.Command(buildCmd, projectFile, "-game")
|
cmd = exec.Command(buildCmd, projectFile, "-game")
|
||||||
|
|
||||||
case "windows":
|
case "windows":
|
||||||
editor := project.EnginePath + "\\Engine\\Binaries\\Win64\\UnrealEditor.exe"
|
ubtPath := project.EnginePath + "\\Engine\\Binaries\\DotNET\\UnrealBuildTool\\UnrealBuildTool.dll"
|
||||||
cmd = exec.Command(
|
cmd = exec.Command(
|
||||||
editor,
|
"dotnet", ubtPath,
|
||||||
projectFile,
|
|
||||||
"-projectfiles",
|
"-projectfiles",
|
||||||
|
"-project="+projectFile,
|
||||||
|
"-game",
|
||||||
"-progress",
|
"-progress",
|
||||||
"-waitmutex",
|
|
||||||
"-NoHotReloadFromIDE",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -167,18 +166,27 @@ func logToOutput(cmd *exec.Cmd) {
|
|||||||
fmt.Println("Error while loading command")
|
fmt.Println("Error while loading command")
|
||||||
}
|
}
|
||||||
|
|
||||||
readPipe := func(reader io.ReadCloser) {
|
readPipe := func(reader io.ReadCloser, prefix string) {
|
||||||
scanner := bufio.NewScanner(reader)
|
scanner := bufio.NewScanner(reader)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
Log(line)
|
if prefix != "" {
|
||||||
|
Log(prefix + line)
|
||||||
|
} else {
|
||||||
|
Log(line)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
go readPipe(stdout)
|
go readPipe(stdout, "")
|
||||||
go readPipe(stderr)
|
go readPipe(stderr, "[ERR] ")
|
||||||
|
|
||||||
if err := cmd.Wait(); err != nil {
|
// attendre la fin dans une goroutine => pas de blocage de l'UI
|
||||||
fmt.Println("Error")
|
go func() {
|
||||||
}
|
if err := cmd.Wait(); err != nil {
|
||||||
|
Log("[FAIL] " + err.Error())
|
||||||
|
} else {
|
||||||
|
Log("[DONE] Process finished")
|
||||||
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user