diff --git a/packages/geek-auto-start-chat-with-boss/index.mjs b/packages/geek-auto-start-chat-with-boss/index.mjs index 8aff93f..6e5fc2b 100644 --- a/packages/geek-auto-start-chat-with-boss/index.mjs +++ b/packages/geek-auto-start-chat-with-boss/index.mjs @@ -699,7 +699,7 @@ async function toRecommendPage (hooks) { hooks.pageLoaded?.call() let userInfoResponse = await userInfoPromise - await hooks.userInfoResponse?.promise(userInfoResponse) + await hooks.userInfoResponse?.promise({ userInfoResponse, browser }) if (userInfoResponse?.code !== 0) { autoStartChatEventBus.emit('LOGIN_STATUS_INVALID', { userInfoResponse @@ -1713,7 +1713,7 @@ export async function mainLoop (hooks) { //set cookies const bossCookies = readStorageFile('boss-cookies.json') const bossLocalStorage = readStorageFile('boss-local-storage.json') - await hooks.cookieWillSet?.promise(bossCookies) + await hooks.cookieWillSet?.promise({ cookies: bossCookies, browser }) for(let i = 0; i < bossCookies.length; i++){ if (Object.hasOwn(bossCookies[i], 'sameSite')) { bossCookies[i].sameSite = 'unspecified' diff --git a/packages/sqlite-plugin/src/index.ts b/packages/sqlite-plugin/src/index.ts index e9bb038..94a8213 100644 --- a/packages/sqlite-plugin/src/index.ts +++ b/packages/sqlite-plugin/src/index.ts @@ -116,7 +116,7 @@ export default class SqlitePlugin { ) hooks.userInfoResponse.tapPromise( "SqlitePlugin", - async (userInfoResponse) => { + async ({ userInfoResponse } = {}) => { if (!userInfoResponse || userInfoResponse.code !== 0) { return; } diff --git a/packages/ui/src/main/features/cookie-invalid-handle-plugin.ts b/packages/ui/src/main/features/cookie-invalid-handle-plugin.ts index cf2e87a..fba6de8 100644 --- a/packages/ui/src/main/features/cookie-invalid-handle-plugin.ts +++ b/packages/ui/src/main/features/cookie-invalid-handle-plugin.ts @@ -8,9 +8,14 @@ import { readStorageFile } from '@geekgeekrun/geek-auto-start-chat-with-boss/run const runRecordId = minimist(process.argv.slice(2))['run-record-id'] ?? null export class CookieInvalidHandlePlugin { apply(hooks) { - hooks.cookieWillSet.tapPromise('CookieInvalidHandlePlugin', async (cookies) => { + hooks.cookieWillSet.tapPromise('CookieInvalidHandlePlugin', async ({ cookies, browser } = {}) => { let isValid = checkCookieListFormat(cookies) while (!isValid) { + try { + browser && (await browser.close()) + } catch (err) { + console.log(`close browser failed`, err) + } try { // popup login dialog, then update login status await loginWithCookieAssistant() @@ -54,7 +59,7 @@ export class CookieInvalidHandlePlugin { } }) }) - hooks.userInfoResponse.tapPromise('CookieInvalidHandlePlugin', async (userInfoResponse) => { + hooks.userInfoResponse.tapPromise('CookieInvalidHandlePlugin', async ({ userInfoResponse, browser } = {}) => { if (userInfoResponse.code === 0) { sendToDaemon({ type: 'worker-to-gui-message', @@ -70,6 +75,11 @@ export class CookieInvalidHandlePlugin { }) return } + try { + browser && (await browser.close()) + } catch (err) { + console.log(`close browser failed`, err) + } try { // popup login dialog, then update login status await loginWithCookieAssistant() diff --git a/packages/ui/src/main/flow/READ_NO_REPLY_AUTO_REMINDER_MAIN/index.ts b/packages/ui/src/main/flow/READ_NO_REPLY_AUTO_REMINDER_MAIN/index.ts index 1f72e25..4ac47c1 100644 --- a/packages/ui/src/main/flow/READ_NO_REPLY_AUTO_REMINDER_MAIN/index.ts +++ b/packages/ui/src/main/flow/READ_NO_REPLY_AUTO_REMINDER_MAIN/index.ts @@ -89,7 +89,9 @@ const onlyRemindBossWithoutBlockCompanyName = readConfigFile('boss.json').autoReminder?.onlyRemindBossWithoutBlockCompanyName ?? !!blockCompanyNameRegExp -const openContentSource = readConfigFile('boss.json').autoReminder?.openContentSource ?? OPEN_CONTENT_SOURCE.CONSTANT_CONTENT +const openContentSource = + readConfigFile('boss.json').autoReminder?.openContentSource ?? + OPEN_CONTENT_SOURCE.CONSTANT_CONTENT const constantOpenContent = (() => { let constantOpenContent = readConfigFile('boss.json').autoReminder?.constantOpenContent ?? '' if (constantOpenContent?.trim?.()) { @@ -302,6 +304,11 @@ const mainLoop = async () => { let bossCookies = readStorageFile('boss-cookies.json') let cookieCheckResult = checkCookieListFormat(bossCookies) while (!cookieCheckResult) { + try { + browser && (await browser.close()) + } catch (err) { + console.log(`close browser failed`, err) + } try { await loginWithCookieAssistant() bossCookies = readStorageFile('boss-cookies.json') @@ -357,6 +364,11 @@ const mainLoop = async () => { // #region if (currentPageUrl.startsWith('https://www.zhipin.com/web/user/')) { writeStorageFile('boss-cookies.json', []) + try { + browser && (await browser.close()) + } catch (err) { + console.log(`close browser failed`, err) + } try { // popup login dialog, then update login status await loginWithCookieAssistant()