Skip to content

Commit

Permalink
Revert "chore: remove nutjs (#2860)"
Browse files Browse the repository at this point in the history
This reverts commit ce2d8e5.
  • Loading branch information
Van-QA authored May 14, 2024
1 parent 08d15e5 commit 5c56ede
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
3 changes: 2 additions & 1 deletion electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@
"pacote": "^17.0.4",
"request": "^2.88.2",
"request-progress": "^3.0.0",
"ulidx": "^2.3.0"
"ulidx": "^2.3.0",
"@nut-tree/nut-js": "^4.0.0"
},
"devDependencies": {
"@electron/notarize": "^2.1.0",
Expand Down
27 changes: 13 additions & 14 deletions electron/utils/selectedText.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import { clipboard, globalShortcut } from 'electron'
import { keyboard, Key } from '@nut-tree/nut-js'

/**
* Gets selected text by synthesizing the keyboard shortcut
* "CommandOrControl+c" then reading text from the clipboard
*/
export const getSelectedText = async () => {
// TODO: Implement this function
// const currentClipboardContent = clipboard.readText() // preserve clipboard content
// clipboard.clear()
// const hotkeys: Key[] = [
// process.platform === 'darwin' ? Key.LeftCmd : Key.LeftControl,
// Key.C,
// ]
// await keyboard.pressKey(...hotkeys)
// await keyboard.releaseKey(...hotkeys)
// await new Promise((resolve) => setTimeout(resolve, 200)) // add a delay before checking clipboard
// const selectedText = clipboard.readText()
// clipboard.writeText(currentClipboardContent)
// return selectedText
return ''
const currentClipboardContent = clipboard.readText() // preserve clipboard content
clipboard.clear()
const hotkeys: Key[] = [
process.platform === 'darwin' ? Key.LeftCmd : Key.LeftControl,
Key.C,
]
await keyboard.pressKey(...hotkeys)
await keyboard.releaseKey(...hotkeys)
await new Promise((resolve) => setTimeout(resolve, 200)) // add a delay before checking clipboard
const selectedText = clipboard.readText()
clipboard.writeText(currentClipboardContent)
return selectedText
}

/**
Expand Down

0 comments on commit 5c56ede

Please sign in to comment.