Merge lp:~abreu-alexandre/unity-js-scopes/handle-perform-action into lp:unity-js-scopes

Proposed by Alexandre Abreu
Status: Merged
Approved by: Alexandre Abreu
Approved revision: 130
Merged at revision: 130
Proposed branch: lp:~abreu-alexandre/unity-js-scopes/handle-perform-action
Merge into: lp:unity-js-scopes
Diff against target: 286 lines (+82/-44)
5 files modified
examples/soundcloud/soundcloud.js (+35/-9)
src/bindings/index.js (+5/-1)
src/bindings/src/addon.cc (+1/-0)
src/bindings/src/scope-base.cc (+41/-32)
src/bindings/src/scope-base.h (+0/-2)
To merge this branch: bzr merge lp:~abreu-alexandre/unity-js-scopes/handle-perform-action
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Alberto Mardegan (community) Approve
Review via email: mp+285801@code.launchpad.net

Commit message

Handle scope perform_action callback

Description of the change

Handle scope perform_action callback

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
Marcus Tomlinson (marcustomlinson) wrote :

Hey Alex, seeing that I'm away. I think a good candidate to review this branch would be Michael Weimann himself (the bug originator).

I think let's provide him with a build of this branch as ask that he give it a go.

If Michael's happy, then we're happy :)

130. By Alexandre Abreu

Tweaks

Revision history for this message
Alberto Mardegan (mardy) wrote :

LGTM, but consider that I'm not familiar with the project at all. :-)

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'examples/soundcloud/soundcloud.js'
2--- examples/soundcloud/soundcloud.js 2015-11-19 21:17:02 +0000
3+++ examples/soundcloud/soundcloud.js 2016-02-12 15:02:06 +0000
4@@ -61,7 +61,9 @@
5 track_results.push({
6 id: results[i].id,
7 art: results[i].artwork_url ? results[i].artwork_url : "",
8+ streamable: results[i].streamable,
9 stream_url: results[i].stream_url,
10+ duration: results[i].duration,
11 uri: results[i].uri,
12 description: results[i].description,
13 genre: results[i].genre,
14@@ -93,7 +95,12 @@
15 categorised_result.set_art(result.art);
16
17 categorised_result.set("artist", result.artist.username);
18- categorised_result.set("stream", result.artist.stream_url);
19+ categorised_result.set("stream", result.stream_url);
20+ categorised_result.set("duration", result.duration);
21+ categorised_result.set("audio-data", {
22+ "uri": result.stream_url,
23+ "duration": result.duration
24+ });
25
26 return categorised_result
27 }
28@@ -104,14 +111,19 @@
29 \"template\": { \
30 \"category-layout\": \"grid\", \
31 \"card-layout\": \"horizontal\", \
32- \"card-size\": \"large\" \
33+ \"card-size\": \"large\", \
34+ \"quick-preview-type\" : \"audio\" \
35 }, \
36 \"components\": { \
37 \"title\": \"title\", \
38 \"art\" : { \
39- \"field\": \"art\" \
40+ \"field\": \"art\", \
41+ \"conciergeMode\": true \
42 }, \
43- \"subtitle\": \"artist\" \
44+ \"subtitle\": \"artist\", \
45+ \"quick-preview-data\": { \
46+ \"field\": \"audio-data\" \
47+ } \
48 } \
49 }";
50
51@@ -192,11 +204,21 @@
52 var actions_widget = new scopes.lib.PreviewWidget("actionsId", "actions");
53 actions_widget.add_attribute_value(
54 "actions",
55- {
56- "id": "open",
57- "label": "Open",
58- "uri": r.get("uri")
59- }
60+ [
61+ {
62+ "id": "open",
63+ "label": "Open",
64+ "uri": r.get("uri")
65+ },
66+ {
67+ "id": "download",
68+ "label": "Download"
69+ },
70+ {
71+ "id": "test",
72+ "label": "Test"
73+ }
74+ ]
75 );
76 preview_reply.push([header_widget, art_widget, actions_widget])
77 preview_reply.finished()
78@@ -222,5 +244,9 @@
79 },
80 search: on_search,
81 preview: on_preview,
82+ perform_action: function(result, metadata, widget_id, action_id) {
83+ console.log('Action performed', widget_id, action_id)
84+ return null
85+ }
86 }
87 );
88
89=== modified file 'src/bindings/index.js'
90--- src/bindings/index.js 2016-01-11 14:22:53 +0000
91+++ src/bindings/index.js 2016-02-12 15:02:06 +0000
92@@ -62,7 +62,7 @@
93 * - starting {Function(String: scope_id)}: Callback called by the scopes run time after the create function completes
94 * - stop {Function()}: Callback called by the scopes run time when the scope should shut down
95 * - search {Function(CannedQuery: canned_query, SearchMetaData: metadata)}: Callback called by the scopes run time when a scope needs to instantiate a query
96- * - perform_action {Function(Result: result, ActionMetaData: metadata, String: widget_id, String: ation_id)}: Callback invoked when a scope is requested to handle a preview action
97+ * - perform_action {Function(Result: result, ActionMetaData: metadata, String: widget_id, String: action_id)}: Callback invoked when a scope is requested to handle a preview action
98 * - preview {Function(Result: result, ActionMetaData: metadata)}: Callback invoked when a scope is requested to create a preview for a particular result
99 *
100 * @example
101@@ -111,6 +111,10 @@
102 this._base.onpreview(runtime_config.preview);
103 }
104
105+ if (runtime_config.perform_action && typeof(runtime_config.perform_action) === 'function') {
106+ this._base.onperform_action(runtime_config.perform_action);
107+ }
108+
109 if (runtime_config.activate && typeof(runtime_config.activate) === 'function') {
110 // this._base.onactivate(runtime_config.activate);
111 }
112
113=== modified file 'src/bindings/src/addon.cc'
114--- src/bindings/src/addon.cc 2016-01-08 15:39:04 +0000
115+++ src/bindings/src/addon.cc 2016-02-12 15:02:06 +0000
116@@ -130,6 +130,7 @@
117 .add_method("onrun", &ScopeBase::onrun)
118 .add_method("onsearch", &ScopeBase::onsearch)
119 .add_method("onpreview", &ScopeBase::onpreview)
120+ .add_method("onperform_action", &ScopeBase::onperform_action)
121 .add_method("registry", &ScopeBase::get_registry)
122 // unity::scopes::ScopeBase
123 .add_method("scope_directory", &unity::scopes::ScopeBase::scope_directory)
124
125=== modified file 'src/bindings/src/scope-base.cc'
126--- src/bindings/src/scope-base.cc 2015-10-28 18:46:50 +0000
127+++ src/bindings/src/scope-base.cc 2016-02-12 15:02:06 +0000
128@@ -34,18 +34,20 @@
129 : isolate_(v8::Isolate::GetCurrent()) {
130 }
131 ScopeBase::~ScopeBase() {
132- if ( ! start_callback_.IsEmpty()) {
133- start_callback_.Reset();
134- }
135- if ( ! stop_callback_.IsEmpty()) {
136- stop_callback_.Reset();
137- }
138- if ( ! run_callback_.IsEmpty()) {
139- run_callback_.Reset();
140- }
141- if ( ! search_callback_.IsEmpty()) {
142- search_callback_.Reset();
143- }
144+#if defined(SCOPE_JS_DELETE_CALLBACK)
145+#error "Duplicate SCOPE_JS_DELETE_CALLBACK definitions"
146+#endif
147+
148+#define SCOPE_JS_DELETE_CALLBACK(cb) \
149+ do { if ( ! cb.IsEmpty()) cb.Reset(); } while(0)
150+
151+ SCOPE_JS_DELETE_CALLBACK(start_callback_);
152+ SCOPE_JS_DELETE_CALLBACK(stop_callback_);
153+ SCOPE_JS_DELETE_CALLBACK(run_callback_);
154+ SCOPE_JS_DELETE_CALLBACK(search_callback_);
155+ SCOPE_JS_DELETE_CALLBACK(perform_action_callback_);
156+
157+#undef SCOPE_JS_DELETE_CALLBACK
158 }
159
160 void ScopeBase::start(std::string const& scope_id) {
161@@ -130,6 +132,10 @@
162 std::shared_ptr<SearchQuery> sq =
163 v8cpp::from_v8<std::shared_ptr<SearchQuery>>(isolate_, result);
164
165+ if (!sq) {
166+ return unity::scopes::SearchQueryBase::UPtr(nullptr);
167+ }
168+
169 return unity::scopes::SearchQueryBase::UPtr(new SearchQueryProxy(sq));
170 });
171 }
172@@ -177,6 +183,9 @@
173 v8cpp::from_v8<std::shared_ptr<ActivationQuery>>(
174 isolate_,
175 wrapped_activation_query);
176+ if (!aq) {
177+ return unity::scopes::ActivationQueryBase::UPtr(nullptr);
178+ }
179
180 return unity::scopes::ActivationQueryBase::UPtr(new ActivationQueryProxy(aq));
181 });
182@@ -216,6 +225,10 @@
183 isolate_,
184 wrapped_preview);
185
186+ if (!sq) {
187+ return unity::scopes::PreviewQueryBase::UPtr(nullptr);
188+ }
189+
190 return unity::scopes::PreviewQueryBase::UPtr(new PreviewQueryProxy(sq));
191 });
192 }
193@@ -232,10 +245,6 @@
194 return;
195 }
196
197- if (start_callback_.IsEmpty()) {
198- start_callback_.Reset();
199- }
200-
201 v8::Local<v8::Function> cb = v8::Handle<v8::Function>::Cast(args[0]);
202 start_callback_.Reset(args.GetIsolate(), cb);
203 }
204@@ -252,10 +261,6 @@
205 return;
206 }
207
208- if (stop_callback_.IsEmpty()) {
209- stop_callback_.Reset();
210- }
211-
212 v8::Local<v8::Function> cb = v8::Handle<v8::Function>::Cast(args[0]);
213 stop_callback_.Reset(args.GetIsolate(), cb);
214 }
215@@ -272,10 +277,6 @@
216 return;
217 }
218
219- if (run_callback_.IsEmpty()) {
220- run_callback_.Reset();
221- }
222-
223 v8::Local<v8::Function> cb = v8::Handle<v8::Function>::Cast(args[0]);
224 run_callback_.Reset(args.GetIsolate(), cb);
225 }
226@@ -292,10 +293,6 @@
227 return;
228 }
229
230- if (search_callback_.IsEmpty()) {
231- search_callback_.Reset();
232- }
233-
234 v8::Local<v8::Function> cb = v8::Handle<v8::Function>::Cast(args[0]);
235 search_callback_.Reset(args.GetIsolate(), cb);
236 }
237@@ -312,14 +309,26 @@
238 return;
239 }
240
241- if (preview_callback_.IsEmpty()) {
242- preview_callback_.Reset();
243- }
244-
245 v8::Local<v8::Function> cb = v8::Handle<v8::Function>::Cast(args[0]);
246 preview_callback_.Reset(args.GetIsolate(), cb);
247 }
248
249+void ScopeBase::onperform_action(
250+ v8::FunctionCallbackInfo<v8::Value> const& args) {
251+ if (args.Length() != 1) {
252+ // TODO fix
253+ return;
254+ }
255+
256+ if (!args[0]->IsFunction()) {
257+ // TODO fix
258+ return;
259+ }
260+
261+ v8::Local<v8::Function> cb = v8::Handle<v8::Function>::Cast(args[0]);
262+ perform_action_callback_.Reset(args.GetIsolate(), cb);
263+}
264+
265 std::shared_ptr<Registry> ScopeBase::get_registry() const {
266 return std::shared_ptr<Registry>(new Registry(registry()));
267 }
268
269=== modified file 'src/bindings/src/scope-base.h'
270--- src/bindings/src/scope-base.h 2015-10-21 14:17:12 +0000
271+++ src/bindings/src/scope-base.h 2016-02-12 15:02:06 +0000
272@@ -38,7 +38,6 @@
273
274 void onsearch(v8::FunctionCallbackInfo<v8::Value> const& args);
275 void onpreview(v8::FunctionCallbackInfo<v8::Value> const& args);
276- void onactivate(v8::FunctionCallbackInfo<v8::Value> const& args);
277 void onperform_action(v8::FunctionCallbackInfo<v8::Value> const& args);
278
279 std::shared_ptr<Registry> get_registry() const;
280@@ -75,7 +74,6 @@
281
282 v8::Persistent<v8::Function> search_callback_;
283 v8::Persistent<v8::Function> preview_callback_;
284- v8::Persistent<v8::Function> activate_callback_;
285 v8::Persistent<v8::Function> perform_action_callback_;
286 };
287

Subscribers

People subscribed via source and target branches

to all changes: