mirror of
https://github.com/safing/portmaster
synced 2025-09-01 18:19:12 +00:00
Add option to launch notifier
This commit is contained in:
parent
5f21f7bc60
commit
416fea1f17
1 changed files with 39 additions and 34 deletions
73
ui/launch.go
73
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
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue