mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-09-06 07:57:06 +08:00
try to prevent pipe write error , mainWindow null pointer error
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { app } from 'electron'
|
import { app } from 'electron'
|
||||||
import checkAndDownloadPuppeteer from './check-and-download-puppeteer'
|
import checkAndDownloadPuppeteer from './check-and-download-puppeteer'
|
||||||
import * as net from 'net'
|
import * as net from 'net'
|
||||||
|
import { pipeWriteRegardlessError } from '../utils/pipe'
|
||||||
|
|
||||||
export enum DOWNLOAD_ERROR_EXIT_CODE {
|
export enum DOWNLOAD_ERROR_EXIT_CODE {
|
||||||
NO_ERROR = 0,
|
NO_ERROR = 0,
|
||||||
@@ -16,7 +17,8 @@ export const checkAndDownloadDependenciesForInit = async () => {
|
|||||||
console.warn('pipe is not available')
|
console.warn('pipe is not available')
|
||||||
}
|
}
|
||||||
|
|
||||||
pipe?.write(
|
pipeWriteRegardlessError(
|
||||||
|
pipe,
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
type: 'NEED_RESETUP_DEPENDENCIES'
|
type: 'NEED_RESETUP_DEPENDENCIES'
|
||||||
}) + '\r\n'
|
}) + '\r\n'
|
||||||
@@ -35,7 +37,8 @@ export const checkAndDownloadDependenciesForInit = async () => {
|
|||||||
}, 30 * 1000)
|
}, 30 * 1000)
|
||||||
}
|
}
|
||||||
console.log(downloadedBytes / totalBytes)
|
console.log(downloadedBytes / totalBytes)
|
||||||
pipe?.write(
|
pipeWriteRegardlessError(
|
||||||
|
pipe,
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
type: 'PUPPETEER_DOWNLOAD_PROGRESS',
|
type: 'PUPPETEER_DOWNLOAD_PROGRESS',
|
||||||
totalBytes,
|
totalBytes,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import * as net from 'net'
|
|||||||
import {
|
import {
|
||||||
checkPuppeteerExecutable,
|
checkPuppeteerExecutable,
|
||||||
} from './CHECK_AND_DOWNLOAD_DEPENDENCIES/check-and-download-puppeteer'
|
} from './CHECK_AND_DOWNLOAD_DEPENDENCIES/check-and-download-puppeteer'
|
||||||
|
import { pipeWriteRegardlessError } from './utils/pipe'
|
||||||
|
|
||||||
const { groupRobotAccessToken: dingTalkAccessToken } = readConfigFile('dingtalk.json')
|
const { groupRobotAccessToken: dingTalkAccessToken } = readConfigFile('dingtalk.json')
|
||||||
|
|
||||||
@@ -31,14 +32,16 @@ export const runAutoChat = async () => {
|
|||||||
} catch {
|
} catch {
|
||||||
console.warn('pipe is not available')
|
console.warn('pipe is not available')
|
||||||
}
|
}
|
||||||
pipe?.write(
|
pipeWriteRegardlessError(
|
||||||
|
pipe,
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
type: 'INITIALIZE_PUPPETEER'
|
type: 'INITIALIZE_PUPPETEER'
|
||||||
}) + '\r\n'
|
}) + '\r\n'
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
await initPuppeteer()
|
await initPuppeteer()
|
||||||
pipe?.write(
|
pipeWriteRegardlessError(
|
||||||
|
pipe,
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
type: 'PUPPETEER_INITIALIZE_SUCCESSFULLY'
|
type: 'PUPPETEER_INITIALIZE_SUCCESSFULLY'
|
||||||
}) + '\r\n'
|
}) + '\r\n'
|
||||||
@@ -65,7 +68,8 @@ export const runAutoChat = async () => {
|
|||||||
errorEncounter: new SyncHook(['errorInfo'])
|
errorEncounter: new SyncHook(['errorInfo'])
|
||||||
}
|
}
|
||||||
initPlugins(hooks)
|
initPlugins(hooks)
|
||||||
pipe?.write(
|
pipeWriteRegardlessError(
|
||||||
|
pipe,
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
type: 'GEEK_AUTO_START_CHAT_WITH_BOSS_STARTED' //geek-auto-start-chat-with-boss-started
|
type: 'GEEK_AUTO_START_CHAT_WITH_BOSS_STARTED' //geek-auto-start-chat-with-boss-started
|
||||||
}) + '\r\n'
|
}) + '\r\n'
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import * as net from 'net'
|
||||||
|
|
||||||
|
export const pipeWriteRegardlessError = (
|
||||||
|
pipe: net.Socket | null,
|
||||||
|
...writeArgs: Parameters<net.Socket['write']>
|
||||||
|
) => {
|
||||||
|
try {
|
||||||
|
pipe?.write(...writeArgs)
|
||||||
|
} catch (error) {
|
||||||
|
console.log('pipe.write Error', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -122,7 +122,7 @@ export function createMainWindow(): void {
|
|||||||
// means cannot find downloaded puppeteer
|
// means cannot find downloaded puppeteer
|
||||||
reject('NEED_TO_CHECK_RUNTIME_DEPENDENCIES')
|
reject('NEED_TO_CHECK_RUNTIME_DEPENDENCIES')
|
||||||
} else {
|
} else {
|
||||||
mainWindow.webContents.send('geek-auto-start-chat-with-boss-stopped')
|
mainWindow?.webContents.send('geek-auto-start-chat-with-boss-stopped')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -162,7 +162,7 @@ export function createMainWindow(): void {
|
|||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
case 'NEED_RESETUP_DEPENDENCIES':
|
case 'NEED_RESETUP_DEPENDENCIES':
|
||||||
case 'PUPPETEER_DOWNLOAD_PROGRESS': {
|
case 'PUPPETEER_DOWNLOAD_PROGRESS': {
|
||||||
mainWindow.webContents.send(data.type, data)
|
mainWindow?.webContents.send(data.type, data)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@@ -188,7 +188,7 @@ export function createMainWindow(): void {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.handle('stop-geek-auto-start-chat-with-boss', async () => {
|
ipcMain.handle('stop-geek-auto-start-chat-with-boss', async () => {
|
||||||
mainWindow.webContents.send('geek-auto-start-chat-with-boss-stopping')
|
mainWindow?.webContents.send('geek-auto-start-chat-with-boss-stopping')
|
||||||
subProcessOfPuppeteer?.kill('SIGINT')
|
subProcessOfPuppeteer?.kill('SIGINT')
|
||||||
})
|
})
|
||||||
ipcMain.on('open-project-homepage-on-github', () => {
|
ipcMain.on('open-project-homepage-on-github', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user