WIP: use fs.WriteStream to replace net.Socket to fix stdio data event not trigger on windows TODO: the content expect no print seems printed to stdout, normal JSON mix with console.log, may cause download process of puppeteer interrupted (near 44%)

This commit is contained in:
geekgeekrun
2024-02-24 23:36:20 +08:00
parent b115f0fbc3
commit 6adaf28096
3 changed files with 20 additions and 15 deletions

View File

@@ -1,6 +1,6 @@
import { app } from 'electron'
import checkAndDownloadPuppeteerExecutable from './check-and-download-puppeteer-executable'
import * as net from 'net'
import * as fs from 'fs'
import { pipeWriteRegardlessError } from '../utils/pipe'
export enum DOWNLOAD_ERROR_EXIT_CODE {
@@ -10,9 +10,9 @@ export enum DOWNLOAD_ERROR_EXIT_CODE {
export const checkAndDownloadDependenciesForInit = async () => {
process.on('disconnect', () => app.exit())
app.dock?.hide()
let pipe: null | net.Socket = null
let pipe: null | fs.WriteStream = null
try {
pipe = new net.Socket({ fd: 3 })
pipe = fs.createWriteStream(null, { fd: 3 })
} catch {
console.warn('pipe is not available')
}

View File

@@ -2,7 +2,7 @@ import DingtalkPlugin from '@geekgeekrun/dingtalk-plugin/index.mjs'
import { app } from 'electron'
import { SyncHook, AsyncSeriesHook } from 'tapable'
import { readConfigFile } from '@geekgeekrun/geek-auto-start-chat-with-boss/runtime-file-utils.mjs'
import * as net from 'net'
import * as fs from 'fs'
import {
checkPuppeteerExecutable,
} from './CHECK_AND_DOWNLOAD_DEPENDENCIES/check-and-download-puppeteer-executable'
@@ -26,9 +26,9 @@ export const runAutoChat = async () => {
app.exit()
})
app.dock?.hide()
let pipe: null | net.Socket = null
let pipe: null | fs.WriteStream = null
try {
pipe = new net.Socket({ fd: 3 })
pipe = fs.createWriteStream(null, { fd: 3 })
} catch {
console.warn('pipe is not available')
}

View File

@@ -1,12 +1,17 @@
import * as net from 'net'
import * as fs from 'fs'
export const pipeWriteRegardlessError = (
pipe: net.Socket | null,
...writeArgs: Parameters<net.Socket['write']>
export const pipeWriteRegardlessError = async (
pipe: fs.WriteStream | null,
chunk: unknown,
option?
) => {
try {
pipe?.write(...writeArgs)
} catch (error) {
console.log('pipe.write Error', error)
}
return new Promise((resolve) => {
// debugger
pipe?.write(chunk, option, (error) => {
if (error) {
console.log('pipe.write Error', error)
}
resolve(undefined)
})
})
}