mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-06-06 08:00:32 +08:00
use file instead of port to listen server
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export const DAEMON_PORT = 12345;
|
||||
@@ -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}`);
|
||||
|
||||
Reference in New Issue
Block a user