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
=== modified file 'bus/notifications/app_helper/app_helper_c.go'
--- bus/notifications/app_helper/app_helper_c.go 2014-06-26 17:03:34 +0000
+++ bus/notifications/app_helper/app_helper_c.go 2014-07-03 14:52:16 +0000
@@ -19,23 +19,27 @@
1919
20/*20/*
21#cgo pkg-config: gio-unix-2.021#cgo pkg-config: gio-unix-2.0
22#cgo pkg-config: gio-2.0
23#include <stdlib.h>
24#include <glib.h>22#include <glib.h>
25#include <gio/gdesktopappinfo.h>23#include <gio/gdesktopappinfo.h>
24
25gchar* app_icon_filename_from_id (gchar* app_id) {
26 gchar* filename = NULL;
27 GAppInfo* app_info = (GAppInfo*)g_desktop_app_info_new (app_id);
28 if (app_info != NULL) {
29 GIcon* icon = g_app_info_get_icon (app_info);
30 if (icon != NULL) {
31 filename = g_icon_to_string (icon);
32 }
33 g_object_unref (app_info);
34 }
35 g_free (app_id);
36 return filename;
37}
26*/38*/
27import "C"39import "C"
28import "unsafe"
2940
30func AppIconFromId(appId string) string {41func AppIconFromId(appId string) string {
31 _id := C.CString(appId)42 name := C.app_icon_filename_from_id((*C.gchar)(C.CString(appId)))
32 defer C.free(unsafe.Pointer(_id))43 defer C.g_free((C.gpointer)(name))
33 _app_info := C.g_desktop_app_info_new(_id)44 return C.GoString((*C.char)(name))
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}45}
4246
=== modified file 'client/client.go'
--- client/client.go 2014-07-01 11:55:30 +0000
+++ client/client.go 2014-07-03 14:52:16 +0000
@@ -320,9 +320,7 @@
320 if !client.filterBroadcastNotification(msg) {320 if !client.filterBroadcastNotification(msg) {
321 return nil321 return nil
322 }322 }
323 not_id, err := client.postalService.SendNotification(service.ACTION_ID_BROADCAST,323 not_id, err := client.postalService.InjectBroadcast()
324 "update_manager_icon", "There's an updated system image.",
325 "Tap to open the system updater.")
326 if err != nil {324 if err != nil {
327 client.log.Errorf("showing notification: %s", err)325 client.log.Errorf("showing notification: %s", err)
328 return err326 return err
@@ -338,15 +336,20 @@
338}336}
339337
340// handleClick deals with the user clicking a notification338// handleClick deals with the user clicking a notification
341func (client *PushClient) handleClick(action_id string) error {339func (client *PushClient) handleClick(actionId string) error {
342 // “The string is a stark data structure and everywhere it is passed340 // “The string is a stark data structure and everywhere it is passed
343 // there is much duplication of process. It is a perfect vehicle for341 // there is much duplication of process. It is a perfect vehicle for
344 // hiding information.”342 // hiding information.”
345 //343 //
346 // From ACM's SIGPLAN publication, (September, 1982), Article344 // From ACM's SIGPLAN publication, (September, 1982), Article
347 // "Epigrams in Programming", by Alan J. Perlis of Yale University.345 // "Epigrams in Programming", by Alan J. Perlis of Yale University.
348 url := strings.TrimPrefix(action_id, service.ACTION_ID_SNOWFLAKE)346 url := actionId
349 if len(url) == len(action_id) || len(url) == 0 {347 // XXX: branch for the broadcast notifications
348 if strings.HasPrefix(actionId, service.ACTION_ID_PREFIX) {
349 parts := strings.Split(actionId, "::")
350 url = parts[1]
351 }
352 if len(url) == len(actionId) || len(url) == 0 {
350 // it didn't start with the prefix353 // it didn't start with the prefix
351 return nil354 return nil
352 }355 }
353356
=== modified file 'client/client_test.go'
--- client/client_test.go 2014-07-01 11:55:30 +0000
+++ client/client_test.go 2014-07-03 14:52:16 +0000
@@ -712,6 +712,8 @@
712 handleClick tests712 handleClick tests
713******************************************************************/713******************************************************************/
714714
715var ACTION_ID_BROADCAST = service.ACTION_ID_PREFIX + service.SystemUpdateUrl + service.ACTION_ID_SUFFIX
716
715func (cs *clientSuite) TestHandleClick(c *C) {717func (cs *clientSuite) TestHandleClick(c *C) {
716 cli := NewPushClient(cs.configPath, cs.leveldbPath)718 cli := NewPushClient(cs.configPath, cs.leveldbPath)
717 cli.log = cs.log719 cli.log = cs.log
@@ -723,14 +725,14 @@
723 args := testibus.GetCallArgs(endp)725 args := testibus.GetCallArgs(endp)
724 c.Assert(args, HasLen, 0)726 c.Assert(args, HasLen, 0)
725 // check we worked with the right action id727 // check we worked with the right action id
726 c.Check(cli.handleClick(service.ACTION_ID_BROADCAST), IsNil)728 c.Check(cli.handleClick(ACTION_ID_BROADCAST), IsNil)
727 // check we sent the notification729 // check we sent the notification
728 args = testibus.GetCallArgs(endp)730 args = testibus.GetCallArgs(endp)
729 c.Assert(args, HasLen, 1)731 c.Assert(args, HasLen, 1)
730 c.Check(args[0].Member, Equals, "DispatchURL")732 c.Check(args[0].Member, Equals, "DispatchURL")
731 c.Check(args[0].Args, DeepEquals, []interface{}{service.SystemUpdateUrl})733 c.Check(args[0].Args, DeepEquals, []interface{}{service.SystemUpdateUrl})
732 // check we worked with the right action id734 // check we worked with the right action id
733 c.Check(cli.handleClick(service.ACTION_ID_SNOWFLAKE+"foo"), IsNil)735 c.Check(cli.handleClick(service.ACTION_ID_PREFIX+"foo"), IsNil)
734 // check we sent the notification736 // check we sent the notification
735 args = testibus.GetCallArgs(endp)737 args = testibus.GetCallArgs(endp)
736 c.Assert(args, HasLen, 2)738 c.Assert(args, HasLen, 2)
@@ -879,7 +881,7 @@
879 c.Check(cs.log.Captured(), Matches, "(?ms).*Session connected after 42 attempts$")881 c.Check(cs.log.Captured(), Matches, "(?ms).*Session connected after 42 attempts$")
880882
881 // * actionsCh to the click handler/url dispatcher883 // * actionsCh to the click handler/url dispatcher
882 aCh <- notifications.RawActionReply{ActionId: service.ACTION_ID_BROADCAST}884 aCh <- notifications.RawActionReply{ActionId: ACTION_ID_BROADCAST}
883 tick()885 tick()
884 uargs := testibus.GetCallArgs(cli.urlDispatcherEndp)886 uargs := testibus.GetCallArgs(cli.urlDispatcherEndp)
885 c.Assert(uargs, HasLen, 1)887 c.Assert(uargs, HasLen, 1)
886888
=== modified file 'client/service/postal.go'
--- client/service/postal.go 2014-07-01 11:55:30 +0000
+++ client/service/postal.go 2014-07-03 14:52:16 +0000
@@ -20,7 +20,6 @@
20 "strings"20 "strings"
2121
22 "code.google.com/p/go-uuid/uuid"22 "code.google.com/p/go-uuid/uuid"
23 "launchpad.net/go-dbus/v1"
2423
25 "launchpad.net/ubuntu-push/bus"24 "launchpad.net/ubuntu-push/bus"
26 "launchpad.net/ubuntu-push/bus/notifications"25 "launchpad.net/ubuntu-push/bus/notifications"
@@ -50,9 +49,9 @@
50)49)
5150
52var (51var (
53 SystemUpdateUrl = "settings:///system/system-update"52 SystemUpdateUrl = "settings:///system/system-update"
54 ACTION_ID_SNOWFLAKE = "::ubuntu-push-client::"53 ACTION_ID_PREFIX = "ubuntu-push-client::"
55 ACTION_ID_BROADCAST = ACTION_ID_SNOWFLAKE + SystemUpdateUrl54 ACTION_ID_SUFFIX = "::0"
56)55)
5756
58// NewPostalService() builds a new service and returns it.57// NewPostalService() builds a new service and returns it.
@@ -90,9 +89,7 @@
90}89}
9190
92func (svc *PostalService) TakeTheBus() (<-chan notifications.RawActionReply, error) {91func (svc *PostalService) TakeTheBus() (<-chan notifications.RawActionReply, error) {
93 iniCh := make(chan uint32)92 util.NewAutoRedialer(svc.notificationsEndp).Redial()
94 go func() { iniCh <- util.NewAutoRedialer(svc.notificationsEndp).Redial() }()
95 <-iniCh
96 actionsCh, err := notifications.Raw(svc.notificationsEndp, svc.Log).WatchActions()93 actionsCh, err := notifications.Raw(svc.notificationsEndp, svc.Log).WatchActions()
97 return actionsCh, err94 return actionsCh, err
98}95}
@@ -164,18 +161,14 @@
164 return err161 return err
165}162}
166163
167func (svc *PostalService) SendNotification(action_id, icon, summary, body string) (uint32, error) {164func (svc *PostalService) InjectBroadcast() (uint32, error) {
168 a := []string{action_id, "Switch to app"} // action value not visible on the phone165 // XXX: call a helper?
169 h := map[string]*dbus.Variant{"x-canonical-switch-to-application": &dbus.Variant{true}}166 // XXX: Present force us to send the url as the notificationId
170 nots := notifications.Raw(svc.notificationsEndp, svc.Log)167 icon := "update_manager_icon"
171 return nots.Notify(168 summary := "There's an updated system image."
172 "ubuntu-push-client", // app name169 body := "Tap to open the system updater."
173 uint32(0), // id170 actions := []string{"Switch to app"} // action value not visible on the phone
174 icon, // icon171 card := &launch_helper.Card{Icon: icon, Summary: summary, Body: body, Actions: actions, Popup: true}
175 summary, // summary172 output := &launch_helper.HelperOutput{[]byte(""), &launch_helper.Notification{Card: card}}
176 body, // body173 return 0, svc.msgHandler("ubuntu-push-client", SystemUpdateUrl, output)
177 a, // actions
178 h, // hints
179 int32(10*1000), // timeout (ms)
180 )
181}174}
182175
=== modified file 'client/service/postal_test.go'
--- client/service/postal_test.go 2014-07-01 11:55:30 +0000
+++ client/service/postal_test.go 2014-07-03 14:52:16 +0000
@@ -157,6 +157,38 @@
157}157}
158158
159//159//
160// Injection (Broadcast) tests
161
162func (ss *postalSuite) TestInjectBroadcast(c *C) {
163 bus := testibus.NewTestingEndpoint(nil, condition.Work(true), uint32(1))
164 svc := NewPostalService(ss.bus, bus, ss.log)
165 //svc.msgHandler = nil
166 rvs, err := svc.InjectBroadcast()
167 c.Assert(err, IsNil)
168 c.Check(rvs, Equals, uint32(0))
169 c.Assert(err, IsNil)
170 // and check it fired the right signal (twice)
171 callArgs := testibus.GetCallArgs(bus)
172 c.Assert(callArgs, HasLen, 1)
173 c.Check(callArgs[0].Member, Equals, "Notify")
174 c.Check(callArgs[0].Args[0:6], DeepEquals, []interface{}{"ubuntu-push-client", uint32(0), "update_manager_icon",
175 "There's an updated system image.", "Tap to open the system updater.",
176 []string{"ubuntu-push-client::settings:///system/system-update::0", "Switch to app"}})
177 // TODO: check the map in callArgs?
178 // c.Check(callArgs[0].Args[7]["x-canonical-secondary-icon"], NotNil)
179 // c.Check(callArgs[0].Args[7]["x-canonical-snap-decisions"], NotNil)
180}
181
182func (ss *postalSuite) TestInjectBroadcastFails(c *C) {
183 bus := testibus.NewTestingEndpoint(condition.Work(true),
184 condition.Work(false))
185 svc := NewPostalService(ss.bus, bus, ss.log)
186 svc.SetMessageHandler(func(string, string, *launch_helper.HelperOutput) error { return errors.New("fail") })
187 _, err := svc.InjectBroadcast()
188 c.Check(err, NotNil)
189}
190
191//
160// Notifications tests192// Notifications tests
161func (ss *postalSuite) TestNotificationsWorks(c *C) {193func (ss *postalSuite) TestNotificationsWorks(c *C) {
162 svc := NewPostalService(ss.bus, ss.notifBus, ss.log)194 svc := NewPostalService(ss.bus, ss.notifBus, ss.log)

Subscribers

People subscribed via source and target branches