qz, auto-table control, auto-git pull, etc

This commit is contained in:
2026-02-12 16:18:43 +07:00
parent eb62ba5ee1
commit 71e587a8ca
10 changed files with 724 additions and 565 deletions
+27 -17
View File
@@ -4,16 +4,25 @@
Desc. : JS Setup QZ Connection
Created By : Siau Pheng ([email protected]).
Created Date : May 27th, 2007.
Last Modified : January 9th, 2021.
Last Modified : February 8th, 2026.
(c) 2008 - 2021, 3FONIA Software; WWW.3FONIA.COM.
(c) 2008 - 2026, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
function startConnection() {
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().then(function() {
qz.websocket.connect(config).then(() => {
_updateState('Active');
_findDefaultPrinter();
});
@@ -24,7 +33,7 @@ function startConnection() {
function endConnection(){
if (qz.websocket.isActive()) {
qz.websocket.disconnect().then(function() {
qz.websocket.disconnect().then(() => {
_updateState('Inactive');
});
} else {
@@ -33,7 +42,7 @@ function endConnection(){
}
function _findDefaultPrinter(){
qz.printers.getDefault().then(function(data) {
qz.printers.getDefault().then((data) => {
var _printer = data;
if (typeof data === 'object' && data.name == undefined) {
if (data.file != undefined) _printer = "FILE: " + data.file;
@@ -44,35 +53,36 @@ function _findDefaultPrinter(){
}
FoniaJS._def_printer = data;
FoniaJS._def_printname = _printer;
$(_divStatus).html($(_divStatus).html() + ' // ' + _printer);
setTimeout(() => $(_divStatus).html($(_divStatus).html() + ' // ' + _printer), 2000);
});
}
function _updateState(text){
$(_divStatus).html(text);
$(_divStatus).html(text).removeClass('border-success border-warning text-success');
if (text == "Active") {
$(_divStatus).css("background-color", "#AAFFAA");
$(_divStatus).addClass('border-success text-success');
} else {
$(_divStatus).css("background-color", "#FFFFC0");
$(_divStatus).addClass('border-warning');
}
}
var _divStatus = '#divQZStatus';
const _divStatus = '#divQZStatus';
if (typeof qz !== 'undefined') {
qz.security.setCertificatePromise(function(resolve, reject) {
jQuery.ajax({ url:FoniaJS.WEB_PATH+'assets/signing/cert.pem', cache:false, dataType:'text' }).then(resolve, reject);
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(function(toSign) {
return function(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(function(evt) {
qz.websocket.setClosedCallbacks((evt) => {
_updateState('Inactive');
if (evt.reason) console.info("Connection closed: " + evt.reason);
});
qz.websocket.setErrorCallbacks(function(evt){
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";
+467 -352
View File
File diff suppressed because it is too large Load Diff