first commit

This commit is contained in:
2026-07-25 16:54:11 +07:00
commit 36395c2b55
84 changed files with 40698 additions and 0 deletions
+93
View File
@@ -0,0 +1,93 @@
/*******************************************************************
Module : /js3/qz/qz-start.js
Desc. : JS Setup QZ Connection
Created By : Siau Pheng ([email protected]).
Created Date : May 27th, 2007.
Last Modified : February 8th, 2026.
(c) 2008 - 2026, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
function launchQZ() {
if (!qz.websocket.isActive()) {
window.location.assign("qz:launch");
//Retry 5 times, pausing 1 second between each attempt
startConnection({ retries: 5, delay: 1 });
}
}
function startConnection(config) {
config = config ? config : {};
if (!qz.websocket.isActive()) {
_updateState('Waiting');
qz.websocket.connect(config).then(() => {
_updateState('Active');
_findDefaultPrinter();
});
} else {
console.info('An active connection with QZ already exists.');
}
}
function endConnection(){
if (qz.websocket.isActive()) {
qz.websocket.disconnect().then(() => {
_updateState('Inactive');
});
} else {
console.info('No active connection with QZ exists.');
}
}
function _findDefaultPrinter(){
qz.printers.getDefault().then((data) => {
var _printer = data;
if (typeof data === 'object' && data.name == undefined) {
if (data.file != undefined) _printer = "FILE: " + data.file;
if (data.host != undefined) _printer = "HOST: " + data.host + ":" + data.port;
} else {
if (data.name != undefined) _printer = data.name;
if (data== undefined) _printer = 'NONE';
}
FoniaJS._def_printer = data;
FoniaJS._def_printname = _printer;
setTimeout(() => $(_divStatus).html($(_divStatus).html() + ' // ' + _printer), 2000);
});
}
function _updateState(text){
$(_divStatus).html(text).removeClass('border-success border-warning text-success');
if (text == "Active") {
$(_divStatus).addClass('border-success text-success');
} else {
$(_divStatus).addClass('border-warning');
}
}
const _divStatus = '#divQZStatus';
if (typeof qz !== 'undefined') {
qz.security.setSignatureAlgorithm("SHA512");
qz.security.setCertificatePromise((resolve, reject) => {
jQuery.ajax({url:FoniaJS.WEB_PATH+'assets/signing/cert.pem', cache:false, dataType:'text'}).then(resolve, reject);
});
qz.security.setSignaturePromise((toSign) => {
return (resolve, reject) => {
jQuery.post(FoniaJS.WEB_PATH+"assets/signing/sign.php?req="+toSign).then(resolve, reject);
};
});
qz.websocket.setClosedCallbacks((evt) => {
_updateState('Inactive');
if (evt.reason) console.info("Connection closed: " + evt.reason);
});
qz.websocket.setErrorCallbacks((evt) => {
_updateState('Error');
if (evt.target != undefined) {
var err = (evt.target.readyState >= 2) ? "Connection to QZ Tray was closed" : "A connection error occurred, check log for details";
console.info(err)
}
});
startConnection();
}