Skip to content

Commit a899edf

Browse files
committed
UI/AppKit: Add a Launch Client button to the DevTools banner
Extend the shared info bar with an action button that launches the application-owned Firefox client. Report discovery or startup errors through the existing error dialog.
1 parent 102c048 commit a899edf

3 files changed

Lines changed: 34 additions & 9 deletions

File tree

UI/AppKit/Application/ApplicationDelegate.mm

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,16 @@ - (void)onDevtoolsEnabled
181181
auto message = MUST(String::formatted("DevTools is enabled on port {}", WebView::Application::browser_options().devtools_port));
182182

183183
[self.info_bar showWithMessage:Ladybird::string_to_ns_string(message)
184-
dismissButtonTitle:@"Disable"
185-
dismissButtonClicked:^{
186-
MUST(WebView::Application::the().toggle_devtools_enabled());
187-
}
188-
activeTab:self.active_tab];
184+
actionButtonTitle:@"Launch Client"
185+
actionButtonClicked:^{
186+
if (auto result = WebView::Application::the().launch_devtools_client(); result.is_error())
187+
WebView::Application::the().display_error_dialog(MUST(String::formatted("Unable to launch the DevTools client: {}", result.error())));
188+
}
189+
dismissButtonTitle:@"Disable"
190+
dismissButtonClicked:^{
191+
MUST(WebView::Application::the().toggle_devtools_enabled());
192+
}
193+
activeTab:self.active_tab];
189194
}
190195

191196
- (void)onDevtoolsDisabled

UI/AppKit/Interface/InfoBar.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010

1111
@class Tab;
1212

13-
using InfoBarDismissed = void (^)(void);
13+
using InfoBarButtonClicked = void (^)(void);
1414

1515
@interface InfoBar : NSStackView
1616

1717
- (void)showWithMessage:(NSString*)message
18+
actionButtonTitle:(NSString*)action_title
19+
actionButtonClicked:(InfoBarButtonClicked)on_action
1820
dismissButtonTitle:(NSString*)title
19-
dismissButtonClicked:(InfoBarDismissed)on_dismissed
21+
dismissButtonClicked:(InfoBarButtonClicked)on_dismissed
2022
activeTab:(Tab*)tab;
2123
- (void)hide;
2224

UI/AppKit/Interface/InfoBar.mm

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
@interface InfoBar ()
1717

1818
@property (nonatomic, strong) NSTextField* text_label;
19+
@property (nonatomic, strong) NSButton* action_button;
1920
@property (nonatomic, strong) NSButton* dismiss_button;
20-
@property (nonatomic, copy) InfoBarDismissed on_dismissed;
21+
@property (nonatomic, copy) InfoBarButtonClicked on_action;
22+
@property (nonatomic, copy) InfoBarButtonClicked on_dismissed;
2123

2224
@end
2325

@@ -28,12 +30,18 @@ - (instancetype)init
2830
if (self = [super init]) {
2931
self.text_label = [NSTextField labelWithString:@""];
3032

33+
self.action_button = [NSButton buttonWithTitle:@""
34+
target:self
35+
action:@selector(performAction:)];
36+
[self.action_button setBezelStyle:NSBezelStyleAccessoryBarAction];
37+
3138
self.dismiss_button = [NSButton buttonWithTitle:@""
3239
target:self
3340
action:@selector(dismiss:)];
3441
[self.dismiss_button setBezelStyle:NSBezelStyleAccessoryBarAction];
3542

3643
[self addView:self.text_label inGravity:NSStackViewGravityLeading];
44+
[self addView:self.action_button inGravity:NSStackViewGravityTrailing];
3745
[self addView:self.dismiss_button inGravity:NSStackViewGravityTrailing];
3846

3947
[self setOrientation:NSUserInterfaceLayoutOrientationHorizontal];
@@ -46,12 +54,16 @@ - (instancetype)init
4654
}
4755

4856
- (void)showWithMessage:(NSString*)message
57+
actionButtonTitle:(NSString*)action_title
58+
actionButtonClicked:(InfoBarButtonClicked)on_action
4959
dismissButtonTitle:(NSString*)title
50-
dismissButtonClicked:(InfoBarDismissed)on_dismissed
60+
dismissButtonClicked:(InfoBarButtonClicked)on_dismissed
5161
activeTab:(Tab*)tab
5262
{
5363
[self.text_label setStringValue:message];
5464

65+
self.action_button.title = action_title;
66+
self.on_action = on_action;
5567
self.dismiss_button.title = title;
5668
self.on_dismissed = on_dismissed;
5769

@@ -62,6 +74,12 @@ - (void)showWithMessage:(NSString*)message
6274
[self setHidden:NO];
6375
}
6476

77+
- (void)performAction:(id)sender
78+
{
79+
if (self.on_action)
80+
self.on_action();
81+
}
82+
6583
- (void)dismiss:(id)sender
6684
{
6785
if (self.on_dismissed) {

0 commit comments

Comments
 (0)