Merge pull request #671 from E1int/start-minimized-flag
Add CLI flag to start app minimized
This commit is contained in:
+3
-1
@@ -437,7 +437,7 @@ func (a *App) SetupWindowsSMTC(hwnd uintptr) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) LoginToDefaultServer(string) error {
|
func (a *App) LoginToDefaultServer() error {
|
||||||
serverCfg := a.ServerManager.GetDefaultServer()
|
serverCfg := a.ServerManager.GetDefaultServer()
|
||||||
if serverCfg == nil {
|
if serverCfg == nil {
|
||||||
return ErrNoServers
|
return ErrNoServers
|
||||||
@@ -548,6 +548,8 @@ func (a *App) checkFlagsAndSendIPCMsg(cli *ipc.Client) error {
|
|||||||
return cli.SeekBackOrPrevious()
|
return cli.SeekBackOrPrevious()
|
||||||
case *FlagNext:
|
case *FlagNext:
|
||||||
return cli.SeekNext()
|
return cli.SeekNext()
|
||||||
|
case *FlagShow:
|
||||||
|
return cli.Show()
|
||||||
case VolumeCLIArg >= 0:
|
case VolumeCLIArg >= 0:
|
||||||
return cli.SetVolume(VolumeCLIArg)
|
return cli.SetVolume(VolumeCLIArg)
|
||||||
case VolumePctCLIArg != 0:
|
case VolumePctCLIArg != 0:
|
||||||
|
|||||||
@@ -12,13 +12,15 @@ var (
|
|||||||
SeekByCLIArg float64 = 0
|
SeekByCLIArg float64 = 0
|
||||||
VolumePctCLIArg float64 = 0
|
VolumePctCLIArg float64 = 0
|
||||||
|
|
||||||
FlagPlay = flag.Bool("play", false, "unpause or begin playback")
|
FlagPlay = flag.Bool("play", false, "unpause or begin playback")
|
||||||
FlagPause = flag.Bool("pause", false, "pause playback")
|
FlagPause = flag.Bool("pause", false, "pause playback")
|
||||||
FlagPlayPause = flag.Bool("play-pause", false, "toggle play/pause state")
|
FlagPlayPause = flag.Bool("play-pause", false, "toggle play/pause state")
|
||||||
FlagPrevious = flag.Bool("previous", false, "seek to previous track or beginning of current")
|
FlagPrevious = flag.Bool("previous", false, "seek to previous track or beginning of current")
|
||||||
FlagNext = flag.Bool("next", false, "seek to next track")
|
FlagNext = flag.Bool("next", false, "seek to next track")
|
||||||
FlagVersion = flag.Bool("version", false, "print app version and exit")
|
FlagStartMinimized = flag.Bool("start-minimized", false, "start app minimized")
|
||||||
FlagHelp = flag.Bool("help", false, "print command line options and exit")
|
FlagShow = flag.Bool("show", false, "show minimized app")
|
||||||
|
FlagVersion = flag.Bool("version", false, "print app version and exit")
|
||||||
|
FlagHelp = flag.Bool("help", false, "print command line options and exit")
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -50,8 +52,11 @@ func init() {
|
|||||||
|
|
||||||
func HaveCommandLineOptions() bool {
|
func HaveCommandLineOptions() bool {
|
||||||
visitedAny := false
|
visitedAny := false
|
||||||
flag.Visit(func(*flag.Flag) {
|
flag.Visit(func(f *flag.Flag) {
|
||||||
visitedAny = true
|
// We skip `start-minimized` because it should't send an IPC message.
|
||||||
|
if f.Name != "start-minimized" {
|
||||||
|
visitedAny = true
|
||||||
|
}
|
||||||
})
|
})
|
||||||
return visitedAny
|
return visitedAny
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ func main() {
|
|||||||
defaultServer := myApp.ServerManager.GetDefaultServer()
|
defaultServer := myApp.ServerManager.GetDefaultServer()
|
||||||
if defaultServer == nil {
|
if defaultServer == nil {
|
||||||
mainWindow.Controller.PromptForFirstServer()
|
mainWindow.Controller.PromptForFirstServer()
|
||||||
} else {
|
} else if !*backend.FlagStartMinimized { // If the minimized start flag was passed, the connection is already established.
|
||||||
mainWindow.Controller.DoConnectToServerWorkflow(defaultServer)
|
mainWindow.Controller.DoConnectToServerWorkflow(defaultServer)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,7 +103,15 @@ func main() {
|
|||||||
})
|
})
|
||||||
fyneApp.Lifecycle().SetOnEnteredForeground(windowStartupTasks)
|
fyneApp.Lifecycle().SetOnEnteredForeground(windowStartupTasks)
|
||||||
|
|
||||||
mainWindow.ShowAndRun()
|
if *backend.FlagStartMinimized {
|
||||||
|
if err = myApp.LoginToDefaultServer(); err != nil {
|
||||||
|
log.Fatalf("failed to connect to server: %v", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fyneApp.Run()
|
||||||
|
} else {
|
||||||
|
mainWindow.ShowAndRun()
|
||||||
|
}
|
||||||
|
|
||||||
log.Println("Running shutdown tasks...")
|
log.Println("Running shutdown tasks...")
|
||||||
myApp.Shutdown()
|
myApp.Shutdown()
|
||||||
|
|||||||
Reference in New Issue
Block a user