Skip to content

Commit e0f69a3

Browse files
committed
iina地址
1 parent d97e1c6 commit e0f69a3

2 files changed

Lines changed: 51 additions & 10 deletions

File tree

internal/player/iina.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,7 @@ func ActivateIINA() error {
6868
}
6969

7070
func resolveIINABin(configured string) (string, error) {
71-
candidates := []string{}
72-
if strings.TrimSpace(configured) != "" {
73-
candidates = append(candidates, strings.TrimSpace(configured))
74-
}
75-
candidates = append(candidates,
76-
"/Users/nuc/.local/bin/iina-cli",
77-
"/Applications/IINA.app/Contents/MacOS/iina-cli",
78-
"iina-cli",
79-
"iina",
80-
)
71+
candidates := iinaBinCandidates(configured)
8172
for _, candidate := range candidates {
8273
if candidate == "" {
8374
continue
@@ -95,6 +86,22 @@ func resolveIINABin(configured string) (string, error) {
9586
return "", fmt.Errorf("iina executable not found")
9687
}
9788

89+
func iinaBinCandidates(configured string) []string {
90+
candidates := []string{}
91+
if strings.TrimSpace(configured) != "" {
92+
candidates = append(candidates, strings.TrimSpace(configured))
93+
}
94+
if home, err := os.UserHomeDir(); err == nil && strings.TrimSpace(home) != "" {
95+
candidates = append(candidates, filepath.Join(home, ".local", "bin", "iina-cli"))
96+
}
97+
candidates = append(candidates,
98+
"/Applications/IINA.app/Contents/MacOS/iina-cli",
99+
"iina-cli",
100+
"iina",
101+
)
102+
return candidates
103+
}
104+
98105
func WaitForFirstSample(ctx context.Context, socketPath string) error {
99106
client := NewIPCClient(socketPath, 12*time.Second)
100107
if err := client.WaitUntilReady(ctx); err != nil {

internal/player/mpvipc_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package player
22

33
import (
44
"errors"
5+
"os"
6+
"path/filepath"
57
"testing"
68
)
79

@@ -21,3 +23,35 @@ func TestIsIdleStopError(t *testing.T) {
2123
t.Fatal("unexpected idle stop error when idle check fails")
2224
}
2325
}
26+
27+
func TestIINABinCandidates(t *testing.T) {
28+
configured := "/custom/iina-cli"
29+
candidates := iinaBinCandidates(configured)
30+
if len(candidates) < 4 {
31+
t.Fatalf("unexpected candidate count: %d", len(candidates))
32+
}
33+
if candidates[0] != configured {
34+
t.Fatalf("configured path not first: %#v", candidates)
35+
}
36+
if candidates[len(candidates)-3] != "/Applications/IINA.app/Contents/MacOS/iina-cli" {
37+
t.Fatalf("unexpected app candidate order: %#v", candidates)
38+
}
39+
if candidates[len(candidates)-2] != "iina-cli" || candidates[len(candidates)-1] != "iina" {
40+
t.Fatalf("unexpected path lookup order: %#v", candidates)
41+
}
42+
43+
home, err := os.UserHomeDir()
44+
if err == nil && home != "" {
45+
want := filepath.Join(home, ".local", "bin", "iina-cli")
46+
found := false
47+
for _, candidate := range candidates {
48+
if candidate == want {
49+
found = true
50+
break
51+
}
52+
}
53+
if !found {
54+
t.Fatalf("home candidate missing: want %q candidates=%#v", want, candidates)
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)