mirror of
https://github.com/rclone/rclone.git
synced 2024-11-07 09:04:52 +01:00
fs: add support for flag --no-console on windows to hide the console window
This commit is contained in:
parent
b569dc11a0
commit
7a496752f3
@ -382,6 +382,11 @@ func initConfig() {
|
||||
// Finish parsing any command line flags
|
||||
configflags.SetFlags(ci)
|
||||
|
||||
// Hide console window
|
||||
if ci.NoConsole {
|
||||
terminal.HideConsole()
|
||||
}
|
||||
|
||||
// Load filters
|
||||
err := filterflags.Reload(ctx)
|
||||
if err != nil {
|
||||
|
@ -121,6 +121,7 @@ type ConfigInfo struct {
|
||||
DownloadHeaders []*HTTPOption
|
||||
Headers []*HTTPOption
|
||||
RefreshTimes bool
|
||||
NoConsole bool
|
||||
}
|
||||
|
||||
// NewConfig creates a new config with everything set to the default
|
||||
|
@ -124,6 +124,7 @@ func AddFlags(ci *fs.ConfigInfo, flagSet *pflag.FlagSet) {
|
||||
flags.StringArrayVarP(flagSet, &downloadHeaders, "header-download", "", nil, "Set HTTP header for download transactions")
|
||||
flags.StringArrayVarP(flagSet, &headers, "header", "", nil, "Set HTTP header for all transactions")
|
||||
flags.BoolVarP(flagSet, &ci.RefreshTimes, "refresh-times", "", ci.RefreshTimes, "Refresh the modtime of remote files.")
|
||||
flags.BoolVarP(flagSet, &ci.NoConsole, "no-console", "", ci.NoConsole, "Hide console window. Supported on Windows only.")
|
||||
}
|
||||
|
||||
// ParseHeaders converts the strings passed in via the header flags into HTTPOptions
|
||||
|
7
lib/terminal/hidden_other.go
Normal file
7
lib/terminal/hidden_other.go
Normal file
@ -0,0 +1,7 @@
|
||||
// +build !windows
|
||||
|
||||
package terminal
|
||||
|
||||
// HideConsole is only supported on windows
|
||||
func HideConsole() {
|
||||
}
|
19
lib/terminal/hidden_windows.go
Normal file
19
lib/terminal/hidden_windows.go
Normal file
@ -0,0 +1,19 @@
|
||||
// +build windows
|
||||
|
||||
package terminal
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// HideConsole hides the console window and activates another window
|
||||
func HideConsole() {
|
||||
getConsoleWindow := syscall.NewLazyDLL("kernel32.dll").NewProc("GetConsoleWindow")
|
||||
showWindow := syscall.NewLazyDLL("user32.dll").NewProc("ShowWindow")
|
||||
if getConsoleWindow.Find() == nil && showWindow.Find() == nil {
|
||||
hwnd, _, _ := getConsoleWindow.Call()
|
||||
if hwnd != 0 {
|
||||
showWindow.Call(hwnd, 0)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user