Merge lp:~chipaca/ubuntu-push/fixes-to-app_helper into lp:ubuntu-push

Proposed by John Lenton
Status: Superseded
Proposed branch: lp:~chipaca/ubuntu-push/fixes-to-app_helper
Merge into: lp:ubuntu-push
Diff against target: 230 lines (+77/-43)
5 files modified
bus/notifications/app_helper/app_helper_c.go (+17/-13)
client/client.go (+9/-6)
client/client_test.go (+5/-3)
client/service/postal.go (+14/-21)
client/service/postal_test.go (+32/-0)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/fixes-to-app_helper
Reviewer Review Type Date Requested Status
Ubuntu Push Hackers Pending
Review via email: mp+225499@code.launchpad.net

This proposal has been superseded by a proposal from 2014-07-03.

Commit message

fixes to app_helper

Description of the change

Fixes to app_helper

To post a comment you must log in.
216. By John Lenton

commented the surprising bit

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bus/notifications/app_helper/app_helper_c.go'
2--- bus/notifications/app_helper/app_helper_c.go 2014-06-26 17:03:34 +0000
3+++ bus/notifications/app_helper/app_helper_c.go 2014-07-03 14:52:16 +0000
4@@ -19,23 +19,27 @@
5
6 /*
7 #cgo pkg-config: gio-unix-2.0
8-#cgo pkg-config: gio-2.0
9-#include <stdlib.h>
10 #include <glib.h>
11 #include <gio/gdesktopappinfo.h>
12+
13+gchar* app_icon_filename_from_id (gchar* app_id) {
14+ gchar* filename = NULL;
15+ GAppInfo* app_info = (GAppInfo*)g_desktop_app_info_new (app_id);
16+ if (app_info != NULL) {
17+ GIcon* icon = g_app_info_get_icon (app_info);
18+ if (icon != NULL) {
19+ filename = g_icon_to_string (icon);
20+ }
21+ g_object_unref (app_info);
22+ }
23+ g_free (app_id);
24+ return filename;
25+}
26 */
27 import "C"
28-import "unsafe"
29
30 func AppIconFromId(appId string) string {
31- _id := C.CString(appId)
32- defer C.free(unsafe.Pointer(_id))
33- _app_info := C.g_desktop_app_info_new(_id)
34- defer C.g_app_info_delete(_app_info)
35- _app_icon := C.g_app_info_get_icon(_app_info)
36- defer C.g_object_unref((C.gpointer)(_app_icon))
37- _icon_string := C.g_icon_to_string(_app_icon)
38- defer C.free(unsafe.Pointer(_icon_string))
39- name := C.GoString((*C.char)(_icon_string))
40- return name
41+ name := C.app_icon_filename_from_id((*C.gchar)(C.CString(appId)))
42+ defer C.g_free((C.gpointer)(name))
43+ return C.GoString((*C.char)(name))
44 }
45
46=== modified file 'client/client.go'
47--- client/client.go 2014-07-01 11:55:30 +0000
48+++ client/client.go 2014-07-03 14:52:16 +0000
49@@ -320,9 +320,7 @@
50 if !client.filterBroadcastNotification(msg) {
51 return nil
52 }
53- not_id, err := client.postalService.SendNotification(service.ACTION_ID_BROADCAST,
54- "update_manager_icon", "There's an updated system image.",
55- "Tap to open the system updater.")
56+ not_id, err := client.postalService.InjectBroadcast()
57 if err != nil {
58 client.log.Errorf("showing notification: %s", err)
59 return err
60@@ -338,15 +336,20 @@
61 }
62
63 // handleClick deals with the user clicking a notification
64-func (client *PushClient) handleClick(action_id string) error {
65+func (client *PushClient) handleClick(actionId string) error {
66 // “The string is a stark data structure and everywhere it is passed
67 // there is much duplication of process. It is a perfect vehicle for
68 // hiding information.”
69 //
70 // From ACM's SIGPLAN publication, (September, 1982), Article
71 // "Epigrams in Programming", by Alan J. Perlis of Yale University.
72- url := strings.TrimPrefix(action_id, service.ACTION_ID_SNOWFLAKE)
73- if len(url) == len(action_id) || len(url) == 0 {
74+ url := actionId
75+ // XXX: branch for the broadcast notifications
76+ if strings.HasPrefix(actionId, service.ACTION_ID_PREFIX) {
77+ parts := strings.Split(actionId, "::")
78+ url = parts[1]
79+ }
80+ if len(url) == len(actionId) || len(url) == 0 {
81 // it didn't start with the prefix
82 return nil
83 }
84
85=== modified file 'client/client_test.go'
86--- client/client_test.go 2014-07-01 11:55:30 +0000
87+++ client/client_test.go 2014-07-03 14:52:16 +0000
88@@ -712,6 +712,8 @@
89 handleClick tests
90 ******************************************************************/
91
92+var ACTION_ID_BROADCAST = service.ACTION_ID_PREFIX + service.SystemUpdateUrl + service.ACTION_ID_SUFFIX
93+
94 func (cs *clientSuite) TestHandleClick(c *C) {
95 cli := NewPushClient(cs.configPath, cs.leveldbPath)
96 cli.log = cs.log
97@@ -723,14 +725,14 @@
98 args := testibus.GetCallArgs(endp)
99 c.Assert(args, HasLen, 0)
100 // check we worked with the right action id
101- c.Check(cli.handleClick(service.ACTION_ID_BROADCAST), IsNil)
102+ c.Check(cli.handleClick(ACTION_ID_BROADCAST), IsNil)
103 // check we sent the notification
104 args = testibus.GetCallArgs(endp)
105 c.Assert(args, HasLen, 1)
106 c.Check(args[0].Member, Equals, "DispatchURL")
107 c.Check(args[0].Args, DeepEquals, []interface{}{service.SystemUpdateUrl})
108 // check we worked with the right action id
109- c.Check(cli.handleClick(service.ACTION_ID_SNOWFLAKE+"foo"), IsNil)
110+ c.Check(cli.handleClick(service.ACTION_ID_PREFIX+"foo"), IsNil)
111 // check we sent the notification
112 args = testibus.GetCallArgs(endp)
113 c.Assert(args, HasLen, 2)
114@@ -879,7 +881,7 @@
115 c.Check(cs.log.Captured(), Matches, "(?ms).*Session connected after 42 attempts$")
116
117 // * actionsCh to the click handler/url dispatcher
118- aCh <- notifications.RawActionReply{ActionId: service.ACTION_ID_BROADCAST}
119+ aCh <- notifications.RawActionReply{ActionId: ACTION_ID_BROADCAST}
120 tick()
121 uargs := testibus.GetCallArgs(cli.urlDispatcherEndp)
122 c.Assert(uargs, HasLen, 1)
123
124=== modified file 'client/service/postal.go'
125--- client/service/postal.go 2014-07-01 11:55:30 +0000
126+++ client/service/postal.go 2014-07-03 14:52:16 +0000
127@@ -20,7 +20,6 @@
128 "strings"
129
130 "code.google.com/p/go-uuid/uuid"
131- "launchpad.net/go-dbus/v1"
132
133 "launchpad.net/ubuntu-push/bus"
134 "launchpad.net/ubuntu-push/bus/notifications"
135@@ -50,9 +49,9 @@
136 )
137
138 var (
139- SystemUpdateUrl = "settings:///system/system-update"
140- ACTION_ID_SNOWFLAKE = "::ubuntu-push-client::"
141- ACTION_ID_BROADCAST = ACTION_ID_SNOWFLAKE + SystemUpdateUrl
142+ SystemUpdateUrl = "settings:///system/system-update"
143+ ACTION_ID_PREFIX = "ubuntu-push-client::"
144+ ACTION_ID_SUFFIX = "::0"
145 )
146
147 // NewPostalService() builds a new service and returns it.
148@@ -90,9 +89,7 @@
149 }
150
151 func (svc *PostalService) TakeTheBus() (<-chan notifications.RawActionReply, error) {
152- iniCh := make(chan uint32)
153- go func() { iniCh <- util.NewAutoRedialer(svc.notificationsEndp).Redial() }()
154- <-iniCh
155+ util.NewAutoRedialer(svc.notificationsEndp).Redial()
156 actionsCh, err := notifications.Raw(svc.notificationsEndp, svc.Log).WatchActions()
157 return actionsCh, err
158 }
159@@ -164,18 +161,14 @@
160 return err
161 }
162
163-func (svc *PostalService) SendNotification(action_id, icon, summary, body string) (uint32, error) {
164- a := []string{action_id, "Switch to app"} // action value not visible on the phone
165- h := map[string]*dbus.Variant{"x-canonical-switch-to-application": &dbus.Variant{true}}
166- nots := notifications.Raw(svc.notificationsEndp, svc.Log)
167- return nots.Notify(
168- "ubuntu-push-client", // app name
169- uint32(0), // id
170- icon, // icon
171- summary, // summary
172- body, // body
173- a, // actions
174- h, // hints
175- int32(10*1000), // timeout (ms)
176- )
177+func (svc *PostalService) InjectBroadcast() (uint32, error) {
178+ // XXX: call a helper?
179+ // XXX: Present force us to send the url as the notificationId
180+ icon := "update_manager_icon"
181+ summary := "There's an updated system image."
182+ body := "Tap to open the system updater."
183+ actions := []string{"Switch to app"} // action value not visible on the phone
184+ card := &launch_helper.Card{Icon: icon, Summary: summary, Body: body, Actions: actions, Popup: true}
185+ output := &launch_helper.HelperOutput{[]byte(""), &launch_helper.Notification{Card: card}}
186+ return 0, svc.msgHandler("ubuntu-push-client", SystemUpdateUrl, output)
187 }
188
189=== modified file 'client/service/postal_test.go'
190--- client/service/postal_test.go 2014-07-01 11:55:30 +0000
191+++ client/service/postal_test.go 2014-07-03 14:52:16 +0000
192@@ -157,6 +157,38 @@
193 }
194
195 //
196+// Injection (Broadcast) tests
197+
198+func (ss *postalSuite) TestInjectBroadcast(c *C) {
199+ bus := testibus.NewTestingEndpoint(nil, condition.Work(true), uint32(1))
200+ svc := NewPostalService(ss.bus, bus, ss.log)
201+ //svc.msgHandler = nil
202+ rvs, err := svc.InjectBroadcast()
203+ c.Assert(err, IsNil)
204+ c.Check(rvs, Equals, uint32(0))
205+ c.Assert(err, IsNil)
206+ // and check it fired the right signal (twice)
207+ callArgs := testibus.GetCallArgs(bus)
208+ c.Assert(callArgs, HasLen, 1)
209+ c.Check(callArgs[0].Member, Equals, "Notify")
210+ c.Check(callArgs[0].Args[0:6], DeepEquals, []interface{}{"ubuntu-push-client", uint32(0), "update_manager_icon",
211+ "There's an updated system image.", "Tap to open the system updater.",
212+ []string{"ubuntu-push-client::settings:///system/system-update::0", "Switch to app"}})
213+ // TODO: check the map in callArgs?
214+ // c.Check(callArgs[0].Args[7]["x-canonical-secondary-icon"], NotNil)
215+ // c.Check(callArgs[0].Args[7]["x-canonical-snap-decisions"], NotNil)
216+}
217+
218+func (ss *postalSuite) TestInjectBroadcastFails(c *C) {
219+ bus := testibus.NewTestingEndpoint(condition.Work(true),
220+ condition.Work(false))
221+ svc := NewPostalService(ss.bus, bus, ss.log)
222+ svc.SetMessageHandler(func(string, string, *launch_helper.HelperOutput) error { return errors.New("fail") })
223+ _, err := svc.InjectBroadcast()
224+ c.Check(err, NotNil)
225+}
226+
227+//
228 // Notifications tests
229 func (ss *postalSuite) TestNotificationsWorks(c *C) {
230 svc := NewPostalService(ss.bus, ss.notifBus, ss.log)

Subscribers

People subscribed via source and target branches