aboutsummaryrefslogtreecommitdiff
path: root/cmd/aerc/main.go
blob: 420d7a825249887e49f2f2bc9603b366e19fae2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main

import (
	"time"

	"git.sr.ht/~sircmpwn/aerc2/config"
	"git.sr.ht/~sircmpwn/aerc2/ui"
	"git.sr.ht/~sircmpwn/aerc2/worker"
	"git.sr.ht/~sircmpwn/aerc2/worker/types"
)

func main() {
	conf, err := config.LoadConfig(nil)
	if err != nil {
		panic(err)
	}
	_ui, err := ui.Initialize(conf)
	if err != nil {
		panic(err)
	}
	defer _ui.Close()
	var workers []worker.Worker
	for _, account := range conf.Accounts {
		work, err := worker.NewWorker(account.Source)
		if err != nil {
			panic(err)
		}
		go work.Run()
		work.PostAction(types.Configure{Config: account})
		workers = append(workers, work)
		// TODO: Give tabs ownership over their workers
		_ui.AddTab(ui.NewAccountTab(&account, &work))
	}
	for !_ui.Exit {
		activity := false
		for _, worker := range workers {
			if msg := worker.GetMessage(); msg != nil {
				activity = true
			}
		}
		activity = _ui.Tick() || activity
		if !activity {
			time.Sleep(100 * time.Millisecond)
		}
	}
}