diff --git a/app/common/state/defaultBrowserState.js b/app/common/state/defaultBrowserState.js new file mode 100644 index 00000000000..9e2c833e4c8 --- /dev/null +++ b/app/common/state/defaultBrowserState.js @@ -0,0 +1,12 @@ +/* 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/. */ + +const getSetting = require('../../../js/settings').getSetting +const settings = require('../../../js/constants/settings') + +module.exports.shouldDisplayDialog = (state) => { + return !getSetting(settings.IS_DEFAULT_BROWSER) && + !state.get('defaultBrowserCheckComplete') && + getSetting(settings.CHECK_DEFAULT_ON_STARTUP) +} diff --git a/app/extensions/brave/locales/en-US/app.properties b/app/extensions/brave/locales/en-US/app.properties index ea1ee92fa10..0ae1f3105f2 100644 --- a/app/extensions/brave/locales/en-US/app.properties +++ b/app/extensions/brave/locales/en-US/app.properties @@ -223,3 +223,7 @@ cookies=Cookies licenseTextOk=Ok closeFirefoxWarningOk=Ok importSuccessOk=Ok +makeBraveDefault=Ready to make Brave your default Browser? +checkDefaultOnStartup=Always check on startup +useBrave=Use Brave +notNow=Not Now diff --git a/app/extensions/brave/locales/en-US/preferences.properties b/app/extensions/brave/locales/en-US/preferences.properties index 6bca8a185a8..8ee99a137ac 100644 --- a/app/extensions/brave/locales/en-US/preferences.properties +++ b/app/extensions/brave/locales/en-US/preferences.properties @@ -249,3 +249,7 @@ sendUsageStatistics=Automatically send usage statistics to Brave bookmarksBarTextOnly=Text only bookmarksBarTextAndFavicon=Text and Favicons bookmarksBarFaviconOnly=Favicons only +defaultBrowser=Brave is your default browser. +notDefaultBrowser=Brave is not your default browser. +setAsDefault=Set as default… +checkDefaultOnStartup=Always check on startup diff --git a/app/index.js b/app/index.js index 4f155a19ad1..40df0bb43ca 100644 --- a/app/index.js +++ b/app/index.js @@ -58,7 +58,6 @@ const downloadActions = require('../js/actions/downloadActions') const SessionStore = require('./sessionStore') const AppStore = require('../js/stores/appStore') const PackageLoader = require('./package-loader') -const Autofill = require('./autofill') const Extensions = require('./extensions') const Filtering = require('./filtering') const TrackingProtection = require('./trackingProtection') @@ -82,6 +81,7 @@ const privacy = require('../js/state/privacy') const basicAuth = require('./browser/basicAuth') const async = require('async') const tabs = require('./browser/tabs') +const settings = require('../js/constants/settings') // temporary fix for #4517, #4518 and #4472 app.commandLine.appendSwitch('enable-use-zoom-for-dsf', 'false') @@ -107,6 +107,8 @@ const prefsRestartLastValue = {} const unsafeTestMasterKey = 'c66af15fc6555ebecf7cee3a5b82c108fd3cb4b587ab0b299d28e39c79ecc708' +const defaultProtocols = ['http', 'https'] + const sessionStoreQueue = async.queue((task, callback) => { task(callback) }, 1) @@ -421,7 +423,6 @@ app.on('ready', () => { basicAuth.init() contentSettings.init() privacy.init() - Autofill.init() Extensions.init() Filtering.init() SiteHacks.init() @@ -442,6 +443,10 @@ app.on('ready', () => { } process.emit(messages.APP_INITIALIZED) + // Default browser checking + let isDefaultBrowser = defaultProtocols.every(p => app.isDefaultProtocolClient(p)) + appActions.changeSetting(settings.IS_DEFAULT_BROWSER, isDefaultBrowser) + if (CmdLine.newWindowURL) { appActions.newWindow(Immutable.fromJS({ location: CmdLine.newWindowURL diff --git a/app/renderer/components/checkDefaultBrowserDialog.js b/app/renderer/components/checkDefaultBrowserDialog.js new file mode 100644 index 00000000000..41f06bf4134 --- /dev/null +++ b/app/renderer/components/checkDefaultBrowserDialog.js @@ -0,0 +1,51 @@ +/* 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/. */ + +const React = require('react') +const ImmutableComponent = require('../../../js/components/immutableComponent') +const Dialog = require('../../../js/components/dialog') +const Button = require('../../../js/components/button') +const SwitchControl = require('../../../js/components/switchControl') +const appActions = require('../../../js/actions/appActions') +const windowActions = require('../../../js/actions/windowActions') +const settings = require('../../../js/constants/settings') + +class CheckDefaultBrowserDialog extends ImmutableComponent { + constructor () { + super() + this.onCheckDefaultOnStartup = this.onCheckDefaultOnStartup.bind(this) + this.onNotNow = this.onNotNow.bind(this) + this.onUseBrave = this.onUseBrave.bind(this) + } + + onCheckDefaultOnStartup (e) { + windowActions.setModalDialogDetail('checkDefaultBrowserDialog', {checkDefaultOnStartup: e.target.value}) + } + onNotNow () { + appActions.defaultBrowserUpdated(false) + appActions.defaultBrowserCheckComplete() + appActions.changeSetting(settings.CHECK_DEFAULT_ON_STARTUP, this.props.checkDefaultOnStartup) + } + onUseBrave () { + appActions.defaultBrowserUpdated(true) + appActions.defaultBrowserCheckComplete() + appActions.changeSetting(settings.CHECK_DEFAULT_ON_STARTUP, this.props.checkDefaultOnStartup) + } + render () { + return + } +} + +module.exports = CheckDefaultBrowserDialog diff --git a/app/sessionStore.js b/app/sessionStore.js index 3309bf64b44..ea3da5b6265 100644 --- a/app/sessionStore.js +++ b/app/sessionStore.js @@ -234,6 +234,8 @@ module.exports.cleanAppData = (data, isShutdown) => { data.temporarySiteSettings = {} // Delete Flash state since this is checked on startup delete data.flashInitialized + // Delete defaultBrowserCheckComplete state since this is checked on startup + delete data.defaultBrowserCheckComplete // Delete Recovery status on shut down try { delete data.ui.about.preferences.recoverySucceeded diff --git a/docs/appActions.md b/docs/appActions.md index a8647eac992..2d1ceb23418 100644 --- a/docs/appActions.md +++ b/docs/appActions.md @@ -466,6 +466,22 @@ Dispatches a message to submit feedback +### defaultBrowserUpdated(useBrave) + +Dispatch a message to set default browser + +**Parameters** + +**useBrave**: `boolean`, whether set Brave as default browser + + + +### defaultBrowserCheckComplete() + +Dispatch a message to indicate default browser check is complete + + + * * * diff --git a/docs/state.md b/docs/state.md index 3a3d6066658..1322169aff4 100644 --- a/docs/state.md +++ b/docs/state.md @@ -150,6 +150,8 @@ AppStore 'general.downloads.default-save-path': string, // default path for saving files 'general.autohide-menu': boolean, // true if the Windows menu should be autohidden 'general.disable-title-mode': boolean, // true if title mode should always be disabled + 'general.check-default-on-startup': boolean, // true to check whether brave is default browser on startup + 'general.is-default-browser': boolean, // true if brave is default browser 'search.default-search-engine': string, // name of search engine, from js/data/searchProviders.js 'search.offer-search-suggestions': boolean, // true if suggestions should be offered from the default search engine when available. 'tabs.switch-to-new-tabs': boolean, // true if newly opened tabs should be focused immediately @@ -205,7 +207,8 @@ AppStore }, menu: { template: object // used on Windows and by our tests: template object with Menubar control - } + }, + defaultBrowserCheckComplete: boolean // true to indicate default browser check is complete } ``` @@ -526,6 +529,12 @@ WindowStore favorites: boolean, mergeFavorites: boolean, cookies: boolean + }, + modalDialogDetail: { + [className]: { + Object // props + }, + ... } } ``` diff --git a/docs/windowActions.md b/docs/windowActions.md index 66b50dc58b8..0934184d637 100644 --- a/docs/windowActions.md +++ b/docs/windowActions.md @@ -912,6 +912,18 @@ Fired when window receives or loses focus +### setModalDialogDetail(className, props) + +Set Modal Dialog detail + +**Parameters** + +**className**: `string`, name of modal dialog + +**props**: `Object`, properties of the modal dialog + + + * * * diff --git a/js/about/aboutActions.js b/js/about/aboutActions.js index 5702f55b1c4..2af93a7dec9 100644 --- a/js/about/aboutActions.js +++ b/js/about/aboutActions.js @@ -312,6 +312,16 @@ const aboutActions = { aboutActions.dispatchAction({ actionType: appConstants.APP_SUBMIT_FEEDBACK }) + }, + + /** + * Dispatch a message to set default browser + */ + setAsDefaultBrowser: function () { + aboutActions.dispatchAction({ + actionType: appConstants.APP_DEFAULT_BROWSER_UPDATED, + useBrave: true + }) } } module.exports = aboutActions diff --git a/js/about/preferences.js b/js/about/preferences.js index daab6c2f1f9..08eba2cebe6 100644 --- a/js/about/preferences.js +++ b/js/about/preferences.js @@ -581,6 +581,7 @@ class GeneralTab extends ImmutableComponent { super() this.importBrowserDataNow = this.importBrowserDataNow.bind(this) this.onChangeSetting = this.onChangeSetting.bind(this) + this.setAsDefaultBrowser = this.setAsDefaultBrowser.bind(this) } importBrowserDataNow () { @@ -598,6 +599,10 @@ class GeneralTab extends ImmutableComponent { this.props.onChangeSetting(key, value) } + setAsDefaultBrowser () { + aboutActions.setAsDefaultBrowser() + } + enabled (keyArray) { return keyArray.every((key) => getSetting(key, this.props.settings) === true) } @@ -613,6 +618,13 @@ class GeneralTab extends ImmutableComponent { const disableShowHomeButton = !homepage || !homepage.length const disableBookmarksBarSelect = !getSetting(settings.SHOW_BOOKMARKS_TOOLBAR, this.props.settings) const defaultLanguage = this.props.languageCodes.find((lang) => lang.includes(navigator.language)) || 'en-US' + const defaultBrowser = getSetting(settings.IS_DEFAULT_BROWSER, this.props.settings) + ?
+ :