From 522c16f46419ddc19cb07808c53862292b8fd3ba Mon Sep 17 00:00:00 2001 From: Andinus Date: Tue, 24 Mar 2020 11:49:57 +0530 Subject: Add darwin support --- build/ci/gitlab-ci.yml | 2 ++ pkg/background/set.go | 28 ---------------------------- pkg/background/set_darwin.go | 14 ++++++++++++++ pkg/background/set_unix.go | 30 ++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 28 deletions(-) delete mode 100644 pkg/background/set.go create mode 100644 pkg/background/set_darwin.go create mode 100644 pkg/background/set_unix.go diff --git a/build/ci/gitlab-ci.yml b/build/ci/gitlab-ci.yml index f6d776e..2a140ea 100644 --- a/build/ci/gitlab-ci.yml +++ b/build/ci/gitlab-ci.yml @@ -18,7 +18,9 @@ compile: - cd $GOPATH/src/$REPO_NAME/cmd/cetus - GOOS=openbsd GOARCH=amd64 go build -o $CI_PROJECT_DIR/cetus-openbsd-amd64 - GOOS=linux GOARCH=amd64 go build -o $CI_PROJECT_DIR/cetus-linux-amd64 + - GOOS=darwin GOARCH=amd64 go build -o $CI_PROJECT_DIR/cetus-darwin-amd64 artifacts: paths: - cetus-openbsd-amd64 - cetus-linux-amd64 + - cetus-darwin-amd64 diff --git a/pkg/background/set.go b/pkg/background/set.go deleted file mode 100644 index 0f7333d..0000000 --- a/pkg/background/set.go +++ /dev/null @@ -1,28 +0,0 @@ -package background - -import ( - "fmt" - "os" - "os/exec" -) - -// Set calls feh to set the background -func Set(path string) error { - var err error - switch os.Getenv("XDG_CURRENT_DESKTOP") { - case "GNOME", "Unity", "Pantheon": - path = fmt.Sprintf("%s%s", "file://", path) - err = exec.Command("gsettings", "set org.gnome.desktop.background picture-uri", path).Run() - return err - case "LXDE": - err = exec.Command("pcmanfm", "-w", path).Run() - return err - default: - feh, err := exec.LookPath("feh") - if err != nil { - return err - } - err = exec.Command(feh, "--bg-fill", path).Run() - return err - } -} diff --git a/pkg/background/set_darwin.go b/pkg/background/set_darwin.go new file mode 100644 index 0000000..2ead214 --- /dev/null +++ b/pkg/background/set_darwin.go @@ -0,0 +1,14 @@ +// +build darwin + +package background + +import ( + "os/exec" + "strconv" +) + +// Set calls feh to set the background +func Set(path string) error { + err := exec.Command("osascript", "-e", `tell application "System Events" to tell every desktop to set picture to `+strconv.Quote(path)).Run() + return err +} diff --git a/pkg/background/set_unix.go b/pkg/background/set_unix.go new file mode 100644 index 0000000..cd75ae3 --- /dev/null +++ b/pkg/background/set_unix.go @@ -0,0 +1,30 @@ +// +build linux netbsd openbsd freebsd dragonfly + +package background + +import ( + "fmt" + "os" + "os/exec" +) + +// Set calls feh to set the background +func Set(path string) error { + var err error + switch os.Getenv("XDG_CURRENT_DESKTOP") { + case "GNOME", "Unity", "Pantheon": + path = fmt.Sprintf("%s%s", "file://", path) + err = exec.Command("gsettings", "set org.gnome.desktop.background picture-uri", path).Run() + return err + case "LXDE": + err = exec.Command("pcmanfm", "-w", path).Run() + return err + default: + feh, err := exec.LookPath("feh") + if err != nil { + return err + } + err = exec.Command(feh, "--bg-fill", path).Run() + return err + } +} -- cgit 1.4.1-2-gfad0