Repository navigation
Expand file tree
/
Copy pathjava_actions.go
More file actions
80 lines (76 loc) · 2.49 KB
/
Copy pathjava_actions.go
File metadata and controls
80 lines (76 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"context"
"sync"
"mcl/internal/app"
"mcl/internal/core/java"
"mcl/internal/core/meta"
"mcl/internal/platform"
launcherui "mcl/internal/ui"
"github.com/egoist/mygo"
)
func connectJava(ctx context.Context, workers *sync.WaitGroup, window *mygo.Window, shell *launcherui.Shell, service *app.JavaService) {
shell.ConnectJava(launcherui.JavaActions{
Inventory: func(selected string, done func(app.JavaInventory, error)) func() {
return marketWork(ctx, workers, window, func(ctx context.Context) (app.JavaInventory, error) {
return service.Inventory(ctx, selected)
}, done)
},
Pick: func(home bool, done func(app.JavaEnvironment, error)) func() {
return marketWork(ctx, workers, window, func(ctx context.Context) (app.JavaEnvironment, error) {
title := "选择 Java 可执行文件"
if home {
title = "选择 Java Home 或 JDK 目录"
}
files, err := mygo.Dialog.Open(mygo.OpenDialogOptions{
Parent: window, Title: title, ButtonLabel: "添加", Directory: home, TreatPackagesAsDirectories: true,
})
if err != nil {
return app.JavaEnvironment{}, err
}
if len(files) == 0 {
return app.JavaEnvironment{}, context.Canceled
}
path := files[0]
if home {
path = platform.JavaExecutable(path)
}
return service.Add(ctx, path)
}, done)
},
Remove: func(path string, done func(error)) {
background(ctx, workers, window, func(ctx context.Context) (struct{}, error) {
return struct{}{}, service.Remove(ctx, path)
}, func(_ struct{}, err error) { done(err) })
},
Catalog: func(major int, done func(java.Catalog, error)) func() {
return marketWork(ctx, workers, window, func(ctx context.Context) (java.Catalog, error) {
return service.Catalog(ctx, major, meta.CurrentPlatform())
}, done)
},
Install: func(p java.Package, progress func(java.Progress), done func(app.JavaEnvironment, error)) func() {
task, cancel := context.WithCancel(ctx)
workers.Go(func() {
defer cancel()
value, err := service.Install(task, p, func(p java.Progress) {
window.Update(func() {
if ctx.Err() == nil {
progress(p)
}
})
})
window.Update(func() {
if ctx.Err() == nil {
done(value, err)
}
})
})
return cancel
},
Open: func(path string, done func(error)) {
background(ctx, workers, window, func(context.Context) (struct{}, error) {
return struct{}{}, mygo.Shell.OpenPath(path)
}, func(_ struct{}, err error) { done(err) })
},
})
}