From 228038dffd5fa73df652dce37eb590a1e5d05104 Mon Sep 17 00:00:00 2001 From: "Rodrigo M. Albuquerque" Date: Tue, 9 Aug 2016 12:20:18 -0300 Subject: [PATCH] add an option to keep tcp socket alive --- ZplPrinter/js/background.js | 1 + ZplPrinter/js/main.js | 11 ++++++++++- ZplPrinter/main.html | 17 ++++++++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/ZplPrinter/js/background.js b/ZplPrinter/js/background.js index 9f199e9..0caabc6 100644 --- a/ZplPrinter/js/background.js +++ b/ZplPrinter/js/background.js @@ -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, diff --git a/ZplPrinter/js/main.js b/ZplPrinter/js/main.js index 4e0d9cc..1458f82 100644 --- a/ZplPrinter/js/main.js +++ b/ZplPrinter/js/main.js @@ -19,7 +19,12 @@ $(document).ready(function () { chrome.sockets.tcp.onReceive.addListener(function (info) { notify('{0} bytes received from Client: {1} Port: {2}'.format(info.data.byteLength, clientSocketInfo.peerAddress, clientSocketInfo.peerPort), 'print', 'info', 1000); var zpls = String.fromCharCode.apply(null, new Uint8Array(info.data)).split(/\^XZ/); - chrome.sockets.tcp.close(info.socketId); + 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) { diff --git a/ZplPrinter/main.html b/ZplPrinter/main.html index 0fc6515..a11adcc 100644 --- a/ZplPrinter/main.html +++ b/ZplPrinter/main.html @@ -120,7 +120,22 @@ - + +
+
+ +
+
+