Skip to content

Commit

Permalink
Added to dock when Brave is set as a default browser
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhong committed Aug 23, 2022
1 parent 099ae8e commit fb49a9e
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 19 deletions.
15 changes: 15 additions & 0 deletions browser/brave_shell_integration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,23 @@
#include "chrome/installer/util/shell_util.h"
#endif

#if BUILDFLAG(IS_MAC)
#include "brave/browser/brave_shell_integration_mac.h"
#endif

namespace shell_integration {

void PinShortcut(Profile* profile) {
#if BUILDFLAG(IS_WIN)
win::PinToTaskbar(profile);
#elif BUILDFLAG(IS_MAC)
// Mac doesn't support profile specific icon in dock.
mac::AddIconToDock();
#elif BUILDFLAG(IS_LINUX)
// Not supported on linux yet.
#endif
}

BraveDefaultBrowserWorker::BraveDefaultBrowserWorker() = default;
BraveDefaultBrowserWorker::~BraveDefaultBrowserWorker() = default;

Expand Down
4 changes: 4 additions & 0 deletions browser/brave_shell_integration.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@

#include "chrome/browser/shell_integration.h"

class Profile;

namespace shell_integration {

void PinShortcut(Profile* profile = nullptr);

class BraveDefaultBrowserWorker : public DefaultBrowserWorker {
public:
BraveDefaultBrowserWorker();
Expand Down
16 changes: 16 additions & 0 deletions browser/brave_shell_integration_mac.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* Copyright (c) 2022 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_BROWSER_BRAVE_SHELL_INTEGRATION_MAC_H_
#define BRAVE_BROWSER_BRAVE_SHELL_INTEGRATION_MAC_H_

namespace shell_integration::mac {

// No-op if already added.
void AddIconToDock();

} // namespace shell_integration::mac

#endif // BRAVE_BROWSER_BRAVE_SHELL_INTEGRATION_MAC_H_
18 changes: 18 additions & 0 deletions browser/brave_shell_integration_mac.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* Copyright (c) 2022 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/brave_shell_integration_mac.h"

#include "base/mac/bundle_locations.h"
#include "chrome/browser/mac/dock.h"

namespace shell_integration::mac {

void AddIconToDock() {
if (dock::ChromeIsInTheDock() == dock::ChromeInDockFalse)
dock::AddIcon([base::mac::MainBundle() bundlePath], nullptr);
}

} // namespace shell_integration::mac
6 changes: 4 additions & 2 deletions browser/sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ brave_chrome_browser_sources = [
"//brave/browser/brave_local_state_prefs.h",
"//brave/browser/brave_profile_prefs.cc",
"//brave/browser/brave_profile_prefs.h",
"//brave/browser/brave_shell_integration.cc",
"//brave/browser/brave_shell_integration.h",
"//brave/browser/brave_tab_helpers.cc",
"//brave/browser/brave_tab_helpers.h",
"//brave/browser/browser_context_keyed_service_factories.cc",
Expand Down Expand Up @@ -217,6 +215,8 @@ if (is_mac) {
brave_chrome_browser_sources += [
"//brave/browser/brave_browser_main_parts_mac.h",
"//brave/browser/brave_browser_main_parts_mac.mm",
"//brave/browser/brave_shell_integration_mac.h",
"//brave/browser/brave_shell_integration_mac.mm",
]
}

Expand Down Expand Up @@ -254,6 +254,8 @@ if (is_android) {
]
} else {
brave_chrome_browser_sources += [
"//brave/browser/brave_shell_integration.cc",
"//brave/browser/brave_shell_integration.h",
"//brave/browser/p3a/p3a_core_metrics.cc",
"//brave/browser/p3a/p3a_core_metrics.h",
"//brave/browser/profile_resetter/brave_profile_resetter.cc",
Expand Down
10 changes: 1 addition & 9 deletions browser/ui/views/brave_default_browser_dialog_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/layout_provider.h"

#if BUILDFLAG(IS_WIN)
#include "brave/browser/brave_shell_integration_win.h"
#endif

namespace brave {

void ShowDefaultBrowserDialog(Browser* browser) {
Expand Down Expand Up @@ -167,15 +163,11 @@ void BraveDefaultBrowserDialogView::OnAcceptButtonClicked() {
// message loops of the FILE and UI thread will hold references to it
// and it will be automatically freed once all its tasks have finished.
base::MakeRefCounted<shell_integration::BraveDefaultBrowserWorker>()
#if BUILDFLAG(IS_WIN)
->StartSetAsDefault(
base::BindOnce([](shell_integration::DefaultWebClientState state) {
if (state == shell_integration::DefaultWebClientState::IS_DEFAULT) {
// Try to pin to taskbar when Brave is set as a default browser.
shell_integration::win::PinToTaskbar();
shell_integration::PinShortcut();
}
}));
#else
->StartSetAsDefault(base::NullCallback());
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@

#include "brave/browser/ui/webui/settings/brave_settings_default_browser_handler.h"

#include "build/build_config.h"

#if BUILDFLAG(IS_WIN)
#include "brave/browser/brave_shell_integration_win.h"
#endif
#include "brave/browser/brave_shell_integration.h"

namespace settings {

Expand All @@ -19,10 +15,8 @@ void BraveDefaultBrowserHandler::SetAsDefaultBrowser(
const base::Value::List& args) {
DefaultBrowserHandler::SetAsDefaultBrowser(args);

#if BUILDFLAG(IS_WIN)
// Trying to pin when user ask this as a default browser.
shell_integration::win::PinToTaskbar(Profile::FromWebUI(web_ui()));
#endif
shell_integration::PinShortcut(Profile::FromWebUI(web_ui()));
}

} // namespace settings
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/i18n/rtl.h"
#include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h"
#include "brave/browser/brave_shell_integration.h"
#include "brave/browser/metrics/metrics_reporting_util.h"
#include "brave/components/l10n/common/locale_util.h"
#include "brave/grit/brave_generated_resources.h"
Expand Down Expand Up @@ -170,6 +171,8 @@ - (BOOL)isMakeDefaultBrowserEnabled {
}

- (void)ok:(id)sender {
shell_integration::PinShortcut();

_setAsDefaultBrowser = YES;
[[[self view] window] close];
[NSApp stopModal];
Expand Down

0 comments on commit fb49a9e

Please sign in to comment.