Merge pull request #10633 from electron/update-default-app
updates to default app and cli usage
This commit is contained in:
commit
85ef1ee21f
4 changed files with 248 additions and 198 deletions
|
@ -11,7 +11,7 @@ app.on('window-all-closed', () => {
|
||||||
exports.load = (appUrl) => {
|
exports.load = (appUrl) => {
|
||||||
app.on('ready', () => {
|
app.on('ready', () => {
|
||||||
const options = {
|
const options = {
|
||||||
width: 800,
|
width: 900,
|
||||||
height: 600,
|
height: 600,
|
||||||
autoHideMenuBar: true,
|
autoHideMenuBar: true,
|
||||||
backgroundColor: '#FFFFFF',
|
backgroundColor: '#FFFFFF',
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -7,21 +7,28 @@ const url = require('url')
|
||||||
|
|
||||||
// Parse command line options.
|
// Parse command line options.
|
||||||
const argv = process.argv.slice(1)
|
const argv = process.argv.slice(1)
|
||||||
const option = { file: null, help: null, version: null, abi: null, webdriver: null, modules: [] }
|
|
||||||
|
const option = {
|
||||||
|
file: null,
|
||||||
|
help: null,
|
||||||
|
default: null,
|
||||||
|
version: null,
|
||||||
|
webdriver: null,
|
||||||
|
modules: []
|
||||||
|
}
|
||||||
|
|
||||||
for (let i = 0; i < argv.length; i++) {
|
for (let i = 0; i < argv.length; i++) {
|
||||||
if (argv[i] === '--version' || argv[i] === '-v') {
|
if (argv[i] === '--version' || argv[i] === '-v') {
|
||||||
option.version = true
|
option.version = true
|
||||||
break
|
break
|
||||||
} else if (argv[i] === '--abi') {
|
|
||||||
option.abi = true
|
|
||||||
break
|
|
||||||
} else if (argv[i].match(/^--app=/)) {
|
} else if (argv[i].match(/^--app=/)) {
|
||||||
option.file = argv[i].split('=')[1]
|
option.file = argv[i].split('=')[1]
|
||||||
break
|
break
|
||||||
} else if (argv[i] === '--help' || argv[i] === '-h') {
|
} else if (argv[i] === '--default' || argv[i] === '-d') {
|
||||||
option.help = true
|
option.default = true
|
||||||
break
|
break
|
||||||
} else if (argv[i] === '--interactive' || argv[i] === '-i') {
|
} else if (argv[i] === '--interactive' || argv[i] === '-i' ||
|
||||||
|
argv[i] === '-repl' || argv[i] === '-r') {
|
||||||
option.interactive = true
|
option.interactive = true
|
||||||
} else if (argv[i] === '--test-type=webdriver') {
|
} else if (argv[i] === '--test-type=webdriver') {
|
||||||
option.webdriver = true
|
option.webdriver = true
|
||||||
|
@ -190,22 +197,19 @@ app.once('ready', () => {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
template[1].submenu.push(
|
template[1].submenu.push({
|
||||||
{
|
type: 'separator'
|
||||||
type: 'separator'
|
}, {
|
||||||
},
|
label: 'Speech',
|
||||||
{
|
submenu: [
|
||||||
label: 'Speech',
|
{
|
||||||
submenu: [
|
role: 'startspeaking'
|
||||||
{
|
},
|
||||||
role: 'startspeaking'
|
{
|
||||||
},
|
role: 'stopspeaking'
|
||||||
{
|
}
|
||||||
role: 'stopspeaking'
|
]
|
||||||
}
|
})
|
||||||
]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
template[3].submenu = [
|
template[3].submenu = [
|
||||||
{
|
{
|
||||||
role: 'close'
|
role: 'close'
|
||||||
|
@ -226,11 +230,9 @@ app.once('ready', () => {
|
||||||
} else {
|
} else {
|
||||||
template.unshift({
|
template.unshift({
|
||||||
label: 'File',
|
label: 'File',
|
||||||
submenu: [
|
submenu: [{
|
||||||
{
|
role: 'quit'
|
||||||
role: 'quit'
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,16 +329,19 @@ if (option.file && !option.webdriver) {
|
||||||
} else if (option.version) {
|
} else if (option.version) {
|
||||||
console.log('v' + process.versions.electron)
|
console.log('v' + process.versions.electron)
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
} else if (option.abi) {
|
} else if (option.default) {
|
||||||
console.log(process.versions.modules)
|
const indexPath = path.join(__dirname, '/index.html')
|
||||||
process.exit(0)
|
loadApplicationByUrl(`file://${indexPath}`)
|
||||||
} else if (option.help) {
|
} else if (option.interactive) {
|
||||||
const helpMessage = `Electron ${process.versions.electron} - Build cross platform desktop apps with JavaScript, HTML, and CSS
|
startRepl()
|
||||||
|
} else {
|
||||||
|
const welcomeMessage = `
|
||||||
|
Deprecation Warning: To render the default app, the -d or --default flags will soon need to be used.
|
||||||
|
|
||||||
|
Electron ${process.versions.electron} - Build cross platform desktop apps with JavaScript, HTML, and CSS
|
||||||
Usage: electron [options] [path]
|
Usage: electron [options] [path]
|
||||||
|
|
||||||
A path to an Electron app may be specified. The path must be one of the following:
|
A path to an Electron app may be specified. It must be one of the following:
|
||||||
|
|
||||||
- index.js file.
|
- index.js file.
|
||||||
- Folder containing a package.json file.
|
- Folder containing a package.json file.
|
||||||
- Folder containing an index.js file.
|
- Folder containing an index.js file.
|
||||||
|
@ -344,16 +349,13 @@ if (option.file && !option.webdriver) {
|
||||||
- http://, https://, or file:// URL.
|
- http://, https://, or file:// URL.
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-h, --help Print this usage message.
|
-d, --default Run the default bundled Electron app.
|
||||||
-i, --interactive Open a REPL to the main process.
|
-i, --interactive Open a REPL to the main process.
|
||||||
-r, --require Module to preload (option can be repeated)
|
-r, --require Module to preload (option can be repeated)
|
||||||
-v, --version Print the version.
|
-v, --version Print the version.`
|
||||||
--abi Print the application binary interface.`
|
|
||||||
console.log(helpMessage)
|
console.log(welcomeMessage)
|
||||||
process.exit(0)
|
|
||||||
} else if (option.interactive) {
|
|
||||||
startRepl()
|
|
||||||
} else {
|
|
||||||
const indexPath = path.join(__dirname, '/index.html')
|
const indexPath = path.join(__dirname, '/index.html')
|
||||||
loadApplicationByUrl(`file://${indexPath}`)
|
loadApplicationByUrl(`file://${indexPath}`)
|
||||||
|
process.exit(0)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,45 +1,22 @@
|
||||||
const {remote, shell} = require('electron')
|
const {remote, shell} = require('electron')
|
||||||
const {execFile} = require('child_process')
|
const path = require('path')
|
||||||
|
const URL = require('url')
|
||||||
|
const electronPath = path.relative(process.cwd(), remote.process.execPath)
|
||||||
|
|
||||||
const {execPath} = remote.process
|
Array.from(document.querySelectorAll('a[href]')).forEach(link => {
|
||||||
|
// safely add `?utm_source=default_app
|
||||||
|
let url = URL.parse(link.getAttribute('href'), true)
|
||||||
|
url.query = Object.assign(url.query, {utm_source: 'default_app'})
|
||||||
|
url = URL.format(url)
|
||||||
|
|
||||||
document.onclick = function (e) {
|
link.addEventListener('click', (e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
if (e.target.tagName === 'A') {
|
shell.openExternal(url)
|
||||||
shell.openExternal(e.target.href)
|
})
|
||||||
}
|
})
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
document.ondragover = document.ondrop = function (e) {
|
document.querySelector('.electron-version').innerText = `Electron v${process.versions.electron}`
|
||||||
e.preventDefault()
|
document.querySelector('.chrome-version').innerText = `Chromium v${process.versions.chrome}`
|
||||||
return false
|
document.querySelector('.node-version').innerText = `Node v${process.versions.node}`
|
||||||
}
|
document.querySelector('.v8-version').innerText = `v8 v${process.versions.v8}`
|
||||||
|
document.querySelector('.command-example').innerText = `${electronPath} path-to-app`
|
||||||
const holder = document.getElementById('holder')
|
|
||||||
holder.ondragover = function () {
|
|
||||||
this.className = 'hover'
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
holder.ondragleave = holder.ondragend = function () {
|
|
||||||
this.className = ''
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
holder.ondrop = function (e) {
|
|
||||||
this.className = ''
|
|
||||||
e.preventDefault()
|
|
||||||
|
|
||||||
const file = e.dataTransfer.files[0]
|
|
||||||
execFile(execPath, [file.path], {
|
|
||||||
detached: true, stdio: 'ignore'
|
|
||||||
}).unref()
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
const version = process.versions.electron
|
|
||||||
document.querySelector('.header-version').innerText = version
|
|
||||||
document.querySelector('.command-example').innerText = `${execPath} path-to-your-app`
|
|
||||||
document.querySelector('.quick-start-link').href = `https://github.com/electron/electron/blob/v${version}/docs/tutorial/quick-start.md`
|
|
||||||
document.querySelector('.docs-link').href = `https://github.com/electron/electron/tree/v${version}/docs#readme`
|
|
||||||
|
|
Loading…
Reference in a new issue