Example #1
0
func WaitStopTime() {
	var first bool
	for {
		if utils.DB == nil || utils.DB.DB == nil {
			utils.Sleep(3)
			continue
		}
		if !first {
			err := utils.DB.ExecSql(`DELETE FROM stop_daemons`)
			if err != nil {
				log.Error("%v", utils.ErrInfo(err))
			}
			first = true
		}
		dExists, err := utils.DB.Single(`SELECT stop_time FROM stop_daemons`).Int64()
		if err != nil {
			log.Error("%v", utils.ErrInfo(err))
		}
		log.Debug("dExtit: %d", dExists)
		if dExists > 0 {
			fmt.Println("Stop_daemons from DB!")
			for _, ch := range utils.DaemonsChans {
				fmt.Println("ch.ChBreaker<-true")
				ch.ChBreaker <- true
			}
			for _, ch := range utils.DaemonsChans {
				fmt.Println(<-ch.ChAnswer)
			}
			fmt.Println("Daemons killed")
			err := utils.DB.Close()
			if err != nil {
				log.Error("%v", utils.ErrInfo(err))
			}
			fmt.Println("DB Closed")
			err = os.Remove(*utils.Dir + "/dcoin.pid")
			if err != nil {
				log.Error("%v", utils.ErrInfo(err))
				panic(err)
			}
			fmt.Println("removed " + *utils.Dir + "/dcoin.pid")
			thrust.Exit()
			os.Exit(1)
		}
		utils.Sleep(1)
	}
}
Example #2
0
func main() {

	runtime.LockOSThread()

	var width uint = 800
	var height uint = 600
	var thrustWindow *window.Window
	if runtime.GOOS == "darwin" {
		height = 578
	}
	if utils.Desktop() && (winVer() >= 6 || winVer() == 0) {
		thrust.Start()
		thrustWindow = thrust.NewWindow(thrust.WindowOptions{
			RootUrl:  "http://localhost:8989/loader.html",
			HasFrame: true,
			Title:    "Dcoin",
			Size:     commands.SizeHW{Width: width, Height: height},
		})

		thrust.NewEventHandler("*", func(cr commands.CommandResponse) {
			//fmt.Println(fmt.Sprintf("======Event(%s %d) - Signaled by Command (%s)", cr.TargetID, cr.Type))
			if cr.TargetID > 1 && cr.Type == "closed" {
				if utils.DB != nil && utils.DB.DB != nil {
					utils.DB.ExecSql(`INSERT INTO stop_daemons(stop_time) VALUES (?)`, utils.Time())
				} else {
					thrust.Exit()
					os.Exit(0)
				}
			}
		})
		thrustWindow.Show()
		thrustWindow.Focus()
		go func() {
			http.HandleFunc("/static/img/main_loader.gif", main_loader)
			http.HandleFunc("/loader.html", main_loader_html)
			http.ListenAndServe(":8989", nil)
		}()
	}
	tray()

	go dcoin.Start("", thrustWindow)

	enterLoop()

}