Commit 4e4d2010 authored by Laurent Wouters's avatar Laurent Wouters
Browse files

[fix] Fixing Chrome compatibility

parent da0755d6b8fb
......@@ -39,8 +39,7 @@ import {
import {
getResourceContent,
getViewRegistry,
fetchObservableAt,
updateSidebar
fetchObservableAt
} from "../common/messages";
require("./view-defaults-impl");
......@@ -494,7 +493,6 @@ class LDBrowserImpl implements LDBrowser {
} else {
this.handler.onError("Rendering failed: Cannot resolve a view");
}
updateSidebar(data, registry);
} catch (e) {
this.handler.onError("Rendering failed: " + e);
}
......@@ -535,7 +533,17 @@ class LDBrowserImpl implements LDBrowser {
* Gets the current resource
*/
public getCurrentResource(): ResourceData {
return this.currentData;
if (this.currentData) {
return {
resource: this.currentData.resource,
observations: this.currentData.observations,
command: this.currentData.command,
rendering: application.serializableResult(this.currentData.rendering),
supplements: this.currentData.supplements
};
} else {
return this.currentData;
}
}
/**
......
......@@ -287,34 +287,6 @@ export function backgroundToggleRawForTab(
);
}
/**
* Updates the content of the sidebar
* @param tabId The identifier for the sending tab
* @param data The data about the tab
* @param registry The registry
*/
export function updateSidebar(
data: ResourceData,
registry: ViewRegistry
): Promise<void> {
return new Promise<void>(
(resolve: (result: void) => void, reject: (reason: any) => void) => {
chrome.runtime.sendMessage(
{
requestType: "UpdateSidebar",
payload: {
data: data,
registry: registry
}
},
(result: void) => {
resolve(result);
}
);
}
);
}
/**
* Sends to a tab a message to turn the browser off
* @param id The identifier of a tab
......
......@@ -85,21 +85,6 @@ class Sidebar extends React.Component<{}, State> {
// listen for change of the current tab
chrome.tabs.onActivated.addListener(this.onTabActivated);
chrome.tabs.onUpdated.addListener(this.onTabUpdated);
// listen to messages
let self = this;
chrome.runtime.onMessage.addListener(
(request: Message<any>, sender, sendResponse) => {
if (request.requestType == "UpdateSidebar") {
let tabId = sender.tab.id;
if (self.state.tabId == tabId) {
self.state.data = request.payload.data;
self.state.registry = request.payload.registry;
self.state.pane = "main";
self.setState(self.state);
}
}
}
);
}
onTabActivated(activeInfo: chrome.tabs.TabActiveInfo) {
......
......@@ -332,6 +332,20 @@ export interface RenderingResult {
languages: Language[];
}
/**
* Gets a clean serializable version of the rendering result
* @param result The initial result
*/
export function serializableResult(result: RenderingResult): RenderingResult {
return {
dom: null,
viewId: result.viewId,
suggestedResources: result.suggestedResources,
evaluations: result.evaluations,
languages: result.languages
};
}
/**
* A renderer for an application
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment