Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[blink GUI] windowsgui flag flash console windows. #5

Closed
wsteel opened this issue Dec 11, 2019 · 3 comments
Closed

[blink GUI] windowsgui flag flash console windows. #5

wsteel opened this issue Dec 11, 2019 · 3 comments

Comments

@wsteel
Copy link

wsteel commented Dec 11, 2019

Describe the bug
when i build a local web application on windows, use build cmd

   go build -ldflags -H=windowsgui -o "test.exe"

,when i run , it's strange. first show a console windows, then the console window closed . console window will show twice. final my windows show out.
i don't kown how to block the console window's show . so need help.
when i use gin , this's ok . no console window show out.

To Reproduce
Steps to reproduce the behavior:

package main

import (
	"github.com/kataras/iris/v12"
	"github.com/raintean/blink"
	"log"
)

func main() {
	exit := make(chan bool)

	blink.SetDebugMode(true)
	errv := blink.InitBlink()
	if errv != nil {
		log.Fatal(errv)
	}

	go func() {
		app := iris.New()
		app.Get("/ping", func(ctx iris.Context) {
			ctx.WriteString("pong")
		})
		app.Run(iris.Addr("127.0.0.1:8080"))
	}()

	view := blink.NewWebView(false, 1366, 920)
	view.LoadURL("http://127.0.0.1:8080/ping")
	view.SetWindowTitle("test")
	view.MoveToCenter()
	view.ShowWindow()
	view.On("destroy", func(_ *blink.WebView) {
		close(exit)
	})

	<-exit
}

Screenshots
shot

Desktop (please complete the following information):

  • OS: windows 10
@kataras kataras removed their assignment Dec 11, 2019
@kataras kataras changed the title [BUG] windowsgui flag flash console windows. [blink GUI] windowsgui flag flash console windows. Dec 11, 2019
@kataras kataras closed this as completed Dec 11, 2019
@kataras
Copy link
Owner

kataras commented Dec 11, 2019

@wsteel seems like that one posted on

The problem does not derives from Iris or even blink or gin, it was a Go bug which will be fixed on the next release. You posted a misdirection sentence when i use gin , this's ok . no console window show out. which is invalid and mistaken, this problem occurs with any of them, even net/http. (See below for solution)

package main

import (
	"log"
	"net/http"

	"github.com/gin-gonic/gin"
	"github.com/kataras/iris/v12"
	"github.com/raintean/blink"
)

const (
	withNethttp uint8 = iota
	withIris
	withGin
)

const (
	runWith = withGin
	addr    = "127.0.0.1:8080"
)

func main() {
	exit := make(chan bool)

	blink.SetDebugMode(true)
	errv := blink.InitBlink()
	if errv != nil {
		log.Fatal(errv)
	}

	go func() {
		switch runWith {
		case withIris:
			app := iris.New()
			app.Get("/ping", func(ctx iris.Context) {
				ctx.WriteString("pong")
			})
			app.Run(iris.Addr(addr))
		case withGin:
			gin.SetMode(gin.ReleaseMode)
			router := gin.New()
			router.GET("/ping", func(ctx *gin.Context) {
				ctx.String(http.StatusOK, "pong")
			})
			router.Run(addr)
		default:
			mux := http.NewServeMux()
			mux.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) {
				if r.Method != http.MethodGet {
					http.Error(w, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
					return
				}
				w.Write([]byte("pong"))
			})
			http.ListenAndServe(addr, mux)
		}
	}()

	view := blink.NewWebView(false, 1366, 920)
	view.LoadURL(addr + "/ping")
	view.SetWindowTitle("test")
	view.MoveToCenter()
	view.ShowWindow()
	view.On("destroy", func(_ *blink.WebView) {
		close(exit)
	})

	<-exit
}

Solution

Changing the GOPATH to the correct capitalization form e.g. "C:\Users$name\go" instead of "c:\users$name\go" is a workaround for on go 1.10.3.

^ golang/go#24232 (comment)


As you can see I am trying to help you even if it's not an Iris-relative issue. Please remember this, not everyone does that.

Thanks,
Gerasimos Maropoulos. Author of Iris.

@wsteel
Copy link
Author

wsteel commented Dec 12, 2019

thanks for your help.
i try your code, all them show the console windows. because you just import "github.com/kataras/iris/v12" . then you drop iris code. the console disappeared. so i am so confused :<

try this code , just drop iris ...


package main

import (
	"log"
	"net/http"
	"github.com/gin-gonic/gin"
	"github.com/raintean/blink"
)

const (
	withNethttp uint8 = iota
	withGin
)

const (
	runWith = withNethttp
	addr    = "127.0.0.1:8080"
)

func main() { 
	exit := make(chan bool)

	blink.SetDebugMode(false)
	errv := blink.InitBlink()
	if errv != nil {
		log.Fatal(errv)
	}

	go func() {
		switch runWith {

		case withGin:
			gin.SetMode(gin.ReleaseMode)
			router := gin.New()
			router.GET("/ping", func(ctx *gin.Context) {
				ctx.String(http.StatusOK, "pong gin")
			})
			router.Run(addr)
		default:
			mux := http.NewServeMux()
			mux.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) {
				if r.Method != http.MethodGet {
					http.Error(w, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
					return
				}
				w.Write([]byte("pong net"))
			})
			http.ListenAndServe(addr, mux)
		}
	}()

	view := blink.NewWebView(false, 1366, 920)
	view.LoadURL(addr + "/ping")
	view.SetWindowTitle("test")
	view.MoveToCenter()
	view.ShowWindow()
	view.On("destroy", func(_ *blink.WebView) {
		close(exit)
	})

	<-exit
}

@kataras kataras reopened this Dec 12, 2019
@kataras kataras transferred this issue from kataras/iris Dec 12, 2019
@kataras kataras added the bug label Dec 12, 2019
@kataras
Copy link
Owner

kataras commented Dec 12, 2019

OK that was a tough one, but I found the origin of the problem, it's not iris itself but a dependency that golog uses, the pio library which has a code which runs on init for windowsand runs a command to get the current windows version, which didn't contain the HideWindow attr.

stdout, stderr := &bytes.Buffer{}, &bytes.Buffer{}
cmd := exec.Command("cmd", "ver")
cmd.Stdout = stdout
cmd.Stderr = stderr
err := cmd.Run()

This is now fixed.

However, in order to see that in action, you have to modify your go mod to update kataras/[email protected] which contains the updated kataras/[email protected] dependency or wait for Iris v12.1.0 which is not far behind, all new features are almost implemented.

Your contribution @wsteel, especially with your last comment, was priceless. Thank you.


This issue was transferred from iris to pio.

kataras added a commit that referenced this issue Dec 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants