From 7b75ec466c80b3febcf88bf918bc2a9de62cf11f Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Mon, 26 Sep 2022 18:56:30 +0700 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B1=D0=B0=D0=B3=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/Api/Api.vue | 64 ++++++++++++++++++++++++----------- client/share/LockQueue.js | 2 +- 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/client/components/Api/Api.vue b/client/components/Api/Api.vue index c9869d0..717c2c3 100644 --- a/client/components/Api/Api.vue +++ b/client/components/Api/Api.vue @@ -35,6 +35,7 @@ import vueComponent from '../vueComponent.js'; import wsc from './webSocketConnection'; import * as utils from '../../share/utils'; import * as cryptoUtils from '../../share/cryptoUtils'; +import LockQueue from '../../share/LockQueue'; const rotor = '|/-\\'; const stepBound = [ @@ -72,6 +73,7 @@ class Api { created() { this.commit = this.$store.commit; + this.lock = new LockQueue(); this.loadSettings(); } @@ -103,14 +105,50 @@ class Api { return this.$store.state.settings; } + async showPasswordDialog() { + try { + await this.lock.get();//заход только один раз, остальные ждут закрытия диалога + } catch (e) { + return; + } + + try { + const result = await this.$root.stdDialog.password(`Введите пароль для доступа:`, ' ', { + inputValidator: (str) => (str ? true : 'Пароль не должен быть пустым'), + userName: 'access', + noEscDismiss: true, + noBackdropDismiss: true, + noCancel: true, + }); + + if (result && result.value) { + const accessToken = utils.toHex(cryptoUtils.sha256(result.value)); + this.commit('setSettings', {accessToken}); + } + } finally { + this.lock.errAll(); + this.lock.ret(); + } + } + async showBusyDialog() { + try { + await this.lock.get();//заход только один раз, остальные ждут закрытия диалога + } catch (e) { + return; + } + this.mainMessage = ''; this.jobMessage = ''; this.busyDialogVisible = true; try { let ri = 0; while (1) {// eslint-disable-line - const server = await wsc.message(await wsc.send({action: 'get-worker-state', workerId: 'server_state'})); + const params = {action: 'get-worker-state', workerId: 'server_state'}; + if (this.accessToken) + params.accessToken = this.accessToken; + + const server = await wsc.message(await wsc.send(params)); if (server.state != 'normal') { this.mainMessage = `${server.serverMessage} ${rotor[ri]}`; @@ -138,22 +176,8 @@ class Api { } } finally { this.busyDialogVisible = false; - } - } - - - async showPasswordDialog() { - const result = await this.$root.stdDialog.password(`Введите пароль для доступа:`, ' ', { - inputValidator: (str) => (str ? true : 'Пароль не должен быть пустым'), - userName: 'access', - noEscDismiss: true, - noBackdropDismiss: true, - noCancel: true, - }); - - if (result && result.value) { - const accessToken = utils.toHex(cryptoUtils.sha256(result.value)); - this.commit('setSettings', {accessToken}); + this.lock.errAll(); + this.lock.ret(); } } @@ -164,10 +188,10 @@ class Api { const response = await wsc.message(await wsc.send(params), timeoutSecs); - if (response && response.error == 'server_busy') { - await this.showBusyDialog(); - } else if (response && response.error == 'need_access_token') { + if (response && response.error == 'need_access_token') { await this.showPasswordDialog(); + } else if (response && response.error == 'server_busy') { + await this.showBusyDialog(); } else { return response; } diff --git a/client/share/LockQueue.js b/client/share/LockQueue.js index ed350c5..854dc52 100644 --- a/client/share/LockQueue.js +++ b/client/share/LockQueue.js @@ -1,5 +1,5 @@ class LockQueue { - constructor(queueSize) { + constructor(queueSize = 100) { this.queueSize = queueSize; this.freed = true; this.waitingQueue = [];