escrcpy/electron/exposes/search/helper.js
2024-05-14 19:16:46 +08:00

41 lines
873 B
JavaScript

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)
}
}