소스 검색

feat(ui): use open-golang pkg (#142)

ayntgl 4 년 전
부모
커밋
86c7adcac7
3개의 변경된 파일6개의 추가작업 그리고 26개의 파일을 삭제
  1. 1 0
      go.mod
  2. 2 0
      go.sum
  3. 3 26
      ui/messages.go

+ 1 - 0
go.mod

@@ -20,6 +20,7 @@ require (
 	github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
 	github.com/mattn/go-runewidth v0.0.13 // indirect
 	github.com/rivo/uniseg v0.2.0 // indirect
+	github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
 	golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect
 	golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 // indirect
 	golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect

+ 2 - 0
go.sum

@@ -31,6 +31,8 @@ github.com/rivo/tview v0.0.0-20220216162559-96063d6082f3 h1:crs4rrYnQqsZpz/Etjez
 github.com/rivo/tview v0.0.0-20220216162559-96063d6082f3/go.mod h1:WIfMkQNY+oq/mWwtsjOYHIZBuwthioY2srOmljJkTnk=
 github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
 github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
+github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 h1:JIAuq3EEf9cgbU6AtGPK4CTG3Zf6CKMNqf0MHTggAUA=
+github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog=
 github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=

+ 3 - 26
ui/messages.go

@@ -8,7 +8,6 @@ import (
 	"os/exec"
 	"path/filepath"
 	"regexp"
-	"runtime"
 	"strings"
 
 	"github.com/atotto/clipboard"
@@ -16,6 +15,7 @@ import (
 	"github.com/ayntgl/discordo/discord"
 	"github.com/gdamore/tcell/v2"
 	"github.com/rivo/tview"
+	"github.com/skratchdot/open-golang/open"
 )
 
 var linkRegex = regexp.MustCompile("https?://.+")
@@ -135,7 +135,7 @@ func (mtv *MessagesTextView) onInputCapture(e *tcell.EventKey) *tcell.EventKey {
 		if len(links) != 0 {
 			messageActionsList.AddItem("Open Link", "", 'l', func() {
 				for _, l := range links {
-					go Open(l)
+					go open.Run(l)
 				}
 			})
 		}
@@ -245,36 +245,13 @@ func onMessageActionsListSelected(app *App, mainText string, m *discordgo.Messag
 			}
 
 			f.Write(d)
-			go Open(f.Name())
+			go open.Run(f.Name())
 		}
 
 		app.SetRoot(app.MainFlex, false)
 	}
 }
 
-func Open(input string) {
-	switch runtime.GOOS {
-	case "windows":
-		cmd := exec.Command("cmd", "/C start "+input)
-		err := cmd.Run()
-		if err != nil {
-			return
-		}
-	case "darwin":
-		cmd := exec.Command("open", input)
-		err := cmd.Run()
-		if err != nil {
-			return
-		}
-	default: // Unix
-		cmd := exec.Command("xdg-open", input)
-		err := cmd.Run()
-		if err != nil {
-			return
-		}
-	}
-}
-
 type MessageInputField struct {
 	*tview.InputField
 	app *App