设置文件路径

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 parentDirectory = path.resolve(currentDirectory, '../..');
const parentDirectory = path.resolve(currentDirectory, '..');
const customFolderPath = path.join(parentDirectory, 'Downloads');
if (!fs.existsSync(customFolderPath)) {
// 如果不存在,则创建文件夹

View File

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