Skip to content

Commit 855bee0

Browse files
committed
add message type parameter to notifyDevtools function to categorize messages
1 parent b2259b8 commit 855bee0

2 files changed

Lines changed: 18 additions & 13 deletions

File tree

background.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ function processBackgroundIncomingMessage(msg) {
3636
}
3737

3838
// Function to send a message to main.js
39-
function notifyDevtools(msg) {
40-
console.log('Background.js Sending Message', msg);
39+
function notifyDevtools(msgType, msg) {
40+
var packagedMessage = new Object();
41+
packagedMessage.msgType = msgType;
42+
packagedMessage.msg = msg;
4143
ports.forEach(function (port) {
42-
port.postMessage(msg);
44+
port.postMessage(packagedMessage);
4345
});
4446
}
4547

@@ -54,18 +56,19 @@ function getJsonResource(tabID) {
5456
if (xhr.readyState === 4 && isSolidus) { // Is complete Solidus response?
5557
if(xhr.status !== 200){ // Check that Solidus response didn't fail
5658
errMsg = 'Failed to get Solidus context. Status: ' + xhr.status;
57-
notifyDevtools(JSON.parse('{"error":"' + errMsg + '"}'));
59+
notifyDevtools('error', errMsg);
5860
} else {
5961
try {
6062
// Send Solidus JSON to devpanel
61-
notifyDevtools(JSON.parse(xhr.responseText));
63+
notifyDevtools('context', JSON.parse(xhr.responseText));
64+
notifyDevtools('status', 'The x-powered-by header is' + xhr.getResponseHeader('X-Powered-By'));
6265
} catch (e) {
63-
notifyDevtools(JSON.parse('{"error":"' + e + '"}'));
66+
notifyDevtools('error', e);
6467
}
6568
}
6669
} else {
6770
errMsg = 'Looks like you\'re not inspecting a Solidus Page.';
68-
notifyDevtools(JSON.parse('{"error":"' + errMsg + '"}'));
71+
notifyDevtools('error', errMsg);
6972
}
7073
};
7174
xhr.send();

views/devpanel.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,25 @@ var inspector;
1212

1313
function processMainIncomingMessage(msg) {
1414
console.log('Devpanel Processing Message', msg);
15-
if (msg.hasOwnProperty('page')) {
15+
if (msg.msgType === 'context') {
1616
displayMessage('Looks like a Solidus page!');
1717
//Check if there is an initialized InspectorJSON that hasn't been destroyed
1818
if ((inspector instanceof InspectorJSON) && (inspector.page)) {
19-
inspector.view(msg);
19+
inspector.view(msg.msg);
2020
} else {
2121
inspector = new InspectorJSON({
2222
element: 'pagecontext',
23-
url: msg.url.path,
24-
json: msg
23+
url: msg.msg.url.path,
24+
json: msg.msg
2525
});
2626
}
27-
} else if (msg.hasOwnProperty('error')) {
27+
} else if (msg.msgType === 'error') {
2828
if (inspector instanceof InspectorJSON) {
2929
inspector.destroy();
3030
}
31-
displayMessage(msg.error);
31+
displayMessage(msg.msg);
32+
} else if (msg.msgType === 'status') {
33+
displayMessage(msg.msg);
3234
} else {
3335
console.log('Message Not Processed', msg);
3436
}

0 commit comments

Comments
 (0)