event.Wait to be Poll

This commit is contained in:
cuu 2019-06-21 21:44:54 +08:00
parent df2cc2c931
commit 0833c64b9d
4 changed files with 38 additions and 46 deletions

View File

@ -0,0 +1,7 @@
ROM=/home/cpi/games/PCSX
ROM_SO=/home/cpi/apps/emulators/pcsx
EXT=bin,cue,img,mdf,pbp,toc,cbn,m3u,ccd
LAUNCHER=
TITLE=PS Roms
SO_URL=https://github.com/cuu/Pcsx/raw/master/pcsx.zip

View File

@ -347,7 +347,7 @@ func run() int {
running := true
for running {
ev := event.Wait()
ev := event.Poll()
if ev.Type == event.QUIT {
running = false
break
@ -475,6 +475,8 @@ func run() int {
main_screen.KeyDown(ev)
main_screen.LastKeyDown = everytime_keydown
}
gotime.Sleep(50*gotime.Millisecond)
}
return 0

View File

@ -105,7 +105,7 @@ func (self *RomSoConfirmPage) KeyDown(ev *event.Event) {
}else{
so_url := ec.SO_URL
self.DownloadPage.StartDownload(so_url,filepath.Dir(ec.ROM_SO))
go self.DownloadPage.StartDownload(so_url,filepath.Dir(ec.ROM_SO))
}
}
}

View File

@ -105,19 +105,16 @@ func (self *DownloadProcessPage) OnExitCb() {
}
// should be in a gorotine
func (self *DownloadProcessPage) UpdateProcessInterval() {
if self.TheTicker == nil {
func (self *DownloadProcessPage) UpdateProcessInterval() {
if self.Doing == true {
return
}
if self.Screen.CurPage() != self {
return
}
Loop:
self.Doing = true
for {
select {
case <-self.TheTicker.C:
gotime.Sleep(150 * gotime.Millisecond)
fmt.Printf(" transferred %v / %v bytes (%.2f%%)\n",
self.resp.BytesComplete(),
self.resp.Size,
@ -131,17 +128,22 @@ Loop:
self.SizeLabel.SetText(lb_str)
self.FileNameLabel.SetText(filepath.Base(self.resp.Filename))
self.Screen.Draw()
self.Screen.SwapAndShow()
case <-self.resp.Done:
// download is complete
fmt.Println("download is complete ",self.Value)
self.Value = 0
self.TheTicker.Stop()
self.Doing=false
break Loop
}
if self.resp.Progress() >= 1.0 {
// download is complete
fmt.Println("download is complete ",self.Value)
self.Value = 0
self.Doing=false
break
}
if self.Doing == false {
break
}
}
self.Doing=false
@ -176,8 +178,6 @@ Loop:
cmd := exec.Command("rm","-rf",filename)
cmd.Dir = self.DST_DIR
cmd.Run()
self.TheTicker.Stop()
self.DoneAndReturnUpLevel()
@ -215,40 +215,23 @@ func (self *DownloadProcessPage) StartDownload(_url,dst_dir string) {
fmt.Println("DownloadProcessPage StartDownload Invalid ",err)
return
}
self.req, _ = grab.NewRequest(self.DST_DIR, _url)
fmt.Printf("Downloading %v...\n", self.req.URL())
self.resp = self.Downloader.Do(self.req)
fmt.Printf(" %v\n", self.resp.HTTPResponse.Status)
self.TheTicker = gotime.NewTicker(100 * gotime.Millisecond)
if self.Doing == false {
self.Doing = true
go self.UpdateProcessInterval()
self.req, _ = grab.NewRequest(self.DST_DIR, _url)
fmt.Printf("Downloading %v...\n", self.req.URL())
self.resp = self.Downloader.Do(self.req)
fmt.Printf(" %v\n", self.resp.HTTPResponse.Status)
self.UpdateProcessInterval()
}
}
func (self *DownloadProcessPage) StopDownload() {
if self.TheTicker != nil {
self.TheTicker.Stop()
}
if self.resp != nil {
self.resp.Cancel()
}
self.Doing=false
}
func (self *DownloadProcessPage) KeyDown( ev *event.Event) {
if ev.Data["Key"] == CurKeys["A"] || ev.Data["Key"] == CurKeys["Menu"] {
self.StopDownload()
self.ReturnToUpLevelPage()