From ae170a9d58b4f91a225eada1dc83ed4a116b8d50 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期日, 25 八月 2024 00:57:37 +0800 Subject: [PATCH] 2024-08-25 --- src/tabviews/zshare/settingcomponent/index.jsx | 49 ++++++++++++++++++++++++++++++++----------------- 1 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/tabviews/zshare/settingcomponent/index.jsx b/src/tabviews/zshare/settingcomponent/index.jsx index 77e2230..dd87d2c 100644 --- a/src/tabviews/zshare/settingcomponent/index.jsx +++ b/src/tabviews/zshare/settingcomponent/index.jsx @@ -316,9 +316,14 @@ }) } else if (!links.includes(item.verify.linkUrl)) { links.push(item.verify.linkUrl) + } + }) - let socket = null - socket = new WebSocket('ws://' + item.verify.linkUrl) + if (links.length === 0) return + + let defers = links.map(link => { + return new Promise((resolve) => { + let socket = new WebSocket('ws://' + link) // 鎵撳紑Socket socket.onopen = () =>{ let request = { @@ -360,29 +365,39 @@ }) } - window.GLOB.UserCacheMap.set(item.verify.linkUrl, _printers) - } else if (data && data.cmd === 'getPrinters') { - notification.warning({ - top: 92, - message: data.message, - duration: 5 - }) + resolve({status: true, printers: _printers}) + } else if (data && data.cmd === 'getPrinters' && data.message) { + resolve({status: false, printers: null, message: data.message}) } } socket.onerror = () => { - let tool = item.verify.linkUrl - if (item.verify.linkUrl === '127.0.0.1:13529') { + let tool = link + + if (link === '127.0.0.1:13529') { tool = '鏄庣閫氳缁勪欢' - } else if (item.verify.linkUrl === '127.0.0.1:13528') { + } else if (link === '127.0.0.1:13528') { tool = 'CAINIAO鎵撳嵃缁勪欢' } - notification.warning({ - top: 92, - message: '鏃犳硶杩炴帴鍒�: ' + tool, - duration: 5 - }) + + resolve({status: false, printers: null, message: '鏃犳硶杩炴帴鍒�: ' + tool}) + } + }) + }) + + Promise.all(defers).then(results => { + let res = results.filter(item => item.status)[0] + if (res) { + links.forEach(link => { + window.GLOB.UserCacheMap.set(link, res.printers) + }) + } else { + notification.warning({ + top: 92, + message: results[0].message, + duration: 5 + }) } }) } -- Gitblit v1.8.0