|
4 | 4 | // chrome.devtools.* |
5 | 5 | // chrome.extension.* |
6 | 6 |
|
| 7 | +var inspector; |
| 8 | + |
7 | 9 | function processMainIncomingMessage(msg) { |
8 | 10 | console.log("Devpanel Processing Message", msg); |
9 | | - var msgJson = 0; |
10 | | - try { |
11 | | - msgJson = JSON.parse(msg); //This doesn't work if it's not a JSON string |
12 | | - } catch (e) { |
13 | | - console.log("Ooops, the message wasnt a JSON string"); |
14 | | - } |
15 | | - if (msgJson.hasOwnProperty('page')) { |
16 | | - console.log("Message contains page object!"); |
17 | | - updateInspectorJSON(msg); |
18 | | - } else if (msg === "Bad Response") { |
19 | | - displayMessage("This isnt what we need"); |
20 | | - } else { |
21 | | - console.log("Ooops!", msg.page); |
22 | | - } |
23 | | -} |
24 | | - |
25 | | -function updateInspectorJSON(msg) { |
26 | | - if(!inspector) { |
27 | | - var inspector = new InspectorJSON({ |
28 | | - element: 'pagecontext', |
29 | | - json: '{"hello":"world"}' |
| 11 | + if (msg.hasOwnProperty('page')) { |
| 12 | + displayMessage("Looks like a Solidus page!"); |
| 13 | + //Check if there is an initialized InspectorJSON that hasn't been destroyed |
| 14 | + if ((inspector instanceof InspectorJSON) && (inspector.page)) { |
| 15 | + inspector.view(msg); |
| 16 | + } |
| 17 | + else { |
| 18 | + inspector = new InspectorJSON({ |
| 19 | + element: 'pagecontext', |
| 20 | + json: msg |
30 | 21 | }); |
31 | 22 | } |
32 | | - inspector.view(msg); |
| 23 | + } else if (msg.hasOwnProperty('error')) { |
| 24 | + if (inspector instanceof InspectorJSON) { |
| 25 | + inspector.destroy(); |
| 26 | + } |
| 27 | + displayMessage(msg.error); |
| 28 | + } else { |
| 29 | + console.log("Message Not Processed", msg); |
| 30 | + } |
33 | 31 | } |
34 | 32 |
|
35 | 33 | function displayMessage(msg) { |
|
0 commit comments