diff --git a/ui/launch.go b/ui/launch.go index e0f4086b..35c1ee92 100644 --- a/ui/launch.go +++ b/ui/launch.go @@ -1,27 +1,27 @@ package ui import ( - "errors" "flag" "fmt" "os" "os/exec" - "runtime" "github.com/Safing/portbase/modules" "github.com/Safing/portmaster/updates" ) var ( - launchUI bool + launchUI bool + launchNotifier bool ) func init() { flag.BoolVar(&launchUI, "ui", false, "launch user interface and exit") + flag.BoolVar(&launchNotifier, "notifier", false, "launch notifier and exit") } func launchUIByFlag() error { - if !launchUI { + if !launchUI && !launchNotifier { return nil } @@ -30,37 +30,42 @@ func launchUIByFlag() error { return err } - osAndPlatform := fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH) - - switch osAndPlatform { - case "linux_amd64": - - file, err := updates.GetPlatformFile("app/portmaster-ui") + if launchUI { + err = launch("app/portmaster-ui") if err != nil { - return fmt.Errorf("ui currently not available: %s - you may need to first start portmaster and wait for it to fetch the update index", err) + return err } - - // check permission - info, err := os.Stat(file.Path()) - if info.Mode() != 0755 { - fmt.Printf("%v\n", info.Mode()) - err := os.Chmod(file.Path(), 0755) - if err != nil { - return fmt.Errorf("failed to set exec permissions on %s: %s", file.Path(), err) - } - } - - // exec - cmd := exec.Command(file.Path()) - err = cmd.Start() - if err != nil { - return fmt.Errorf("failed to start ui: %s", err) - } - - // gracefully exit portmaster - return modules.ErrCleanExit - - default: - return errors.New("this os/platform is no UI support yet") } + + if launchNotifier { + return launch("notifier/portmaster-notifier") + } + + return nil +} + +func launch(identifier string) error { + file, err := updates.GetPlatformFile(identifier) + if err != nil { + return fmt.Errorf("%s currently not available: %s - you may need to first start portmaster and wait for it to fetch the update index", identifier, err) + } + + // check permission + info, err := os.Stat(file.Path()) + if info.Mode() != 0755 { + err := os.Chmod(file.Path(), 0755) + if err != nil { + return fmt.Errorf("failed to set exec permissions on %s: %s", file.Path(), err) + } + } + + // exec + cmd := exec.Command(file.Path()) + err = cmd.Start() + if err != nil { + return fmt.Errorf("failed to start %s: %s", identifier, err) + } + + // gracefully exit portmaster + return modules.ErrCleanExit }