mirror of
https://github.com/dream-pep/koring-launcher.git
synced 2026-09-12 05:45:18 +08:00
Migrate app from Tauri to Electron
Replace the Tauri/sidecar architecture with an Electron main process. Adds an electron/ directory (main, preload, handlers, core integrations for @xmcl/*), electron-builder.yml, TypeScript electron config and declarations, and updated IPC utilities (ipc.ts) so frontend uses ipcRenderer/ipcMain. Removes Tauri sidecar and src-tauri artifacts, deletes sidecar sources and keys, updates .gitignore, VSCode recommendations, package scripts and icons, and updates documentation (README, AGENTS, DEV) and frontend stores/apis to reflect the Electron-based architecture and config/auth persistence changes.
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.registerTaskHandlers = registerTaskHandlers;
|
||||
const electron_1 = __importDefault(require("electron"));
|
||||
const { ipcMain } = electron_1.default;
|
||||
const runningTasks = new Map();
|
||||
function registerTaskHandlers(win) {
|
||||
ipcMain.handle('task:start', async (_event, payload) => {
|
||||
try {
|
||||
const controller = new AbortController();
|
||||
runningTasks.set(payload.taskId, controller);
|
||||
win.mainWindow?.webContents.send('task:started', {
|
||||
taskId: payload.taskId,
|
||||
xmclPath: payload.executorName,
|
||||
});
|
||||
// Simulate task execution
|
||||
const steps = 20;
|
||||
for (let i = 0; i <= steps; i++) {
|
||||
if (controller.signal.aborted) {
|
||||
win.mainWindow?.webContents.send('task:failed', {
|
||||
taskId: payload.taskId,
|
||||
error: 'Task cancelled',
|
||||
});
|
||||
runningTasks.delete(payload.taskId);
|
||||
return { success: true, data: null, error: null };
|
||||
}
|
||||
win.mainWindow?.webContents.send('task:progress', {
|
||||
taskId: payload.taskId,
|
||||
current: i,
|
||||
total: steps,
|
||||
stage: `步骤 ${i}/${steps}`,
|
||||
});
|
||||
await new Promise((r) => setTimeout(r, 150));
|
||||
}
|
||||
runningTasks.delete(payload.taskId);
|
||||
win.mainWindow?.webContents.send('task:completed', {
|
||||
taskId: payload.taskId,
|
||||
});
|
||||
return { success: true, data: null, error: null };
|
||||
}
|
||||
catch (e) {
|
||||
runningTasks.delete(payload.taskId);
|
||||
return { success: false, data: null, error: String(e) };
|
||||
}
|
||||
});
|
||||
ipcMain.handle('task:cancel', async (_event, payload) => {
|
||||
try {
|
||||
const controller = runningTasks.get(payload.taskId);
|
||||
if (controller) {
|
||||
controller.abort();
|
||||
}
|
||||
return { success: true, data: null, error: null };
|
||||
}
|
||||
catch (e) {
|
||||
return { success: false, data: null, error: String(e) };
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user