escrcpy/electron/exposes/search/helper.js

41 lines
873 B
JavaScript
Raw Normal View History

2024-05-13 16:49:39 +02:00
export class FindInPageManager {
constructor(webContents) {
this.webContents = webContents
this.text = ''
}
update({ webContents } = {}) {
this.webContents = webContents
}
async start({ text, args = {} } = {}) {
this.text = text
this.webContents.on('found-in-page', (event, result) => {
console.log('found-in-page.result', result)
})
return this.webContents.findInPage(this.text, { findNext: false, ...args })
}
async next({ ...args } = {}) {
return this.webContents.findInPage(this.text, {
forward: true,
findNext: true,
...args,
})
}
async prev({ ...args } = {}) {
return this.webContents.findInPage(this.text, {
forward: false,
findNext: true,
...args,
})
}
async stop(action = 'clearSelection') {
return this.webContents.stopFindInPage(action)
}
}