Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

speech recognition - minor changes

DanielŻuławskiefcf24260841
diff --git a/src/Web/Grand.Web/Views/Shared/Components/SearchBox/Default.cshtml b/src/Web/Grand.Web/Views/Shared/Components/SearchBox/Default.cshtml
index c880f404f..70c56a6fc 100644
--- a/src/Web/Grand.Web/Views/Shared/Components/SearchBox/Default.cshtml
+++ b/src/Web/Grand.Web/Views/Shared/Components/SearchBox/Default.cshtml
@@ -18,7 +18,8 @@
@await Component.InvokeAsync("Widget", new { widgetZone = "searchbox_before_search_button" })
<div class="input-group-append">
- <button id="voiceSearchButton"
+ <button id="voiceSearchButton"
+ v-if="searchbox.allowed"
@@touchstart="searchbox.recording = true"
@@touchcancel="searchbox.recording = false; $root.$emit('bv::hide::tooltip')"
@@touchend="searchbox.recording = false; $root.$emit('bv::hide::tooltip')"
@@ -128,6 +129,7 @@
searchbrands: null,
searchblog: null,
searchproducts: null,
+ allowed: true,
}),
methods: {
startRecording() {
@@ -196,6 +198,27 @@
}, 600);
}
},
+ created() {
+ navigator.permissions.query(
+ { name: 'microphone' }
+ ).then(function (permissionStatus) {
+
+ if (permissionStatus.state == "denied") {
+ searchbox.allowed = false;
+ } else {
+ searchbox.allowed = true;
+ }
+
+ permissionStatus.onchange = function () {
+ if (this.state == "denied") {
+ searchbox.allowed = false;
+ } else {
+ searchbox.allowed = true;
+ }
+ }
+
+ });
+ },
watch: {
text: function () {
const searchBoxInput = vm.$refs.searchBoxInput;
@@ -253,7 +276,7 @@
}
} else {
- this.micMessage = '@Loc["search.voice.notsupported"]';
+ this.allowed = false;
}
}
}
diff --git a/src/Web/Grand.Web/Views/Shared/Components/VoiceNavigation/Default.cshtml b/src/Web/Grand.Web/Views/Shared/Components/VoiceNavigation/Default.cshtml
index 04fc3dda0..ca4ca2161 100644
--- a/src/Web/Grand.Web/Views/Shared/Components/VoiceNavigation/Default.cshtml
+++ b/src/Web/Grand.Web/Views/Shared/Components/VoiceNavigation/Default.cshtml
@@ -2,7 +2,7 @@
@{
var lang = workContext.WorkingLanguage.LanguageCulture;
}
-<template>
+<template v-if="voicenavigator.allowed">
<button id="voicePageButton"
@@touchstart="voicenavigator.recording = true"
@@touchcancel="voicenavigator.recording = false; $root.$emit('bv::hide::tooltip')"
@@ -33,7 +33,7 @@
</div>
<input type="text" placeholder="@Loc["voicenavigator.voice.placeholder"]" v-model="voicenavigator.transcript" class="form-control" readonly />
</div>
- <small class="form-text text-muted w-100">@Loc["voicenavigator.voice.annotation"]</small>
+ <small class="form-text w-100">@Loc["voicenavigator.voice.annotation"]</small>
</b-alert>
</template>
<script asp-location="Footer" asp-order="300">
@@ -82,7 +82,8 @@
transcript: "",
variant: "info",
micMessage: "@Loc["voicenavigator.voice.holdtospeak"]",
- voiceMessage: "@Loc["voicenavigator.voice.tryagain"]"
+ voiceMessage: "@Loc["voicenavigator.voice.tryagain"]",
+ allowed: true,
}),
methods: {
startRecording() {
@@ -92,6 +93,27 @@
this.recognition.stop();
},
},
+ created() {
+ navigator.permissions.query(
+ { name: 'microphone' }
+ ).then(function (permissionStatus) {
+
+ if (permissionStatus.state == "denied") {
+ voicenavigator.allowed = false;
+ } else {
+ voicenavigator.allowed = true;
+ }
+
+ permissionStatus.onchange = function () {
+ if (this.state == "denied") {
+ voicenavigator.allowed = false;
+ } else {
+ voicenavigator.allowed = true;
+ }
+ }
+
+ });
+ },
watch: {
recording: function () {
const speech = window.SpeechRecognition || window.webkitSpeechRecognition;
@@ -143,6 +165,7 @@
}
}
}
+
} else {
this.stopRecording();
this.transcript = "";
@@ -150,7 +173,7 @@
this.micMessage = '@Loc["voicenavigator.voice.holdtospeak"]';
}
} else {
- this.micMessage = '@Loc["voicenavigator.voice.notsupported"]';
+ this.allowed = false;
}
}
}
diff --git a/src/Web/Grand.Web/wwwroot/theme/css/common/common.css b/src/Web/Grand.Web/wwwroot/theme/css/common/common.css
index 701a50838..f829bd572 100644
--- a/src/Web/Grand.Web/wwwroot/theme/css/common/common.css
+++ b/src/Web/Grand.Web/wwwroot/theme/css/common/common.css
@@ -1677,7 +1677,7 @@ footer .list-group-item span:last-child {
[dark-theme="true"] .date-text, [dark-theme="true"] .product-box .spec-value {
color: #aaa;
}
-[dark-theme="true"] footer .list-group-item-action, [dark-theme="true"] .generalLeftSide .btn.color-container,
+[dark-theme="true"] footer .list-group-item-action, [dark-theme="true"] .generalLeftSide .btn.color-container, [dark-theme="true"] .recording-window input.form-control,
[dark-theme="true"] footer .list-group-item:not(.list-group-item-action), [dark-theme="true"] .newsletter-email-button, [dark-theme="true"] .product-box::before, [dark-theme="true"] .product-box {
background-color: transparent;
}
diff --git a/src/Web/Grand.Web/wwwroot/theme/css/common/common.rtl.css b/src/Web/Grand.Web/wwwroot/theme/css/common/common.rtl.css
index 1edaad430..ea29c03a7 100644
--- a/src/Web/Grand.Web/wwwroot/theme/css/common/common.rtl.css
+++ b/src/Web/Grand.Web/wwwroot/theme/css/common/common.rtl.css
@@ -1828,7 +1828,7 @@ footer .list-group-item span:last-child {
[dark-theme="true"] .date-text, [dark-theme="true"] .product-box .spec-value {
color: #aaa;
}
-[dark-theme="true"] footer .list-group-item-action, [dark-theme="true"] .generalLeftSide .btn.color-container,
+[dark-theme="true"] footer .list-group-item-action, [dark-theme="true"] .generalLeftSide .btn.color-container, [dark-theme="true"] .recording-window input.form-control,
[dark-theme="true"] footer .list-group-item:not(.list-group-item-action), [dark-theme="true"] .newsletter-email-button, [dark-theme="true"] .product-box::before, [dark-theme="true"] .product-box {
background-color: transparent;
}