Skip to content

Commit 7cd81c1

Browse files
EdmondChuiHWhuntie
authored andcommitted
Add 'Reconnect DevTools' toolbar button
1 parent e087a5d commit 7cd81c1

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

front_end/entrypoints/rn_fusebox/rn_fusebox.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ const UIStrings = {
4848
*@description Label of the FB-only 'send feedback' action button in the toolbar
4949
*/
5050
sendFeedback: '[FB-only] Send feedback',
51+
/**
52+
*@description Tooltip of the connection status toolbar button while disconnected
53+
*/
54+
connectionStatusDisconnectedTooltip: 'Debugging connection was closed',
55+
/**
56+
*@description Button label of the connection status toolbar button while disconnected
57+
*/
58+
connectionStatusDisconnectedLabel: 'Reconnect DevTools',
5159
};
5260
const str_ = i18n.i18n.registerUIStrings('entrypoints/rn_fusebox/rn_fusebox.ts', UIStrings);
5361
const i18nLazyString = i18n.i18n.getLazilyComputedLocalizedString.bind(undefined, str_);
@@ -171,4 +179,47 @@ if (globalThis.FB_ONLY__reactNativeFeedbackLink) {
171179
});
172180
}
173181

182+
class ConnectionStatusToolbarItemProvider extends SDK.TargetManager.Observer implements UI.Toolbar.Provider {
183+
#button = new UI.Toolbar.ToolbarButton('');
184+
185+
constructor() {
186+
super();
187+
this.#button.setVisible(false);
188+
this.#button.element.classList.add('fusebox-connection-status');
189+
this.#button.addEventListener(UI.Toolbar.ToolbarButton.Events.Click, this.onClick.bind(this));
190+
191+
SDK.TargetManager.TargetManager.instance().observeTargets(this, {scoped: true});
192+
}
193+
194+
override targetAdded(_target: SDK.Target.Target): void {
195+
this.#updateRootTarget();
196+
}
197+
override targetRemoved(_target: SDK.Target.Target): void {
198+
this.#updateRootTarget();
199+
}
200+
201+
#updateRootTarget(): void {
202+
const rootTarget = SDK.TargetManager.TargetManager.instance().rootTarget();
203+
this.#button.setTitle(i18nLazyString(UIStrings.connectionStatusDisconnectedTooltip)());
204+
this.#button.setText(i18nLazyString(UIStrings.connectionStatusDisconnectedLabel)());
205+
this.#button.setVisible(!rootTarget);
206+
}
207+
208+
onClick(): void {
209+
window.location.reload();
210+
}
211+
212+
item(): UI.Toolbar.ToolbarItem {
213+
return this.#button;
214+
}
215+
}
216+
217+
const connectionStatusToolbarItemProvider = new ConnectionStatusToolbarItemProvider();
218+
UI.Toolbar.registerToolbarItem({
219+
location: UI.Toolbar.ToolbarItemLocation.MAIN_TOOLBAR_RIGHT,
220+
loadItem: async () => {
221+
return connectionStatusToolbarItemProvider;
222+
},
223+
});
224+
174225
Host.rnPerfMetrics.entryPointLoadingFinished('rn_fusebox');

front_end/ui/legacy/toolbar.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,3 +581,22 @@ devtools-icon.leading-issue-icon {
581581
[aria-label="[FB-only] Send feedback"] .toolbar-glyph {
582582
color: white !important;
583583
}
584+
585+
/* [RN] Customise styling for Fusebox's connection status button */
586+
587+
.fusebox-connection-status {
588+
margin: 4px;
589+
height: 20px;
590+
padding: 0 4px;
591+
border-radius: 4px;
592+
background: color-mix(in srgb, var(--color-red) 80%, transparent);
593+
}
594+
595+
.fusebox-connection-status:hover {
596+
background: color-mix(in srgb, var(--color-red) 90%, transparent);
597+
}
598+
599+
.fusebox-connection-status .toolbar-text,
600+
.fusebox-connection-status .toolbar-glyph {
601+
color: white !important;
602+
}

0 commit comments

Comments
 (0)