escrcpy/electron/exposes/search/index.js

76 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-09-07 19:55:54 +02:00
import { primaryColor } from '$renderer/configs/index.js'
import remote from '@electron/remote'
import { FindInPage } from 'electron-find-in-page'
export default () => {
const theme = {
isDark: false,
}
2024-05-15 05:16:02 +02:00
let findInPage = null
2024-05-15 05:16:02 +02:00
async function open({ ...args } = {}) {
await create(args)
return findInPage.openFindWindow()
}
function close() {
2024-05-15 05:56:56 +02:00
remote.getCurrentWebContents().stopFindInPage('clearSelection')
2024-05-15 05:16:02 +02:00
if (!findInPage) {
return false
}
2024-05-15 05:56:56 +02:00
return findInPage.closeFindWindow()
}
2024-05-15 05:16:02 +02:00
async function update({ isDark = false, ...args } = {}) {
if (isDark === theme.isDark) {
return findInPage
}
try {
await findInPage.destroy()
}
catch (error) {
console.warn('error', error.message)
}
2024-05-15 05:16:02 +02:00
findInPage = null
return create({ ...args, isDark })
}
2024-05-15 05:16:02 +02:00
async function create({ ...args } = {}) {
if (findInPage) {
return update(args)
}
theme.isDark = args.isDark
findInPage = new FindInPage(remote.getCurrentWebContents(), {
...args,
preload: true,
inputFocusColor: primaryColor,
...(theme.isDark
? {
boxShadowColor: '#4C4D4F',
2024-05-15 08:03:06 +02:00
boxBgColor: '#262626',
inputColor: '#CFD3DC',
inputBgColor: '#141414',
textColor: '#CFD3DC',
textHoverBgColor: '#4C4D4F',
}
: {}),
})
2024-05-15 05:16:02 +02:00
return findInPage
}
return {
open,
close,
}
}