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) => {
|
||||
app.on('ready', () => {
|
||||
const options = {
|
||||
width: 800,
|
||||
width: 900,
|
||||
height: 600,
|
||||
autoHideMenuBar: true,
|
||||
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.
|
||||
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++) {
|
||||
if (argv[i] === '--version' || argv[i] === '-v') {
|
||||
option.version = true
|
||||
break
|
||||
} else if (argv[i] === '--abi') {
|
||||
option.abi = true
|
||||
break
|
||||
} else if (argv[i].match(/^--app=/)) {
|
||||
option.file = argv[i].split('=')[1]
|
||||
break
|
||||
} else if (argv[i] === '--help' || argv[i] === '-h') {
|
||||
option.help = true
|
||||
} else if (argv[i] === '--default' || argv[i] === '-d') {
|
||||
option.default = true
|
||||
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
|
||||
} else if (argv[i] === '--test-type=webdriver') {
|
||||
option.webdriver = true
|
||||
|
@ -190,11 +197,9 @@ app.once('ready', () => {
|
|||
}
|
||||
]
|
||||
})
|
||||
template[1].submenu.push(
|
||||
{
|
||||
template[1].submenu.push({
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
}, {
|
||||
label: 'Speech',
|
||||
submenu: [
|
||||
{
|
||||
|
@ -204,8 +209,7 @@ app.once('ready', () => {
|
|||
role: 'stopspeaking'
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
})
|
||||
template[3].submenu = [
|
||||
{
|
||||
role: 'close'
|
||||
|
@ -226,11 +230,9 @@ app.once('ready', () => {
|
|||
} else {
|
||||
template.unshift({
|
||||
label: 'File',
|
||||
submenu: [
|
||||
{
|
||||
submenu: [{
|
||||
role: 'quit'
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -327,16 +329,19 @@ if (option.file && !option.webdriver) {
|
|||
} else if (option.version) {
|
||||
console.log('v' + process.versions.electron)
|
||||
process.exit(0)
|
||||
} else if (option.abi) {
|
||||
console.log(process.versions.modules)
|
||||
process.exit(0)
|
||||
} else if (option.help) {
|
||||
const helpMessage = `Electron ${process.versions.electron} - Build cross platform desktop apps with JavaScript, HTML, and CSS
|
||||
} else if (option.default) {
|
||||
const indexPath = path.join(__dirname, '/index.html')
|
||||
loadApplicationByUrl(`file://${indexPath}`)
|
||||
} else if (option.interactive) {
|
||||
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]
|
||||
|
||||
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.
|
||||
- Folder containing a package.json file.
|
||||
- Folder containing an index.js file.
|
||||
|
@ -344,16 +349,13 @@ if (option.file && !option.webdriver) {
|
|||
- http://, https://, or file:// URL.
|
||||
|
||||
Options:
|
||||
-h, --help Print this usage message.
|
||||
-d, --default Run the default bundled Electron app.
|
||||
-i, --interactive Open a REPL to the main process.
|
||||
-r, --require Module to preload (option can be repeated)
|
||||
-v, --version Print the version.
|
||||
--abi Print the application binary interface.`
|
||||
console.log(helpMessage)
|
||||
process.exit(0)
|
||||
} else if (option.interactive) {
|
||||
startRepl()
|
||||
} else {
|
||||
-v, --version Print the version.`
|
||||
|
||||
console.log(welcomeMessage)
|
||||
const indexPath = path.join(__dirname, '/index.html')
|
||||
loadApplicationByUrl(`file://${indexPath}`)
|
||||
process.exit(0)
|
||||
}
|
||||
|
|
|
@ -1,45 +1,22 @@
|
|||
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()
|
||||
if (e.target.tagName === 'A') {
|
||||
shell.openExternal(e.target.href)
|
||||
}
|
||||
return false
|
||||
}
|
||||
shell.openExternal(url)
|
||||
})
|
||||
})
|
||||
|
||||
document.ondragover = document.ondrop = function (e) {
|
||||
e.preventDefault()
|
||||
return false
|
||||
}
|
||||
|
||||
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`
|
||||
document.querySelector('.electron-version').innerText = `Electron v${process.versions.electron}`
|
||||
document.querySelector('.chrome-version').innerText = `Chromium v${process.versions.chrome}`
|
||||
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`
|
||||
|
|
Loading…
Reference in a new issue