Merge pull request #4 from tuping/keep_alive

Keep alive
This commit is contained in:
sbinkert 2016-08-15 13:32:37 +02:00 committed by GitHub
commit 90f4869419
3 changed files with 27 additions and 2 deletions

View File

@ -19,6 +19,7 @@ chrome.runtime.onInstalled.addListener(function (details) {
unit: '1',
host: '127.0.0.1',
port: '9100',
keepTcpSocket: false,
saveLabels: false,
filetype: '1',
path: null,

View File

@ -19,7 +19,12 @@ $(document).ready(function () {
chrome.sockets.tcp.onReceive.addListener(function (info) {
notify('{0} bytes received from Client: <b>{1}</b> Port: <b>{2}</b>'.format(info.data.byteLength, clientSocketInfo.peerAddress, clientSocketInfo.peerPort), 'print', 'info', 1000);
var zpls = String.fromCharCode.apply(null, new Uint8Array(info.data)).split(/\^XZ/);
if (!configs.keepTcpSocket) {
chrome.sockets.tcp.close(info.socketId);
notify('Closing TCP Socket.');
} else {
notify('Keeping TCP Socket.');
}
var factor = (configs.unit == '1') ? 1 : (configs.unit == '2') ? 2.54 : 25.4;
var width = parseFloat(configs.width) / factor;
var height = parseFloat(configs.height) / factor;
@ -283,6 +288,8 @@ function saveConfigs() {
configs[key] = $('#btn-filetype').attr('aria-valuenow');
} else if (key == 'saveLabels') {
configs[key] = $('#ckb-saveLabels').is(':checked');
} else if (key == 'keepTcpSocket') {
configs[key] = $('#ckb-keep-tcp-socket').is(':checked');
} else if (key == 'path') {
configs[key] = retainEntry
} else {
@ -314,6 +321,8 @@ function initConfigs() {
} else if (key == 'isOn' && configs[key]) {
toggleSwitch('.btn-toggle');
startTcpServer();
} else if (key == 'keepTcpSocket') {
$('#ckb-keep-tcp-socket').prop('checked', configs[key]);
} else if (key == 'path' && configs[key]) {
retainEntry = configs[key];
chrome.fileSystem.restoreEntry(configs[key], function (entry) {

View File

@ -120,7 +120,22 @@
<input id="port" name="port" class="form-control" placeholder="9100" type="number" min="1" max="65535" required>
</div>
</td>
<td width="30%"></td>
<td width="30%">
<div class="checkbox" style="padding-right: 10px;">
<h5>
<label>
<input id="ckb-keep-tcp-socket" type="checkbox" />
Keep TCP socket
<a
href="#"
data-toggle="tooltip"
title="Useful when using redirection serial port programs (eg socat on Linux).">
<span class="glyphicon glyphicon-question-sign"></span>
</a>
</label>
</h5>
</div>
</td>
</tr>
</table>
</div>