Skip to content

Commit a529425

Browse files
committed
Send detection state to each bg script connection
1 parent f09e900 commit a529425

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

extension/src/content.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
port_on_message, port_post_message_obj, port_post_message,
1515
window_post_message_obj, window_on_message, window_post_message,
1616
place_error, place_log,
17-
type Message, type Versions,
17+
type Message, type Versions, type DetectionState,
1818
} from './shared.ts'
1919

2020
// @ts-expect-error ?script&module query ensures output in ES module format and only import the script path
@@ -68,6 +68,7 @@ let versions: Versions = {
6868
extension: chrome.runtime.getManifest().version,
6969
client_expected: import.meta.env.EXPECTED_CLIENT,
7070
}
71+
let detection: DetectionState | null = null
7172

7273
let connecting = false
7374
function connect_port() {
@@ -81,6 +82,11 @@ function connect_port() {
8182
bg_port = new_port
8283
DEV: {place_log(Place_Name.Content, 'Port connected successfully')}
8384

85+
// Post detection state to each background port
86+
if (detection) {
87+
port_post_message(new_port, 'Detected', detection)
88+
}
89+
8490
// Post versions to each background port
8591
port_post_message(new_port, 'Versions', versions)
8692

@@ -142,6 +148,20 @@ window_on_message(e => {
142148

143149
break
144150
}
151+
// From Detector_Real_World
152+
case 'Detected': {
153+
DEV: {place_log(Place_Name.Content, 'Detected', e.data)}
154+
155+
detection = e.data
156+
157+
if (bg_port) {
158+
port_post_message_obj(bg_port, e)
159+
} else {
160+
connect_port()
161+
}
162+
163+
break
164+
}
145165
default:
146166
/* Client -> Background */
147167
if (bg_port) {

0 commit comments

Comments
 (0)