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

Commit

Permalink
Webextension ready (#22)
Browse files Browse the repository at this point in the history
* Fix messaging, make compatible with webext
* Fix `updateHistoryUrls` action handling
  • Loading branch information
private-face authored Jan 18, 2019
1 parent 7f775b1 commit a291eca
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 28 deletions.
58 changes: 32 additions & 26 deletions app/services/cliqz.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,42 @@ import spanan from 'npm:spanan';

const Spanan = spanan.default;

function createSpananForModule(moduleName) {
const spanan = new Spanan(({ uuid, action, args }) => {
const message = {
module: moduleName,
action,
requestId: uuid,
args
};
const onResponse = (response) => {
if (!response) {
return;
}
spanan.handleMessage({
uuid,
response: response.response
});
};

const promise = chrome.runtime.sendMessage(message, onResponse);

if (promise && promise.then) {
promise.then(onResponse);
}
});

return spanan;
}

export default Ember.Service.extend({
historySync: Ember.inject.service('history-sync'),

init() {
this._super(...arguments);

const history = new Spanan(({ uuid, action, args }) => {
const message = {
target: 'cliqz',
module: 'history',
action,
requestId: uuid,
args,
};
chrome.runtime.sendMessage(message);
});
const history = createSpananForModule('history');
const historyProxy = history.createProxy();

this.deleteVisit = historyProxy.deleteVisit;
this.deleteVisits = historyProxy.deleteVisits;
this.showHistoryDeletionPopup = historyProxy.showHistoryDeletionPopup;
Expand All @@ -34,30 +52,19 @@ export default Ember.Service.extend({
this.openUrl = historyProxy.openUrl;
this.selectTabAtIndex = historyProxy.selectTabAtIndex;

const core = new Spanan(({ uuid, action, args }) => {
const message = {
target: 'cliqz',
module: 'core',
action,
requestId: uuid,
args,
};
chrome.runtime.sendMessage(message);
});
const core = createSpananForModule('core');
const coreProxy = core.createProxy();

this.getCliqzStatus = coreProxy.status;
this.queryCliqz = coreProxy.queryCliqz;
this.redoQuery = coreProxy.redoQuery;
this.sendTelemetry = coreProxy.sendTelemetry;
this.openFeedbackPage = coreProxy.openFeedbackPage;


chrome.runtime.onMessage.addListener(message => {
chrome.runtime.onMessage.addListener((message) => {
if(message.action === "updateHistoryUrls" && message.message) {
this.get('historySync').updateHistoryUrls(message.message.urls);
}

if (message.response) {
const spananMessage = {
uuid: message.requestId,
Expand All @@ -68,5 +75,4 @@ export default Ember.Service.extend({
}
});
},

});
2 changes: 1 addition & 1 deletion config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = function(environment) {
}

if (environment === 'production') {
ENV.rootURL = 'resource://cliqz/cliqz-history/';
ENV.rootURL = '';
}

return ENV;
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cliqz-history",
"version": "1.0.9",
"version": "1.1.0",
"description": "",
"license": "MPL-2.0",
"author": "",
Expand All @@ -11,6 +11,7 @@
"repository": "",
"scripts": {
"build": "ember build --environment production",
"build-watch": "ember build --environment production --watch",
"start": "ember server -p 3000",
"test": "ember test"
},
Expand Down

0 comments on commit a291eca

Please sign in to comment.