Merge lp:~mikemc/unity-scope-click/fix-1262780-use-dotdesktop into lp:unity-scope-click

Proposed by Mike McCracken
Status: Merged
Approved by: dobey
Approved revision: 98
Merged at revision: 97
Proposed branch: lp:~mikemc/unity-scope-click/fix-1262780-use-dotdesktop
Merge into: lp:unity-scope-click
Diff against target: 175 lines (+68/-9)
3 files modified
src/click-interface.vala (+6/-3)
src/click-scope.vala (+5/-6)
src/test-click-webservice.vala (+57/-0)
To merge this branch: bzr merge lp:~mikemc/unity-scope-click/fix-1262780-use-dotdesktop
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve
dobey (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+199730@code.launchpad.net

Commit message

- Send correct application:/// url to preview after install (LP: #1262780)

Description of the change

- Send correct application:/// url to preview after install (LP: #1262780)

Reinstate use of url generated from dot-desktop filename so that the "Open" button shown by the preview after install works.

Adds a few tests to verify correct installed preview generation.

Also avoids logging two lines for each installed app every time we get the list, which is fairly often.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
dobey (dobey) :
review: Approve
Revision history for this message
Roberto Alsina (ralsina) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/click-interface.vala'
--- src/click-interface.vala 2013-12-04 13:31:52 +0000
+++ src/click-interface.vala 2013-12-19 23:53:33 +0000
@@ -106,7 +106,7 @@
106 return versions;106 return versions;
107 }107 }
108108
109 public async string get_dotdesktop (string app_id) throws ClickError {109 public virtual async string get_dotdesktop (string app_id) throws ClickError {
110 foreach (var element in yield get_manifests()) {110 foreach (var element in yield get_manifests()) {
111 var manifest = element.get_object();111 var manifest = element.get_object();
112 var pkg_name = manifest.get_string_member("name");112 var pkg_name = manifest.get_string_member("name");
@@ -115,7 +115,10 @@
115 var hooks = manifest.get_object_member("hooks");115 var hooks = manifest.get_object_member("hooks");
116 foreach (var app_name in hooks.get_members()) {116 foreach (var app_name in hooks.get_members()) {
117 // FIXME: "Primary app" is not defined yet, so we take the first one117 // FIXME: "Primary app" is not defined yet, so we take the first one
118 return "%s_%s_%s.desktop".printf(pkg_name, app_name, version);118 var ddstr = "%s_%s_%s.desktop".printf(pkg_name, app_name, version);
119 debug ("get_dotdesktop: using first of %u hooks members, returning %s",
120 hooks.get_members().length(), ddstr);
121 return ddstr;
119 }122 }
120 }123 }
121 }124 }
@@ -123,7 +126,7 @@
123 throw new ClickError.EXEC_FAILURE(msg);126 throw new ClickError.EXEC_FAILURE(msg);
124 }127 }
125128
126 public async bool can_uninstall (string app_id) {129 public virtual async bool can_uninstall (string app_id) {
127 const string REMOVABLE_FIELD = "_removable";130 const string REMOVABLE_FIELD = "_removable";
128 GLib.List<weak Json.Node> manifests;131 GLib.List<weak Json.Node> manifests;
129 try {132 try {
130133
=== modified file 'src/click-scope.vala'
--- src/click-scope.vala 2013-12-17 20:17:01 +0000
+++ src/click-scope.vala 2013-12-19 23:53:33 +0000
@@ -148,10 +148,10 @@
148 return preview;148 return preview;
149 }149 }
150150
151 async Unity.Preview build_installed_preview (Unity.ScopeResult result) {151 public async Unity.Preview build_installed_preview (Unity.ScopeResult result, string application_uri) {
152 var app_id = result.metadata.get(METADATA_APP_ID).get_string();152 var app_id = result.metadata.get(METADATA_APP_ID).get_string();
153 Unity.Preview preview = yield build_app_preview (result);153 Unity.Preview preview = yield build_app_preview (result);
154 preview.add_action (new Unity.PreviewAction (ACTION_OPEN_CLICK + ":" + result.uri, ("Open"), null));154 preview.add_action (new Unity.PreviewAction (ACTION_OPEN_CLICK + ":" + application_uri, ("Open"), null));
155155
156 if (yield click_if.can_uninstall (app_id)) {156 if (yield click_if.can_uninstall (app_id)) {
157 preview.add_action (new Unity.PreviewAction (ACTION_UNINSTALL_CLICK, ("Uninstall"), null));157 preview.add_action (new Unity.PreviewAction (ACTION_UNINSTALL_CLICK, ("Uninstall"), null));
@@ -192,7 +192,7 @@
192 if (uri_is_click_install(result.uri)) {192 if (uri_is_click_install(result.uri)) {
193 return yield build_uninstalled_preview (result);193 return yield build_uninstalled_preview (result);
194 } else {194 } else {
195 return yield build_installed_preview (result);195 return yield build_installed_preview (result, result.uri);
196 }196 }
197 }197 }
198198
@@ -236,7 +236,7 @@
236 // application name *must* be in path part of URL as host part236 // application name *must* be in path part of URL as host part
237 // might get lowercased237 // might get lowercased
238 var application_uri = "application:///" + dotdesktop;238 var application_uri = "application:///" + dotdesktop;
239 preview = yield build_installed_preview (result);239 preview = yield build_installed_preview (result, application_uri);
240 } else if (action_id.has_prefix(ACTION_OPEN_CLICK)) {240 } else if (action_id.has_prefix(ACTION_OPEN_CLICK)) {
241 var application_uri = action_id.split(":", 2)[1];241 var application_uri = action_id.split(":", 2)[1];
242 debug ("Let the dash launch the app: %s", application_uri);242 debug ("Let the dash launch the app: %s", application_uri);
@@ -386,7 +386,6 @@
386386
387 private void add_app (App app, int category)387 private void add_app (App app, int category)
388 {388 {
389 debug (app.title);
390 var uri = app.uri;389 var uri = app.uri;
391 var comment = "";390 var comment = "";
392 var dnd_uri = uri;391 var dnd_uri = uri;
@@ -403,8 +402,8 @@
403 var result = Unity.ScopeResult.create(uri, app.icon_url, category, Unity.ResultType.DEFAULT, mimetype, app.title, comment, dnd_uri, metadata);402 var result = Unity.ScopeResult.create(uri, app.icon_url, category, Unity.ResultType.DEFAULT, mimetype, app.title, comment, dnd_uri, metadata);
404403
405 var download_progress = get_download_progress(app.app_id);404 var download_progress = get_download_progress(app.app_id);
406 debug ("download progress source for app %s: %s", app.app_id, download_progress);
407 if (download_progress != null) {405 if (download_progress != null) {
406 debug ("download in progress for %s: progress source path = %s", app.app_id, download_progress);
408 result.metadata.insert("show_progressbar", new Variant.boolean(true));407 result.metadata.insert("show_progressbar", new Variant.boolean(true));
409 result.metadata.insert("progressbar_source", new GLib.Variant.string(download_progress));408 result.metadata.insert("progressbar_source", new GLib.Variant.string(download_progress));
410 }409 }
411410
=== modified file 'src/test-click-webservice.vala'
--- src/test-click-webservice.vala 2013-12-19 19:58:49 +0000
+++ src/test-click-webservice.vala 2013-12-19 23:53:33 +0000
@@ -17,6 +17,7 @@
17using Assertions;17using Assertions;
1818
19const string FAKE_APP_ID = "FAKE_APP_ID";19const string FAKE_APP_ID = "FAKE_APP_ID";
20const string FAKE_DOT_DESKTOP = "FAKE_DOT_DESKTOP";
20const string FAKE_OBJECT_PATH = "/com/fake/object";21const string FAKE_OBJECT_PATH = "/com/fake/object";
21const string FAKE_DOWNLOAD_ERROR_MESSAGE = "fake generic download error message";22const string FAKE_DOWNLOAD_ERROR_MESSAGE = "fake generic download error message";
22const string FAKE_CREDS_ERROR_MESSAGE = "fake creds error message";23const string FAKE_CREDS_ERROR_MESSAGE = "fake creds error message";
@@ -121,6 +122,15 @@
121 parser.load_from_data (FAKE_APP_MANIFEST);122 parser.load_from_data (FAKE_APP_MANIFEST);
122 return parser.get_root().get_array().get_elements();123 return parser.get_root().get_array().get_elements();
123 }124 }
125
126 public override async string get_dotdesktop (string app_id) throws ClickError {
127 return FAKE_DOT_DESKTOP;
128 }
129
130 public bool fake_can_uninstall = true;
131 public override async bool can_uninstall (string app_id) {
132 return fake_can_uninstall;
133 }
124 }134 }
125135
126 public static void test_click_architecture ()136 public static void test_click_architecture ()
@@ -420,6 +430,49 @@
420 assert (run_with_timeout (mainloop, 10000));430 assert (run_with_timeout (mainloop, 10000));
421 }431 }
422432
433 public static void test_scope_build_installed_preview_with_uninstall ()
434 {
435 do_test_build_installed_preview_uninstall (true);
436 }
437
438 public static void test_scope_build_installed_preview_without_uninstall ()
439 {
440 do_test_build_installed_preview_uninstall (false);
441 }
442
443 private static void do_test_build_installed_preview_uninstall (bool can_uninstall)
444 {
445 MainLoop mainloop = new MainLoop ();
446 ClickScope scope = new ClickScope ();
447 scope.webservice = new FakeClickWebservice ();
448 scope.click_if = new FakeClickInterface ();
449 ((FakeClickInterface) scope.click_if).fake_can_uninstall = can_uninstall;
450
451 var metadata = new HashTable<string, Variant> (str_hash, str_equal);
452 metadata.insert(METADATA_APP_ID, new GLib.Variant.string(FAKE_APP_ID));
453 var fake_result = Unity.ScopeResult.create("", "", 0,
454 Unity.ResultType.DEFAULT,
455 "application/x-desktop",
456 "", "", "", metadata);
457
458 string fake_app_uri = "application:///" + FAKE_DOT_DESKTOP;
459 scope.build_installed_preview.begin(fake_result, fake_app_uri, (obj, res) => {
460 mainloop.quit ();
461 try {
462 var preview = scope.build_installed_preview.end(res);
463 assert(preview_has_action(preview, "open_click:" + fake_app_uri, "Open"));
464
465 bool has_uninstall = preview_has_action(preview, "uninstall_click", "Uninstall");
466 assert(can_uninstall == has_uninstall);
467
468 } catch (GLib.Error e) {
469 error ("Exception caught building installed preview: %s", e.message);
470 }
471 });
472
473 assert (run_with_timeout (mainloop, 10000));
474 }
475
423 public static Unity.ScopeResult create_fake_result () {476 public static Unity.ScopeResult create_fake_result () {
424 uint fake_category = 0;477 uint fake_category = 0;
425 var fake_result_type = Unity.ResultType.DEFAULT;478 var fake_result_type = Unity.ResultType.DEFAULT;
@@ -488,6 +541,10 @@
488 Test.add_data_func ("/Unit/ClickChecker/Test_Click_GetDotDesktop", test_click_get_dotdesktop);541 Test.add_data_func ("/Unit/ClickChecker/Test_Click_GetDotDesktop", test_click_get_dotdesktop);
489 Test.add_data_func ("/Unit/ClickChecker/Test_Scope_Build_Purchasing_Preview", 542 Test.add_data_func ("/Unit/ClickChecker/Test_Scope_Build_Purchasing_Preview",
490 test_scope_build_purchasing_preview);543 test_scope_build_purchasing_preview);
544 Test.add_data_func ("/Unit/ClickChecker/Test_Scope_Build_Installed_Preview_With_Uninstall",
545 test_scope_build_installed_preview_with_uninstall);
546 Test.add_data_func ("/Unit/ClickChecker/Test_Scope_Build_Installed_Preview_Without_Uninstall",
547 test_scope_build_installed_preview_without_uninstall);
491 Test.add_data_func ("/Unit/ClickChecker/Test_Scope_InProgress", test_scope_in_progress);548 Test.add_data_func ("/Unit/ClickChecker/Test_Scope_InProgress", test_scope_in_progress);
492 return Test.run ();549 return Test.run ();
493 }550 }

Subscribers

People subscribed via source and target branches

to all changes: