Beispiel #1
0
// Load user configuration if needed and initialise applet.
//
func (app *AppletGmail) Init(loadConf bool) {
	if loadConf { // Try to load config. Exit if not found.
		app.conf = &mailConf{}
		log.Fatal(app.LoadConfig(&app.conf, dock.GetKey), "config")
	}
	log.SetDebug(app.conf.Debug)

	// Reset data to be sure our display will be refreshed.
	app.data.Clear()
	app.err = nil

	// Fill config empty settings.
	if app.conf.MonitorName == "" {
		app.conf.MonitorName = app.conf.DefaultMonitorName
	}
	if app.conf.AlertSoundFile == "" {
		app.conf.AlertSoundFile = app.conf.DefaultAlertSoundFile
	}
	if app.conf.UpdateDelay == 0 {
		app.conf.UpdateDelay = defaultUpdateDelay
	}

	// Set defaults to dock icon: display and controls.
	def := cdtype.Defaults{
		Shortkeys: []string{app.conf.ShortkeyOpen, app.conf.ShortkeyCheck},
		Label:     "Mail unchecked",
		Templates: []string{"InternalDialog"},
	}
	if app.conf.Icon != "" && app.conf.Renderer != EmblemSmall && app.conf.Renderer != EmblemLarge { // User selected icon.
		def.Icon = app.conf.Icon
	}
	if app.conf.MonitorEnabled {
		def.MonitorName = app.conf.MonitorName
	}
	app.SetDefaults(def)

	// Create the renderer.
	switch app.conf.Renderer {
	case QuickInfo:
		app.render = NewRenderedQuick(app.CDApplet)

	case EmblemSmall, EmblemLarge:
		app.render = NewRenderedSVG(app.CDApplet, app.conf.Renderer)

	default: // NoDisplay case, but using default to be sure we have a valid renderer.
		app.render = NewRenderedNone()
	}

	// Configure the mail polling loop.
	app.poller.SetInterval(app.conf.UpdateDelay)
}
Beispiel #2
0
func (h *GameHub) Run() {
	log.SetPrefix("GameHub")
	log.SetDebug(true)
	log.Info("Started GameHub")

	h.createDemoRooms()

	//InitTest()
	h.TestQuiz()

	for {
		select {

		// Player entered lobby.
		case p := <-h.register:
			h.players[p.id] = p
			h.connections[p.conn] = true
			h.lobby.addPlayer(p)
			log.Debug("Added Player " + p.id)

		// Player exited website.
		case p := <-h.unregister:
			delete(h.players, p.id)
			delete(h.connections, p.conn)
			close(p.conn.send)
			log.Debug("Player " + p.id + " exited")

		// Distribute broadcast messages to all connections.
		case m := <-h.broadcast:
			if h.handleMessage(m) != true {
				for c := range h.connections {
					select {
					case c.send <- m:
					default:
						delete(h.connections, c)
						close(c.send)
						go c.ws.Close()
					}
				}
			}
		}
	}
}