qzind / tray

Browser plugin for sending documents and raw commands to a printer or attached device.
https://qz.io
Other
823 stars 266 forks source link

callCert incorrect behavior in async detection code #1255

Closed Martin-for-mqt closed 2 months ago

Martin-for-mqt commented 2 months ago

when i use async function in setCertificatePromise, sendCert params is undefined, example:

qz.security.setCertificatePromise( async (sendCert) => {
      const res = await request.get('/print/certification');
      sendCert(res.data);
})

i change source code to , it is work!

callCert: function () {
                if (typeof _qz.security.certHandler.then === 'function') {
                    //already a promise
                    return _qz.security.certHandler;
                } else if (_qz.security.certHandler.constructor.name === "AsyncFunction") {
                    //already callable as a promise
                    // before
                    // return _qz.security.certHandler();
                    // after
                    return _qz.tools.promise(_qz.security.certHandler);
                } else {
                    //turn into a promise
                    return _qz.tools.promise(_qz.security.certHandler);
                }
            }
tresf commented 2 months ago

Hi,

I was able to reproduce the problem... this is my solution:

qz.security.setCertificatePromise(async () => {
   const res = await fetch('mycert.crt');
   return await res.text();
});
tresf commented 2 months ago

Hi,

I am closing this bug report, since I believe it to be incorrect usage of the API. If you believe this was closed in error, or if you believe that this problem can be rectified by addition code, please share!