diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2021-09-23 23:23:55 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2021-09-25 15:53:36 +0900 |
commit | b72728bdabf140c77f165b35813595dcaa060eea (patch) | |
tree | 774dc608f28101ac4a0ecce02e458e421b94dcdc /src/background/infrastructures | |
parent | 01242a2f0d174b4bf8b51fd5627edced465757e9 (diff) |
Create find targets by port connections
Diffstat (limited to 'src/background/infrastructures')
-rw-r--r-- | src/background/infrastructures/FindPortListener.ts | 23 |
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); + }); + } +} |