Skip to content
This repository was archived by the owner on Sep 21, 2021. It is now read-only.

Commit 8953734

Browse files
author
Vladimir Zhuravlev
authored
Compatibility with new messaging format (#29)
* Use new module wrapper * Bump version
1 parent 5c6c80c commit 8953734

File tree

3 files changed

+25
-52
lines changed

3 files changed

+25
-52
lines changed

app/services/cliqz.js

+22-42
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,26 @@
1-
/* global chrome */
1+
/* global browser, Proxy */
22

33
import Ember from 'ember';
4-
import spanan from 'npm:spanan';
54

6-
const Spanan = spanan.default;
5+
function createActionWrapperForModule(module) {
6+
const actionHandler = (action, ...args) => browser.runtime.sendMessage({
7+
module,
8+
action,
9+
args,
10+
});
711

8-
function createSpananForModule(moduleName) {
9-
const spanan = new Spanan(({ uuid, action, args }) => {
10-
const message = {
11-
module: moduleName,
12-
action,
13-
requestId: uuid,
14-
args
15-
};
16-
const onResponse = (response) => {
17-
if (!response) {
18-
return;
12+
// Return a proxy so that people can call `module.actionName(...args)` instead
13+
// of `module.action('actionName', ...args)`. This is not strictly needed but
14+
// modules are expecting this API.
15+
return new Proxy({}, {
16+
get: (obj, prop) => {
17+
if (prop === 'action') {
18+
return actionHandler;
1919
}
20-
spanan.handleMessage({
21-
uuid,
22-
response: response.response
23-
});
24-
};
25-
26-
const promise = chrome.runtime.sendMessage(message, onResponse);
2720

28-
if (promise && promise.then) {
29-
promise.then(onResponse);
30-
}
21+
return actionHandler.bind(obj, prop);
22+
},
3123
});
32-
33-
return spanan;
3424
}
3525

3626
export default Ember.Service.extend({
@@ -39,8 +29,7 @@ export default Ember.Service.extend({
3929
init() {
4030
this._super(...arguments);
4131

42-
const history = createSpananForModule('history');
43-
const historyProxy = history.createProxy();
32+
const historyProxy = createActionWrapperForModule('history');
4433
this.deleteVisit = historyProxy.deleteVisit;
4534
this.deleteVisits = historyProxy.deleteVisits;
4635
this.showHistoryDeletionPopup = historyProxy.showHistoryDeletionPopup;
@@ -52,26 +41,17 @@ export default Ember.Service.extend({
5241
this.openUrl = historyProxy.openUrl;
5342
this.selectTabAtIndex = historyProxy.selectTabAtIndex;
5443

55-
const core = createSpananForModule('core');
56-
const coreProxy = core.createProxy();
44+
const coreProxy = createActionWrapperForModule('core');
5745
this.getCliqzStatus = coreProxy.status;
5846
this.queryCliqz = coreProxy.queryCliqz;
5947
this.redoQuery = coreProxy.redoQuery;
6048
this.sendTelemetry = coreProxy.sendTelemetry;
6149
this.openFeedbackPage = coreProxy.openFeedbackPage;
6250

63-
chrome.runtime.onMessage.addListener((message) => {
64-
if(message.action === "updateHistoryUrls" && message.message) {
65-
this.get('historySync').updateHistoryUrls(message.message.urls);
66-
}
67-
68-
if (message.response) {
69-
const spananMessage = {
70-
uuid: message.requestId,
71-
response: message.response
72-
};
73-
history.handleMessage(spananMessage);
74-
core.handleMesssage(spananMessage);
51+
browser.runtime.onMessage.addListener((message) => {
52+
if(message.action === "updateHistoryUrls") {
53+
const { urls } = message.args[0];
54+
this.get('historySync').updateHistoryUrls(urls);
7555
}
7656
});
7757
},

package-lock.json

+1-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cliqz-history",
3-
"version": "1.1.3",
3+
"version": "1.2.0",
44
"description": "",
55
"license": "MPL-2.0",
66
"author": "",
@@ -42,8 +42,7 @@
4242
"ember-source": "~2.14.0",
4343
"ember-welcome-page": "^3.2.0",
4444
"liquid-fire": "^0.29.5",
45-
"loader.js": "^4.2.3",
46-
"spanan": "^2.0.0"
45+
"loader.js": "^4.2.3"
4746
},
4847
"engines": {
4948
"node": "^4.5 || 6.* || >= 7.*"

0 commit comments

Comments
 (0)