Browse Source

help windows users by detecting if the program was invoked from explorer

Alan Shreve 11 years ago
parent
commit
f2686d7de8
1 changed files with 14 additions and 0 deletions
  1. 14 0
      src/ngrok/client/main.go

+ 14 - 0
src/ngrok/client/main.go

@@ -2,12 +2,26 @@ package client
 
 import (
 	"fmt"
+	"github.com/inconshreveable/mousetrap"
 	"math/rand"
 	"ngrok/log"
 	"ngrok/util"
 	"os"
+	"runtime"
+	"time"
 )
 
+func init() {
+	if runtime.GOOS == "windows" {
+		if ok, err := mousetrap.InvokedFromCommandLine(); err == nil && !ok {
+			fmt.Println("Don't double-click ngrok!")
+			fmt.Println("You need to open cmd.exe and run it from the command line!")
+			time.Sleep(5 * time.Second)
+			os.Exit(1)
+		}
+	}
+}
+
 func Main() {
 	// parse options
 	opts, err := ParseArgs()