Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.

Commit 23a8571

Browse files
committed
Manual merge of the deprecation notice that was included in #15309
1 parent c3748b1 commit 23a8571

File tree

8 files changed

+350
-100
lines changed

8 files changed

+350
-100
lines changed

app/browser/tabs.js

+4
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,10 @@ const updateAboutDetails = (tabId) => {
371371
adblockCount,
372372
httpsUpgradedCount,
373373
torEnabled,
374+
versionInformation: {
375+
browserLaptop: app.getVersion().toString(),
376+
initState: appState.getIn(['about', 'init']).toJS()
377+
},
374378
newTabDetail: newTabDetail.toJS()
375379
})
376380
} else if (location === 'about:autofill') {

app/darwinInit.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
if (process.platform === 'darwin') {
6+
const childProcess = require('child_process')
7+
const execSync = childProcess.execSync
8+
const fs = require('fs')
9+
const os = require('os')
10+
const appName = 'Brave Browser.app'
11+
const homedir = os.homedir()
12+
13+
const getBraveCoreInstallPath = () => {
14+
const braveCoreInstallLocations = [
15+
`${homedir}/Applications/${appName}/`,
16+
`/Applications/${appName}/`
17+
]
18+
19+
// check for existing installations
20+
for (var i = 0; i < braveCoreInstallLocations.length; i++) {
21+
if (fs.existsSync(braveCoreInstallLocations[i])) {
22+
console.log(`brave-core already installed at "${braveCoreInstallLocations[i]}"`)
23+
return braveCoreInstallLocations[i]
24+
}
25+
}
26+
27+
return false
28+
}
29+
30+
module.exports = function () {
31+
// If brave-core is installed, find the path and version
32+
const braveCoreInstallPath = getBraveCoreInstallPath()
33+
if (braveCoreInstallPath) {
34+
const getVersionCmd = `defaults read "${braveCoreInstallPath}/Contents/Info" CFBundleShortVersionString`
35+
let braveCoreVersion
36+
try {
37+
// format will be like `71.0.57.4`
38+
braveCoreVersion = execSync(getVersionCmd).toString().trim()
39+
// remove the Chromium version from the string
40+
const versionAsArray = braveCoreVersion.split('.')
41+
if (versionAsArray.length === 4) {
42+
braveCoreVersion = versionAsArray.slice(1).join('.')
43+
}
44+
} catch (e) {}
45+
46+
return {braveCoreInstalled: true, braveCoreInstallPath, braveCoreVersion}
47+
}
48+
49+
return {braveCoreInstalled: false}
50+
}
51+
}

app/index.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ process.on('unhandledRejection', function (reason, promise) {
4949

5050
process.on('warning', warning => console.warn(warning.stack))
5151

52-
if (process.platform === 'win32') {
53-
require('./windowsInit')
54-
}
52+
let initState
5553

56-
if (process.platform === 'linux') {
54+
if (process.platform === 'win32') {
55+
initState = require('./windowsInit')()
56+
} else if (process.platform === 'linux') {
5757
require('./linuxInit')
58+
} else if (process.platform === 'darwin') {
59+
initState = require('./darwinInit')()
5860
}
5961

6062
const electron = require('electron')
@@ -188,6 +190,10 @@ app.on('ready', () => {
188190
})
189191

190192
loadAppStatePromise.then((initialImmutableState) => {
193+
// merge state which was set during optional platform-specific init
194+
initialImmutableState = initialImmutableState.setIn(['about', 'init'],
195+
Immutable.fromJS(initState || {}))
196+
191197
// Do this after loading the state
192198
// For tests we always want to load default app state
193199
const loadedPerWindowImmutableState = initialImmutableState.get('perWindowState')

app/windowsInit.js

+148-94
Original file line numberDiff line numberDiff line change
@@ -2,109 +2,163 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
33
* You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
const electron = require('electron')
6-
const path = require('path')
7-
const childProcess = require('child_process')
8-
const spawn = childProcess.spawn
9-
const spawnSync = childProcess.spawnSync
10-
const execSync = childProcess.execSync
11-
const app = electron.app
12-
const Channel = require('./channel')
13-
const cmdLine = require('./cmdLine')
14-
const promoCodeFirstRunStorage = require('./promoCodeFirstRunStorage')
15-
16-
let appUserModelId = 'com.squirrel.brave.Brave'
17-
switch (Channel.channel()) {
18-
case 'nightly':
19-
appUserModelId = 'com.squirrel.BraveNightly.BraveNightly'
20-
break
21-
case 'developer':
22-
appUserModelId = 'com.squirrel.BraveDeveloper.BraveDeveloper'
23-
break
24-
case 'beta':
25-
appUserModelId = 'com.squirrel.BraveBeta.BraveBeta'
26-
break
27-
case 'dev':
28-
appUserModelId = 'com.squirrel.brave.Brave'
29-
break
30-
default:
31-
appUserModelId = 'com.squirrel.brave.Brave'
32-
break
33-
}
34-
35-
const getBraveBinPath = () => {
36-
const appPath = app.getPath('exe')
37-
return path.dirname(appPath)
38-
}
5+
if (process.platform === 'win32') {
6+
const electron = require('electron')
7+
const path = require('path')
8+
const childProcess = require('child_process')
9+
const spawn = childProcess.spawn
10+
const spawnSync = childProcess.spawnSync
11+
const execSync = childProcess.execSync
12+
const app = electron.app
13+
const fs = require('fs')
14+
const Channel = require('./channel')
15+
const cmdLine = require('./cmdLine')
16+
const promoCodeFirstRunStorage = require('./promoCodeFirstRunStorage')
3917

40-
const getBraveDefaultsBinPath = () => {
41-
const appDir = getBraveBinPath()
42-
return path.join(appDir, 'resources', 'braveDefaults.exe')
43-
}
18+
let appUserModelId = 'com.squirrel.brave.Brave'
19+
switch (Channel.channel()) {
20+
case 'nightly':
21+
appUserModelId = 'com.squirrel.BraveNightly.BraveNightly'
22+
break
23+
case 'developer':
24+
appUserModelId = 'com.squirrel.BraveDeveloper.BraveDeveloper'
25+
break
26+
case 'beta':
27+
appUserModelId = 'com.squirrel.BraveBeta.BraveBeta'
28+
break
29+
case 'dev':
30+
appUserModelId = 'com.squirrel.brave.Brave'
31+
break
32+
default:
33+
appUserModelId = 'com.squirrel.brave.Brave'
34+
break
35+
}
4436

45-
const getVisualElementsManifestPath = () => {
46-
const appDir = getBraveBinPath()
47-
return path.join(appDir, 'resources', 'Update.VisualElementsManifest.xml')
48-
}
37+
const getBraveBinPath = () => {
38+
const appPath = app.getPath('exe')
39+
return path.dirname(appPath)
40+
}
4941

50-
function CopyManifestFile () {
51-
const versionedRoot = getBraveBinPath()
52-
let updateRoot = versionedRoot.split('\\')
53-
updateRoot.pop()
54-
updateRoot = updateRoot.join('\\')
55-
const cmd = 'copy "' + getVisualElementsManifestPath() + '" "' + updateRoot + '"'
56-
execSync(cmd)
57-
}
42+
const getBraveDefaultsBinPath = () => {
43+
const appDir = getBraveBinPath()
44+
return path.join(appDir, 'resources', 'braveDefaults.exe')
45+
}
5846

59-
// windows installation events etc...
60-
if (process.platform === 'win32') {
61-
const shouldQuit = require('electron-squirrel-startup')
62-
const channel = Channel.channel()
63-
const isSquirrelInstall = process.argv.includes('--squirrel-install')
64-
const isSquirrelUpdate = process.argv.includes('--squirrel-updated')
65-
const isSquirrelUninstall = process.argv.includes('--squirrel-uninstall')
66-
const isSquirrelFirstRun = process.argv.includes('--squirrel-firstrun')
67-
// handle running as part of install process
68-
if (isSquirrelInstall) {
69-
// determine if promo code was provided by setup.exe
70-
const promoCode = cmdLine.getFirstRunPromoCode()
71-
if (promoCode) {
72-
// write promo code so state can access it
73-
promoCodeFirstRunStorage.writeFirstRunPromoCodeSync(promoCode)
74-
}
47+
const getVisualElementsManifestPath = () => {
48+
const appDir = getBraveBinPath()
49+
return path.join(appDir, 'resources', 'Update.VisualElementsManifest.xml')
7550
}
76-
// first-run after install / update
77-
if (isSquirrelInstall || isSquirrelUpdate) {
78-
// The manifest file is used to customize the look of the Start menu tile.
79-
// This function copies it from the versioned folder to the parent folder
80-
// (where the auto-update executable lives)
81-
CopyManifestFile()
82-
// Launch defaults helper to add defaults on install
83-
spawn(getBraveDefaultsBinPath(), [], { detached: true })
84-
} else if (isSquirrelUninstall) {
85-
// Launch defaults helper to remove defaults on uninstall
86-
// Sync to avoid file path in use on uninstall
87-
spawnSync(getBraveDefaultsBinPath(), ['-uninstall'])
51+
52+
const copyManifestFile = () => {
53+
const versionedRoot = getBraveBinPath()
54+
let updateRoot = versionedRoot.split('\\')
55+
updateRoot.pop()
56+
updateRoot = updateRoot.join('\\')
57+
const cmd = 'copy "' + getVisualElementsManifestPath() + '" "' + updateRoot + '"'
58+
execSync(cmd)
8859
}
8960

90-
if (shouldQuit(channel)) {
91-
process.exit(0)
61+
const getBraveCoreInstallPath = () => {
62+
const braveCoreInstallLocations = [
63+
'%USERPROFILE%\\AppData\\Local\\BraveSoftware\\Brave-Browser\\Application',
64+
'%ProgramFiles(x86)%\\BraveSoftware\\Brave-Browser\\Application',
65+
'%ProgramFiles%\\BraveSoftware\\Brave-Browser\\Application'
66+
]
67+
68+
// check for existing installations
69+
for (let i = 0; i < braveCoreInstallLocations.length; i++) {
70+
const path = braveCoreInstallLocations[i]
71+
const resolvedPath = path.replace(/%([^%]+)%/g, function (_, variableToResolve) {
72+
return process.env[variableToResolve]
73+
})
74+
if (fs.existsSync(resolvedPath)) {
75+
console.log(`brave-core already installed at "${resolvedPath}"`)
76+
return resolvedPath
77+
}
78+
}
79+
80+
return false
9281
}
9382

94-
const userDataDirSwitch = '--user-data-dir-name=brave-' + channel
95-
if (channel !== 'dev' && !process.argv.includes(userDataDirSwitch) &&
96-
!process.argv.includes('--relaunch') &&
97-
!process.argv.includes('--user-data-dir-name=brave-development')) {
98-
delete process.env.CHROME_USER_DATA_DIR
99-
if (isSquirrelFirstRun) {
100-
app.relaunch({args: [userDataDirSwitch, '--relaunch']})
101-
} else {
102-
app.relaunch({args: process.argv.slice(1).concat([userDataDirSwitch, '--relaunch'])})
83+
module.exports = function () {
84+
const shouldQuit = require('electron-squirrel-startup')
85+
const channel = Channel.channel()
86+
const isSquirrelInstall = process.argv.includes('--squirrel-install')
87+
const isSquirrelUpdate = process.argv.includes('--squirrel-updated')
88+
const isSquirrelUninstall = process.argv.includes('--squirrel-uninstall')
89+
const isSquirrelFirstRun = process.argv.includes('--squirrel-firstrun')
90+
91+
// Events like `--squirrel-install` and `--squirrel-updated`
92+
// are fired by Update.exe DURING the install/upgrade. Since
93+
// we don't intend to actually launch the executable, we need
94+
// to exit after performing housekeeping tasks.
95+
if (isSquirrelInstall || isSquirrelUpdate) {
96+
// Detect promoCode (via CLI) and write to disk for later use
97+
const promoCode = isSquirrelInstall && cmdLine.getFirstRunPromoCode()
98+
if (promoCode) {
99+
promoCodeFirstRunStorage.writeFirstRunPromoCodeSync(promoCode)
100+
}
101+
// The manifest file is used to customize the look of the Start menu tile.
102+
// This function copies it from the versioned folder to the parent folder
103+
// (where the auto-update executable lives)
104+
copyManifestFile()
105+
// Launch defaults helper to add defaults on install
106+
spawn(getBraveDefaultsBinPath(), [], { detached: true })
107+
} else if (isSquirrelUninstall) {
108+
// Launch defaults helper to remove defaults on uninstall
109+
// Sync to avoid file path in use on uninstall
110+
spawnSync(getBraveDefaultsBinPath(), ['-uninstall'])
111+
}
112+
113+
// Quit if this is only an install or update event.
114+
// This logic also creates the shortcuts (desktop, etc)
115+
if (shouldQuit(channel)) {
116+
process.exit(0)
117+
}
118+
119+
// If executable is on BETA/DEVELOPER/NIGHTLY channels, there
120+
// is a different `user-data-dir-name`. This logic will
121+
// relaunch using the proper profile if it was omitted for
122+
// some reason.
123+
const userDataDirSwitch = '--user-data-dir-name=brave-' + channel
124+
if (channel !== 'dev' && !process.argv.includes(userDataDirSwitch) &&
125+
!process.argv.includes('--relaunch') &&
126+
!process.argv.includes('--user-data-dir-name=brave-development')) {
127+
delete process.env.CHROME_USER_DATA_DIR
128+
if (isSquirrelFirstRun) {
129+
app.relaunch({args: [userDataDirSwitch, '--relaunch']})
130+
} else {
131+
app.relaunch({args: process.argv.slice(1).concat([userDataDirSwitch, '--relaunch'])})
132+
}
133+
app.exit()
134+
return
103135
}
104-
app.exit()
136+
137+
app.on('will-finish-launching', () => {
138+
app.setAppUserModelId(appUserModelId)
139+
})
140+
141+
// If brave-core is installed, find the path and version
142+
const braveCoreInstallPath = getBraveCoreInstallPath()
143+
if (braveCoreInstallPath) {
144+
const getVersionCmd = `wmic datafile where name='${braveCoreInstallPath.replace(/\\/g, '\\\\')}\\\\brave.exe' get Version /value`
145+
let braveCoreVersion
146+
try {
147+
// format will be like `Version=70.0.56.8`
148+
braveCoreVersion = execSync(getVersionCmd).toString().trim()
149+
const keyValue = braveCoreVersion.split('=')
150+
if (keyValue.length === 2) {
151+
// remove the Chromium version from the string
152+
const versionAsArray = keyValue[1].split('.')
153+
if (versionAsArray.length === 4) {
154+
braveCoreVersion = versionAsArray.slice(1).join('.')
155+
}
156+
}
157+
} catch (e) {}
158+
159+
return {braveCoreInstalled: true, braveCoreInstallPath, braveCoreVersion}
160+
}
161+
162+
return {braveCoreInstalled: false}
105163
}
106164
}
107-
108-
app.on('will-finish-launching', () => {
109-
app.setAppUserModelId(appUserModelId)
110-
})

0 commit comments

Comments
 (0)