commit c42d39ee9f0af2dd211b2aa1c7174e278cadd2e4
parent db2488f471d2cb412c546ae4937fc40bfbc833f3
Author: Sean Enck <sean@ttypty.com>
Date: Sun, 5 Feb 2023 09:28:26 -0500
removing duplicated vars
Diffstat:
5 files changed, 30 insertions(+), 40 deletions(-)
diff --git a/internal/inputs/env.go b/internal/inputs/env.go
@@ -85,6 +85,8 @@ type (
Start int
End int
}
+ // SystemPlatform represents the platform lockbox is running on.
+ SystemPlatform string
)
func toString(windows []ColorWindow) string {
diff --git a/internal/platform/clipboard.go b/internal/platform/clipboard.go
@@ -75,16 +75,16 @@ func NewClipboard() (Clipboard, error) {
var copying []string
var pasting []string
switch sys {
- case MacOS:
+ case inputs.MacOSPlatform:
copying = []string{"pbcopy"}
pasting = []string{"pbpaste"}
- case LinuxX:
+ case inputs.LinuxXPlatform:
copying = []string{"xclip"}
pasting = []string{"xclip", "-o"}
- case LinuxWayland:
+ case inputs.LinuxWaylandPlatform:
copying = []string{"wl-copy"}
pasting = []string{"wl-paste"}
- case WindowsLinux:
+ case inputs.WindowsLinuxPlatform:
copying = []string{"clip.exe"}
pasting = []string{"powershell.exe", "-command", "Get-Clipboard"}
default:
diff --git a/internal/platform/clipboard_test.go b/internal/platform/clipboard_test.go
@@ -5,6 +5,7 @@ import (
"os"
"testing"
+ "github.com/enckse/lockbox/internal/inputs"
"github.com/enckse/lockbox/internal/platform"
)
@@ -21,7 +22,7 @@ func TestNoClipboard(t *testing.T) {
func TestMaxTime(t *testing.T) {
os.Setenv("LOCKBOX_NOCLIP", "no")
os.Setenv("LOCKBOX_CLIP_OSC52", "no")
- os.Setenv("LOCKBOX_PLATFORM", string(platform.LinuxWayland))
+ os.Setenv("LOCKBOX_PLATFORM", string(inputs.LinuxWaylandPlatform))
os.Setenv("LOCKBOX_CLIP_MAX", "")
c, err := platform.NewClipboard()
if err != nil {
@@ -54,7 +55,7 @@ func TestClipboardInstances(t *testing.T) {
os.Setenv("LOCKBOX_NOCLIP", "no")
os.Setenv("LOCKBOX_CLIP_MAX", "")
os.Setenv("LOCKBOX_CLIP_OSC52", "no")
- for _, item := range []platform.System{platform.MacOS, platform.LinuxWayland, platform.LinuxX, platform.WindowsLinux} {
+ for _, item := range []inputs.SystemPlatform{inputs.MacOSPlatform, inputs.LinuxWaylandPlatform, inputs.LinuxXPlatform, inputs.WindowsLinuxPlatform} {
os.Setenv("LOCKBOX_PLATFORM", string(item))
_, err := platform.NewClipboard()
if err != nil {
@@ -79,7 +80,7 @@ func TestOSC52(t *testing.T) {
func TestArgsOverride(t *testing.T) {
os.Setenv("LOCKBOX_CLIP_PASTE", "abc xyz 111")
os.Setenv("LOCKBOX_CLIP_OSC52", "no")
- os.Setenv("LOCKBOX_PLATFORM", string(platform.WindowsLinux))
+ os.Setenv("LOCKBOX_PLATFORM", string(inputs.WindowsLinuxPlatform))
c, _ := platform.NewClipboard()
cmd, args, ok := c.Args(true)
if cmd != "clip.exe" || len(args) != 0 || !ok {
diff --git a/internal/platform/core.go b/internal/platform/core.go
@@ -10,61 +10,47 @@ import (
"github.com/enckse/lockbox/internal/inputs"
)
-type (
- // System represents the platform lockbox is running on.
- System string
-)
-
const (
- // MacOS based systems.
- MacOS System = inputs.MacOSPlatform
- // LinuxWayland running Wayland.
- LinuxWayland System = inputs.LinuxWaylandPlatform
- // LinuxX running X.
- LinuxX System = inputs.LinuxXPlatform
- // WindowsLinux with WSL.
- WindowsLinux System = inputs.WindowsLinuxPlatform
- // Unknown platform.
- Unknown = ""
+ unknownPlatform = ""
)
// NewPlatform gets a new system platform.
-func NewPlatform() (System, error) {
+func NewPlatform() (inputs.SystemPlatform, error) {
env := os.Getenv(inputs.PlatformEnv)
if env != "" {
switch env {
- case string(MacOS):
- return MacOS, nil
- case string(LinuxWayland):
- return LinuxWayland, nil
- case string(WindowsLinux):
- return WindowsLinux, nil
- case string(LinuxX):
- return LinuxX, nil
+ case inputs.MacOSPlatform:
+ return inputs.MacOSPlatform, nil
+ case inputs.LinuxWaylandPlatform:
+ return inputs.LinuxWaylandPlatform, nil
+ case inputs.WindowsLinuxPlatform:
+ return inputs.WindowsLinuxPlatform, nil
+ case inputs.LinuxXPlatform:
+ return inputs.LinuxXPlatform, nil
default:
- return Unknown, errors.New("unknown platform mode")
+ return unknownPlatform, errors.New("unknown platform mode")
}
}
b, err := exec.Command("uname", "-a").Output()
if err != nil {
- return Unknown, err
+ return unknownPlatform, err
}
raw := strings.ToLower(strings.TrimSpace(string(b)))
parts := strings.Split(raw, " ")
switch parts[0] {
case "darwin":
- return MacOS, nil
+ return inputs.MacOSPlatform, nil
case "linux":
if strings.Contains(raw, "microsoft-standard-wsl") {
- return WindowsLinux, nil
+ return inputs.WindowsLinuxPlatform, nil
}
if strings.TrimSpace(os.Getenv("WAYLAND_DISPLAY")) == "" {
if strings.TrimSpace(os.Getenv("DISPLAY")) == "" {
- return Unknown, errors.New("unable to detect linux clipboard mode")
+ return unknownPlatform, errors.New("unable to detect linux clipboard mode")
}
- return LinuxX, nil
+ return inputs.LinuxXPlatform, nil
}
- return LinuxWayland, nil
+ return inputs.LinuxWaylandPlatform, nil
}
- return Unknown, errors.New("unable to detect clipboard mode")
+ return unknownPlatform, errors.New("unable to detect clipboard mode")
}
diff --git a/internal/platform/core_test.go b/internal/platform/core_test.go
@@ -4,11 +4,12 @@ import (
"os"
"testing"
+ "github.com/enckse/lockbox/internal/inputs"
"github.com/enckse/lockbox/internal/platform"
)
func TestNewPlatform(t *testing.T) {
- for _, item := range []platform.System{platform.MacOS, platform.LinuxWayland, platform.LinuxX, platform.WindowsLinux} {
+ for _, item := range []inputs.SystemPlatform{inputs.MacOSPlatform, inputs.LinuxWaylandPlatform, inputs.LinuxXPlatform, inputs.WindowsLinuxPlatform} {
os.Setenv("LOCKBOX_PLATFORM", string(item))
s, err := platform.NewPlatform()
if err != nil {