mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-09-08 00:47:15 +08:00
Merge branch 'feature/ui' into feature/ui-use-users-own-browser
This commit is contained in:
@@ -3,7 +3,7 @@ import checkAndDownloadPuppeteerExecutable, {
|
|||||||
checkCachedPuppeteerExecutable,
|
checkCachedPuppeteerExecutable,
|
||||||
getExpectCachedPuppeteerExecutablePath
|
getExpectCachedPuppeteerExecutablePath
|
||||||
} from './check-and-download-puppeteer-executable'
|
} from './check-and-download-puppeteer-executable'
|
||||||
import * as net from 'net'
|
import * as fs from 'fs'
|
||||||
import { pipeWriteRegardlessError } from '../utils/pipe'
|
import { pipeWriteRegardlessError } from '../utils/pipe'
|
||||||
import {
|
import {
|
||||||
removeLastUsedAndAvailableBrowserPath,
|
removeLastUsedAndAvailableBrowserPath,
|
||||||
@@ -42,10 +42,10 @@ export const getAnyAvailablePuppeteerExecutablePath = async (): Promise<string |
|
|||||||
|
|
||||||
export const checkAndDownloadDependenciesForInit = async () => {
|
export const checkAndDownloadDependenciesForInit = async () => {
|
||||||
process.on('disconnect', () => app.exit())
|
process.on('disconnect', () => app.exit())
|
||||||
app.dock.hide()
|
app.dock?.hide()
|
||||||
let pipe: null | net.Socket = null
|
let pipe: null | fs.WriteStream = null
|
||||||
try {
|
try {
|
||||||
pipe = new net.Socket({ fd: 3 })
|
pipe = fs.createWriteStream(null, { fd: 3 })
|
||||||
} catch {
|
} catch {
|
||||||
console.warn('pipe is not available')
|
console.warn('pipe is not available')
|
||||||
}
|
}
|
||||||
@@ -59,37 +59,65 @@ export const checkAndDownloadDependenciesForInit = async () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
let timeoutTimer = 0
|
let timeoutTimer = 0
|
||||||
await new Promise((resolve, reject) => {
|
const promiseWithResolver = (() => {
|
||||||
checkAndDownloadPuppeteerExecutable({
|
const o = {} as unknown as {
|
||||||
downloadProgressCallback(downloadedBytes: number, totalBytes: number) {
|
promise: Promise<unknown>
|
||||||
clearTimeout(timeoutTimer)
|
resolve: (result: unknown) => void
|
||||||
if (downloadedBytes !== totalBytes) {
|
reject: (reason: unknown) => void
|
||||||
timeoutTimer = setTimeout(() => {
|
}
|
||||||
// will encounter this when network disconnected when downloading
|
o.promise = new Promise((resolve, reject) => {
|
||||||
reject(new Error('PROGRESS_NOT_CHANGED_TOO_LONG'))
|
o.resolve = resolve
|
||||||
}, 30 * 1000)
|
o.reject = reject
|
||||||
}
|
})
|
||||||
console.log(downloadedBytes / totalBytes)
|
return o
|
||||||
|
})()
|
||||||
|
|
||||||
|
let throttleProgressTimer: number | null = null
|
||||||
|
checkAndDownloadPuppeteerExecutable({
|
||||||
|
downloadProgressCallback(downloadedBytes: number, totalBytes: number) {
|
||||||
|
clearTimeout(timeoutTimer)
|
||||||
|
if (downloadedBytes !== totalBytes) {
|
||||||
|
timeoutTimer = setTimeout(() => {
|
||||||
|
// will encounter this when network disconnected when downloading
|
||||||
|
promiseWithResolver.reject(new Error('PROGRESS_NOT_CHANGED_TOO_LONG'))
|
||||||
|
}, 5 * 1000)
|
||||||
|
} else {
|
||||||
|
clearTimeout(throttleProgressTimer)
|
||||||
|
throttleProgressTimer = null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!throttleProgressTimer) {
|
||||||
|
// console.log(JSON.stringify({
|
||||||
|
// type: 'DOWNLOAD_PROGRESS_UPDATE',
|
||||||
|
// level: 'DEBUG',
|
||||||
|
// percent: downloadedBytes / totalBytes
|
||||||
|
// }))
|
||||||
|
|
||||||
pipeWriteRegardlessError(
|
pipeWriteRegardlessError(
|
||||||
pipe,
|
pipe,
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
type: 'PUPPETEER_DOWNLOAD_PROGRESS',
|
type: 'PUPPETEER_DOWNLOAD_PROGRESS',
|
||||||
totalBytes,
|
totalBytes,
|
||||||
downloadedBytes
|
downloadedBytes
|
||||||
})
|
}) + '\r\n'
|
||||||
) + '\r\n'
|
)
|
||||||
|
throttleProgressTimer = setTimeout(() => {
|
||||||
|
throttleProgressTimer = null
|
||||||
|
}, 2500)
|
||||||
}
|
}
|
||||||
}).then(
|
}
|
||||||
() => {
|
|
||||||
resolve(void 0)
|
|
||||||
},
|
|
||||||
(err) => {
|
|
||||||
reject(err)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
.then(() => {
|
||||||
|
promiseWithResolver.resolve(void 0)
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
promiseWithResolver.reject(err)
|
||||||
|
})
|
||||||
|
|
||||||
|
await promiseWithResolver.promise
|
||||||
app.exit(DOWNLOAD_ERROR_EXIT_CODE.NO_ERROR)
|
app.exit(DOWNLOAD_ERROR_EXIT_CODE.NO_ERROR)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
app.exit(DOWNLOAD_ERROR_EXIT_CODE.DOWNLOAD_ERROR)
|
app.exit(DOWNLOAD_ERROR_EXIT_CODE.DOWNLOAD_ERROR)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ import DingtalkPlugin from '@geekgeekrun/dingtalk-plugin/index.mjs'
|
|||||||
import { app } from 'electron'
|
import { app } from 'electron'
|
||||||
import { SyncHook, AsyncSeriesHook } from 'tapable'
|
import { SyncHook, AsyncSeriesHook } from 'tapable'
|
||||||
import { readConfigFile } from '@geekgeekrun/geek-auto-start-chat-with-boss/runtime-file-utils.mjs'
|
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'
|
||||||
import { pipeWriteRegardlessError } from './utils/pipe'
|
import { pipeWriteRegardlessError } from './utils/pipe'
|
||||||
import { getAnyAvailablePuppeteerExecutablePath } from './CHECK_AND_DOWNLOAD_DEPENDENCIES'
|
import { getAnyAvailablePuppeteerExecutablePath } from './CHECK_AND_DOWNLOAD_DEPENDENCIES'
|
||||||
|
|
||||||
@@ -23,11 +26,11 @@ export const runAutoChat = async () => {
|
|||||||
closeBrowserWindow()
|
closeBrowserWindow()
|
||||||
app.exit()
|
app.exit()
|
||||||
})
|
})
|
||||||
app.dock.hide()
|
app.dock?.hide()
|
||||||
let pipe: null | net.Socket = null
|
let pipe: null | fs.WriteStream = null
|
||||||
try {
|
try {
|
||||||
pipe = new net.Socket({ fd: 3 })
|
pipe = fs.createWriteStream(null, { fd: 3 })
|
||||||
} catch (err) {
|
} catch {
|
||||||
console.warn('pipe is not available')
|
console.warn('pipe is not available')
|
||||||
}
|
}
|
||||||
pipeWriteRegardlessError(
|
pipeWriteRegardlessError(
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
import * as net from 'net'
|
import * as fs from 'fs'
|
||||||
|
|
||||||
export const pipeWriteRegardlessError = (
|
export const pipeWriteRegardlessError = async (
|
||||||
pipe: net.Socket | null,
|
pipe: fs.WriteStream | null,
|
||||||
...writeArgs: Parameters<net.Socket['write']>
|
chunk: unknown,
|
||||||
|
option?
|
||||||
) => {
|
) => {
|
||||||
try {
|
return new Promise((resolve) => {
|
||||||
pipe?.write(...writeArgs)
|
// debugger
|
||||||
} catch (error) {
|
pipe?.write(chunk, option, (error) => {
|
||||||
console.log('pipe.write Error', error)
|
if (error) {
|
||||||
}
|
console.log('pipe.write Error', error)
|
||||||
|
}
|
||||||
|
resolve(undefined)
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user