// 浏览器环境中模拟 electron API if (typeof window !== 'undefined' && !window.electronAPI) { window.electronAPI = { // SSH 相关 sshConnect: async (config) => ({ success: true, connectionId: 'mock-' + Date.now() }), sshDisconnect: async () => ({ success: true }), sshExec: async () => ({ success: true, result: '' }), sshCreateShell: async () => ({ success: true, shellId: 'shell-' + Date.now() }), sshShellWrite: async () => ({ success: true }), sshShellResize: async () => ({ success: true }), // 会话管理 sessionGetAll: async () => ({ success: true, sessions: [ { id: '1', name: '本地开发服务器', host: '192.168.1.100', port: 22, username: 'root', authType: 'password' }, { id: '2', name: '阿里云生产', host: '47.100.1.1', port: 22, username: 'admin', authType: 'key' }, { id: '3', name: '腾讯云测试', host: '119.29.1.1', port: 2222, username: 'ubuntu', authType: 'password' }, ] }), sessionGetById: async (id) => ({ success: true, session: { id, name: '测试服务器', host: '192.168.1.100', port: 22, username: 'root', authType: 'password' } }), sessionCreate: async (session) => ({ success: true, session: { ...session, id: 'new-' + Date.now() } }), sessionUpdate: async (id, updates) => ({ success: true, session: { id, ...updates } }), sessionDelete: async () => ({ success: true }), // SFTP sftpConnect: async () => ({ success: true, sftpId: 'sftp-' + Date.now() }), sftpListDirectory: async () => ({ success: true, files: [ { filename: 'documents', longname: 'drwxr-xr-x', attrs: { mode: 16877, size: 4096 } }, { filename: 'file.txt', longname: '-rw-r--r--', attrs: { mode: 33188, size: 1024 } }, ] }), sftpUpload: async () => ({ success: true }), sftpDownload: async () => ({ success: true }), // 端口转发 sshForwardLocal: async () => ({ success: true, boundPort: 1080 }), sshForwardRemote: async () => ({ success: true }), sshForwardDynamic: async () => ({ success: true, boundPort: 1080 }), // 设置 settingsGet: async () => ({ success: true, value: null }), settingsSet: async () => ({ success: true }), // 对话框 showSaveDialog: async () => ({ canceled: false, filePath: '/mock/path' }), showOpenDialog: async () => ({ canceled: false, filePaths: ['/mock/path'] }), // 应用信息 getVersion: async () => '1.0.0', // 事件监听 onMenuNewSession: () => {}, onMenuQuickConnect: () => {}, onMenuImportSessions: () => {}, onMenuExportSessions: () => {}, onShellData: () => {}, onSFTPProgress: () => {}, removeAllListeners: () => {}, }; console.log('[Mock] electronAPI loaded for browser preview'); }