-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
linux: import clipboard after app ready
- Loading branch information
1 parent
84bd33a
commit 28902c9
Showing
3 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
interface Operation { | ||
key: string; | ||
args: any[]; | ||
} | ||
|
||
function delay( | ||
target: any, | ||
propertyKey: string, | ||
descriptor: PropertyDescriptor | ||
) { | ||
const newMethod = function(...args: any[]) { | ||
if (target["clipboard"] == undefined) { | ||
target["operations"].push({ | ||
key: propertyKey, | ||
args | ||
}); | ||
return; | ||
} else { | ||
const clipboard = target["clipboard"]; | ||
return clipboard[propertyKey].call(clipboard, ...args); | ||
} | ||
}; | ||
descriptor.value = newMethod; // 替换原声明 | ||
} | ||
|
||
class ClipboardWarpper { | ||
static clipboard: any = undefined; | ||
static operations: Array<Operation> = []; | ||
static init() { | ||
ClipboardWarpper.clipboard = require("electron-clipboard-extended"); | ||
ClipboardWarpper.operations.forEach(operation => { | ||
return ClipboardWarpper.clipboard[operation["key"]].call( | ||
ClipboardWarpper.clipboard, | ||
...operation["args"] | ||
); | ||
}); | ||
ClipboardWarpper.operations = []; | ||
} | ||
|
||
@delay | ||
static on(...args: any[]) {} | ||
|
||
@delay | ||
static writeText(text: string) {} | ||
|
||
@delay | ||
static readText(): any {} | ||
|
||
@delay | ||
static startWatching() {} | ||
|
||
@delay | ||
static stopWatching() {} | ||
|
||
@delay | ||
static readImage(): any {} | ||
} | ||
|
||
export const clipboard = ClipboardWarpper; |