Skip to content

Commit 79a6bc1

Browse files
committed
feat: support linux(WIP)
1 parent f5e28a6 commit 79a6bc1

24 files changed

+648
-361
lines changed

build/darwin/icons.icns

98.1 KB
Binary file not shown.

internal/config/config.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@ type AppConfig struct {
1414
}
1515

1616
func localAppData() string {
17-
if v := os.Getenv("APPDATA"); strings.TrimSpace(v) != "" {
18-
return v
19-
}
20-
if v, _ := os.UserCacheDir(); strings.TrimSpace(v) != "" {
21-
return v
22-
}
23-
return "."
17+
if v, _ := os.UserConfigDir(); strings.TrimSpace(v) != "" {
18+
return v
19+
}
20+
return "."
2421
}
2522

2623
func configPath() string {

internal/explorer/explorer.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
//go:build windows
2+
13
package explorer
24

35
import (
4-
"log"
5-
"os"
6-
"os/exec"
7-
"path/filepath"
8-
"strings"
9-
"syscall"
10-
11-
"github.com/liteldev/LeviLauncher/internal/utils"
6+
"log"
7+
"os"
8+
"os/exec"
9+
"path/filepath"
10+
"strings"
11+
"syscall"
12+
"github.com/liteldev/LeviLauncher/internal/utils"
1213
)
1314

1415
func OpenPath(dir string) bool {
@@ -21,9 +22,9 @@ func OpenPath(dir string) bool {
2122
return false
2223
}
2324
}
24-
cmd := exec.Command("powershell", "explorer \""+d+"\"")
25-
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
26-
if err := cmd.Run(); err != nil {
25+
cmd := exec.Command("powershell", "explorer \""+d+"\"")
26+
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
27+
if err := cmd.Run(); err != nil {
2728
log.Println("explorer.OpenPath error:", err)
2829
return false
2930
}
@@ -35,9 +36,9 @@ func SelectFile(path string) bool {
3536
if p == "" || !utils.FileExists(p) {
3637
return false
3738
}
38-
cmd := exec.Command("explorer", "/select,\""+p+"\"")
39-
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
40-
if err := cmd.Run(); err != nil {
39+
cmd := exec.Command("explorer", "/select,\""+p+"\"")
40+
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
41+
if err := cmd.Run(); err != nil {
4142
log.Println("explorer.SelectFile error:", err)
4243
return false
4344
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//go:build linux
2+
3+
package explorer
4+
5+
import (
6+
"log"
7+
"os"
8+
"os/exec"
9+
"path/filepath"
10+
"strings"
11+
"github.com/liteldev/LeviLauncher/internal/utils"
12+
)
13+
14+
func OpenPath(dir string) bool {
15+
d := strings.TrimSpace(dir)
16+
if d == "" {
17+
return false
18+
}
19+
if !utils.DirExists(d) {
20+
if err := os.MkdirAll(d, 0755); err != nil {
21+
return false
22+
}
23+
}
24+
cmd := exec.Command("xdg-open", d)
25+
if err := cmd.Run(); err != nil {
26+
log.Println("explorer.OpenPath error:", err)
27+
return false
28+
}
29+
return true
30+
}
31+
32+
func SelectFile(path string) bool {
33+
p := strings.TrimSpace(path)
34+
if p == "" || !utils.FileExists(p) {
35+
return false
36+
}
37+
dir := filepath.Dir(p)
38+
cmd := exec.Command("xdg-open", dir)
39+
if err := cmd.Run(); err != nil {
40+
log.Println("explorer.SelectFile error:", err)
41+
return false
42+
}
43+
return true
44+
}
45+
46+
func OpenMods(name string) bool {
47+
n := strings.TrimSpace(name)
48+
if n == "" {
49+
return false
50+
}
51+
vdir, err := utils.GetVersionsDir()
52+
if err != nil || strings.TrimSpace(vdir) == "" {
53+
return false
54+
}
55+
dir := filepath.Join(vdir, n, "mods")
56+
return OpenPath(dir)
57+
}
58+
59+
func OpenWorlds(isPreview bool) bool {
60+
dir := filepath.Join(utils.GetMinecraftGDKDataPath(isPreview), "worlds")
61+
return OpenPath(dir)
62+
}
63+
64+
func OpenInstallers() bool {
65+
dir, err := utils.GetInstallerDir()
66+
if err != nil || dir == "" {
67+
return false
68+
}
69+
return OpenPath(dir)
70+
}

internal/extractor/extractor.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build windows
2+
13
package extractor
24

35
import (
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//go:build linux
2+
3+
package extractor
4+
5+
func Init() {}
6+
7+
func MiHoYo(msixvcPath string, outDir string) (int, string) {
8+
return 1, "ERR_APPX_INSTALL_UNSUPPORTED_ON_LINUX"
9+
}

internal/gameinput/gameinput.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build windows
2+
13
package gameinput
24

35
import (
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//go:build linux
2+
3+
package gameinput
4+
5+
import (
6+
"context"
7+
"sync"
8+
"github.com/wailsapp/wails/v3/pkg/application"
9+
)
10+
11+
var (
12+
mu sync.Mutex
13+
ensuring bool
14+
)
15+
16+
func IsInstalled() bool { return true }
17+
18+
func EnsureInteractive(ctx context.Context) {
19+
mu.Lock()
20+
if ensuring { mu.Unlock(); return }
21+
ensuring = true
22+
mu.Unlock()
23+
defer func(){ mu.Lock(); ensuring = false; mu.Unlock() }()
24+
application.Get().Event.Emit("gameinput.ensure.start", struct{}{})
25+
application.Get().Event.Emit("gameinput.ensure.done", struct{}{})
26+
}

internal/launch/launch.go

Lines changed: 0 additions & 65 deletions
This file was deleted.

internal/launch/launch_linux.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//go:build linux
2+
3+
package launch
4+
5+
import (
6+
"context"
7+
"github.com/wailsapp/wails/v3/pkg/application"
8+
)
9+
10+
const (
11+
EventMcLaunchStart = "mc.launch.start"
12+
EventMcLaunchDone = "mc.launch.done"
13+
EventMcLaunchFailed = "mc.launch.failed"
14+
EventGamingServicesMissing = "gamingservices.missing"
15+
)
16+
17+
func FindWindowByTitleExact(title string) bool { return false }
18+
19+
func EnsureGamingServicesInstalled(ctx context.Context) bool { return true }
20+
21+
func MonitorMinecraftWindow(ctx context.Context) {
22+
application.Get().Event.Emit(EventMcLaunchStart, struct{}{})
23+
application.Get().Event.Emit(EventMcLaunchDone, struct{}{})
24+
}

0 commit comments

Comments
 (0)