This commit is contained in:
Vanessa 2022-10-31 22:25:01 +08:00
parent ad8b04ccec
commit 5deacf31d5
8 changed files with 50 additions and 8 deletions

View file

@ -1,4 +1,6 @@
{
"microphoneDenied": "Need to allow Siyuan to access the microphone in System Preferences",
"microphoneNotAccess": "Access to the microphone is denied, go to System Preferences to reset",
"dynamicLoadBlocks": "Number of dynamically loaded blocks",
"dynamicLoadBlocksTip": "This value contains the number of subblocks. If there are many code blocks, formula blocks or chart blocks that need to be rendered, it is recommended not to set too large",
"googleAnalytics": "Google Analytics",

View file

@ -1,4 +1,6 @@
{
"microphoneDenied": "Necesito permitir que Siyuan acceda al micrófono en Preferencias del Sistema",
"microphoneNotAccess": "Acceso al micrófono denegado, ve a Preferencias del Sistema para reiniciar",
"dynamicLoadBlocks": "Número de bloques cargados dinámicamente",
"dynamicLoadBlocksTip": "Este valor contiene el número de subbloques. Si hay muchos bloques de código, bloques de fórmulas o bloques de gráficos que necesitan renderizarse, se recomienda no configurarlos demasiado grandes",
"googleAnalytics": "Google Analytics",

View file

@ -1,4 +1,6 @@
{
"microphoneDenied": "Vous devez autoriser Siyuan à accéder au microphone dans les Préférences Système",
"microphoneNotAccess": "L'accès au microphone est refusé, allez dans les Préférences Système pour réinitialiser",
"dynamicLoadBlocks": "Nombre de blocs chargés dynamiquement",
"dynamicLoadBlocksTip": "Cette valeur contient le nombre de sous-blocs. S'il y a beaucoup de blocs de code, de blocs de formule ou de blocs de graphique qui doivent être rendus, il est recommandé de ne pas définir trop grand",
"googleAnalytics": "Google Analytics",

View file

@ -1,4 +1,6 @@
{
"microphoneDenied": "需在系統偏好設置中允許思源訪問麥克風",
"microphoneNotAccess": "麥克風被拒絕訪問,可前往系統偏好設置中重新設置",
"dynamicLoadBlocks": "動態加載塊數",
"dynamicLoadBlocksTip": "該值包含了子塊數。如果需要渲染的代碼塊、公式塊或圖表塊較多,建議不要設置過大",
"googleAnalytics": "Google Analytics",

View file

@ -1,4 +1,6 @@
{
"microphoneDenied": "需在系统偏好设置中允许思源访问麦克风",
"microphoneNotAccess": "麦克风被拒绝访问,可前往系统偏好设置中重新设置",
"dynamicLoadBlocks": "动态加载块数",
"dynamicLoadBlocksTip": "该值包含了子块数。如果需要渲染的代码块、公式块或图表块较多,建议不要设置过大",
"googleAnalytics": "Google Analytics",

View file

@ -18,6 +18,8 @@ mac:
gatekeeperAssess: false
hardenedRuntime: true
entitlements: "../../entitlements.mas.plist"
extendInfo:
- NSMicrophoneUsageDescription: "This app requires microphone access to record audio."
entitlementsInherit: "../../entitlements.mas.plist"
extraResources:
- from: "kernel-darwin-arm64"
@ -51,4 +53,4 @@ extraResources:
to: "appearance/themes/daylight"
filter: "!**/{.DS_Store,custom.css}"
- from: "pandoc/pandoc-darwin-amd64.zip"
to: "pandoc.zip"
to: "pandoc.zip"

View file

@ -18,6 +18,8 @@ mac:
gatekeeperAssess: false
hardenedRuntime: true
entitlements: "../../entitlements.mas.plist"
extendInfo:
- NSMicrophoneUsageDescription: "This app requires microphone access to record audio."
entitlementsInherit: "../../entitlements.mas.plist"
extraResources:
- from: "kernel-darwin"
@ -50,4 +52,4 @@ extraResources:
to: "appearance/themes/daylight"
filter: "!**/{.DS_Store,custom.css}"
- from: "pandoc/pandoc-darwin-amd64.zip"
to: "pandoc.zip"
to: "pandoc.zip"

View file

@ -19,7 +19,7 @@ import {openFileById} from "../../editor/util";
import {getAllModels} from "../../layout/getAll";
/// #endif
/// #if !BROWSER
import {getCurrentWindow} from "@electron/remote";
import {getCurrentWindow, systemPreferences} from "@electron/remote";
/// #endif
import {onGet} from "../util/onGet";
import {saveScroll} from "../scroll/saveScroll";
@ -130,6 +130,20 @@ export class Breadcrumb {
/// #endif
}
private startRecord(protyle: IProtyle) {
this.messageId = showMessage(`<div class="fn__flex fn__flex-wrap">
<span class="fn__flex-center">${window.siyuan.languages.recording}</span><span class="fn__space"></span>
<button class="b3-button b3-button--white">${window.siyuan.languages.endRecord}</button></div>`, -1);
document.querySelector(`#message [data-id="${this.messageId}"] button`).addEventListener("click", () => {
this.mediaRecorder.stopRecording();
hideMessage(this.messageId);
const file: File = new File([this.mediaRecorder.buildWavFileBlob()],
`record${(new Date()).getTime()}.wav`, {type: "video/webm"});
uploadFiles(protyle, [file]);
});
this.mediaRecorder.startRecordingNewWavFile();
}
private showMenu(protyle: IProtyle, position: { x: number, y: number }) {
let id;
const cursorNodeElement = hasClosestBlock(getEditorRange(protyle.element).startContainer);
@ -164,7 +178,23 @@ export class Breadcrumb {
current: this.mediaRecorder && this.mediaRecorder.isRecording,
icon: "iconRecord",
label: this.mediaRecorder?.isRecording ? window.siyuan.languages.endRecord : window.siyuan.languages.startRecord,
click: () => {
click: async () => {
/// #if !BROWSER
if (window.siyuan.config.system.os === "darwin") {
const status = systemPreferences.getMediaAccessStatus('microphone')
if (["denied", "restricted", "unknown"].includes(status)) {
showMessage(window.siyuan.languages.microphoneDenied);
return;
} else if (status === "not-determined") {
const isAccess = await systemPreferences.askForMediaAccess('microphone')
if (!isAccess) {
showMessage(window.siyuan.languages.microphoneNotAccess);
return;
}
}
}
/// #endif
if (!this.mediaRecorder) {
navigator.mediaDevices.getUserMedia({audio: true}).then((mediaStream: MediaStream) => {
this.mediaRecorder = new RecordMedia(mediaStream);
@ -178,8 +208,7 @@ export class Breadcrumb {
const right = e.inputBuffer.getChannelData(1);
this.mediaRecorder.cloneChannelData(left, right);
};
this.mediaRecorder.startRecordingNewWavFile();
this.messageId = showMessage(window.siyuan.languages.recording, -1);
this.startRecord(protyle);
}).catch(() => {
showMessage(window.siyuan.languages["record-tip"]);
});
@ -194,8 +223,7 @@ export class Breadcrumb {
uploadFiles(protyle, [file]);
} else {
hideMessage(this.messageId);
this.messageId = showMessage(window.siyuan.languages.recording, -1);
this.mediaRecorder.startRecordingNewWavFile();
this.startRecord(protyle)
}
}
}).element);