设置文件路径

This commit is contained in:
梅航 2024-08-13 16:00:04 +08:00
parent 5454d5ceba
commit 2704511e75
2 changed files with 556 additions and 541 deletions

View File

@ -138,7 +138,7 @@ app.on('ready', () => {
// 获取当前脚本所在目录的绝对路径 // 获取当前脚本所在目录的绝对路径
const currentDirectory = __dirname; const currentDirectory = __dirname;
// 获取安装父目录 // 获取安装父目录
const parentDirectory = path.resolve(currentDirectory, '../..'); const parentDirectory = path.resolve(currentDirectory, '..');
const customFolderPath = path.join(parentDirectory, 'Downloads'); const customFolderPath = path.join(parentDirectory, 'Downloads');
if (!fs.existsSync(customFolderPath)) { if (!fs.existsSync(customFolderPath)) {
// 如果不存在,则创建文件夹 // 如果不存在,则创建文件夹

View File

@ -1,13 +1,14 @@
import styles from '@/components/StupWizard/index.module.scss' import styles from '@/components/StupWizard/index.module.scss'
import ImageUrl from '@/utils/package/ImageUrl'; import ImageUrl from '@/utils/package/ImageUrl';
import { Button, Checkbox, Empty, Input, Modal, Popover, Radio, Select, Slider, message } from 'antd'; import {Button, Checkbox, Empty, Input, message, Modal, Popover, Radio, Select, Slider} from 'antd';
import { useState, useImperativeHandle, forwardRef, useEffect } from "react"; import {forwardRef, useEffect, useImperativeHandle, useState} from "react";
import agora from '@/utils/package/agora' import agora from '@/utils/package/agora'
import { CloseOutlined, LoadingOutlined, QuestionCircleOutlined } from '@ant-design/icons'; import {CloseOutlined, LoadingOutlined, QuestionCircleOutlined} from '@ant-design/icons';
import { storage } from '@/utils'; import {storage} from '@/utils';
import path from 'path'; import path from 'path';
const fs = require('fs').promises; const fs = require('fs').promises;
const { exec } = require('child_process'); const {exec} = require('child_process');
const StupWizard = forwardRef((props: any, ref: any) => { const StupWizard = forwardRef((props: any, ref: any) => {
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
changeModal: () => { changeModal: () => {
@ -73,7 +74,7 @@ const StupWizard = forwardRef((props: any, ref: any) => {
agora.stopPlaybackDeviceTest() agora.stopPlaybackDeviceTest()
agora.stopRecordingDeviceTest() agora.stopRecordingDeviceTest()
}}> }}>
<img src={row.active ? row.iconActive : row.icon} alt="" /> <img src={row.active ? row.iconActive : row.icon} alt=""/>
<span>{row.title}</span> <span>{row.title}</span>
</div> </div>
) )
@ -94,11 +95,11 @@ const StupWizard = forwardRef((props: any, ref: any) => {
setIsStupWizard(false) setIsStupWizard(false)
}} }}
/> />
{list[0].active ? <CurrencyComponents /> : null} {list[0].active ? <CurrencyComponents/> : null}
{list[1].active ? <VideoComponents /> : null} {list[1].active ? <VideoComponents/> : null}
{list[2].active ? <AudioComponents /> : null} {list[2].active ? <AudioComponents/> : null}
{list[3].active ? <RecordingComponents /> : null} {list[3].active ? <RecordingComponents/> : null}
{list[4].active ? <FileComponents /> : null} {list[4].active ? <FileComponents/> : null}
</div> </div>
</div> </div>
</Modal> </Modal>
@ -123,7 +124,7 @@ const CurrencyComponents = () => {
setting.closeSetting = e.target.value; setting.closeSetting = e.target.value;
storage.setItem('setting', JSON.stringify(setting)) storage.setItem('setting', JSON.stringify(setting))
setOperationValue(e.target.value) setOperationValue(e.target.value)
}} style={{ flexShrink: 0, margin: '10px 0' }} value={optionsValue}> }} style={{flexShrink: 0, margin: '10px 0'}} value={optionsValue}>
<Radio value={'quit'}>退</Radio> <Radio value={'quit'}>退</Radio>
<Radio value={'hide'}>退</Radio> <Radio value={'hide'}>退</Radio>
</Radio.Group> </Radio.Group>
@ -146,7 +147,7 @@ const VideoComponents = () => {
const getVideoDeviceList = async (): Promise<void> => { const getVideoDeviceList = async (): Promise<void> => {
const userInfo = JSON.parse(storage.getItem('user') as string) const userInfo = JSON.parse(storage.getItem('user') as string)
agora.getVideoDeviceManager().then(async (res) => { agora.getVideoDeviceManager().then(async (res) => {
const { item, list } = res const {item, list} = res
if ((!setting.videoDeviceId && item) || (!(list.find((item: any) => item.deviceId === setting.videoDeviceId)) && item)) { if ((!setting.videoDeviceId && item) || (!(list.find((item: any) => item.deviceId === setting.videoDeviceId)) && item)) {
setting.videoDeviceId = item setting.videoDeviceId = item
} }
@ -184,12 +185,12 @@ const VideoComponents = () => {
right: '50%', right: '50%',
fontSize: '30px', fontSize: '30px',
top: '50%', top: '50%',
}} /> }}/>
</div> </div>
</div> : </div> :
<div> <div>
<div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }}> <div style={{display: 'flex', justifyContent: 'center', alignItems: 'center'}}>
<Empty description={'未检测到摄像头'} /> <Empty description={'未检测到摄像头'}/>
</div> </div>
</div> </div>
} }
@ -210,11 +211,11 @@ const VideoComponents = () => {
color: 'white', color: 'white',
cursor: 'pointer', cursor: 'pointer',
marginRight: '10px' marginRight: '10px'
}} /> }}/>
</Popover> </Popover>
<Select <Select
placeholder={videoDeviceManager.list.length ? '请选择设备' : '未检测到摄像头'} placeholder={videoDeviceManager.list.length ? '请选择设备' : '未检测到摄像头'}
options={videoDeviceManager.list} style={{ flexGrow: 1, marginRight: '10px' }} options={videoDeviceManager.list} style={{flexGrow: 1, marginRight: '10px'}}
value={videoDeviceManager.item} onChange={async (e) => { value={videoDeviceManager.item} onChange={async (e) => {
setting.videoDeviceId = e; setting.videoDeviceId = e;
storage.setItem('setting', JSON.stringify(setting)) storage.setItem('setting', JSON.stringify(setting))
@ -223,7 +224,7 @@ const VideoComponents = () => {
item: e item: e
}) })
agora.setVideoDeviceManager(e) agora.setVideoDeviceManager(e)
}} /> }}/>
</div> </div>
</div> </div>
@ -256,7 +257,13 @@ const AudioComponents = () => {
}) })
}, []); }, []);
const getAudioMediaList = async (): Promise<void> => { const getAudioMediaList = async (): Promise<void> => {
const { playBackList, ecordingList, playBackItem, ecordingItem, ecordingVolume } = await agora.getAudioMediaList(); const {
playBackList,
ecordingList,
playBackItem,
ecordingItem,
ecordingVolume
} = await agora.getAudioMediaList();
if ((!setting.ecordingDeviceId && ecordingItem.deviceId) || (!(ecordingList.find((item: any) => item.deviceId === setting.ecordingDeviceId)) && ecordingItem.deviceId)) { if ((!setting.ecordingDeviceId && ecordingItem.deviceId) || (!(ecordingList.find((item: any) => item.deviceId === setting.ecordingDeviceId)) && ecordingItem.deviceId)) {
setting.ecordingDeviceId = ecordingItem.deviceId setting.ecordingDeviceId = ecordingItem.deviceId
} }
@ -307,7 +314,7 @@ const AudioComponents = () => {
<span></span> <span></span>
<Select <Select
placeholder={audioDeviceManager.ecordingList.length ? '请选择设备' : '未检测到麦克风'} placeholder={audioDeviceManager.ecordingList.length ? '请选择设备' : '未检测到麦克风'}
options={audioDeviceManager.ecordingList} style={{ flexGrow: 1 }} options={audioDeviceManager.ecordingList} style={{flexGrow: 1}}
value={audioDeviceManager.ecordingItem} onChange={async (e) => { value={audioDeviceManager.ecordingItem} onChange={async (e) => {
setting.ecordingDeviceId = e; setting.ecordingDeviceId = e;
storage.setItem('setting', JSON.stringify(setting)) storage.setItem('setting', JSON.stringify(setting))
@ -316,7 +323,7 @@ const AudioComponents = () => {
ecordingItem: e ecordingItem: e
}) })
agora.setRecordingDevice(e) agora.setRecordingDevice(e)
}} />; }}/>;
{audioDeviceManager.ecordingActive ? <div onClick={() => { {audioDeviceManager.ecordingActive ? <div onClick={() => {
agora.stopRecordingDeviceTest() agora.stopRecordingDeviceTest()
setAudioDeviceManager({ setAudioDeviceManager({
@ -335,17 +342,18 @@ const AudioComponents = () => {
}}></div>} }}></div>}
</div> </div>
{audioDeviceManager.ecordingActive ? <div className={styles.audioComponentsVolume}> {audioDeviceManager.ecordingActive ? <div className={styles.audioComponentsVolume}>
<img src={ImageUrl.icon36} alt="" /> <img src={ImageUrl.icon36} alt=""/>
<div> <div>
<img src={ImageUrl.icon34} alt="" /> <img src={ImageUrl.icon34} alt=""/>
<div id='deviceTest'> <div id='deviceTest'>
<img src={ImageUrl.icon35} alt="" /> <img src={ImageUrl.icon35} alt=""/>
</div> </div>
</div> </div>
</div> : null} </div> : null}
<div className={styles.audioComponentsSlider}> <div className={styles.audioComponentsSlider}>
<span></span> <span></span>
<Slider value={audioDeviceManager.ecordingVolume} style={{ flexGrow: 1 }} max={255} onChange={async (e) => { <Slider value={audioDeviceManager.ecordingVolume} style={{flexGrow: 1}} max={255}
onChange={async (e) => {
setting.ecordingVolume = e; setting.ecordingVolume = e;
storage.setItem('setting', JSON.stringify(setting)) storage.setItem('setting', JSON.stringify(setting))
await agora.setRecordingDeviceVolume(e) await agora.setRecordingDeviceVolume(e)
@ -353,7 +361,7 @@ const AudioComponents = () => {
...audioDeviceManager, ...audioDeviceManager,
ecordingVolume: e, ecordingVolume: e,
}) })
}} disabled={!audioDeviceManager.ecordingItem} /> }} disabled={!audioDeviceManager.ecordingItem}/>
</div> </div>
<div> <div>
<Checkbox onChange={async (e) => { <Checkbox onChange={async (e) => {
@ -371,7 +379,7 @@ const AudioComponents = () => {
<span></span> <span></span>
<Select <Select
placeholder={audioDeviceManager.playBackList.length ? '请选择设备' : '未检测到麦克风'} placeholder={audioDeviceManager.playBackList.length ? '请选择设备' : '未检测到麦克风'}
options={audioDeviceManager.playBackList} style={{ flexGrow: 1 }} options={audioDeviceManager.playBackList} style={{flexGrow: 1}}
value={audioDeviceManager.playBackItem} onChange={async (e) => { value={audioDeviceManager.playBackItem} onChange={async (e) => {
setting.playBackDeviceId = e; setting.playBackDeviceId = e;
storage.setItem('setting', JSON.stringify(setting)) storage.setItem('setting', JSON.stringify(setting))
@ -380,7 +388,7 @@ const AudioComponents = () => {
playBackItem: e playBackItem: e
}) })
agora.setPlaybackDevice(e) agora.setPlaybackDevice(e)
}} />; }}/>;
{audioDeviceManager.playBackActive ? <div onClick={() => { {audioDeviceManager.playBackActive ? <div onClick={() => {
agora.stopPlaybackDeviceTest() agora.stopPlaybackDeviceTest()
setAudioDeviceManager({ setAudioDeviceManager({
@ -399,17 +407,18 @@ const AudioComponents = () => {
}}></div>} }}></div>}
</div> </div>
{audioDeviceManager.playBackActive ? <div className={styles.audioComponentsVolume}> {audioDeviceManager.playBackActive ? <div className={styles.audioComponentsVolume}>
<img src={ImageUrl.icon36} alt="" /> <img src={ImageUrl.icon36} alt=""/>
<div> <div>
<img src={ImageUrl.icon34} alt="" /> <img src={ImageUrl.icon34} alt=""/>
<div id='deviceTest'> <div id='deviceTest'>
<img src={ImageUrl.icon35} alt="" /> <img src={ImageUrl.icon35} alt=""/>
</div> </div>
</div> </div>
</div> : null} </div> : null}
<div className={styles.audioComponentsSlider}> <div className={styles.audioComponentsSlider}>
<span></span> <span></span>
<Slider value={audioDeviceManager.playBackVolume} style={{ flexGrow: 1 }} max={255} onChange={async (e) => { <Slider value={audioDeviceManager.playBackVolume} style={{flexGrow: 1}} max={255}
onChange={async (e) => {
setting.playBackVolume = e; setting.playBackVolume = e;
storage.setItem('setting', JSON.stringify(setting)) storage.setItem('setting', JSON.stringify(setting))
agora.setPlaybackDeviceVolume(e) agora.setPlaybackDeviceVolume(e)
@ -417,7 +426,7 @@ const AudioComponents = () => {
...audioDeviceManager, ...audioDeviceManager,
playBackVolume: e, playBackVolume: e,
}) })
}} disabled={!audioDeviceManager.playBackItem} /> }} disabled={!audioDeviceManager.playBackItem}/>
</div> </div>
</div> </div>
</div> </div>
@ -430,7 +439,10 @@ const RecordingComponents = () => {
const setting = JSON.parse(storage.getItem('setting') as string) const setting = JSON.parse(storage.getItem('setting') as string)
useEffect(() => { useEffect(() => {
if (!setting.recordingFilesPath) { if (!setting.recordingFilesPath) {
setting.recordingFilesPath = path.dirname(process.execPath) + '\\'; // 获取安装父目录
const currentDirectory = __dirname;
const parentDirectory = path.resolve(currentDirectory, '../../Downloads');
setting.recordingFilesPath = parentDirectory;
setFilePath(setting.recordingFilesPath) setFilePath(setting.recordingFilesPath)
storage.setItem('setting', JSON.stringify(setting)) storage.setItem('setting', JSON.stringify(setting))
} else { } else {
@ -457,7 +469,7 @@ const RecordingComponents = () => {
<Input <Input
disabled={true} disabled={true}
placeholder="请填入文件路径" placeholder="请填入文件路径"
style={{ margin: '0 14px', flexGrow: 1 }} style={{margin: '0 14px', flexGrow: 1}}
value={filePath} value={filePath}
onChange={async (e) => { onChange={async (e) => {
setting.recordingFilesPath = e.target.value; setting.recordingFilesPath = e.target.value;
@ -469,7 +481,7 @@ const RecordingComponents = () => {
window.electron.selectFilePath({ window.electron.selectFilePath({
key: 'recordingFilesPath', key: 'recordingFilesPath',
}) })
}} style={{ backgroundColor: '#31353A', marginRight: '10px' }}></Button> }} style={{backgroundColor: '#31353A', marginRight: '10px'}}></Button>
<Button type="primary" onClick={async () => { <Button type="primary" onClick={async () => {
try { try {
await fs.access(filePath, fs.constants.F_OK); await fs.access(filePath, fs.constants.F_OK);
@ -485,7 +497,7 @@ const RecordingComponents = () => {
message.error(error) message.error(error)
} }
} }
}} style={{ backgroundColor: '#31353A' }}></Button> }} style={{backgroundColor: '#31353A'}}></Button>
</div> </div>
</div> </div>
</div> </div>
@ -498,7 +510,10 @@ const FileComponents = () => {
const setting = JSON.parse(storage.getItem('setting') as string) const setting = JSON.parse(storage.getItem('setting') as string)
useEffect(() => { useEffect(() => {
if (!setting.shareFilesPath) { if (!setting.shareFilesPath) {
setting.shareFilesPath = path.dirname(process.execPath) + '\\'; // 获取安装父目录
const currentDirectory = __dirname;
const parentDirectory = path.resolve(currentDirectory, '../../Downloads');
setting.shareFilesPath = parentDirectory
setFilePath(setting.shareFilesPath) setFilePath(setting.shareFilesPath)
storage.setItem('setting', JSON.stringify(setting)) storage.setItem('setting', JSON.stringify(setting))
} else { } else {
@ -526,7 +541,7 @@ const FileComponents = () => {
<Input <Input
disabled={true} disabled={true}
placeholder="请填入保存目录" placeholder="请填入保存目录"
style={{ margin: '0 14px', flexGrow: 1 }} style={{margin: '0 14px', flexGrow: 1}}
value={filePath} value={filePath}
onChange={async (e) => { onChange={async (e) => {
setting.shareFilesPath = e.target.value; setting.shareFilesPath = e.target.value;
@ -538,7 +553,7 @@ const FileComponents = () => {
window.electron.selectFilePath({ window.electron.selectFilePath({
key: 'shareFilesPath', key: 'shareFilesPath',
}) })
}} style={{ backgroundColor: '#31353A', marginRight: '10px' }}></Button> }} style={{backgroundColor: '#31353A', marginRight: '10px'}}></Button>
<Button type="primary" onClick={async () => { <Button type="primary" onClick={async () => {
try { try {
await fs.access(filePath, fs.constants.F_OK); await fs.access(filePath, fs.constants.F_OK);
@ -554,7 +569,7 @@ const FileComponents = () => {
message.error(error) message.error(error)
} }
} }
}} style={{ backgroundColor: '#31353A' }}></Button> }} style={{backgroundColor: '#31353A'}}></Button>
</div> </div>
<div> <div>
<Checkbox onChange={async (e) => { <Checkbox onChange={async (e) => {