Remove Profiles menu while Brave Origin startup dialog is swhown (#34699)

This commit is contained in:
Brian R. Bondy
2026-03-18 20:43:18 -04:00
committed by GitHub
parent f29428fc57
commit 1b75c1f19f
3 changed files with 69 additions and 0 deletions
+4
View File
@@ -8,11 +8,15 @@
#import <Cocoa/Cocoa.h>
#import "brave/components/brave_origin/buildflags/buildflags.h"
#import "chrome/browser/app_controller_mac.h"
// * Manages logic to switch hotkey between copy and copy clean link item.
// * Add "New Private Window with Tor" to the dock menu.
@interface BraveAppController : AppController
#if BUILDFLAG(IS_BRAVE_ORIGIN_BRANDED)
- (void)restoreProfileMenu;
#endif
@end
#endif // BRAVE_BROWSER_BRAVE_APP_CONTROLLER_MAC_H_
+51
View File
@@ -87,6 +87,11 @@ class TorPrefObserver : public BooleanPrefMember {
NSMenuItem* _copyMenuItem;
NSMenuItem* _copyCleanLinkMenuItem;
#if BUILDFLAG(IS_BRAVE_ORIGIN_BRANDED)
NSMenuItem* _profileMenuItem; // Stashed while startup dialog is showing
NSInteger _profileMenuIndex; // Original position in the menu bar
#endif
#if BUILDFLAG(ENABLE_TOR)
NSMenuItem* _torMenuItem; // For dock menu
NSMenuItem* _torMainMenuItem; // For main menu
@@ -96,6 +101,14 @@ class TorPrefObserver : public BooleanPrefMember {
}
@end
#if BUILDFLAG(IS_BRAVE_ORIGIN_BRANDED)
void BraveRestoreProfileMenu() {
auto* controller =
static_cast<BraveAppController*>(AppController.sharedController);
[controller restoreProfileMenu];
}
#endif
@implementation BraveAppController
#if BUILDFLAG(IS_BRAVE_ORIGIN_BRANDED)
@@ -132,11 +145,41 @@ class TorPrefObserver : public BooleanPrefMember {
return [super applicationShouldHandleReopen:theApplication
hasVisibleWindows:hasVisibleWindows];
}
- (void)application:(NSApplication*)sender openURLs:(NSArray<NSURL*>*)urls {
if (BraveOriginStartupView::IsShowing()) {
return;
}
[super application:sender openURLs:urls];
}
- (void)restoreProfileMenu {
if (_profileMenuItem) {
[[NSApp mainMenu] insertItem:_profileMenuItem atIndex:_profileMenuIndex];
_profileMenuItem = nil;
}
}
#endif // BUILDFLAG(IS_BRAVE_ORIGIN_BRANDED)
- (void)mainMenuCreated {
[super mainMenuCreated];
#if BUILDFLAG(IS_BRAVE_ORIGIN_BRANDED)
// Stash and remove the Profiles top-level menu. Profile switching, "Manage",
// and "Add Profile" all open browser windows that bypass the startup dialog.
// restoreProfileMenu re-inserts it. It is called from the startup completion
// callback, or immediately if no dialog is needed.
{
NSMenu* mainMenu = [NSApp mainMenu];
NSMenuItem* profileMenu = [mainMenu itemWithTag:IDC_PROFILE_MAIN_MENU];
if (profileMenu) {
_profileMenuIndex = [mainMenu indexOfItem:profileMenu];
_profileMenuItem = profileMenu;
[mainMenu removeItem:profileMenu];
}
}
#endif // BUILDFLAG(IS_BRAVE_ORIGIN_BRANDED)
NSMenu* editMenu = [[[NSApp mainMenu] itemWithTag:IDC_EDIT_MENU] submenu];
_copyMenuItem = [editMenu itemWithTag:IDC_CONTENT_CONTEXT_COPY];
DCHECK(_copyMenuItem);
@@ -302,6 +345,14 @@ class TorPrefObserver : public BooleanPrefMember {
}
- (NSMenu*)applicationDockMenu:(NSApplication*)sender {
#if BUILDFLAG(IS_BRAVE_ORIGIN_BRANDED)
if (BraveOriginStartupView::IsShowing()) {
// Return an empty dock menu while the startup dialog is showing.
// The system always adds "Quit" automatically.
return [[NSMenu alloc] initWithTitle:@""];
}
#endif // BUILDFLAG(IS_BRAVE_ORIGIN_BRANDED)
auto* menu = [super applicationDockMenu:sender];
#if BUILDFLAG(ENABLE_TOR)
@@ -23,6 +23,11 @@
#include "chrome/browser/platform_util.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "components/prefs/pref_service.h"
#if BUILDFLAG(IS_MAC)
// Defined in brave_app_controller_mac.mm. We can't include the ObjC header
// from a .cc file, so declare the free function directly.
void BraveRestoreProfileMenu();
#endif
#endif
#ifdef LaunchModeRecorder
@@ -154,6 +159,11 @@ bool StartupBrowserCreator::Start(const base::CommandLine& cmd_line,
const base::CommandLine& cmd_line, const base::FilePath& cur_dir,
StartupProfileInfo profile_info,
const Profiles& last_opened_profiles) {
#if BUILDFLAG(IS_MAC)
// Re-insert the Profiles menu that was stashed while the
// startup dialog was showing.
BraveRestoreProfileMenu();
#endif
StartupBrowserCreator browser_creator;
browser_creator.AddFirstRunTabs(first_run_tabs);
browser_creator.Start_ChromiumImpl(cmd_line, cur_dir,
@@ -165,6 +175,10 @@ bool StartupBrowserCreator::Start(const base::CommandLine& cmd_line,
std::make_unique<StartupDialogDelegate>());
return true;
}
#if BUILDFLAG(IS_MAC)
// No dialog needed, restore the Profiles menu immediately.
BraveRestoreProfileMenu();
#endif
#endif // BUILDFLAG(IS_BRAVE_ORIGIN_BRANDED)
return Start_ChromiumImpl(cmd_line, cur_dir, std::move(profile_info),
last_opened_profiles);