-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
68 lines (57 loc) · 1.34 KB
/
main.go
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
//go:build js
package main
import (
"encoding/json"
"fmt"
"loldrivers-webclient/internal/loldrivers"
"syscall/js"
)
// Wrapper for loldrivers.MatchHash
func MatchHashWrapper(this js.Value, p []js.Value) interface{} {
hash := p[0].String()
if hash == "" {
return map[string]interface{}{
"driver": nil,
"ok": false,
}
}
// Fetch driver
ok, driver := loldrivers.MatchHash(hash)
if !ok {
// No driver
return map[string]interface{}{
"driver": nil,
"ok": false,
}
}
// To JSON
driverJson, err := json.Marshal(driver)
if err != nil {
return map[string]interface{}{
"driver": nil,
"ok": false,
}
}
return map[string]interface{}{
"driver": string(driverJson),
"ok": true,
}
}
func main() {
// Get the button from the DOM
jsDoc := js.Global().Get("document")
folderButton := jsDoc.Call("getElementById", "select-folder-button")
fmt.Println("Loading drivers")
if err := loldrivers.LoadDrivers(); err != nil {
fmt.Println(err)
folderButton.Set("innerHTML", "There was an error fetching the driver data, check the console")
return
}
fmt.Println("Registering lookupHash function")
js.Global().Set("lookupHash", js.FuncOf(MatchHashWrapper))
// Enable the button if we get here
folderButton.Set("innerHTML", "Select folder")
folderButton.Set("disabled", false)
// Do not quit
select {}
}