mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-10-31 09:15:07 +03:00 
			
		
		
		
	Merge pull request #25 from RiV-chain/show_console_in_ui_options
Added mesh-ui start options and ability to enable debug console
This commit is contained in:
		
						commit
						081bfdf062
					
				
					 6 changed files with 58 additions and 15 deletions
				
			
		
							
								
								
									
										4
									
								
								build
									
										
									
									
									
								
							
							
						
						
									
										4
									
								
								build
									
										
									
									
									
								
							|  | @ -58,10 +58,6 @@ build_meshctl() { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| build_mesh_ui() { | build_mesh_ui() { | ||||||
|   #only UI should be built with windowsgui flag |  | ||||||
|   if [ "$GOOS" == "windows" ]; then |  | ||||||
|     LDFLAGS2=" -H windowsgui" |  | ||||||
|   fi |  | ||||||
|   buildbin ./contrib/ui/mesh-ui |   buildbin ./contrib/ui/mesh-ui | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										47
									
								
								contrib/ui/mesh-ui/webview.go
									
										
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										47
									
								
								contrib/ui/mesh-ui/webview.go
									
										
									
									
									
										
										
										Executable file → Normal file
									
								
							|  | @ -2,6 +2,7 @@ package main | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"encoding/json" | 	"encoding/json" | ||||||
|  | 	"errors" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io/ioutil" | 	"io/ioutil" | ||||||
| 	"log" | 	"log" | ||||||
|  | @ -18,11 +19,34 @@ import ( | ||||||
| 	"github.com/webview/webview" | 	"github.com/webview/webview" | ||||||
| 
 | 
 | ||||||
| 	"github.com/RiV-chain/RiV-mesh/src/admin" | 	"github.com/RiV-chain/RiV-mesh/src/admin" | ||||||
|  | 	"github.com/docopt/docopt-go" | ||||||
| ) | ) | ||||||
|  | var usage = `Graphical interface for RiV mesh. | ||||||
| 
 | 
 | ||||||
|  | Usage: | ||||||
|  |   mesh-ui [<index>] [-c] | ||||||
|  |   mesh-ui -h | --help | ||||||
|  |   mesh-ui -v | --version | ||||||
|  | 
 | ||||||
|  | Options: | ||||||
|  |   <index>       Index file name [default: index.html]. | ||||||
|  |   -c --console  Show debug console window. | ||||||
|  |   -h --help     Show this screen. | ||||||
|  |   -v --version  Show version.` | ||||||
|  | 
 | ||||||
|  | var confui struct { | ||||||
|  | 	IndexHtml string `docopt:"<index>"` | ||||||
|  | 	Console   bool   `docopt:"-c,--console"` | ||||||
|  | } | ||||||
|  | ======= | ||||||
| var uiVersion = "0.0.1" | var uiVersion = "0.0.1" | ||||||
| 
 | 
 | ||||||
| func main() { | func main() { | ||||||
|  | 	opts, _ := docopt.ParseArgs(usage, os.Args[1:], uiVersion) | ||||||
|  | 	opts.Bind(&confui) | ||||||
|  | 	if !confui.Console { | ||||||
|  | 		Console(false) | ||||||
|  | 	} | ||||||
| 	debug := true | 	debug := true | ||||||
| 	w := webview.New(debug) | 	w := webview.New(debug) | ||||||
| 	defer w.Destroy() | 	defer w.Destroy() | ||||||
|  | @ -67,18 +91,21 @@ func main() { | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	var path string |  | ||||||
| 
 | 
 | ||||||
| 	if len(os.Args) > 1 { | 	if confui.IndexHtml == "" { | ||||||
| 		path, err = filepath.Abs(filepath.Dir(os.Args[1])) | 		confui.IndexHtml = "index.html" | ||||||
| 	} else { |  | ||||||
| 		path, err = filepath.Abs(filepath.Dir(os.Args[0])) |  | ||||||
| 	} | 	} | ||||||
|  | 	confui.IndexHtml, err = filepath.Abs(confui.IndexHtml) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		log.Fatal(err) | 		panic(errors.New("Index file not found: " + err.Error())) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	if stat, err := os.Stat(confui.IndexHtml); err != nil { | ||||||
|  | 		panic(errors.New("Index file not found or permissians denied: " + err.Error())) | ||||||
|  | 	} else if stat.IsDir() { | ||||||
|  | 		panic(errors.New(fmt.Sprintf("Index file %v not found", confui.IndexHtml))) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	log.Println(path) |  | ||||||
| 	w.Bind("onLoad", func() { | 	w.Bind("onLoad", func() { | ||||||
| 		log.Println("page loaded") | 		log.Println("page loaded") | ||||||
| 		go run(w) | 		go run(w) | ||||||
|  | @ -105,10 +132,8 @@ func main() { | ||||||
| 	w.Bind("ping", func(peer_list string) { | 	w.Bind("ping", func(peer_list string) { | ||||||
| 		go ping(w, peer_list) | 		go ping(w, peer_list) | ||||||
| 	}) | 	}) | ||||||
| 	//dat, err := ioutil.ReadFile(path+"/index.html") | 	log.Printf("Opening: %v", confui.IndexHtml) | ||||||
| 	//w.Navigate("data:text/html,"+url.QueryEscape(string(dat))) | 	w.Navigate(confui.IndexHtml) | ||||||
| 	//w.Navigate("data:text/html,"+"<html>"+path+"</html>") |  | ||||||
| 	w.Navigate("file://" + path + "/index.html") |  | ||||||
| 	w.Run() | 	w.Run() | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -30,3 +30,6 @@ func run_command_with_arg(command string, arg string) []byte { | ||||||
| 	} | 	} | ||||||
| 	return out | 	return out | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | func Console(show bool) { | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -33,3 +33,19 @@ func run_command_with_arg(command string, arg string) []byte { | ||||||
| 	} | 	} | ||||||
| 	return out | 	return out | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | func Console(show bool) { | ||||||
|  | 	var getWin = syscall.NewLazyDLL("kernel32.dll").NewProc("GetConsoleWindow") | ||||||
|  | 	var showWin = syscall.NewLazyDLL("user32.dll").NewProc("ShowWindow") | ||||||
|  | 	hwnd, _, _ := getWin.Call() | ||||||
|  | 	if hwnd == 0 { | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
|  | 	if show { | ||||||
|  | 		var SW_RESTORE uintptr = 9 | ||||||
|  | 		showWin.Call(hwnd, SW_RESTORE) | ||||||
|  | 	} else { | ||||||
|  | 		var SW_HIDE uintptr = 0 | ||||||
|  | 		showWin.Call(hwnd, SW_HIDE) | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
							
								
								
									
										1
									
								
								go.mod
									
										
									
									
									
								
							
							
						
						
									
										1
									
								
								go.mod
									
										
									
									
									
								
							|  | @ -23,6 +23,7 @@ require ( | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| require ( | require ( | ||||||
|  | 	github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 // indirect | ||||||
| 	github.com/dustin/go-humanize v1.0.0 // indirect | 	github.com/dustin/go-humanize v1.0.0 // indirect | ||||||
| 	github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 // indirect | 	github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 // indirect | ||||||
| 	github.com/getlantern/ema v0.0.0-20190620044903-5943d28f40e4 // indirect | 	github.com/getlantern/ema v0.0.0-20190620044903-5943d28f40e4 // indirect | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								go.sum
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								go.sum
									
										
									
									
									
								
							|  | @ -12,6 +12,8 @@ github.com/cheggaaa/pb/v3 v3.0.8/go.mod h1:UICbiLec/XO6Hw6k+BHEtHeQFzzBH4i2/qk/o | ||||||
| github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||||||
| github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||||||
| github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||||||
|  | github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 h1:bWDMxwH3px2JBh6AyO7hdCn/PkvCZXii8TGj7sbtEbQ= | ||||||
|  | github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= | ||||||
| github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= | github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= | ||||||
| github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= | github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= | ||||||
| github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= | github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Vadym Vikulin
						Vadym Vikulin