enhance the page status ui detail. such as not use collected value override user inputted content in cookie textarea, restore page alert bar status when user close browser without cookie being collected

This commit is contained in:
geekgeekrun
2024-03-03 16:33:30 +08:00
parent 17c17bb6e6
commit 4b7733c8a2
2 changed files with 68 additions and 8 deletions
+14 -2
View File
@@ -225,8 +225,10 @@ export function createMainWindow(): void {
let subProcessOfBossZhipinLoginPageWithPreloadExtension: ChildProcess | null = null let subProcessOfBossZhipinLoginPageWithPreloadExtension: ChildProcess | null = null
ipcMain.on('launch-bosszhipin-login-page-with-preload-extension', async () => { ipcMain.on('launch-bosszhipin-login-page-with-preload-extension', async () => {
if (subProcessOfBossZhipinLoginPageWithPreloadExtension) { try {
return subProcessOfBossZhipinLoginPageWithPreloadExtension?.kill()
} catch {
//
} }
const subProcessEnv = { const subProcessEnv = {
...process.env, ...process.env,
@@ -258,9 +260,19 @@ export function createMainWindow(): void {
) )
subProcessOfBossZhipinLoginPageWithPreloadExtension!.once('exit', () => { subProcessOfBossZhipinLoginPageWithPreloadExtension!.once('exit', () => {
mainWindow?.webContents.send('BOSS_ZHIPIN_LOGIN_PAGE_CLOSED')
subProcessOfBossZhipinLoginPageWithPreloadExtension = null subProcessOfBossZhipinLoginPageWithPreloadExtension = null
}) })
}) })
ipcMain.on('kill-bosszhipin-login-page-with-preload-extension', async () => {
try {
subProcessOfBossZhipinLoginPageWithPreloadExtension?.kill()
} catch {
//
} finally {
subProcessOfBossZhipinLoginPageWithPreloadExtension = null
}
})
mainWindow!.once('closed', () => { mainWindow!.once('closed', () => {
mainWindow = null mainWindow = null
@@ -70,27 +70,49 @@
maxRows: 10 maxRows: 10
}" }"
font-size-12px font-size-12px
@input="hasUserMutateInput = true"
></el-input> ></el-input>
<el-alert <el-alert
v-if="!formContent.collectedCookies" v-if="loginCookieWaitingStatus === LOGIN_COOKIE_WAITING_STATUS.WAITING_FOR_LOGIN"
:closable="false" :closable="false"
title="正在等待登录……" >正在等待登录</el-alert
></el-alert> >
<el-alert
v-if="loginCookieWaitingStatus === LOGIN_COOKIE_WAITING_STATUS.COOKIE_COLLECTED"
:closable="false"
type="success"
>已获取到Cookie<template v-if="hasUserMutateInput"
>看起来您似乎正在尝试手动输入Cookie<el-button
size="small"
type="primary"
font-size-inherit
@click="fillCollectedCookie"
>使用获取到的Cookie</el-button
></template
></el-alert
>
</el-form-item> </el-form-item>
</el-form> </el-form>
<template #footer> <template #footer>
<el-button type="primary" @click="handleSubmit">确定</el-button> <el-button type="primary" @click="handleSubmit">保存Cookie</el-button>
</template> </template>
</el-dialog> </el-dialog>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ElForm, ElMessage } from 'element-plus'; import { ElForm, ElMessage } from 'element-plus'
import { ref, onUnmounted, onMounted } from 'vue' import { ref, onUnmounted, onMounted } from 'vue'
const props = defineProps({ const props = defineProps({
dispose: Function dispose: Function
}) })
enum LOGIN_COOKIE_WAITING_STATUS {
INIT,
WAITING_FOR_LOGIN,
COOKIE_COLLECTED
}
const loginCookieWaitingStatus = ref(LOGIN_COOKIE_WAITING_STATUS.INIT)
const formRef = ref<InstanceType<typeof ElForm>>() const formRef = ref<InstanceType<typeof ElForm>>()
const formContent = ref({ const formContent = ref({
collectedCookies: '' collectedCookies: ''
@@ -153,12 +175,26 @@ const formRules = {
] ]
} }
const hasUserMutateInput = ref(false)
const collectedCookie = ref()
const handleCookieCollected = (_, payload) => { const handleCookieCollected = (_, payload) => {
formContent.value.collectedCookies = JSON.stringify(payload.cookies, null, 2) loginCookieWaitingStatus.value = LOGIN_COOKIE_WAITING_STATUS.COOKIE_COLLECTED
collectedCookie.value = payload.cookies
if (!hasUserMutateInput.value) {
fillCollectedCookie()
}
}
const fillCollectedCookie = () => {
if (loginCookieWaitingStatus.value !== LOGIN_COOKIE_WAITING_STATUS.COOKIE_COLLECTED) {
return
}
formContent.value.collectedCookies = JSON.stringify(collectedCookie.value, null, 2)
hasUserMutateInput.value = false
} }
const handleClickLaunchLogin = () => { const handleClickLaunchLogin = () => {
electron.ipcRenderer.send('launch-bosszhipin-login-page-with-preload-extension') electron.ipcRenderer.send('launch-bosszhipin-login-page-with-preload-extension')
loginCookieWaitingStatus.value = LOGIN_COOKIE_WAITING_STATUS.WAITING_FOR_LOGIN
} }
const handleEditThisCookieExtensionStoreLinkClick = () => { const handleEditThisCookieExtensionStoreLinkClick = () => {
@@ -178,11 +214,23 @@ const handleSubmit = async () => {
props.dispose() props.dispose()
} }
const handleBossZhipinLoginPageClosed = () => {
if (loginCookieWaitingStatus.value === LOGIN_COOKIE_WAITING_STATUS.WAITING_FOR_LOGIN) {
loginCookieWaitingStatus.value = LOGIN_COOKIE_WAITING_STATUS.INIT
}
}
onMounted(() => { onMounted(() => {
electron.ipcRenderer.once('BOSS_ZHIPIN_COOKIE_COLLECTED', handleCookieCollected) electron.ipcRenderer.once('BOSS_ZHIPIN_COOKIE_COLLECTED', handleCookieCollected)
electron.ipcRenderer.on('BOSS_ZHIPIN_LOGIN_PAGE_CLOSED', handleBossZhipinLoginPageClosed)
}) })
onUnmounted(() => { onUnmounted(() => {
electron.ipcRenderer.removeListener('BOSS_ZHIPIN_COOKIE_COLLECTED', handleCookieCollected) electron.ipcRenderer.removeListener('BOSS_ZHIPIN_COOKIE_COLLECTED', handleCookieCollected)
electron.ipcRenderer.removeListener(
'BOSS_ZHIPIN_LOGIN_PAGE_CLOSED',
handleBossZhipinLoginPageClosed
)
electron.ipcRenderer.send('kill-bosszhipin-login-page-with-preload-extension')
}) })
</script> </script>