Skip to content

Commit

Permalink
Fixed restore clipboard content Closed #6
Browse files Browse the repository at this point in the history
  • Loading branch information
mantou132 committed Dec 12, 2020
1 parent a604509 commit 8cbfa31
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/main/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,21 @@ export async function delay(time: number) {
}

export async function getSelectionText() {
const oldString = clipboard.readText();
clipboard.writeText('');
function restoreContent() {
const oldString = clipboard.readHTML();
const oldImage = clipboard.readImage();
clipboard.writeHTML('');
if (!oldImage.isEmpty()) {
return () => clipboard.writeImage(oldImage);
}
if (oldString) {
return () => clipboard.writeHTML(oldString);
}
return () => {
//
};
}
const restore = restoreContent();
// window 平台下,ctrl+q 调用此函数时如果 ctrl 弹起的早则会输入 'c'
if (config.platform === 'win32') {
await delay(200);
Expand All @@ -20,6 +33,6 @@ export async function getSelectionText() {
await delay(300);
}
const newString = clipboard.readText();
clipboard.writeText(oldString);
restore();
return newString;
}

0 comments on commit 8cbfa31

Please sign in to comment.