From 2704511e75231f24ad2ffcb30e5a2faed905aab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=85=E8=88=AA?= <602869941@qq.com> Date: Tue, 13 Aug 2024 16:00:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=96=87=E4=BB=B6=E8=B7=AF?= =?UTF-8?q?=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.js | 2 +- src/components/StupWizard/index.tsx | 1095 ++++++++++++++------------- 2 files changed, 556 insertions(+), 541 deletions(-) diff --git a/main.js b/main.js index 0d0fc20..ac6b73b 100644 --- a/main.js +++ b/main.js @@ -138,7 +138,7 @@ app.on('ready', () => { // 获取当前脚本所在目录的绝对路径 const currentDirectory = __dirname; // 获取安装父目录 - const parentDirectory = path.resolve(currentDirectory, '../..'); + const parentDirectory = path.resolve(currentDirectory, '..'); const customFolderPath = path.join(parentDirectory, 'Downloads'); if (!fs.existsSync(customFolderPath)) { // 如果不存在,则创建文件夹 diff --git a/src/components/StupWizard/index.tsx b/src/components/StupWizard/index.tsx index 9dbe933..c30e120 100644 --- a/src/components/StupWizard/index.tsx +++ b/src/components/StupWizard/index.tsx @@ -1,572 +1,587 @@ import styles from '@/components/StupWizard/index.module.scss' import ImageUrl from '@/utils/package/ImageUrl'; -import { Button, Checkbox, Empty, Input, Modal, Popover, Radio, Select, Slider, message } from 'antd'; -import { useState, useImperativeHandle, forwardRef, useEffect } from "react"; +import {Button, Checkbox, Empty, Input, message, Modal, Popover, Radio, Select, Slider} from 'antd'; +import {forwardRef, useEffect, useImperativeHandle, useState} from "react"; import agora from '@/utils/package/agora' -import { CloseOutlined, LoadingOutlined, QuestionCircleOutlined } from '@ant-design/icons'; -import { storage } from '@/utils'; +import {CloseOutlined, LoadingOutlined, QuestionCircleOutlined} from '@ant-design/icons'; +import {storage} from '@/utils'; import path from 'path'; + const fs = require('fs').promises; -const { exec } = require('child_process'); +const {exec} = require('child_process'); const StupWizard = forwardRef((props: any, ref: any) => { - useImperativeHandle(ref, () => ({ - changeModal: () => { - if (location.hash.indexOf('/meeting') === -1) { - agora.init() - } - setIsStupWizard(true) - } - })) - const [list, setList] = useState([ - { - title: '通用', - icon: ImageUrl.icon39, - iconActive: ImageUrl.icon39Active, - active: true, - }, - { - title: '视频', - icon: ImageUrl.icon39, - iconActive: ImageUrl.icon39Active, - active: false, - }, - { - title: '音频', - icon: ImageUrl.icon40, - iconActive: ImageUrl.icon40Active, - active: false, - }, - { - title: '录制', - icon: ImageUrl.icon41, - iconActive: ImageUrl.icon41Active, - active: false, - }, - { - title: '共享文件', - icon: ImageUrl.icon42, - iconActive: ImageUrl.icon42Active, - active: false, - } - ]) - const [isStupWizard, setIsStupWizard] = useState(false); - return ( - <> - -
-
- {list.map((row: any, index: number) => { - return ( -
{ - const newList = [...list]; - newList.forEach(item => item.active = false); - newList[index].active = true; - setList(newList) - agora.stopPlaybackDeviceTest() - agora.stopRecordingDeviceTest() - }}> - - {row.title} + useImperativeHandle(ref, () => ({ + changeModal: () => { + if (location.hash.indexOf('/meeting') === -1) { + agora.init() + } + setIsStupWizard(true) + } + })) + const [list, setList] = useState([ + { + title: '通用', + icon: ImageUrl.icon39, + iconActive: ImageUrl.icon39Active, + active: true, + }, + { + title: '视频', + icon: ImageUrl.icon39, + iconActive: ImageUrl.icon39Active, + active: false, + }, + { + title: '音频', + icon: ImageUrl.icon40, + iconActive: ImageUrl.icon40Active, + active: false, + }, + { + title: '录制', + icon: ImageUrl.icon41, + iconActive: ImageUrl.icon41Active, + active: false, + }, + { + title: '共享文件', + icon: ImageUrl.icon42, + iconActive: ImageUrl.icon42Active, + active: false, + } + ]) + const [isStupWizard, setIsStupWizard] = useState(false); + return ( + <> + +
+
+ {list.map((row: any, index: number) => { + return ( +
{ + const newList = [...list]; + newList.forEach(item => item.active = false); + newList[index].active = true; + setList(newList) + agora.stopPlaybackDeviceTest() + agora.stopRecordingDeviceTest() + }}> + + {row.title} +
+ ) + })} +
+
+ { + if (location.hash.indexOf('/meeting') === -1) { + agora.release() + } + setIsStupWizard(false) + }} + /> + {list[0].active ? : null} + {list[1].active ? : null} + {list[2].active ? : null} + {list[3].active ? : null} + {list[4].active ? : null} +
- ) - })} -
-
- { - if (location.hash.indexOf('/meeting') === -1) { - agora.release() - } - setIsStupWizard(false) - }} - /> - {list[0].active ? : null} - {list[1].active ? : null} - {list[2].active ? : null} - {list[3].active ? : null} - {list[4].active ? : null} -
-
- - - ) + + + ) }) const CurrencyComponents = () => { - const [optionsValue, setOperationValue] = useState<'hide' | 'quit'>('hide'); - const setting = JSON.parse(storage.getItem('setting') as string) - useEffect(() => { - setOperationValue(setting.closeSetting) - }, []); - return ( - <> -
- 通用 -
-
+ const [optionsValue, setOperationValue] = useState<'hide' | 'quit'>('hide'); + const setting = JSON.parse(storage.getItem('setting') as string) + useEffect(() => { + setOperationValue(setting.closeSetting) + }, []); + return ( + <>
- 关闭按钮设置 - { - setting.closeSetting = e.target.value; - storage.setItem('setting', JSON.stringify(setting)) - setOperationValue(e.target.value) - }} style={{ flexShrink: 0, margin: '10px 0' }} value={optionsValue}> - 退出主程序 - 不退出程序,最小化到托盘 - + 通用 +
+
+
+ 关闭按钮设置 + { + setting.closeSetting = e.target.value; + storage.setItem('setting', JSON.stringify(setting)) + setOperationValue(e.target.value) + }} style={{flexShrink: 0, margin: '10px 0'}} value={optionsValue}> + 退出主程序 + 不退出程序,最小化到托盘 + +
+
+
-
-
-
- - ) + + ) } const VideoComponents = () => { - const [videoDeviceManager, setVideoDeviceManager] = useState({ - list: [], - item: null, - }); - const setting = JSON.parse(storage.getItem('setting') as string) - useEffect(() => { - getVideoDeviceList() - }, []); - const getVideoDeviceList = async (): Promise => { - const userInfo = JSON.parse(storage.getItem('user') as string) - agora.getVideoDeviceManager().then(async (res) => { - const { item, list } = res - if ((!setting.videoDeviceId && item) || (!(list.find((item: any) => item.deviceId === setting.videoDeviceId)) && item)) { - setting.videoDeviceId = item - } - if (!list.length) { - setting.videoDeviceId = '' - } - storage.setItem('setting', JSON.stringify(setting)) - setVideoDeviceManager({ - list: list.map((row: any) => { - return { - value: row.deviceId, - label: row.deviceName - } - }), - item: setting.videoDeviceId ? setting.videoDeviceId : item || null, - }) - if (setting.videoDeviceId && list.length) { - await agora.setVideoDeviceManager(setting.videoDeviceId) - await agora.startPreview('videoPreview', Number(userInfo.account)) - } - }) - } - return ( - <> -
- 视频 -
- { - videoDeviceManager.item ? -
-
- -
-
: -
-
- -
-
- } -
- 摄像头: - + const [videoDeviceManager, setVideoDeviceManager] = useState({ + list: [], + item: null, + }); + const setting = JSON.parse(storage.getItem('setting') as string) + useEffect(() => { + getVideoDeviceList() + }, []); + const getVideoDeviceList = async (): Promise => { + const userInfo = JSON.parse(storage.getItem('user') as string) + agora.getVideoDeviceManager().then(async (res) => { + const {item, list} = res + if ((!setting.videoDeviceId && item) || (!(list.find((item: any) => item.deviceId === setting.videoDeviceId)) && item)) { + setting.videoDeviceId = item + } + if (!list.length) { + setting.videoDeviceId = '' + } + storage.setItem('setting', JSON.stringify(setting)) + setVideoDeviceManager({ + list: list.map((row: any) => { + return { + value: row.deviceId, + label: row.deviceName + } + }), + item: setting.videoDeviceId ? setting.videoDeviceId : item || null, + }) + if (setting.videoDeviceId && list.length) { + await agora.setVideoDeviceManager(setting.videoDeviceId) + await agora.startPreview('videoPreview', Number(userInfo.account)) + } + }) + } + return ( + <> +
+ 视频 +
+ { + videoDeviceManager.item ? +
+
+ +
+
: +
+
+ +
+
+ } +
+ 摄像头: + 解释说明:如未检测到摄像头请插拔后重试 - } - title="" - > - - - { + setting.videoDeviceId = e; + storage.setItem('setting', JSON.stringify(setting)) + setVideoDeviceManager({ + ...videoDeviceManager, + item: e + }) + agora.setVideoDeviceManager(e) + }}/> -
-
-
- - ) +
+
+
+ + ) } const AudioComponents = () => { - const [audioDeviceManager, setAudioDeviceManager] = useState({ - playBackList: [], - ecordingList: [], - playBackItem: null, - ecordingItem: null, - playBackVolume: 0, - playBackActive: false, - ecordingActive: false, - ecordingVolume: 0, - autoEcordingVolume: true, - }); - const setting = JSON.parse(storage.getItem('setting') as string) - useEffect(() => { - getAudioMediaList() - agora.registerEventHandler({ - onAudioVolumeIndication: (percentage: number) => { - const dom = document.getElementById('deviceTest') as any; - if (dom) { - dom.style.width = `${percentage}%` + const [audioDeviceManager, setAudioDeviceManager] = useState({ + playBackList: [], + ecordingList: [], + playBackItem: null, + ecordingItem: null, + playBackVolume: 0, + playBackActive: false, + ecordingActive: false, + ecordingVolume: 0, + autoEcordingVolume: true, + }); + const setting = JSON.parse(storage.getItem('setting') as string) + useEffect(() => { + getAudioMediaList() + agora.registerEventHandler({ + onAudioVolumeIndication: (percentage: number) => { + const dom = document.getElementById('deviceTest') as any; + if (dom) { + dom.style.width = `${percentage}%` + } + } + }) + }, []); + const getAudioMediaList = async (): Promise => { + const { + playBackList, + ecordingList, + playBackItem, + ecordingItem, + ecordingVolume + } = await agora.getAudioMediaList(); + if ((!setting.ecordingDeviceId && ecordingItem.deviceId) || (!(ecordingList.find((item: any) => item.deviceId === setting.ecordingDeviceId)) && ecordingItem.deviceId)) { + setting.ecordingDeviceId = ecordingItem.deviceId } - } - }) - }, []); - const getAudioMediaList = async (): Promise => { - const { playBackList, ecordingList, playBackItem, ecordingItem, ecordingVolume } = await agora.getAudioMediaList(); - if ((!setting.ecordingDeviceId && ecordingItem.deviceId) || (!(ecordingList.find((item: any) => item.deviceId === setting.ecordingDeviceId)) && ecordingItem.deviceId)) { - setting.ecordingDeviceId = ecordingItem.deviceId - } - if ((!setting.playBackDeviceId && playBackItem.deviceId) || (!(playBackList.find((item: any) => item.deviceId === setting.playBackDeviceId)) && playBackItem.deviceId)) { - setting.playBackDeviceId = playBackItem.deviceId - } - if (!ecordingList.length) { - setting.ecordingDeviceId = '' - } - if (!playBackList.length) { - setting.playBackDeviceId = '' - } - if (!setting.ecordingVolume) { - setting.ecordingVolume = ecordingVolume; - } - if (!setting.playBackVolume) { - setting.playBackVolume = 127; - } - storage.setItem('setting', JSON.stringify(setting)) - setAudioDeviceManager({ - ...audioDeviceManager, - playBackList: playBackList.map((row: any) => { - return { - value: row.deviceId, - label: row.deviceName + if ((!setting.playBackDeviceId && playBackItem.deviceId) || (!(playBackList.find((item: any) => item.deviceId === setting.playBackDeviceId)) && playBackItem.deviceId)) { + setting.playBackDeviceId = playBackItem.deviceId } - }), - ecordingList: ecordingList.map((row: any) => { - return { - value: row.deviceId, - label: row.deviceName + if (!ecordingList.length) { + setting.ecordingDeviceId = '' } - }), - playBackItem: setting.playBackDeviceId ? setting.playBackDeviceId : playBackItem.deviceId || null, - ecordingItem: setting.ecordingDeviceId ? setting.ecordingDeviceId : ecordingItem.deviceId || null, - ecordingVolume: setting.ecordingVolume, - playBackVolume: setting.playBackVolume, - autoEcordingVolume: setting.autoEcordingVolume - }) - } - return ( - <> -
- 音频 -
-
-
- 麦克风: - { - setting.playBackDeviceId = e; - storage.setItem('setting', JSON.stringify(setting)) - setAudioDeviceManager({ - ...audioDeviceManager, - playBackItem: e - }) - agora.setPlaybackDevice(e) - }} />; - {audioDeviceManager.playBackActive ?
{ - agora.stopPlaybackDeviceTest() - setAudioDeviceManager({ - ...audioDeviceManager, - playBackActive: false, - ecordingActive: false, - }) - }}>结束
:
{ - agora.stopRecordingDeviceTest() - agora.startPlaybackDeviceTest() - setAudioDeviceManager({ - ...audioDeviceManager, - playBackActive: true, - ecordingActive: false, - }) - }}>测试
} -
- {audioDeviceManager.playBackActive ?
- -
- -
- + 音频 +
+
+
+ 麦克风: + { + setting.playBackDeviceId = e; + storage.setItem('setting', JSON.stringify(setting)) + setAudioDeviceManager({ + ...audioDeviceManager, + playBackItem: e + }) + agora.setPlaybackDevice(e) + }}/>; + {audioDeviceManager.playBackActive ?
{ + agora.stopPlaybackDeviceTest() + setAudioDeviceManager({ + ...audioDeviceManager, + playBackActive: false, + ecordingActive: false, + }) + }}>结束
:
{ + agora.stopRecordingDeviceTest() + agora.startPlaybackDeviceTest() + setAudioDeviceManager({ + ...audioDeviceManager, + playBackActive: true, + ecordingActive: false, + }) + }}>测试
} +
+ {audioDeviceManager.playBackActive ?
+ +
+ +
+ +
+
+
: null} +
+ 输出音量: + { + setting.playBackVolume = e; + storage.setItem('setting', JSON.stringify(setting)) + agora.setPlaybackDeviceVolume(e) + setAudioDeviceManager({ + ...audioDeviceManager, + playBackVolume: e, + }) + }} disabled={!audioDeviceManager.playBackItem}/> +
+
-
-
: null} -
- 输出音量: - { - setting.playBackVolume = e; - storage.setItem('setting', JSON.stringify(setting)) - agora.setPlaybackDeviceVolume(e) - setAudioDeviceManager({ - ...audioDeviceManager, - playBackVolume: e, - }) - }} disabled={!audioDeviceManager.playBackItem} />
-
-
-
- - ) + + ) } const RecordingComponents = () => { - const [filePath, setFilePath] = useState('') - const setting = JSON.parse(storage.getItem('setting') as string) - useEffect(() => { - if (!setting.recordingFilesPath) { - setting.recordingFilesPath = path.dirname(process.execPath) + '\\'; - setFilePath(setting.recordingFilesPath) - storage.setItem('setting', JSON.stringify(setting)) - } else { - setFilePath(setting.recordingFilesPath); - } - window.addEventListener('customStorageChange', handleCustomStorageChange); - return () => { - window.removeEventListener('customStorageChange', handleCustomStorageChange); + const [filePath, setFilePath] = useState('') + const setting = JSON.parse(storage.getItem('setting') as string) + useEffect(() => { + if (!setting.recordingFilesPath) { + // 获取安装父目录 + const currentDirectory = __dirname; + const parentDirectory = path.resolve(currentDirectory, '../../Downloads'); + setting.recordingFilesPath = parentDirectory; + setFilePath(setting.recordingFilesPath) + storage.setItem('setting', JSON.stringify(setting)) + } else { + setFilePath(setting.recordingFilesPath); + } + window.addEventListener('customStorageChange', handleCustomStorageChange); + return () => { + window.removeEventListener('customStorageChange', handleCustomStorageChange); + }; + }, []) + const handleCustomStorageChange = (e: any): void => { + if (e.key === 'setting') { + setFilePath(setting.recordingFilesPath) + } }; - }, []) - const handleCustomStorageChange = (e: any): void => { - if (e.key === 'setting') { - setFilePath(setting.recordingFilesPath) - } - }; - return ( - <> -
- 录制 -
- 本地录制 -
- 本地录制文件路径 - { - setting.recordingFilesPath = e.target.value; - storage.setItem('setting', JSON.stringify(setting)) - setFilePath(e.target.value) - }} - /> - - -
-
-
- - ) + return ( + <> +
+ 录制 +
+ 本地录制 +
+ 本地录制文件路径 + { + setting.recordingFilesPath = e.target.value; + storage.setItem('setting', JSON.stringify(setting)) + setFilePath(e.target.value) + }} + /> + + +
+
+
+ + ) } const FileComponents = () => { - const [filePath, setFilePath] = useState('') - const [isShareSavePath, setIsShareSavePath] = useState(true) - const setting = JSON.parse(storage.getItem('setting') as string) - useEffect(() => { - if (!setting.shareFilesPath) { - setting.shareFilesPath = path.dirname(process.execPath) + '\\'; - setFilePath(setting.shareFilesPath) - storage.setItem('setting', JSON.stringify(setting)) - } else { - setFilePath(setting.shareFilesPath); - } - setIsShareSavePath(setting.isShareSavePath) - window.addEventListener('customStorageChange', handleCustomStorageChange); - return () => { - window.removeEventListener('customStorageChange', handleCustomStorageChange); + const [filePath, setFilePath] = useState('') + const [isShareSavePath, setIsShareSavePath] = useState(true) + const setting = JSON.parse(storage.getItem('setting') as string) + useEffect(() => { + if (!setting.shareFilesPath) { + // 获取安装父目录 + const currentDirectory = __dirname; + const parentDirectory = path.resolve(currentDirectory, '../../Downloads'); + setting.shareFilesPath = parentDirectory + setFilePath(setting.shareFilesPath) + storage.setItem('setting', JSON.stringify(setting)) + } else { + setFilePath(setting.shareFilesPath); + } + setIsShareSavePath(setting.isShareSavePath) + window.addEventListener('customStorageChange', handleCustomStorageChange); + return () => { + window.removeEventListener('customStorageChange', handleCustomStorageChange); + }; + }, []) + const handleCustomStorageChange = (e: any): void => { + if (e.key === 'setting') { + setFilePath(setting.shareFilesPath) + } }; - }, []) - const handleCustomStorageChange = (e: any): void => { - if (e.key === 'setting') { - setFilePath(setting.shareFilesPath) - } - }; - return ( - <> -
- 共享文件 -
- 文件下载 -
- 保存位置 - { - setting.shareFilesPath = e.target.value; - storage.setItem('setting', JSON.stringify(setting)) - setFilePath(e.target.value) - }} - /> - - -
-
- { - setting.isShareSavePath = e.target.checked; - storage.setItem('setting', JSON.stringify(setting)) - setIsShareSavePath(e.target.checked) - }} checked={isShareSavePath}>下载前询问每个文件保存位置 -
-
-
- - ) + return ( + <> +
+ 共享文件 +
+ 文件下载 +
+ 保存位置 + { + setting.shareFilesPath = e.target.value; + storage.setItem('setting', JSON.stringify(setting)) + setFilePath(e.target.value) + }} + /> + + +
+
+ { + setting.isShareSavePath = e.target.checked; + storage.setItem('setting', JSON.stringify(setting)) + setIsShareSavePath(e.target.checked) + }} checked={isShareSavePath}>下载前询问每个文件保存位置 +
+
+
+ + ) } -export default StupWizard \ No newline at end of file +export default StupWizard