This commit is contained in:
parent
c341100d5d
commit
4dc3f10e85
16
main.js
16
main.js
|
|
@ -205,14 +205,26 @@ app.on('ready', () => {
|
|||
}
|
||||
});
|
||||
// 选择文件夹
|
||||
ipcMain.handle('selectFilePath', async (event) => {
|
||||
ipcMain.handle('selectFilePath', async (event, data) => {
|
||||
const result = await dialog.showOpenDialog({
|
||||
properties: ['openDirectory']
|
||||
});
|
||||
if (result.canceled) {
|
||||
|
||||
} else {
|
||||
mainWindow.webContents.send('onFilePath', result.filePaths[0]);
|
||||
switch (data.key) {
|
||||
case 'shareFilesPath':
|
||||
case 'recordingFilesPath':
|
||||
mainWindow.webContents.send('onFilePath', result.filePaths[0] + '\\', data.key);
|
||||
break;
|
||||
default:
|
||||
mainWindow.webContents.send('downFile', {
|
||||
downFilePaths: result.filePaths[0] + '\\',
|
||||
fileName: data.fileName,
|
||||
filePath: data.filePath,
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
// 设置桌面应用基础属性
|
||||
|
|
|
|||
|
|
@ -38,11 +38,15 @@ window.electron = {
|
|||
ipcRenderer.invoke('updateDownload', type)
|
||||
},
|
||||
// 选择文件夹
|
||||
selectFilePath: () => {
|
||||
ipcRenderer.invoke('selectFilePath')
|
||||
selectFilePath: (data) => {
|
||||
ipcRenderer.invoke('selectFilePath', data)
|
||||
},
|
||||
// 发送文件夹路径
|
||||
onFilePath: (callback) => {
|
||||
ipcRenderer.on('onFilePath', callback)
|
||||
},
|
||||
// 下载文件
|
||||
downFile: (callback) => {
|
||||
ipcRenderer.on('downFile', callback)
|
||||
},
|
||||
}
|
||||
|
|
|
|||
28
src/App.tsx
28
src/App.tsx
|
|
@ -16,7 +16,8 @@ import * as CryptoJS from 'crypto-js';
|
|||
import { PostLogin } from "@/api/Login";
|
||||
import agora from "@/utils/package/agora";
|
||||
import QuitTips from "@/components/QuitTips";
|
||||
|
||||
const fs = require('fs').promises;
|
||||
const { exec } = require('child_process');
|
||||
const App: React.FC = () => {
|
||||
const navigate = useNavigate();
|
||||
const { state } = useLocation();
|
||||
|
|
@ -98,7 +99,6 @@ const App: React.FC = () => {
|
|||
window.dispatchEvent(event);
|
||||
};
|
||||
window.addEventListener('customStorageChange', handleCustomStorageChange);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('resize', handleResize);
|
||||
window.removeEventListener('customStorageChange', handleCustomStorageChange);
|
||||
|
|
@ -106,6 +106,30 @@ const App: React.FC = () => {
|
|||
window.removeEventListener('offline', handleNetworkChange);
|
||||
};
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
window.electron.downFile(async (_e: any, data: any) => {
|
||||
const response = await fetch(data.filePath);
|
||||
const arrayBuffer = await response.arrayBuffer();
|
||||
const buffer = Buffer.from(arrayBuffer);
|
||||
fs.writeFile(`${data.downFilePaths}${data.fileName}`, buffer, {});
|
||||
message.success(`下载成功!文件已保存至:${data.downFilePaths}`)
|
||||
await fs.access(data.downFilePaths, fs.constants.F_OK);
|
||||
if (process.platform === 'win32') {
|
||||
exec(`explorer "${data.downFilePaths}"`);
|
||||
} else if (process.platform === 'darwin') {
|
||||
exec(`open "${data.downFilePaths}"`);
|
||||
}
|
||||
})
|
||||
window.electron.onFilePath(async (_e: any, filePath: string, key: string) => {
|
||||
const setting = await JSON.parse(storage.getItem('setting') as string)
|
||||
if (key === 'recordingFilesPath') {
|
||||
setting.recordingFilesPath = filePath
|
||||
} else {
|
||||
setting.shareFilesPath = filePath
|
||||
}
|
||||
storage.setItem('setting', JSON.stringify(setting))
|
||||
})
|
||||
}, [])
|
||||
useEffect(() => {
|
||||
onInvitation((item: any) => {
|
||||
switch (item.key) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import styles from '@/components/SharedFilesModel/index.module.scss'
|
||||
import {
|
||||
DeleteOutlined,
|
||||
FolderOutlined,
|
||||
ProfileOutlined,
|
||||
ReloadOutlined,
|
||||
SearchOutlined,
|
||||
|
|
@ -277,6 +276,12 @@ const SharedFilesModel = forwardRef((props: any, ref: any) => {
|
|||
data: fileItem,
|
||||
})
|
||||
const setting = await JSON.parse(storage.getItem('setting') as string)
|
||||
if (setting.isShareSavePath) {
|
||||
window.electron.selectFilePath({
|
||||
fileName: fileItem[fileIndex].fileName,
|
||||
filePath: res.data
|
||||
})
|
||||
} else {
|
||||
try {
|
||||
await fs.access(setting.shareFilesPath, fs.constants.F_OK)
|
||||
const response = await fetch(res.data);
|
||||
|
|
@ -290,7 +295,6 @@ const SharedFilesModel = forwardRef((props: any, ref: any) => {
|
|||
} else if (process.platform === 'darwin') {
|
||||
exec(`open "${setting.shareFilesPath}"`);
|
||||
}
|
||||
getRoomFile()
|
||||
} catch (error: any) {
|
||||
if (error.code === 'ENOENT') {
|
||||
message.error('文件夹不存在!')
|
||||
|
|
@ -299,6 +303,10 @@ const SharedFilesModel = forwardRef((props: any, ref: any) => {
|
|||
message.error(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
setTimeout(() => {
|
||||
getRoomFile()
|
||||
}, 2000)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -385,13 +385,17 @@ const RecordingComponents = () => {
|
|||
} else {
|
||||
setFilePath(setting.recordingFilesPath);
|
||||
}
|
||||
window.electron.onFilePath(async (_e: any, filePath: string) => {
|
||||
setFilePath(filePath)
|
||||
const setting = await JSON.parse(storage.getItem('setting') as string)
|
||||
setting.recordingFilesPath = filePath
|
||||
storage.setItem('setting', JSON.stringify(setting))
|
||||
})
|
||||
window.addEventListener('customStorageChange', handleCustomStorageChange);
|
||||
return () => {
|
||||
window.removeEventListener('customStorageChange', handleCustomStorageChange);
|
||||
};
|
||||
}, [])
|
||||
const handleCustomStorageChange = (e: any): void => {
|
||||
if (e.key === 'setting') {
|
||||
const setting = JSON.parse(storage.getItem('setting') as string)
|
||||
setFilePath(setting.recordingFilesPath)
|
||||
}
|
||||
};
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
|
|
@ -412,7 +416,9 @@ const RecordingComponents = () => {
|
|||
}}
|
||||
/>
|
||||
<Button type="primary" onClick={() => {
|
||||
window.electron.selectFilePath()
|
||||
window.electron.selectFilePath({
|
||||
key: 'recordingFilesPath',
|
||||
})
|
||||
}} style={{ backgroundColor: '#31353A', marginRight: '10px' }}>选择保存目录</Button>
|
||||
<Button type="primary" onClick={async () => {
|
||||
try {
|
||||
|
|
@ -449,13 +455,17 @@ const FileComponents = () => {
|
|||
setFilePath(setting.shareFilesPath);
|
||||
}
|
||||
setIsShareSavePath(setting.isShareSavePath)
|
||||
window.electron.onFilePath(async (_e: any, filePath: string) => {
|
||||
setFilePath(filePath)
|
||||
const setting = await JSON.parse(storage.getItem('setting') as string)
|
||||
setting.shareFilesPath = filePath
|
||||
storage.setItem('setting', JSON.stringify(setting))
|
||||
})
|
||||
window.addEventListener('customStorageChange', handleCustomStorageChange);
|
||||
return () => {
|
||||
window.removeEventListener('customStorageChange', handleCustomStorageChange);
|
||||
};
|
||||
}, [])
|
||||
const handleCustomStorageChange = (e: any): void => {
|
||||
if (e.key === 'setting') {
|
||||
const setting = JSON.parse(storage.getItem('setting') as string)
|
||||
setFilePath(setting.shareFilesPath)
|
||||
}
|
||||
};
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
|
|
@ -476,7 +486,9 @@ const FileComponents = () => {
|
|||
}}
|
||||
/>
|
||||
<Button type="primary" onClick={() => {
|
||||
window.electron.selectFilePath()
|
||||
window.electron.selectFilePath({
|
||||
key: 'shareFilesPath',
|
||||
})
|
||||
}} style={{ backgroundColor: '#31353A', marginRight: '10px' }}>选择保存目录</Button>
|
||||
<Button type="primary" onClick={async () => {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -8,9 +8,10 @@ export interface IElectronAPI {
|
|||
onUpdate: (callBack: Function) => void;
|
||||
joinNotification: (data: { name: string, body: string }) => void;
|
||||
onDownload: (data: string) => void
|
||||
selectFilePath: () => void
|
||||
selectFilePath: (data?: any) => void
|
||||
onFilePath: (callBack: Function) => void;
|
||||
getSources: () => any;
|
||||
downFile: (callBack: Function) => void;
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
|
|
|||
Loading…
Reference in New Issue