use file instead of port to listen server

This commit is contained in:
geekgeekrun
2026-01-17 12:36:03 +08:00
parent a05c73cbdf
commit 4cf6a7e36f
4 changed files with 30 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
import { randomUUID } from "node:crypto";
import { DAEMON_PORT } from "./daemon-config";
import { EventEmitter } from "node:events";
import { tmpdir } from "node:os";
import path from "node:path";
const net = require('net');
const split2 = require('split2');
@@ -15,7 +16,11 @@ export async function connectToDaemon() {
daemonClient = new net.Socket();
let isConnected = false
await new Promise((resolve, reject) => {
daemonClient.connect(DAEMON_PORT, 'localhost', () => {
const ipcSocketName = process.env.GEEKGEEKRUND_PIPE_NAME
const ipcSocketPath = process.platform === 'win32'
? `\\\\.\\pipe\\${ipcSocketName}`
: path.join(tmpdir(), `${ipcSocketName}.sock`)
daemonClient.connect(ipcSocketPath, 'localhost', () => {
isConnected = true
console.log('已连接到守护进程');
daemonEE.emit('connect')

View File

@@ -1 +0,0 @@
export const DAEMON_PORT = 12345;

View File

@@ -1,3 +1,4 @@
import { randomUUID } from "crypto";
const { app } = require('electron');
const { spawn } = require('child_process');
@@ -27,6 +28,7 @@ export function launchDaemon() {
// 启动守护进程
async function startDaemon() {
console.log('启动守护进程...');
process.env.GEEKGEEKRUND_PIPE_NAME = `geekgeekrun-d_${randomUUID()}`
// 使用 Electron 可执行程序路径,如果没有则回退到 node
const electronPath = process.execPath;
console.log(`使用 Electron 路径: ${electronPath}`);