Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion app/bin/fsh
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ ROOTDIR="$DIR/.."
# determine which argv to ignore
export DEVMODE=true

exec "$ROOTDIR/node_modules/.bin/electron" "$ROOTDIR" --fsh-headless "$@"
#exec "$ROOTDIR/node_modules/.bin/electron" "$ROOTDIR" --fsh-headless "$@"

exec node "$ROOTDIR/main.js" --fsh-headless "$@"
2 changes: 1 addition & 1 deletion app/content/js/command-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ const withEvents = (evaluator, leaf) => {
*/
const _read = (model, argv, contextRetry, originalArgv) => {
let leaf = treeMatch(model, argv, true) // true means read-only, don't modify the context model please
debug('read', argv, contextRetry, leaf)
debug('read', argv)

let evaluator = leaf && leaf.$
if (!evaluator) {
Expand Down
2 changes: 1 addition & 1 deletion app/content/js/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ self.exec = (commandUntrimmed, execOptions) => {
//
const _usage = evaluator.options && evaluator.options.usage,
usage = _usage && _usage.fn ? _usage.fn(_usage.command) : _usage
debug('usage', usage, evaluator)
debug('usage')

if (usage && usage.strict) { // strict: command wants *us* to enforce conformance
// required and optional parameters
Expand Down
2 changes: 1 addition & 1 deletion app/content/js/usage-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const breadcrumbFromCommand = command => usageFromCommand(command)
*
*/
const format = (message, options={}) => {
debug('format', message)
debug('format', typeof message === 'string' ? message : message.title)

if (typeof message === 'string') {
return message
Expand Down
2 changes: 1 addition & 1 deletion app/headless.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ const main = (app, mainFunctions) => {
}

/** main work starts here */
debug('main::bootstrap')
debug('bootstrap')
plugins.init({app}).then(() => {
debug('plugins initialized')

Expand Down
192 changes: 129 additions & 63 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,107 @@
const debug = require('debug')('main')
debug('starting')

// handle squirrel install and update events
if (require('electron-squirrel-startup')) return

const electron = require('electron'),
{ app } = electron

debug('modules loaded')

/**
* Should our BrowerWindows have a window frame?
*
*
*/
const useWindowFrame = true
let electron, app
function initGraphics() {
debug('initGraphics')

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow
// handle squirrel install and update events
if (require('electron-squirrel-startup')) return

// linux oddities
// context mismatch in svga_sampler_view_destroy
if (process.platform === 'linux') {
app.disableHardwareAcceleration()
}
if (!electron) {
debug('loading electron')
electron = require('electron'),
{ app } = electron

/**
* Were we spawned in headless mode?
*
*/
const isRunningHeadless = process.argv.find(arg => arg === '--fsh-headless')
try {
if (isRunningHeadless && app.dock) app.dock.hide()
} catch (e) {
}
debug('isRunningHeadless %s', isRunningHeadless)
if (!app) {
// then we're still in pure headless mode; we'll need to fork ourselves to spawn electron
const path = require('path')
const { spawn } = require('child_process')
const appHome = path.resolve('.')

function createWindow(noHeadless, executeThisArgvPlease, subwindowPlease, subwindowPrefs) {
debug('createWindow')
debug('spawning electron', appHome)

const child = spawn(electron, [appHome])
child.unref()

debug('spawning electron done, this process will soon exit')
process.exit(0)

} else {
debug('loading electron done', electron)
}
}

// linux oddities
// "context mismatch in svga_sampler_view_destroy"
if (process.platform === 'linux') {
app.disableHardwareAcceleration()
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)

if (process.env.RUNNING_SHELL_TEST) {
app.on('before-quit', function() {
const config = { tempDirectory: require('path').join(__dirname, '../tests/.nyc_output') },
nyc = new (require('nyc'))(config) // create the nyc instance
nyc.createTempDirectory() // in case we are the first to the line
nyc.writeCoverageFile() // write out the coverage data for the renderer code

mainWindow.webContents.send('/coverage/dump', config)
})
}

// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin' || isRunningHeadless) { // if we're running headless, then quit on window closed, no matter which platform we're on
app.quit()
}
})

app.on('activate', function () {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow()
}
})
} /* initGraphics */

function initHeadless() {
if (/*noHeadless !== true &&*/ isRunningHeadless) {
debug('initHeadless')

app = {
quit: () => process.exit(0),
getPath: which => {
if (which === 'userData') {
const { join } = require('path')
const { name } = require('./package.json')

switch (process.platform) {
case 'darwin':
return join(process.env.HOME, 'Library', 'Application Support', name)
case 'linux':
const home = process.env.XDG_CONFIG_HOME || require('expand-home-dir')('~/.config')
return join(home, name)
case 'windows':
return join(process.env.APPDATA, name)
}
} else {
throw new Error(`Unsupported getPath request ${which}`)
}
}
}

if (noHeadless !== true && isRunningHeadless) {
//
// HEADLESS MODE
//
Expand Down Expand Up @@ -83,6 +145,39 @@ function createWindow(noHeadless, executeThisArgvPlease, subwindowPlease, subwin
executeThisArgvPlease = undefined
}
}
} /* initHeadless */

/**
* Should our BrowerWindows have a window frame?
*
*/
const useWindowFrame = true

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow


/**
* Were we spawned in headless mode?
*
*/
const fshShell = process.argv.find(arg => arg === 'shell')
const isRunningHeadless = process.argv.find(arg => arg === '--fsh-headless') && !fshShell
if (!isRunningHeadless) {
initGraphics()
} else {
initHeadless()
}

//try {
// if (isRunningHeadless && app.dock) app.dock.hide()
//} catch (e) {
//}
debug('isRunningHeadless %s', isRunningHeadless)

function createWindow(noHeadless, executeThisArgvPlease, subwindowPlease, subwindowPrefs) {
debug('createWindow')

if (subwindowPrefs && subwindowPrefs.bringYourOwnWindow) {
return subwindowPrefs.bringYourOwnWindow()
Expand Down Expand Up @@ -186,6 +281,7 @@ function createWindow(noHeadless, executeThisArgvPlease, subwindowPlease, subwin
slashes: true
}))

debug('install menus')
require('./menu').install(app, electron.Menu, createWindow)

// Open the DevTools.
Expand Down Expand Up @@ -213,6 +309,7 @@ function createWindow(noHeadless, executeThisArgvPlease, subwindowPlease, subwin
// as they are on macOS. oh well! this is why the screenshot
// plugin has to pollute main.js
//
debug('ipc registration')
ipcMain.on('capture-page-to-clipboard', (event, contentsId, rect) => {
try {
const { clipboard, nativeImage, webContents } = electron
Expand Down Expand Up @@ -250,39 +347,8 @@ function createWindow(noHeadless, executeThisArgvPlease, subwindowPlease, subwin
switch (message.operation) {
}
})
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)

if (process.env.RUNNING_SHELL_TEST) {
app.on('before-quit', function() {
const config = { tempDirectory: require('path').join(__dirname, '../tests/.nyc_output') },
nyc = new (require('nyc'))(config) // create the nyc instance
nyc.createTempDirectory() // in case we are the first to the line
nyc.writeCoverageFile() // write out the coverage data for the renderer code

mainWindow.webContents.send('/coverage/dump', config)
})
debug('createWindow done')
}

// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin' || isRunningHeadless) { // if we're running headless, then quit on window closed, no matter which platform we're on
app.quit()
}
})

app.on('activate', function () {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow()
}
})

debug('all done here, the rest is async')
4 changes: 2 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"main": "main.js",
"scripts": {
"start": "electron .",
"postinstall": "./bin/seticon.sh && cd plugins && npm install && cd .. && npm run build && npm run compile",
"postinstall": "cd plugins && npm install && cd .. && npm run build && npm run compile && ./bin/seticon.sh",
"build": "node ./bin/build.js",
"compile": "cd ../dist && npm install && ./compile.js",
"test": "cd ../tests && npm run test"
Expand All @@ -27,7 +27,7 @@
"url": "https://github.com/ibm-functions/shell/issues/new"
},
"devDependencies": {
"electron": "~2.0.2",
"electron": "~2.0.4",
"nyc": "^13.0.0"
},
"dependencies": {
Expand Down
20 changes: 15 additions & 5 deletions app/plugins/openwhisk-extensions/actions/let.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const minimist = require('yargs-parser'),
url = require('url'),
tmp = require('tmp'),
{ ANON_KEY, ANON_KEY_FQN, ANON_CODE, isAnonymousLet } = require('./let-core')(),
base_rp = require('request-promise'),
needle = require('needle'),
withRetry = require('promise-retry'),
expandHomeDir = require('expand-home-dir'),
beautify = require('js-beautify').js_beautify,
Expand All @@ -52,9 +52,19 @@ debug('finished loading modules')
* Mimic the request-promise functionality, but with retry
*
*/
const rp = opts => {
const rp = url => {
return withRetry((retry, iter) => {
return base_rp(Object.assign({ timeout: 10000 }, typeof opts === 'string' ? { url: opts } : opts))
const method = 'get'
const timeout = 10000

return needle(method,
url,
{
open_timeout: timeout,
read_timeout: timeout,
follow_max: 5
})
.then(_ => _.body)
.catch(err => {
const isNormalError = err && (err.statusCode === 400 || err.statusCode === 404 || err.statusCode === 409)
if (!isNormalError && (iter < 10)) {
Expand All @@ -68,7 +78,6 @@ const rp = opts => {
})
}


/**
* Take the output of url.parse, and determine whether it refers to a remote resource
*
Expand All @@ -86,7 +95,8 @@ const fetchRemote = (location, mimeType) => new Promise((resolve, reject) => {
const parsedUrl = url.parse(locationWithoutQuotes)
if (isRemote(parsedUrl)) {
// then fetch it
debug('fetching remote')
debug('fetching remote', locationWithoutQuotes)

return rp(locationWithoutQuotes).then(data => {
debug(`fetchRemote done`)
const extension = mimeType || parsedUrl.pathname.substring(parsedUrl.pathname.lastIndexOf('.'))
Expand Down
2 changes: 0 additions & 2 deletions app/plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
"parse-duration": "^0.1.1",
"promise-retry": "^1.1.1",
"properties-parser": "^0.3.1",
"request": "^2.87.0",
"request-promise": "^4.2.1",
"shelljs": "^0.8.2",
"tmp": "0.0.33"
}
Expand Down
2 changes: 1 addition & 1 deletion app/plugins/ui/commands/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const help = (usage, docs) => (_1, _2, _3, { ui, errors }) => {
}
}

debug('generated top-level usage model', topLevelUsage)
debug('generated top-level usage model')
throw new errors.usage(topLevelUsage)

} else {
Expand Down
Loading