Skip to content

Commit

Permalink
1. 显示版本号
Browse files Browse the repository at this point in the history
  • Loading branch information
xr1627119275 committed Jan 13, 2021
1 parent f012f9e commit 29f8a11
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
29 changes: 26 additions & 3 deletions html/update.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ <h5>{{ data.body }}</h5>
<!-- import JavaScript -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>

window.addEventListener("load",()=>{
document.title += " "
})
Vue.component("VersionInfo", {
template: "#infolist",
props: {
Expand All @@ -111,7 +113,8 @@ <h5>{{ data.body }}</h5>
data: {
data: undefined,
extraData: [],
showMore: false
showMore: false,
versionSize: 0
},

methods: {
Expand All @@ -120,16 +123,36 @@ <h5>{{ data.body }}</h5>
},
showHistory() {
this.showMore = !this.showMore
}
},

},
async created(){
// let res = await fetch("https://api.github.com/repos/xr1627119275/batch-google-tran/releases")
// let data = await res.json()

this.versionSize = await getSize()
let data = JSON.parse(await getUpdateInfo())
console.log(data)
this.data = data?.[0] || undefined
this.extraData = data.slice(1)

console.log(this.data, data)
},
computed: {
version() {
let version = '[测试版]'
for (let i = 0; i < this.extraData; i++) {
let item = this.extraData[i]
if (item.asset[0].size == this.versionSize) {
version = `[${item.tag_name}]`
return version
}
}
return version
}
},
mounted() {
document.title = this.version + document.title
}
})
</script>
Expand Down
13 changes: 9 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func getInfo() (size int64, data string) {
fmt.Println(data)
r := regexp.MustCompile(`\"size\":(.+?),`)
if r.MatchString(data) {
fmt.Println(r.FindStringSubmatch(data))
var data = r.FindStringSubmatch(data)[1]
size, _ = strconv.ParseInt(data, 10, 64)
}
Expand All @@ -47,9 +48,11 @@ func CheckUpdate(size int64) {
}
func main() {
var size, data = getInfo()
if os.Getenv("Mode") != "dev" {
CheckUpdate(size)
}
CheckUpdate(size)
//
//if os.Getenv("Mode") != "dev" {
// CheckUpdate(size)
//}
mux := http.NewServeMux()
box := packr.NewBox("./html")
mux.Handle("/", http.FileServer(box))
Expand All @@ -65,7 +68,9 @@ func main() {

ui, _ := lorca.New("", "", 600, 900)
defer ui.Close()

ui.Bind("getSize", func() int64 {
return size
})
ui.Bind("getUpdateInfo", func() string {
return data
})
Expand Down

0 comments on commit 29f8a11

Please sign in to comment.