summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ui/account.go47
1 files changed, 32 insertions, 15 deletions
diff --git a/ui/account.go b/ui/account.go
index 0cd61c8..f8dcce8 100644
--- a/ui/account.go
+++ b/ui/account.go
@@ -11,11 +11,12 @@ import (
 )
 
 type AccountTab struct {
-	Config  *config.AccountConfig
-	Worker  worker.Worker
-	Parent  *UIState
-	logger  *log.Logger
-	counter int
+	Config    *config.AccountConfig
+	Worker    worker.Worker
+	Parent    *UIState
+	logger    *log.Logger
+	counter   int
+	callbacks map[types.WorkerMessage]func(msg types.WorkerMessage)
 }
 
 func NewAccountTab(conf *config.AccountConfig,
@@ -26,13 +27,21 @@ func NewAccountTab(conf *config.AccountConfig,
 		return nil, err
 	}
 	go work.Run()
-	work.PostAction(types.Configure{Config: conf})
-	work.PostAction(types.Connect{})
-	return &AccountTab{
-		Config: conf,
-		Worker: work,
-		logger: logger,
-	}, nil
+	acc := &AccountTab{
+		Config:    conf,
+		Worker:    work,
+		logger:    logger,
+		callbacks: make(map[types.WorkerMessage]func(msg types.WorkerMessage)),
+	}
+	acc.postAction(types.Configure{Config: conf}, nil)
+	acc.postAction(types.Connect{}, func(msg types.WorkerMessage) {
+		if _, ok := msg.(types.Ack); ok {
+			acc.logger.Println("Connected.")
+		} else {
+			acc.logger.Println("Connection failed.")
+		}
+	})
+	return acc, nil
 }
 
 func (acc *AccountTab) Name() string {
@@ -62,13 +71,21 @@ func (acc *AccountTab) GetChannel() chan types.WorkerMessage {
 	return acc.Worker.GetMessages()
 }
 
-func (acc *AccountTab) postAction(msg types.WorkerMessage) {
+func (acc *AccountTab) postAction(msg types.WorkerMessage,
+	cb func(msg types.WorkerMessage)) {
+
 	acc.logger.Printf("-> %T\n", msg)
 	acc.Worker.PostAction(msg)
+	if cb != nil {
+		acc.callbacks[msg] = cb
+	}
 }
 
 func (acc *AccountTab) HandleMessage(msg types.WorkerMessage) {
 	acc.logger.Printf("<- %T\n", msg)
+	if cb, ok := acc.callbacks[msg.InResponseTo()]; ok {
+		cb(msg)
+	}
 	switch msg.(type) {
 	case types.Ack:
 		// no-op
@@ -77,10 +94,10 @@ func (acc *AccountTab) HandleMessage(msg types.WorkerMessage) {
 		acc.logger.Println("Approving certificate")
 		acc.postAction(types.Ack{
 			Message: types.RespondTo(msg),
-		})
+		}, nil)
 	default:
 		acc.postAction(types.Unsupported{
 			Message: types.RespondTo(msg),
-		})
+		}, nil)
 	}
 }
+0000 committer James Booth <boothj5@gmail.com> 2014-01-19 16:32:31 +0000 Added tests/config/helpers' href='/danisanti/profani-tty/commit/tests/config/helpers.c?id=5f25d99357bd126bbae99c585cc9d84c265b62fc'>5f25d993 ^
6ef1174b ^

a2726b6a ^

6ef1174b ^




a2726b6a ^

6ef1174b ^

a3a73cf0 ^
6ef1174b ^

6ef1174b ^
5f25d993 ^
a2726b6a ^

6ef1174b ^




a2726b6a ^

6ef1174b ^

a2726b6a ^
cb590dd8 ^
10ca3e8c ^
cb590dd8 ^
9b5cdf8e ^
5f25d993 ^

a2726b6a ^

5f25d993 ^
a7a28506 ^

6ef1174b ^
a7a28506 ^
5f25d993 ^
3d7d070b ^
a2726b6a ^

f7843def ^
36790dc2 ^
f7843def ^


a2726b6a ^

f7843def ^

36790dc2 ^
f7843def ^

2cdbfc7e ^
a2726b6a ^
2cdbfc7e ^



a2726b6a ^
2cdbfc7e ^
a2726b6a ^
2cdbfc7e ^








3d7d070b ^








a2726b6a ^
3d7d070b ^
a2726b6a ^

3d7d070b ^
a2726b6a ^
3d7d070b ^
a2726b6a ^
3d7d070b ^





a2726b6a ^

3d7d070b ^







a2726b6a ^
3d7d070b ^








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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141