From b0aff891661dfa2f438a7264607a4e6e9caef026 Mon Sep 17 00:00:00 2001 From: Ophestra Umiker Date: Thu, 12 Sep 2024 20:53:33 +0900 Subject: app: handle launch method in New function Signed-off-by: Ophestra Umiker --- internal/app/run.go | 54 ++++++++++++++++++++--------------------------------- 1 file changed, 20 insertions(+), 34 deletions(-) (limited to 'internal/app/run.go') diff --git a/internal/app/run.go b/internal/app/run.go index b5eec825..0871e899 100644 --- a/internal/app/run.go +++ b/internal/app/run.go @@ -17,15 +17,9 @@ const ( sudoAskPass = "SUDO_ASKPASS" ) const ( - LaunchMethodSudo = iota + LaunchMethodSudo uint8 = iota + LaunchMethodBwrap LaunchMethodMachineCtl - - launchOptionLength -) - -var ( - // LaunchOptions is set in main's cli.go - LaunchOptions [launchOptionLength]bool ) func (a *App) Run() { @@ -34,34 +28,20 @@ func (a *App) Run() { a.AppendEnv(term, t) } - commandBuilder := a.commandBuilderSudo - - var toolPath string - - // dependency checks - const sudoFallback = "Falling back to 'sudo', some desktop integration features may not work" - if LaunchOptions[LaunchMethodMachineCtl] && !LaunchOptions[LaunchMethodSudo] { // sudo argument takes priority - if !util.SdBooted() { - fmt.Println("This system was not booted through systemd") - fmt.Println(sudoFallback) - } else if machineCtlPath, ok := util.Which("machinectl"); !ok { - fmt.Println("Did not find 'machinectl' in PATH") - fmt.Println(sudoFallback) - } else { - toolPath = machineCtlPath - commandBuilder = a.commandBuilderMachineCtl - } - } else if sudoPath, ok := util.Which("sudo"); !ok { - state.Fatal("Did not find 'sudo' in PATH") - } else { - toolPath = sudoPath - } - - if system.V.Verbose { - fmt.Printf("Selected launcher '%s'\n", toolPath) + var commandBuilder func() (args []string) + + switch a.launchOption { + case LaunchMethodSudo: + commandBuilder = a.commandBuilderSudo + case LaunchMethodBwrap: + commandBuilder = a.commandBuilderBwrap + case LaunchMethodMachineCtl: + commandBuilder = a.commandBuilderMachineCtl + default: + panic("unreachable") } - cmd := exec.Command(toolPath, commandBuilder()...) + cmd := exec.Command(a.toolPath, commandBuilder()...) cmd.Env = []string{} cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout @@ -122,6 +102,12 @@ func (a *App) commandBuilderSudo() (args []string) { return } +func (a *App) commandBuilderBwrap() (args []string) { + // TODO: build bwrap command + state.Fatal("bwrap") + panic("unreachable") +} + func (a *App) commandBuilderMachineCtl() (args []string) { args = make([]string, 0, 9+len(a.env)) -- cgit v1.3.1