1 line
12 KiB
Plaintext
1 line
12 KiB
Plaintext
{"version":3,"names":["isMacLike","test","navigator","platform","refreshShortcut","window","onload","document","getElementById","innerHTML","Page","render","onReloadClicked","xhr","XMLHttpRequest","open","location","origin","send","state","isDark","localStorage","getItem","matchMedia","matches","isPriorityMaintained","status","type","visibilityState","setState","partialState","Object","assign","statusNode","textContent","error","reason","linkNode","querySelector","href","grayIcon","blueIcon","orangeIcon","darkCheckbox","body","classList","toggle","checked","setItem","maintainPriorityCheckbox","silence","volume","play","pause","toggleDarkTheme","togglePriorityMaintenance","connectToDebuggerProxy","ws","WebSocket","host","worker","createJSRuntime","Worker","onmessage","message","JSON","stringify","data","onbeforeunload","updateVisibility","shutdownJSRuntime","terminate","postMessage","method","onopen","object","parse","$event","console","clear","replyID","id","onclose","warn","setTimeout","addEventListener"],"sources":["../../src/ui/index.js"],"sourcesContent":["/**\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\n/* eslint-env browser */\nimport './index.css';\nimport blueIcon from './assets/blue-icon.png';\nimport grayIcon from './assets/gray-icon.png';\nimport orangeIcon from './assets/orange-icon.png';\n\nconst isMacLike = /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform);\nconst refreshShortcut = isMacLike ? '⌘R' : 'Ctrl R';\nwindow.onload = function () {\n if (!isMacLike) {\n document.getElementById('shortcut').innerHTML = 'Ctrl⇧J';\n }\n Page.render();\n};\n\nwindow.onReloadClicked = function () {\n var xhr = new XMLHttpRequest();\n xhr.open('GET', `${window.location.origin}/reload`, true);\n xhr.send();\n};\n\nconst Page = (window.Page = {\n state: {\n isDark:\n localStorage.getItem('darkTheme') === null\n ? window.matchMedia('(prefers-color-scheme: dark)').matches\n : localStorage.getItem('darkTheme') === 'on',\n isPriorityMaintained: localStorage.getItem('maintainPriority') === 'on',\n status: {type: 'disconnected'},\n visibilityState: document.visibilityState,\n },\n\n setState(partialState) {\n Page.state = Object.assign({}, Page.state, partialState);\n Page.render();\n },\n\n render() {\n const {isDark, isPriorityMaintained, status, visibilityState} = Page.state;\n\n const statusNode = document.getElementById('status');\n switch (status.type) {\n case 'connected':\n statusNode.textContent = 'Debugger session active.';\n break;\n case 'error':\n statusNode.textContent =\n status.error.reason ||\n 'Disconnected from proxy. Attempting reconnection. Is node server running?';\n break;\n case 'connecting':\n case 'disconnected':\n // Fall through.\n default:\n statusNode.innerHTML =\n 'Waiting, press <span class=\"shortcut\">' +\n refreshShortcut +\n '</span> in simulator to reload and connect.';\n break;\n }\n\n const linkNode = document.querySelector('link[rel=icon]');\n if (status.type === 'disconnected' || status.type === 'error') {\n linkNode.href = grayIcon;\n } else {\n if (visibilityState === 'visible' || isPriorityMaintained) {\n linkNode.href = blueIcon;\n } else {\n linkNode.href = orangeIcon;\n }\n }\n\n const darkCheckbox = document.getElementById('dark');\n document.body.classList.toggle('dark', isDark);\n darkCheckbox.checked = isDark;\n localStorage.setItem('darkTheme', isDark ? 'on' : '');\n\n const maintainPriorityCheckbox = document.getElementById(\n 'maintain-priority',\n );\n const silence = document.getElementById('silence');\n silence.volume = 0.1;\n if (isPriorityMaintained) {\n silence.play();\n } else {\n silence.pause();\n }\n maintainPriorityCheckbox.checked = isPriorityMaintained;\n localStorage.setItem('maintainPriority', isPriorityMaintained ? 'on' : '');\n },\n\n toggleDarkTheme() {\n Page.setState({isDark: !Page.state.isDark});\n },\n\n togglePriorityMaintenance() {\n Page.setState({isPriorityMaintained: !Page.state.isPriorityMaintained});\n },\n});\n\nfunction connectToDebuggerProxy() {\n const ws = new WebSocket(\n 'ws://' +\n window.location.host +\n '/debugger-proxy?role=debugger&name=Chrome',\n );\n let worker;\n\n function createJSRuntime() {\n // This worker will run the application JavaScript code,\n // making sure that it's run in an environment without a global\n // document, to make it consistent with the JSC executor environment.\n worker = new Worker('./debuggerWorker.js');\n worker.onmessage = function (message) {\n ws.send(JSON.stringify(message.data));\n };\n window.onbeforeunload = function () {\n return (\n 'If you reload this page, it is going to break the debugging session. ' +\n 'Press ' +\n refreshShortcut +\n ' on the device to reload.'\n );\n };\n updateVisibility();\n }\n\n function shutdownJSRuntime() {\n if (worker) {\n worker.terminate();\n worker = null;\n window.onbeforeunload = null;\n }\n }\n\n function updateVisibility() {\n if (worker && !Page.state.isPriorityMaintained) {\n worker.postMessage({\n method: 'setDebuggerVisibility',\n visibilityState: document.visibilityState,\n });\n }\n Page.setState({visibilityState: document.visibilityState});\n }\n\n ws.onopen = function () {\n Page.setState({status: {type: 'connecting'}});\n };\n\n ws.onmessage = async function (message) {\n if (!message.data) {\n return;\n }\n const object = JSON.parse(message.data);\n\n if (object.$event === 'client-disconnected') {\n shutdownJSRuntime();\n Page.setState({status: {type: 'disconnected'}});\n return;\n }\n\n if (!object.method) {\n return;\n }\n\n // Special message that asks for a new JS runtime\n if (object.method === 'prepareJSRuntime') {\n shutdownJSRuntime();\n console.clear();\n createJSRuntime();\n ws.send(JSON.stringify({replyID: object.id}));\n Page.setState({status: {type: 'connected', id: object.id}});\n } else if (object.method === '$disconnected') {\n shutdownJSRuntime();\n Page.setState({status: {type: 'disconnected'}});\n } else {\n worker.postMessage(object);\n }\n };\n\n ws.onclose = function (error) {\n shutdownJSRuntime();\n Page.setState({status: {type: 'error', error}});\n if (error.reason) {\n console.warn(error.reason);\n }\n setTimeout(connectToDebuggerProxy, 500);\n };\n\n // Let debuggerWorker.js know when we're not visible so that we can warn about\n // poor performance when using remote debugging.\n document.addEventListener('visibilitychange', updateVisibility, false);\n}\n\nconnectToDebuggerProxy();\n"],"mappings":";;;AASA;AACA;AACA;AACA;AAZA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAMA,MAAMA,SAAS,GAAG,yBAAyB,CAACC,IAAI,CAACC,SAAS,CAACC,QAAQ,CAAC;AACpE,MAAMC,eAAe,GAAGJ,SAAS,GAAG,IAAI,GAAG,QAAQ;AACnDK,MAAM,CAACC,MAAM,GAAG,YAAY;EAC1B,IAAI,CAACN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