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({
|
const result = await dialog.showOpenDialog({
|
||||||
properties: ['openDirectory']
|
properties: ['openDirectory']
|
||||||
});
|
});
|
||||||
if (result.canceled) {
|
if (result.canceled) {
|
||||||
|
|
||||||
} else {
|
} 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)
|
ipcRenderer.invoke('updateDownload', type)
|
||||||
},
|
},
|
||||||
// 选择文件夹
|
// 选择文件夹
|
||||||
selectFilePath: () => {
|
selectFilePath: (data) => {
|
||||||
ipcRenderer.invoke('selectFilePath')
|
ipcRenderer.invoke('selectFilePath', data)
|
||||||
},
|
},
|
||||||
// 发送文件夹路径
|
// 发送文件夹路径
|
||||||
onFilePath: (callback) => {
|
onFilePath: (callback) => {
|
||||||
ipcRenderer.on('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 { PostLogin } from "@/api/Login";
|
||||||
import agora from "@/utils/package/agora";
|
import agora from "@/utils/package/agora";
|
||||||
import QuitTips from "@/components/QuitTips";
|
import QuitTips from "@/components/QuitTips";
|
||||||
|
const fs = require('fs').promises;
|
||||||
|
const { exec } = require('child_process');
|
||||||
const App: React.FC = () => {
|
const App: React.FC = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { state } = useLocation();
|
const { state } = useLocation();
|
||||||
|
|
@ -98,7 +99,6 @@ const App: React.FC = () => {
|
||||||
window.dispatchEvent(event);
|
window.dispatchEvent(event);
|
||||||
};
|
};
|
||||||
window.addEventListener('customStorageChange', handleCustomStorageChange);
|
window.addEventListener('customStorageChange', handleCustomStorageChange);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener('resize', handleResize);
|
window.removeEventListener('resize', handleResize);
|
||||||
window.removeEventListener('customStorageChange', handleCustomStorageChange);
|
window.removeEventListener('customStorageChange', handleCustomStorageChange);
|
||||||
|
|
@ -106,6 +106,30 @@ const App: React.FC = () => {
|
||||||
window.removeEventListener('offline', handleNetworkChange);
|
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(() => {
|
useEffect(() => {
|
||||||
onInvitation((item: any) => {
|
onInvitation((item: any) => {
|
||||||
switch (item.key) {
|
switch (item.key) {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import styles from '@/components/SharedFilesModel/index.module.scss'
|
import styles from '@/components/SharedFilesModel/index.module.scss'
|
||||||
import {
|
import {
|
||||||
DeleteOutlined,
|
DeleteOutlined,
|
||||||
FolderOutlined,
|
|
||||||
ProfileOutlined,
|
ProfileOutlined,
|
||||||
ReloadOutlined,
|
ReloadOutlined,
|
||||||
SearchOutlined,
|
SearchOutlined,
|
||||||
|
|
@ -277,28 +276,37 @@ const SharedFilesModel = forwardRef((props: any, ref: any) => {
|
||||||
data: fileItem,
|
data: fileItem,
|
||||||
})
|
})
|
||||||
const setting = await JSON.parse(storage.getItem('setting') as string)
|
const setting = await JSON.parse(storage.getItem('setting') as string)
|
||||||
try {
|
if (setting.isShareSavePath) {
|
||||||
await fs.access(setting.shareFilesPath, fs.constants.F_OK)
|
window.electron.selectFilePath({
|
||||||
const response = await fetch(res.data);
|
fileName: fileItem[fileIndex].fileName,
|
||||||
const arrayBuffer = await response.arrayBuffer();
|
filePath: res.data
|
||||||
const buffer = Buffer.from(arrayBuffer);
|
})
|
||||||
fs.writeFile(`${setting.shareFilesPath}${fileItem[fileIndex].fileName}`, buffer, {});
|
} else {
|
||||||
message.success(`下载成功!文件已保存至:${setting.shareFilesPath}`)
|
try {
|
||||||
await fs.access(setting.shareFilesPath, fs.constants.F_OK);
|
await fs.access(setting.shareFilesPath, fs.constants.F_OK)
|
||||||
if (process.platform === 'win32') {
|
const response = await fetch(res.data);
|
||||||
exec(`explorer "${setting.shareFilesPath}"`);
|
const arrayBuffer = await response.arrayBuffer();
|
||||||
} else if (process.platform === 'darwin') {
|
const buffer = Buffer.from(arrayBuffer);
|
||||||
exec(`open "${setting.shareFilesPath}"`);
|
fs.writeFile(`${setting.shareFilesPath}${fileItem[fileIndex].fileName}`, buffer, {});
|
||||||
}
|
message.success(`下载成功!文件已保存至:${setting.shareFilesPath}`)
|
||||||
getRoomFile()
|
await fs.access(setting.shareFilesPath, fs.constants.F_OK);
|
||||||
} catch (error: any) {
|
if (process.platform === 'win32') {
|
||||||
if (error.code === 'ENOENT') {
|
exec(`explorer "${setting.shareFilesPath}"`);
|
||||||
message.error('文件夹不存在!')
|
} else if (process.platform === 'darwin') {
|
||||||
return
|
exec(`open "${setting.shareFilesPath}"`);
|
||||||
} else {
|
}
|
||||||
message.error(error)
|
} catch (error: any) {
|
||||||
|
if (error.code === 'ENOENT') {
|
||||||
|
message.error('文件夹不存在!')
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
message.error(error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
setTimeout(() => {
|
||||||
|
getRoomFile()
|
||||||
|
}, 2000)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -385,13 +385,17 @@ const RecordingComponents = () => {
|
||||||
} else {
|
} else {
|
||||||
setFilePath(setting.recordingFilesPath);
|
setFilePath(setting.recordingFilesPath);
|
||||||
}
|
}
|
||||||
window.electron.onFilePath(async (_e: any, filePath: string) => {
|
window.addEventListener('customStorageChange', handleCustomStorageChange);
|
||||||
setFilePath(filePath)
|
return () => {
|
||||||
const setting = await JSON.parse(storage.getItem('setting') as string)
|
window.removeEventListener('customStorageChange', handleCustomStorageChange);
|
||||||
setting.recordingFilesPath = filePath
|
};
|
||||||
storage.setItem('setting', JSON.stringify(setting))
|
|
||||||
})
|
|
||||||
}, [])
|
}, [])
|
||||||
|
const handleCustomStorageChange = (e: any): void => {
|
||||||
|
if (e.key === 'setting') {
|
||||||
|
const setting = JSON.parse(storage.getItem('setting') as string)
|
||||||
|
setFilePath(setting.recordingFilesPath)
|
||||||
|
}
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -412,7 +416,9 @@ const RecordingComponents = () => {
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Button type="primary" onClick={() => {
|
<Button type="primary" onClick={() => {
|
||||||
window.electron.selectFilePath()
|
window.electron.selectFilePath({
|
||||||
|
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 {
|
||||||
|
|
@ -449,13 +455,17 @@ const FileComponents = () => {
|
||||||
setFilePath(setting.shareFilesPath);
|
setFilePath(setting.shareFilesPath);
|
||||||
}
|
}
|
||||||
setIsShareSavePath(setting.isShareSavePath)
|
setIsShareSavePath(setting.isShareSavePath)
|
||||||
window.electron.onFilePath(async (_e: any, filePath: string) => {
|
window.addEventListener('customStorageChange', handleCustomStorageChange);
|
||||||
setFilePath(filePath)
|
return () => {
|
||||||
const setting = await JSON.parse(storage.getItem('setting') as string)
|
window.removeEventListener('customStorageChange', handleCustomStorageChange);
|
||||||
setting.shareFilesPath = filePath
|
};
|
||||||
storage.setItem('setting', JSON.stringify(setting))
|
|
||||||
})
|
|
||||||
}, [])
|
}, [])
|
||||||
|
const handleCustomStorageChange = (e: any): void => {
|
||||||
|
if (e.key === 'setting') {
|
||||||
|
const setting = JSON.parse(storage.getItem('setting') as string)
|
||||||
|
setFilePath(setting.shareFilesPath)
|
||||||
|
}
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -476,7 +486,9 @@ const FileComponents = () => {
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Button type="primary" onClick={() => {
|
<Button type="primary" onClick={() => {
|
||||||
window.electron.selectFilePath()
|
window.electron.selectFilePath({
|
||||||
|
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 {
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,10 @@ export interface IElectronAPI {
|
||||||
onUpdate: (callBack: Function) => void;
|
onUpdate: (callBack: Function) => void;
|
||||||
joinNotification: (data: { name: string, body: string }) => void;
|
joinNotification: (data: { name: string, body: string }) => void;
|
||||||
onDownload: (data: string) => void
|
onDownload: (data: string) => void
|
||||||
selectFilePath: () => void
|
selectFilePath: (data?: any) => void
|
||||||
onFilePath: (callBack: Function) => void;
|
onFilePath: (callBack: Function) => void;
|
||||||
getSources: () => any;
|
getSources: () => any;
|
||||||
|
downFile: (callBack: Function) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue