Skip to content

Commit 8552b0e

Browse files
committed
Support utf8 on socket
1 parent dfe8839 commit 8552b0e

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

ZplEscPrinter/js/main.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ async function zpl(data){
150150
}
151151
async function escpos(data,b64){
152152
let dataAux = data;
153-
try{ dataAux = atob(data.trim()); }catch(e){}
153+
try{ dataAux = base64DecodeUnicode(data.trim()); b64=true; }catch(e){}
154154

155155
if (!dataAux || !dataAux.trim().length) {
156156
console.warn(`esc/pos = '${data}', seems invalid`);
@@ -243,17 +243,18 @@ function startTcpServer() {
243243

244244
server.on('connection', function (sock) {
245245
console.log('CONNECTED: ' + sock.remoteAddress + ':' + sock.remotePort);
246+
sock.setEncoding('utf8');
246247
clientSocketInfo = {
247248
peerAddress: sock.remoteAddress,
248249
peerPort: sock.remotePort
249250
};
250-
sock.write(JSON.stringify({success: true}, 'text/html'));
251+
sock.write(JSON.stringify({success: true}));
251252

252253
sock.on('data', async function (data) {
253254
notify('{0} bytes received from Client: <b>{1}</b> Port: <b>{2}</b>'.format(data.length, clientSocketInfo.peerAddress, clientSocketInfo.peerPort), 'print', 'info', 1000);
254255
//console.log(String.fromCharCode.apply(null, new Uint8Array(data)));
255256
const regex = /POST.*\r\n\r\n/gs;
256-
const code = String.fromCharCode.apply(null, new Uint8Array(data)).replace(regex,'');
257+
const code = (data || '').replace(regex,'');
257258
if (code.includes('Host:') && code.includes('Connection: keep-alive') && code.includes('HTTP')) {
258259
console.log('It\'s an ajax call');
259260
return;

main.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
//const { updateElectronApp, UpdateSourceType } = require('update-electron-app')
2-
//updateElectronApp()
3-
41
const { app, BrowserWindow, dialog, ipcMain } = require('electron')
52
const path = require("path")
63

74
if (require('electron-squirrel-startup')) return app.quit();
5+
6+
const { updateElectronApp, UpdateSourceType } = require('update-electron-app')
7+
updateElectronApp()
8+
89
let win
910
const createWindow = () => {
1011
win = new BrowserWindow({

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"bootstrap": "^5.3.2",
3737
"electron-squirrel-startup": "^1.0.0",
3838
"glyphicons-only-bootstrap": "^1.0.1",
39-
"jquery": "^3.7.1"
39+
"jquery": "^3.7.1",
40+
"update-electron-app": "^3.0.0"
4041
}
4142
}

0 commit comments

Comments
 (0)