aboutsummaryrefslogtreecommitdiff
path: root/src/background/infrastructures
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2021-09-26 11:54:11 +0900
committerGitHub <noreply@github.com>2021-09-26 11:54:11 +0900
commit9154972485c24a5a90782cef17f75b3a79a13774 (patch)
tree4bc3d608f498176f50a74ca7fc03d2d501ac7920 /src/background/infrastructures
parentcbf4b37bd0d5ba277d6400ed460d6a086ae1d7bb (diff)
parent91d4712e676782bb58fd7eb03fdc1f85111fca04 (diff)
Merge pull request #1264 from ueokande/fix-establish-connection-issue
Search a content from frames successfully loaded
Diffstat (limited to 'src/background/infrastructures')
-rw-r--r--src/background/infrastructures/FindPortListener.ts23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/background/infrastructures/FindPortListener.ts b/src/background/infrastructures/FindPortListener.ts
new file mode 100644
index 0000000..ca82439
--- /dev/null
+++ b/src/background/infrastructures/FindPortListener.ts
@@ -0,0 +1,23 @@
+import { injectable } from "tsyringe";
+
+type OnConnectFunc = (port: browser.runtime.Port) => void;
+type OnDisconnectFunc = (port: browser.runtime.Port) => void;
+
+@injectable()
+export default class FindPortListener {
+ constructor(
+ private readonly onConnect: OnConnectFunc,
+ private readonly onDisconnect: OnDisconnectFunc
+ ) {}
+
+ run(): void {
+ browser.runtime.onConnect.addListener((port) => {
+ if (port.name !== "vimvixen-find") {
+ return;
+ }
+
+ port.onDisconnect.addListener(this.onDisconnect);
+ this.onConnect(port);
+ });
+ }
+}