| 59 | }; |
| 60 | |
| 61 | class TranslateController { |
| 62 | translateResult: SharedResult | undefined; |
| 63 | dictResult: SharedDictResult = emptyDictResult(); |
| 64 | |
| 65 | text: string = ""; |
| 66 | lastAppend: string = ""; |
| 67 | |
| 68 | language: { source: Language; target: Language } = { |
| 69 | source: "auto", |
| 70 | target: "auto", |
| 71 | }; |
| 72 | |
| 73 | needDict: boolean = false; |
| 74 | |
| 75 | translating: boolean = false; //正在翻译 |
| 76 | nextEngines?: (TranslatorType | string)[]; |
| 77 | |
| 78 | incrementCounter: number = 0; //增量复制计数器 |
| 79 | |
| 80 | translator: Compound = new Compound([...translatorTypes], "google", {}); |
| 81 | dictionary: Polymer = new Polymer("youdao"); |
| 82 | |
| 83 | controller: MainController; |
| 84 | |
| 85 | get resultString() { |
| 86 | if (this.translateResult) { |
| 87 | return this.translateResult.translation; |
| 88 | } else { |
| 89 | return ""; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | constructor(controller: MainController) { |
| 94 | this.controller = controller; |
| 95 | } |
| 96 | |
| 97 | async onExit() { |
| 98 | pp_recognizer.onExit(); |
| 99 | return this.translator.onExit(); |
| 100 | } |
| 101 | |
| 102 | async init() { |
| 103 | return Promise.allSettled([ |
| 104 | this.translator.initialize(), |
| 105 | new Promise<void>((resolve) => { |
| 106 | // Defer clipboard initialization to unblock main thread |
| 107 | setTimeout(() => { |
| 108 | clipboard.init(); |
| 109 | resolve(); |
| 110 | }, 0); |
| 111 | }), |
| 112 | ]).then(() => { |
| 113 | this.syncSupportLanguages(); |
| 114 | }); |
| 115 | } |
| 116 | |
| 117 | getResultBuffer(engine: TranslatorType | "all") { |
| 118 | if (engine == "all") { |
nothing calls this directly
no test coverage detected