feat(initialization): 添加初始化页面和相关功能
- 新增初始化页面组件和路由 - 实现环境检查、Git下载、后端代码克隆等功能 - 添加下载服务和环境服务模块 - 更新类型定义,增加 Electron API 接口
This commit is contained in:
@@ -35,6 +35,10 @@ var __importStar = (this && this.__importStar) || (function () {
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const electron_1 = require("electron");
|
||||
const path = __importStar(require("path"));
|
||||
const environmentService_1 = require("./services/environmentService");
|
||||
const downloadService_1 = require("./services/downloadService");
|
||||
const pythonService_1 = require("./services/pythonService");
|
||||
const gitService_1 = require("./services/gitService");
|
||||
let mainWindow = null;
|
||||
function createWindow() {
|
||||
mainWindow = new electron_1.BrowserWindow({
|
||||
@@ -42,18 +46,14 @@ function createWindow() {
|
||||
height: 900,
|
||||
minWidth: 800,
|
||||
minHeight: 600,
|
||||
icon: path.join(__dirname, '../src/assets/AUTO_MAA.ico'), // 设置应用图标
|
||||
icon: path.join(__dirname, '../src/assets/AUTO_MAA.ico'),
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, 'preload.js'),
|
||||
nodeIntegration: false,
|
||||
contextIsolation: true,
|
||||
},
|
||||
// 隐藏菜单栏
|
||||
autoHideMenuBar: true,
|
||||
// 或者完全移除菜单栏(推荐)
|
||||
// menuBarVisible: false
|
||||
});
|
||||
// 完全移除菜单栏
|
||||
mainWindow.setMenuBarVisibility(false);
|
||||
const devServer = process.env.VITE_DEV_SERVER_URL;
|
||||
if (devServer) {
|
||||
@@ -66,15 +66,19 @@ function createWindow() {
|
||||
mainWindow.on('closed', () => {
|
||||
mainWindow = null;
|
||||
});
|
||||
// 设置各个服务的主窗口引用
|
||||
if (mainWindow) {
|
||||
(0, downloadService_1.setMainWindow)(mainWindow);
|
||||
(0, pythonService_1.setMainWindow)(mainWindow);
|
||||
(0, gitService_1.setMainWindow)(mainWindow);
|
||||
}
|
||||
}
|
||||
// 处理开发者工具请求
|
||||
// IPC处理函数
|
||||
electron_1.ipcMain.handle('open-dev-tools', () => {
|
||||
if (mainWindow) {
|
||||
// 在新窗口中打开开发者工具
|
||||
mainWindow.webContents.openDevTools({ mode: 'undocked' });
|
||||
}
|
||||
});
|
||||
// 处理文件夹选择请求
|
||||
electron_1.ipcMain.handle('select-folder', async () => {
|
||||
if (!mainWindow)
|
||||
return null;
|
||||
@@ -82,12 +86,8 @@ electron_1.ipcMain.handle('select-folder', async () => {
|
||||
properties: ['openDirectory'],
|
||||
title: '选择文件夹',
|
||||
});
|
||||
if (result.canceled) {
|
||||
return null;
|
||||
}
|
||||
return result.filePaths[0];
|
||||
return result.canceled ? null : result.filePaths[0];
|
||||
});
|
||||
// 处理文件选择请求
|
||||
electron_1.ipcMain.handle('select-file', async (event, filters = []) => {
|
||||
if (!mainWindow)
|
||||
return null;
|
||||
@@ -96,11 +96,40 @@ electron_1.ipcMain.handle('select-file', async (event, filters = []) => {
|
||||
title: '选择文件',
|
||||
filters: filters.length > 0 ? filters : [{ name: '所有文件', extensions: ['*'] }],
|
||||
});
|
||||
if (result.canceled) {
|
||||
return null;
|
||||
}
|
||||
return result.filePaths[0];
|
||||
return result.canceled ? null : result.filePaths[0];
|
||||
});
|
||||
// 环境检查
|
||||
electron_1.ipcMain.handle('check-environment', async () => {
|
||||
const appRoot = (0, environmentService_1.getAppRoot)();
|
||||
return (0, environmentService_1.checkEnvironment)(appRoot);
|
||||
});
|
||||
// Python相关
|
||||
electron_1.ipcMain.handle('download-python', async (event, mirror = 'tsinghua') => {
|
||||
const appRoot = (0, environmentService_1.getAppRoot)();
|
||||
return (0, pythonService_1.downloadPython)(appRoot, mirror);
|
||||
});
|
||||
electron_1.ipcMain.handle('install-dependencies', async (event, mirror = 'tsinghua') => {
|
||||
const appRoot = (0, environmentService_1.getAppRoot)();
|
||||
return (0, pythonService_1.installDependencies)(appRoot, mirror);
|
||||
});
|
||||
electron_1.ipcMain.handle('start-backend', async () => {
|
||||
const appRoot = (0, environmentService_1.getAppRoot)();
|
||||
return (0, pythonService_1.startBackend)(appRoot);
|
||||
});
|
||||
// Git相关
|
||||
electron_1.ipcMain.handle('download-git', async () => {
|
||||
const appRoot = (0, environmentService_1.getAppRoot)();
|
||||
return (0, gitService_1.downloadGit)(appRoot);
|
||||
});
|
||||
electron_1.ipcMain.handle('clone-backend', async (event, repoUrl = 'https://github.com/DLmaster361/AUTO_MAA.git') => {
|
||||
const appRoot = (0, environmentService_1.getAppRoot)();
|
||||
return (0, gitService_1.cloneBackend)(appRoot, repoUrl);
|
||||
});
|
||||
electron_1.ipcMain.handle('update-backend', async (event, repoUrl = 'https://github.com/DLmaster361/AUTO_MAA.git') => {
|
||||
const appRoot = (0, environmentService_1.getAppRoot)();
|
||||
return (0, gitService_1.cloneBackend)(appRoot, repoUrl); // 使用相同的逻辑,会自动判断是pull还是clone
|
||||
});
|
||||
// 应用生命周期
|
||||
electron_1.app.whenReady().then(createWindow);
|
||||
electron_1.app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin')
|
||||
|
||||
Reference in New Issue
Block a user