diff --git a/components.d.ts b/components.d.ts index 5b44071..76a0740 100644 --- a/components.d.ts +++ b/components.d.ts @@ -30,16 +30,6 @@ declare module 'vue' { ElIcon: typeof import('element-plus/es')['ElIcon'] ElIconArrowDownBold: typeof import('@element-plus/icons-vue')['ArrowDownBold'] ElIconArrowUpBold: typeof import('@element-plus/icons-vue')['ArrowUpBold'] - ElIconCaretLeft: typeof import('@element-plus/icons-vue')['CaretLeft'] - ElIconCaretRight: typeof import('@element-plus/icons-vue')['CaretRight'] - ElIconClose: typeof import('@element-plus/icons-vue')['Close'] - ElIconCloseBold: typeof import('@element-plus/icons-vue')['CloseBold'] - ElIconEditPen: typeof import('@element-plus/icons-vue')['EditPen'] - ElIconLoading: typeof import('@element-plus/icons-vue')['Loading'] - ElIconOperation: typeof import('@element-plus/icons-vue')['Operation'] - ElIconQuestionFilled: typeof import('@element-plus/icons-vue')['QuestionFilled'] - ElIconSelect: typeof import('@element-plus/icons-vue')['Select'] - ElIconWarningFilled: typeof import('@element-plus/icons-vue')['WarningFilled'] ElInput: typeof import('element-plus/es')['ElInput'] ElLink: typeof import('element-plus/es')['ElLink'] ElOption: typeof import('element-plus/es')['ElOption'] @@ -69,7 +59,6 @@ declare module 'vue' { Remark: typeof import('./src/components/Device/components/Remark/index.vue')['default'] Rotation: typeof import('./src/components/Device/components/ControlBar/Rotation/index.vue')['default'] Screenshot: typeof import('./src/components/Device/components/ControlBar/Screenshot/index.vue')['default'] - Search: typeof import('./src/components/Search/index.vue')['default'] TerminalAction: typeof import('./src/components/Device/components/TerminalAction/index.vue')['default'] TerminalDialog: typeof import('./src/components/Device/components/TerminalAction/components/TerminalDialog/index.vue')['default'] VideoCodecSelect: typeof import('./src/components/Preference/components/VideoCodecSelect/index.vue')['default'] diff --git a/electron/events/handles/index.js b/electron/events/handles/index.js index a3e839f..b1832a6 100644 --- a/electron/events/handles/index.js +++ b/electron/events/handles/index.js @@ -1,11 +1,9 @@ import fs from 'fs-extra' import { dialog, ipcMain, shell } from 'electron' import themeHandles from './theme/index.js' -import searchHandles from './search/index.js' export default (mainWindow) => { themeHandles(mainWindow) - searchHandles(mainWindow) ipcMain.handle( 'show-open-dialog', diff --git a/electron/events/handles/search/index.js b/electron/events/handles/search/index.js deleted file mode 100644 index adbdbd5..0000000 --- a/electron/events/handles/search/index.js +++ /dev/null @@ -1,12 +0,0 @@ -import { ipcMain } from 'electron' - -export default (mainWindow) => { - ipcMain.handle('find-in-page', async (_, { text, ...args } = {}) => { - return mainWindow.webContents.findInPage(text, { - ...args, - }) - }) - ipcMain.handle('stop-find-in-page', async (_, action = 'clearSelection') => { - return mainWindow.webContents.stopFindInPage(action) - }) -} diff --git a/electron/events/index.js b/electron/events/index.js index 985a816..1429086 100644 --- a/electron/events/index.js +++ b/electron/events/index.js @@ -3,6 +3,7 @@ import { app, ipcMain } from 'electron' import updater from './updater/index.js' import handles from './handles/index.js' import tray from './tray/index.js' +// import search from './search/index.js' export default (mainWindow) => { ipcMain.on('restart-app', () => { @@ -10,7 +11,9 @@ export default (mainWindow) => { app.relaunch() app.quit() }) + handles(mainWindow) updater(mainWindow) tray(mainWindow) + // search(mainWindow) } diff --git a/electron/events/search/helper.js b/electron/events/search/helper.js new file mode 100644 index 0000000..973cb20 --- /dev/null +++ b/electron/events/search/helper.js @@ -0,0 +1,40 @@ +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) + } +} diff --git a/electron/events/search/index.js b/electron/events/search/index.js new file mode 100644 index 0000000..fd763b0 --- /dev/null +++ b/electron/events/search/index.js @@ -0,0 +1,29 @@ +import { globalShortcut, ipcMain } from 'electron' +import { FindInPageManager } from './helper.js' + +export default (mainWindow) => { + mainWindow.on('focus', () => { + globalShortcut.register('CommandOrControl+F', (event) => { + mainWindow.webContents.send('focus-on-search') + }) + }) + + mainWindow.on('blur', () => { + globalShortcut.unregister('CommandOrControl+F') + }) + + const findInPageManager = new FindInPageManager(mainWindow.webContents) + + ipcMain.handle('findInPageStart', async (event, args = {}) => { + return findInPageManager.start(args) + }) + ipcMain.handle('findInPageNext', async (event, args = {}) => { + return findInPageManager.next(args) + }) + ipcMain.handle('findInPagePrev', async (event, args = {}) => { + return findInPageManager.prev(args) + }) + ipcMain.handle('findInPageStop', async (event, args = {}) => { + return findInPageManager.stop(args) + }) +} diff --git a/eslint.config.js b/eslint.config.js index bbc6983..8be5071 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -45,6 +45,7 @@ export default antfu( 'no-restricted-syntax': 'off', 'no-new': 'off', 'prefer-promise-reject-errors': 'off', + 'no-unused-expressions': 'off', 'vue/html-self-closing': 'off', 'vue/block-order': 'off', diff --git a/package.json b/package.json index 29b99af..9f86c27 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,8 @@ "prepare": "husky install" }, "dependencies": { + "electron-find-in-page": "^1.0.8", + "electron-in-page-search": "^1.3.2", "vue": "^3.4.26" }, "devDependencies": { @@ -35,7 +37,7 @@ "@viarotel-org/unocss-preset-shades": "^0.8.2", "@vitejs/plugin-vue": "^5.0.4", "dayjs": "^1.11.11", - "electron": "^30.0.2", + "electron": "^30.0.3", "electron-builder": "^24.13.3", "electron-context-menu": "^4.0.0", "electron-log": "^5.1.2", diff --git a/src/App.vue b/src/App.vue index 9b13bf5..aeb43e8 100644 --- a/src/App.vue +++ b/src/App.vue @@ -3,9 +3,9 @@ + diff --git a/src/components/AppSearch/index.vue b/src/components/AppSearch/index.vue index 030c362..49ebc2c 100644 --- a/src/components/AppSearch/index.vue +++ b/src/components/AppSearch/index.vue @@ -1,31 +1,35 @@