This repository was archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 973
Final browser-laptop update #15309
Merged
Merged
Final browser-laptop update #15309
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
31fe22f
Automate brave-core install for Windows. Includes an updated Squirrel…
bsclifton 3cbd41c
Automate brave-core install for macOS
bsclifton 93fa3b4
Update icons. Fixes https://github.com/brave/brave-browser/issues/1915
bsclifton 66eb6c8
Change the order of operations on Windows brave-core install
bsclifton 52b6946
Deprecation notice is now shown on `New Tab` page
bsclifton 0c2a3e9
macOS and Windows will only try to install brave-core once
bsclifton 31a006c
Show different messaging if user doesn't have brave-core installed
bsclifton ef52127
Added Linux only deprecation notification
bsclifton 5daad5a
If Muon Brave is default browser, prompt user to change to Brave Core…
bsclifton cbe282d
Brave Core binaries
bsclifton f8e887c
Paths for Brave Core binaries
bsclifton 6b93f8e
Version bump
bsclifton f381a3e
Address review feedback
bsclifton b0af328
Updates StartPage branding
jonathansampson 782bc3f
Add debug logging, to make it easier to diagnose issues seen by teamm…
bsclifton cf1d2b3
Remove FindX search engine (I believe it's been EOLed). This was already
bsclifton 09901ae
Allow packager to output a different CFBundleName for the macOS packager
petemill 28adf74
Ran `npm audit fix` to bring vulnerabilities down from 23 to 14
bsclifton 6c98eee
Disable sync
bsclifton 9b52daf
review feedback
bsclifton f0be763
Remove default browser check (and set on launch).
bsclifton ef8f8dc
0.26.0
bsclifton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/* 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/. */ | ||
|
||
if (process.platform === 'darwin') { | ||
const electron = require('electron') | ||
const path = require('path') | ||
const childProcess = require('child_process') | ||
const execSync = childProcess.execSync | ||
const app = electron.app | ||
const fs = require('fs') | ||
const os = require('os') | ||
const appName = 'Brave Browser.app' | ||
const homedir = os.homedir() | ||
|
||
const getBraveBinPath = () => { | ||
const appPath = app.getPath('exe') | ||
const appIndex = appPath.indexOf('.app') + '.app'.length | ||
if (appPath && appIndex > 4) { | ||
// Remove the `Contents`/`MacOS`/`Brave` parts from path | ||
const runningAppPath = appPath.substring(0, appIndex) | ||
return runningAppPath | ||
} | ||
return false | ||
} | ||
|
||
const braveCoreUpgradeFile = path.join(app.getPath('userData'), 'brave-core-upgrade') | ||
|
||
const shouldAttemptInstall = () => { | ||
return !fs.existsSync(braveCoreUpgradeFile) | ||
} | ||
|
||
const getBraveCoreInstallerPath = () => { | ||
const appDir = getBraveBinPath() | ||
if (!appDir) { | ||
return false | ||
} | ||
return path.join(getBraveBinPath(), 'Contents', 'Resources', 'Brave-Browser.pkg') | ||
} | ||
|
||
const getBraveCoreInstallPath = () => { | ||
const braveCoreInstallLocations = [ | ||
`${homedir}/Applications/${appName}/`, | ||
`/Applications/${appName}/` | ||
] | ||
|
||
// check for existing installations | ||
for (var i = 0; i < braveCoreInstallLocations.length; i++) { | ||
if (fs.existsSync(braveCoreInstallLocations[i])) { | ||
console.log(`brave-core already installed at "${braveCoreInstallLocations[i]}"`) | ||
return braveCoreInstallLocations[i] | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
const installBraveCore = () => { | ||
// get path to the bundled brave-core binary | ||
const installerPath = getBraveCoreInstallerPath() | ||
if (!installerPath) { | ||
console.log('brave-core installer not found') | ||
return false | ||
} | ||
|
||
// brave-core is not installed; go ahead with silent install | ||
const tempDir = path.join(os.tmpdir(), 'brave-upgrade') | ||
try { | ||
console.log(`Extracting brave-core binaries from "${installerPath}" into temp directory "${tempDir}"`) | ||
execSync(`pkgutil --expand-full "${installerPath}" "${tempDir}"`) | ||
|
||
let installedPath = '/Applications' | ||
try { | ||
console.log(`Attempting to move extracted brave-core binaries into "${installedPath}/."`) | ||
execSync(`mv "${tempDir}/Payload/${appName}/" "${installedPath}/."`) | ||
} catch (globalPathException) { | ||
installedPath = `${homedir}/Applications` | ||
console.log(`Attempting to move extracted brave-core binaries into "${installedPath}/."`) | ||
execSync(`mv "${tempDir}/Payload/${appName}/" "${installedPath}/."`) | ||
} | ||
|
||
// match expected permissions | ||
// logic borrowed from ./build/pkg-scripts/postinstall | ||
[ | ||
`chmod -R 775 "${installedPath}/${appName}"`, | ||
`chown -R $USER "${installedPath}/${appName}"`, | ||
`chgrp -R admin "${installedPath}/${appName}"` | ||
].forEach((cmd) => { | ||
try { | ||
execSync(cmd) | ||
} catch (e) { | ||
console.log(`Failed adjusting permissions with "${cmd}"\nerror: "${e.toString()}"`) | ||
} | ||
}) | ||
|
||
// store details to disk; no further install attempts will be made | ||
try { | ||
fs.writeFileSync(braveCoreUpgradeFile, `installed: ${new Date().getTime()}`) | ||
} catch (e) { | ||
} | ||
|
||
// launch into freshly installed brave-core and append argument expected in: | ||
// https://github.com/brave/brave-browser/issues/1545 | ||
let openCmd = `open -a "${installedPath}/${appName}/" --args --upgrade-from-muon` | ||
console.log('Launching brave-core') | ||
execSync(openCmd) | ||
} catch (e) { | ||
return false | ||
} finally { | ||
console.log(`Removing temp directory "${tempDir}"`) | ||
try { | ||
execSync(`rm -rf ${tempDir}`) | ||
} catch (e) {} | ||
} | ||
|
||
return true | ||
} | ||
|
||
module.exports = function () { | ||
// If brave-core is installed, find the path and version | ||
const braveCoreInstallPath = getBraveCoreInstallPath() | ||
if (braveCoreInstallPath) { | ||
const getVersionCmd = `defaults read "${braveCoreInstallPath}/Contents/Info" CFBundleShortVersionString` | ||
let braveCoreVersion | ||
try { | ||
// format will be like `71.0.57.4` | ||
braveCoreVersion = execSync(getVersionCmd).toString().trim() | ||
// remove the Chromium version from the string | ||
const versionAsArray = braveCoreVersion.split('.') | ||
if (versionAsArray.length === 4) { | ||
braveCoreVersion = versionAsArray.slice(1).join('.') | ||
} | ||
} catch (e) {} | ||
|
||
return {braveCoreInstalled: true, braveCoreInstallPath, braveCoreVersion} | ||
} | ||
|
||
// If brave-core is NOT installed, attempt to install it | ||
if (shouldAttemptInstall()) { | ||
if (installBraveCore()) { | ||
app.exit() | ||
} | ||
} | ||
|
||
return {braveCoreInstalled: false} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bsclifton - If the init script fails before this, the
<platform>Init.js
script will try to install brave-core again, what do you think about writing errors to the same file? In that case, if the script throws any errors before this line theinit
script will not run again.