-
Notifications
You must be signed in to change notification settings - Fork 43
/
devtools.js
executable file
·66 lines (44 loc) · 1.3 KB
/
devtools.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var verbose = false;
chrome.devtools.panels.create( "WebVR", "icon.png", "panel.html", initialise );
function log( ...args ) {
if( !verbose ) return;
var strArgs = [
'"%c WebVREmu | DevTools "',
'"background: #007AA3; color: #ffffff; text-shadow: 0 -1px #000; padding: 4px 0 4px 0; line-height: 0;"',
...args.map( v => JSON.stringify( v ) )
];
chrome.devtools.inspectedWindow.eval(
`console.log(${strArgs});`,
( result, isException ) => { if( isException ) { console.log( result, isException ) } }
);
}
log( 'Ready' );
var port = chrome.runtime.connect( null, { name: `devtools` } );
var tabId = chrome.devtools.inspectedWindow.tabId
function post( msg ) {
msg.tabId = tabId;
port.postMessage( msg );
}
post( { action: 'start' } );
port.onDisconnect.addListener( function() {
console.log( 'disconnect' );
} );
var settings = {};
var panelWindow = null;
port.onMessage.addListener( function( msg ) {
switch( msg.action ) {
case 'settings':
settings = msg.settings;
if( panelWindow ) panelWindow.updateSettings( settings );
break;
case 'pose':
if( panelWindow ) panelWindow.updatePose( msg.position, msg.rotation );
break;
}
} );
function initialise( panel ) {
panel.onShown.addListener( function ( wnd ) {
panelWindow = wnd;
panelWindow.updateSettings( settings );
} );
}