Allow to customize debug port both in IDEA and Chrome

This commit is contained in:
Alexey Andreev 2018-12-20 12:09:32 +03:00
parent 27d81c4fe6
commit 90c23e6686
5 changed files with 111 additions and 10 deletions

View File

@ -1,8 +1,13 @@
debuggerAgentMap = {};
chrome.browserAction.onClicked.addListener(function(tab) {
new DebuggerAgent(tab, 2357).attach();
chrome.storage.sync.get({
port: 2357,
}, function(items) {
new DebuggerAgent(tab, items.port).attach();
});
});
function DebuggerAgent(tab, port) {
this.pendingMessages = [];
this.connection = null;

View File

@ -5,7 +5,7 @@
"description": "TeaVM debugger agent, that sends RDP commands over WebSocket",
"version": "0.6.0",
"permissions" : ["debugger", "activeTab", "tabs", "*://*/*"],
"permissions" : ["debugger", "activeTab", "tabs", "storage", "*://*/*"],
"browser_action" : {
"default_icon": "teavm-16.png",
@ -21,5 +21,10 @@
"matches": ["http://*/*", "https://*/*", "file://*/*"],
"js": ["contentscript.js"]
}
]
],
"options_ui": {
"page": "options.html",
"open_in_tab": false
}
}

View File

@ -0,0 +1,54 @@
<!DOCTYPE html>
<!--
~ Copyright 2018 Alexey Andreev.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<html>
<head>
<title>TeaVM debug options</title>
<style type="text/css">
body {
margin: 1em;
}
* {
font-size: 14pt;
font-family: sans-serif;
}
.form-item {
margin-top: 0.5em;
margin-bottom: 0.5em;
}
.form-item label {
font-weight: bold;
}
</style>
</head>
<body>
<div class="form-item">
<label for="port">Port:</label>
<input name="port" id="port" type="number" min="1" max="65535">
</div>
<div class="form-item">
<button id="save">Save</button>
</div>
<script src="options.js"></script>
</body>
</html>

View File

@ -0,0 +1,32 @@
/*
* Copyright 2018 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function saveOptions() {
var port = document.getElementById("port").value;
chrome.storage.sync.set({
port: port !== "" ? parseInt(port) : 2357,
});
}
function loadOptions() {
chrome.storage.sync.get({
port: 2357,
}, function(items) {
document.getElementById("port").value = items.port;
});
}
document.addEventListener("DOMContentLoaded", loadOptions);
document.getElementById("save").addEventListener('click', saveOptions);

View File

@ -22,29 +22,34 @@ import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import org.teavm.idea.debug.TeaVMDebugConfiguration;
class TeaVMDebugSettingsPanel extends JPanel {
private final JBTextField portField = new JBTextField();
public TeaVMDebugSettingsPanel() {
setBorder(new EmptyBorder(10, 10, 10, 10));
GridBagConstraints labelConstraints = new GridBagConstraints();
labelConstraints.gridwidth = GridBagConstraints.REMAINDER;
labelConstraints.anchor = GridBagConstraints.BASELINE_LEADING;
labelConstraints.weightx = 1;
labelConstraints.weightx = 0;
labelConstraints.weighty = 1;
labelConstraints.insets.left = 5;
labelConstraints.insets.right = 5;
GridBagConstraints descriptionConstraints = (GridBagConstraints) labelConstraints.clone();
descriptionConstraints.fill = GridBagConstraints.BOTH;
descriptionConstraints.anchor = GridBagConstraints.BASELINE_LEADING;
descriptionConstraints.insets.top = 3;
GridBagConstraints fieldConstraints = (GridBagConstraints) labelConstraints.clone();
fieldConstraints.gridwidth = GridBagConstraints.REMAINDER;
fieldConstraints.weightx = 1;
fieldConstraints.weighty = 1;
fieldConstraints.fill = GridBagConstraints.BOTH;
fieldConstraints.anchor = GridBagConstraints.BASELINE_LEADING;
setLayout(new GridBagLayout());
add(bold(new JBLabel("Listen port:")), labelConstraints);
add(portField);
add(portField, fieldConstraints);
}
public void load(TeaVMDebugConfiguration runConfiguration) {