index.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import React from 'react';
  2. import ReactDOM from 'react-dom';
  3. import Routes from './router/index';
  4. import App from './App';
  5. // 添加electron全局对象检查和降级方案
  6. if (typeof window !== 'undefined' && !window.electron) {
  7. console.warn('Electron API 不可用,使用模拟实现');
  8. // 在浏览器环境中提供一个模拟的electron对象
  9. window.electron = {
  10. // IPC通信
  11. ipcRenderer: {
  12. send: (channel, ...args) => {
  13. console.warn(`[Electron模拟] 发送消息到通道 ${channel}`, args);
  14. },
  15. invoke: (channel, ...args) => {
  16. console.warn(`[Electron模拟] 调用 ${channel}`, args);
  17. // 返回不同API的模拟数据
  18. if (channel === 'save-audio-file') {
  19. return Promise.resolve({
  20. success: true,
  21. filePath: '/模拟路径/audio.mp3'
  22. });
  23. } else if (channel === 'process-project-audio') {
  24. return Promise.resolve({
  25. success: true,
  26. totalSegments: args[0]?.segments?.length || 0,
  27. processedSegments: 0,
  28. segments: []
  29. });
  30. } else if (channel === 'get-audio-duration') {
  31. return Promise.resolve({
  32. success: true,
  33. duration: 60 // 默认返回60秒
  34. });
  35. } else if (channel === 'get-app-version') {
  36. return Promise.resolve('1.0.0');
  37. } else if (channel === 'open-directory-dialog') {
  38. return Promise.resolve({ canceled: false, filePaths: ['/模拟目录路径'] });
  39. } else if (channel === 'open-file-path' || channel === 'open-url' || channel === 'get-file-stats') {
  40. return Promise.resolve(null);
  41. }
  42. return Promise.resolve(null);
  43. },
  44. on: (channel, func) => {
  45. console.warn(`[Electron模拟] 监听通道 ${channel}`);
  46. return () => {}; // 返回清理函数
  47. },
  48. once: (channel, func) => {
  49. console.warn(`[Electron模拟] 一次性监听通道 ${channel}`);
  50. }
  51. },
  52. // 模拟系统相关API
  53. system: {
  54. getAppVersion: () => Promise.resolve('1.0.0')
  55. },
  56. // 模拟文件操作API
  57. files: {
  58. openDirectoryDialog: () => Promise.resolve({ canceled: false, filePaths: ['/模拟目录路径'] }),
  59. showItemInFolder: () => Promise.resolve(),
  60. getFileStats: () => Promise.resolve(null)
  61. },
  62. // 模拟外部链接API
  63. shell: {
  64. openExternal: () => Promise.resolve()
  65. }
  66. };
  67. }
  68. ReactDOM.render(<App />, document.getElementById('root'));