mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-10-26 02:04:37 +08:00
refactor(security): simplify desktop app lock
This commit is contained in:
1 parent
7e46e47d3c
commit
10ead5a306
3 files changed
+74
No files matched your search
@@ -1,8 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onMounted, onUnmounted, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useLayoutStore } from '@/stores/layout'
|
||||
|
||||
const { t } = useI18n()
|
||||
const layoutStore = useLayoutStore()
|
||||
const visible = ref(false)
|
||||
const isUnlocking = ref(false)
|
||||
const password = ref('')
|
||||
@@ -30,6 +32,7 @@ onUnmounted(() => removeLockListener?.())
|
||||
async function showOverlay(): Promise<void> {
|
||||
visible.value = true
|
||||
resetForm()
|
||||
layoutStore.closeOverlaysForAppLock()
|
||||
await nextTick()
|
||||
passwordInputRef.value?.focus()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { before, beforeEach, describe, it } from 'node:test'
|
||||
import { createPinia, setActivePinia } from 'pinia'
|
||||
|
||||
const storageEntries = new Map<string, string>()
|
||||
const memoryStorage: Storage = {
|
||||
get length() {
|
||||
return storageEntries.size
|
||||
},
|
||||
clear() {
|
||||
storageEntries.clear()
|
||||
},
|
||||
getItem(key) {
|
||||
return storageEntries.get(key) ?? null
|
||||
},
|
||||
key(index) {
|
||||
return [...storageEntries.keys()][index] ?? null
|
||||
},
|
||||
removeItem(key) {
|
||||
storageEntries.delete(key)
|
||||
},
|
||||
setItem(key, value) {
|
||||
storageEntries.set(key, value)
|
||||
},
|
||||
}
|
||||
|
||||
Object.defineProperty(globalThis, 'localStorage', {
|
||||
configurable: true,
|
||||
value: memoryStorage,
|
||||
})
|
||||
|
||||
let useLayoutStore: typeof import('./layout').useLayoutStore
|
||||
|
||||
describe('layout store app lock overlays', () => {
|
||||
before(async () => {
|
||||
;({ useLayoutStore } = await import('./layout'))
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
setActivePinia(createPinia())
|
||||
})
|
||||
|
||||
it('closes focus-trapping overlays before showing the app lock screen', () => {
|
||||
const store = useLayoutStore()
|
||||
store.showSettings = true
|
||||
store.showScreenCaptureModal = true
|
||||
store.screenCaptureImage = 'data:image/png;base64,test'
|
||||
store.showChatRecordDrawer = true
|
||||
store.chatRecordQuery = {} as never
|
||||
|
||||
store.closeOverlaysForAppLock()
|
||||
|
||||
assert.equal(store.showSettings, false)
|
||||
assert.equal(store.showScreenCaptureModal, false)
|
||||
assert.equal(store.screenCaptureImage, null)
|
||||
assert.equal(store.showChatRecordDrawer, false)
|
||||
assert.equal(store.chatRecordQuery, null)
|
||||
})
|
||||
})
|
||||
@@ -88,6 +88,17 @@ export const useLayoutStore = defineStore(
|
||||
showSettings.value = false
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用锁显示前关闭会拦截鼠标和键盘焦点的全局浮层。
|
||||
*/
|
||||
function closeOverlaysForAppLock() {
|
||||
showSettings.value = false
|
||||
showScreenCaptureModal.value = false
|
||||
screenCaptureImage.value = null
|
||||
showChatRecordDrawer.value = false
|
||||
chatRecordQuery.value = null
|
||||
}
|
||||
|
||||
function toggleToolsPanelMini() {
|
||||
isToolsPanelMini.value = !isToolsPanelMini.value
|
||||
if (isToolsPanelMini.value) {
|
||||
@@ -118,6 +129,7 @@ export const useLayoutStore = defineStore(
|
||||
closeChatRecordDrawer,
|
||||
openSettings,
|
||||
closeSettings,
|
||||
closeOverlaysForAppLock,
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user