Skip to content

Commit

Permalink
linux: import clipboard after app ready
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottzheng committed Apr 4, 2020
1 parent f68fa22 commit cb8378f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core/actionCallback.ts
Expand Up @@ -6,7 +6,7 @@ import { decompose } from "../tools/action";
import { showSettings } from "../tools/views";
import { Identifier, NormalActionType, RouteActionType } from "../tools/types";

const clipboard = require("electron-clipboard-extended");
import { clipboard } from "../tools/clipboard";

function handleActions(
id: string,
Expand Down
3 changes: 2 additions & 1 deletion src/core/controller.ts
Expand Up @@ -25,7 +25,7 @@ import {
DictFail
} from "../tools/dictionary/types";
import { showDragCopyWarning } from "../tools/views/dialog";
const clipboard = require("electron-clipboard-extended");
import { clipboard } from "../tools/clipboard";

class Controller {
src: string = "";
Expand Down Expand Up @@ -55,6 +55,7 @@ class Controller {
}

createWindow() {
clipboard.init();
this.tray.init();
this.win.createWindow(this.get("frameMode"));
windowController.bind();
Expand Down
59 changes: 59 additions & 0 deletions src/tools/clipboard.ts
@@ -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;

0 comments on commit cb8378f

Please sign in to comment.