Skip to content

Commit ace2dda

Browse files
committed
(#47) Refactored clipboard provider
1 parent 047e07d commit ace2dda

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

Diff for: lib/provider/native/clipboard-action-provider.interface.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface ClipboardActionProvider {
2626
* @param {string} text The text to copy to the clipboard
2727
* @memberof ClipboardActionProvider
2828
*/
29-
copy(text: string): void;
29+
copy(text: string): Promise<void>;
3030

3131
/**
3232
* paste should allow to paste the current text on the system's clipboard

Diff for: lib/provider/native/clipboardy-clipboard-action.class.ts

+18-5
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,29 @@ export class ClipboardAction implements ClipboardActionProvider {
55
constructor() {
66
}
77

8-
public hasText(): Promise<boolean> {
9-
return Promise.resolve(clippy.readSync().length > 0);
8+
public async hasText(): Promise<boolean> {
9+
return new Promise<boolean>((resolve, reject) => {
10+
try {
11+
const content = clippy.readSync();
12+
resolve(content.length > 0);
13+
} catch (e) {
14+
reject(e);
15+
}
16+
});
1017
}
1118

1219
public clear(): Promise<boolean> {
13-
throw new Error("Method not implemented.");
20+
return Promise.reject("Method not implemented.");
1421
}
1522

16-
public copy(text: string): void {
17-
clippy.writeSync(text);
23+
public async copy(text: string): Promise<void> {
24+
return new Promise<void>((resolve, reject) => {
25+
try {
26+
clippy.writeSync(text);
27+
} catch (e) {
28+
reject(e);
29+
}
30+
});
1831
}
1932

2033
public async paste(): Promise<string> {

0 commit comments

Comments
 (0)