mirror of
https://github.com/viarotel-org/escrcpy.git
synced 2024-12-02 19:17:28 +01:00
76 lines
1.4 KiB
JavaScript
76 lines
1.4 KiB
JavaScript
import remote from '@electron/remote'
|
|
import { FindInPage } from 'electron-find-in-page'
|
|
import { primaryColor } from '$renderer/configs/index.js'
|
|
|
|
export default () => {
|
|
const theme = {
|
|
isDark: false,
|
|
}
|
|
|
|
let findInPage = null
|
|
|
|
async function open({ ...args } = {}) {
|
|
await create(args)
|
|
|
|
return findInPage.openFindWindow()
|
|
}
|
|
|
|
function close() {
|
|
remote.getCurrentWebContents().stopFindInPage('clearSelection')
|
|
|
|
if (!findInPage) {
|
|
return false
|
|
}
|
|
|
|
return findInPage.closeFindWindow()
|
|
}
|
|
|
|
async function update({ isDark = false, ...args } = {}) {
|
|
if (isDark === theme.isDark) {
|
|
return findInPage
|
|
}
|
|
|
|
try {
|
|
await findInPage.destroy()
|
|
}
|
|
catch (error) {
|
|
console.warn('error', error.message)
|
|
}
|
|
|
|
findInPage = null
|
|
|
|
return create({ ...args, isDark })
|
|
}
|
|
|
|
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',
|
|
boxBgColor: '#262626',
|
|
inputColor: '#CFD3DC',
|
|
inputBgColor: '#141414',
|
|
textColor: '#CFD3DC',
|
|
textHoverBgColor: '#4C4D4F',
|
|
}
|
|
: {}),
|
|
})
|
|
|
|
return findInPage
|
|
}
|
|
|
|
return {
|
|
open,
|
|
close,
|
|
}
|
|
}
|