Skip to content

Commit

Permalink
Add copy action
Browse files Browse the repository at this point in the history
  • Loading branch information
qianlifeng committed Feb 24, 2024
1 parent e615e75 commit 85b094b
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 20 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.1",
"scripts": {
"build": "pnpm clean && ncc build src/index.ts -o dist && babel dist --out-dir dist && cp -r images dist && cp -r plugin.json dist",
"package": "pnpm build && cd dist && zip -r ../wox.plugin.deepl.wox *.js *.json images",
"package": "pnpm build && cd dist && zip -r ../Wox.Plugin.DeepL.wox *.js *.json images",
"dev": "nodemon --watch src --watch images --watch plugin.json --ext json,ts,js,mjs,png --exec pnpm run build",
"clean": "node -e \"var { rmdirSync, existsSync } = require('fs'), path = require('path'); ['./dist'].forEach(fPath => {if (existsSync(path.join(__dirname, fPath))) rmdirSync(path.join(__dirname, fPath), { recursive: true })}); process.exit(0);\"",
"clean:all": "pnpm run clean && (rm -r ./node_modules || true)",
Expand All @@ -25,6 +25,7 @@
},
"dependencies": {
"@wox-launcher/wox-plugin": "^0.0.57",
"deepl-node": "^1.11.1"
"deepl-node": "^1.11.1",
"clipboardy": "^4.0.0"
}
}
4 changes: 2 additions & 2 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"Id": "09ea2847-929c-440a-aa2c-9b74bcaae69f",
"TriggerKeywords": [
"deep"
"deepl"
],
"Name": "DeepL translator",
"Description": "DeepL translation plugin for Wox",
"Author": "Wox-launcher",
"Version": "0.0.1",
"Version": "0.0.2",
"MinWoxVersion": "2.0.0",
"Runtime": "Nodejs",
"Website": "https://github.com/Wox-launcher/Wox.Plugin.DeepL",
Expand Down
126 changes: 113 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Plugin, PluginInitContext, PublicAPI, Query, Result } from "@wox-launcher/wox-plugin"
import { Plugin, PluginInitContext, PublicAPI, Query, RefreshableResult, Result } from "@wox-launcher/wox-plugin"
import * as deepl from "deepl-node"
import clipboard from "clipboardy"

let api: PublicAPI
let translator: deepl.Translator
Expand Down Expand Up @@ -52,7 +53,7 @@ export const plugin: Plugin = {
targetLang = "en-US"
}

const result = await translator.translateText(query.Search, null, <deepl.TargetLanguageCode>targetLang)
let translateResult = ""

return [
{
Expand All @@ -63,13 +64,22 @@ export const plugin: Plugin = {
},
Preview: {
PreviewType: "text",
PreviewData: result.text,
PreviewData: "Translating...",
PreviewProperties: {}
},
RefreshInterval: 200,
OnRefresh: async (result: RefreshableResult) => {
const newResult = await translator.translateText(query.Search, null, <deepl.TargetLanguageCode>targetLang)
translateResult = newResult.text
result.Preview.PreviewData = translateResult
result.RefreshInterval = 0 // stop refreshing
return result
},
Actions: [
{
Name: "Copy",
Action: async () => {
await clipboard.write(translateResult)
}
}
]
Expand Down

0 comments on commit 85b094b

Please sign in to comment.