cmd: ipfs handle GUI environment on Windows
Dominic Della Valle committed
Sep 15, 2019 at 15:32 UTC
3c9039a00b9c9099f22fddca2bde2493dce3f24f
3 files changed
+34
-2
cmd/ipfs/main.go
+9
-2
@@ -22,10 +22,10 @@ import (
22
repo "github.com/ipfs/go-ipfs/repo"
23
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
24
25
- "github.com/ipfs/go-ipfs-cmds"
25
+ cmds "github.com/ipfs/go-ipfs-cmds"
26
"github.com/ipfs/go-ipfs-cmds/cli"
27
cmdhttp "github.com/ipfs/go-ipfs-cmds/http"
28
- "github.com/ipfs/go-ipfs-config"
28
+ config "github.com/ipfs/go-ipfs-config"
29
u "github.com/ipfs/go-ipfs-util"
30
logging "github.com/ipfs/go-log"
31
loggables "github.com/libp2p/go-libp2p-loggables"
@@ -113,6 +113,9 @@ func mainRet() int {
113
os.Args[1] = "--help"
114
}
115
}
116
+ } else if insideGUI() { // if no args were passed, and we're in a GUI environment
117
+ // launch the daemon instead of launching a ghost window
118
+ os.Args = append(os.Args, "daemon", "--init")
119
}
120
121
// output depends on executable name passed in os.Args
@@ -172,6 +175,10 @@ func mainRet() int {
175
return 0
176
}
177
178
+func insideGUI() bool {
179
+ return util.InsideGUI()
180
+}
181
+
182
func checkDebug(req *cmds.Request) {
183
// check if user wants to debug. option OR env var.
184
debug, _ := req.Options["debug"].(bool)
cmd/ipfs/util/ui.go
new
+7
@@ -0,0 +1,7 @@
1
+//+build !windows
2
+
3
+package util
4
+
5
+func InsideGUI() bool {
6
+ return false
7
+}
cmd/ipfs/util/ui_windows.go
new
+18
@@ -0,0 +1,18 @@
1
+package util
2
+
3
+import "golang.org/x/sys/windows"
4
+
5
+func InsideGUI() bool {
6
+ conhostInfo := &windows.ConsoleScreenBufferInfo{}
7
+ if err := windows.GetConsoleScreenBufferInfo(windows.Stdout, conhostInfo); err != nil {
8
+ return false
9
+ }
10
+
11
+ if (conhostInfo.CursorPosition.X | conhostInfo.CursorPosition.Y) == 0 {
12
+ // console cursor has not moved prior to our execution
13
+ // high probability that we're not in a terminal
14
+ return true
15
+ }
16
+
17
+ return false
18
+}