Skip to content

Commit

Permalink
Merge pull request #6646 from djdv/feat/GUI-launcher
Browse files Browse the repository at this point in the history
cmd: ipfs handle GUI environment on Windows
  • Loading branch information
Stebalien committed Mar 13, 2020
2 parents 36afd0b + 3c9039a commit 457b6e7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cmd/ipfs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
repo "github.com/ipfs/go-ipfs/repo"
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"

"github.com/ipfs/go-ipfs-cmds"
cmds "github.com/ipfs/go-ipfs-cmds"
"github.com/ipfs/go-ipfs-cmds/cli"
cmdhttp "github.com/ipfs/go-ipfs-cmds/http"
"github.com/ipfs/go-ipfs-config"
config "github.com/ipfs/go-ipfs-config"
u "github.com/ipfs/go-ipfs-util"
logging "github.com/ipfs/go-log"
loggables "github.com/libp2p/go-libp2p-loggables"
Expand Down Expand Up @@ -113,6 +113,9 @@ func mainRet() int {
os.Args[1] = "--help"
}
}
} else if insideGUI() { // if no args were passed, and we're in a GUI environment
// launch the daemon instead of launching a ghost window
os.Args = append(os.Args, "daemon", "--init")
}

// output depends on executable name passed in os.Args
Expand Down Expand Up @@ -172,6 +175,10 @@ func mainRet() int {
return 0
}

func insideGUI() bool {
return util.InsideGUI()
}

func checkDebug(req *cmds.Request) {
// check if user wants to debug. option OR env var.
debug, _ := req.Options["debug"].(bool)
Expand Down
7 changes: 7 additions & 0 deletions cmd/ipfs/util/ui.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//+build !windows

package util

func InsideGUI() bool {
return false
}
18 changes: 18 additions & 0 deletions cmd/ipfs/util/ui_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package util

import "golang.org/x/sys/windows"

func InsideGUI() bool {
conhostInfo := &windows.ConsoleScreenBufferInfo{}
if err := windows.GetConsoleScreenBufferInfo(windows.Stdout, conhostInfo); err != nil {
return false
}

if (conhostInfo.CursorPosition.X | conhostInfo.CursorPosition.Y) == 0 {
// console cursor has not moved prior to our execution
// high probability that we're not in a terminal
return true
}

return false
}

0 comments on commit 457b6e7

Please sign in to comment.