clouddisk-project/frontend/src/main/index.js
Team 61117803e1 团队工作进展:
- 后端: 文件管理 API (上传/下载/删除/创建文件夹)
- 前端: Electron 主进程 + React 页面框架
- 测试: 认证和文件管理测试用例
2026-03-10 07:27:10 +00:00

67 lines
1.5 KiB
JavaScript

const { app, BrowserWindow, ipcMain, dialog } = require('electron');
const path = require('path');
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow({
width: 1200,
height: 800,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
preload: path.join(__dirname, 'preload.js')
}
});
// Load the app
if (process.env.NODE_ENV === 'development') {
mainWindow.loadURL('http://localhost:3000');
mainWindow.webContents.openDevTools();
} else {
mainWindow.loadFile(path.join(__dirname, '../renderer/index.html'));
}
mainWindow.on('closed', () => {
mainWindow = null;
});
}
app.whenReady().then(createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
// IPC handlers
ipcMain.handle('select-file', async () => {
const result = await dialog.showOpenDialog(mainWindow, {
properties: ['openFile', 'multiSelections']
});
return result.filePaths;
});
ipcMain.handle('select-folder', async () => {
const result = await dialog.showOpenDialog(mainWindow, {
properties: ['openDirectory']
});
return result.filePaths[0];
});
ipcMain.handle('show-message', async (event, { title, message, type }) => {
const { dialog } = require('electron');
return dialog.showMessageBox(mainWindow, {
type: type || 'info',
title: title || 'CloudDisk',
message: message
});
});