Skip to content

Commit

Permalink
Merge pull request #369 from wowsims/add_version_ui
Browse files Browse the repository at this point in the history
Added UI icon for binary download and updates
  • Loading branch information
lologarithm authored Feb 13, 2022
2 parents bda6a24 + bfbaaf7 commit b9a6e22
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
1 change: 1 addition & 0 deletions assets/gauge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 11 additions & 4 deletions sim/web/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ func init() {
}

var (
Version string
Version string
outdated int
)

func main() {
Expand All @@ -48,7 +49,7 @@ func main() {
flag.Parse()

fmt.Printf("Version: %s\n", Version)
if !*skipVersionCheck {
if !*skipVersionCheck && Version != "development" {
go func() {
resp, err := http.Get("https://api.github.com/repos/wowsims/tbc/releases/latest")
if err != nil {
Expand All @@ -64,7 +65,10 @@ func main() {
json.Unmarshal(body, &result)

if result.Tag != Version {
outdated = 2
fmt.Printf("New version of simulator available: %s\n", result.URL)
} else {
outdated = 1
}
}()
}
Expand Down Expand Up @@ -175,7 +179,6 @@ func setupAsyncServer() {
http.HandleFunc("/asyncProgress", func(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
if err != nil {

return
}
msg := &proto.AsyncAPIResult{}
Expand Down Expand Up @@ -221,6 +224,10 @@ func runServer(useFS bool, host string, launchBrowser bool, simName string, wasm
fs = http.FileServer(http.FS(dist.FS))
}

http.HandleFunc("/version", func(resp http.ResponseWriter, req *http.Request) {
msg := fmt.Sprintf(`{"version": "%s", "outdated": %d}`, Version, outdated)
resp.Write([]byte(msg))
})
http.HandleFunc("/statWeights", handleAPI)
http.HandleFunc("/computeStats", handleAPI)
http.HandleFunc("/individualSim", handleAPI)
Expand All @@ -233,7 +240,7 @@ func runServer(useFS bool, host string, launchBrowser bool, simName string, wasm
<html><body><a href="/tbc/elemental_shaman">Elemental Shaman Sim</a"><br>
<html><body><a href="/tbc/enhancement_shaman">Enhancement Shaman Sim</a"><br>
<a href="/tbc/balance_druid">Balance Druid Sim</a"><br>
<a href="/tbc/hunter">Hunter Sim</a"></body></html>
<a href="/tbc/hunter">Hunter Sim</a"></body><br>
<a href="/tbc/mage">Mage Sim</a"><br>
<a href="/tbc/shadow_priest">Shadow Priest Sim</a"></body></html>
`))
Expand Down
16 changes: 16 additions & 0 deletions ui/core/_sim_ui.scss
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,19 @@ input, select {
font-size: 14px;
font-weight: 900;
}

.downbin {
mask: url(/tbc/assets/gauge.svg);
mask-size: cover;
display: inline-block;
width: 22px;
height: 22px;
}

.downbinnorm {
background-color: white;
}

.downbinalert {
background-color: red;
}
29 changes: 29 additions & 0 deletions ui/core/sim_ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,35 @@ export abstract class SimUI extends Component {
}
});
}

const downloadBinary = document.createElement('span');
// downloadBinary.src = "/tbc/assets/gauge.svg"
downloadBinary.classList.add('downbin');
downloadBinary.addEventListener('click', event => {
window.open('https://github.com/wowsims/tbc/releases', '_blank');
});

if (document.location.href.includes("localhost")) {
fetch(document.location.protocol+"//"+document.location.host+"/version").then(resp=>{
resp.json().then((versionInfo) => {
if (versionInfo.outdated == 2) {
tippy(downloadBinary, {
'content': 'Newer version of simulator available for download',
'allowHTML': true,
});
downloadBinary.classList.add('downbinalert');
this.addToolbarItem(downloadBinary);
}
})
})
} else {
tippy(downloadBinary, {
'content': 'Download simulator for faster simulating',
'allowHTML': true,
});
downloadBinary.classList.add('downbinnorm');
this.addToolbarItem(downloadBinary);
}
}

addAction(name: string, cssClass: string, actFn: () => void) {
Expand Down

0 comments on commit b9a6e22

Please sign in to comment.