AtomEnvironment Essential

Atom global for dealing with packages, themes, menus, and the window.

An instance of this class is always available as the atom global.

Properties

::clipboard

A Clipboard instance

::deserializers

A DeserializerManager instance

::views

A ViewRegistry instance

::notifications

A NotificationManager instance

::config

A Config instance

::keymaps

A KeymapManager instance

::tooltips

A TooltipManager instance

::commands

A CommandRegistry instance

::grammars

A GrammarRegistry instance

::styles

A StyleManager instance

::packages

A PackageManager instance

::themes

A ThemeManager instance

::menu

A MenuManager instance

::contextMenu

A ContextMenuManager instance

::project

A Project instance

::textEditors

A TextEditorRegistry instance

::workspace

A Workspace instance

::history

A HistoryManager instance

Event Subscription

This section only has Extended methods.

Extended Methods

::onDidBeep(callback)

Invoke the given callback whenever ::beep is called.

Argument Description

callback

Function to be called whenever ::beep is called.

Return values

Returns a Disposable on which .dispose() can be called to unsubscribe.

::onWillThrowError(callback)

Invoke the given callback when there is an unhandled error, but before the devtools pop open

Argument Description

callback

Function to be called whenever there is an unhandled error

event

Object

originalError

Object the original error object

message

String the original error object

url

String Url to the file where the error originated.

line

Number

column

Number

preventDefault

Function call this to avoid popping up the dev tools.

Return values

Returns a Disposable on which .dispose() can be called to unsubscribe.

::onDidThrowError(callback)

Invoke the given callback whenever there is an unhandled error.

Argument Description

callback

Function to be called whenever there is an unhandled error

event

Object

originalError

Object the original error object

message

String the original error object

url

String Url to the file where the error originated.

line

Number

column

Number

Return values

Returns a Disposable on which .dispose() can be called to unsubscribe.

::whenShellEnvironmentLoaded(callback)

Invoke the given callback as soon as the shell environment is loaded (or immediately if it was already loaded).

Argument Description

callback

Function to be called whenever there is an unhandled error

Atom Details

::inDevMode()

Return values

Returns a Boolean that is true if the current window is in development mode.

::inSafeMode()

Return values

Returns a Boolean that is true if the current window is in safe mode.

::inSpecMode()

Return values

Returns a Boolean that is true if the current window is running specs.

::getAppName()

Get the full name of this Atom release (e.g. “Atom”, “Atom Beta”)

Return values

Returns the app name String.

::getVersion()

Get the version of the Atom application.

Return values

Returns the version text String.

::getReleaseChannel()

Gets the release channel of the Atom application.

Return values

Returns the release channel as a String. Will return a specific release channel name like ‘beta’ or ‘nightly’ if one is found in the Atom version or ‘stable’ otherwise.

::isReleasedVersion()

Return values

Returns a Boolean that is true if the current version is an official release.

::getWindowLoadTime()

Get the time taken to completely load the current window.

This time include things like loading and activating packages, creating DOM elements for the editor, and reading the config.

Return values

Returns the Number of milliseconds taken to load the window or null if the window hasn’t finished loading yet.

::getStartupMarkers()

Get the all the markers with the information about startup time.

Return values

Returns an array of timing markers. Each timing is an object with two keys:

  • label: string
  • time: Time since the startTime (in milliseconds).

::getLoadSettings()

Get the load settings for the current window.

Return values

Returns an Object containing all the load setting key/value pairs.

Managing The Atom Window

::open(params)

Open a new Atom window using the given options.

Calling this method without an options parameter will open a prompt to pick a file/folder to open in the new window.

Argument Description

params

An Object with the following keys:

pathsToOpen

An Array of String paths to open.

newWindow

A Boolean, true to always open a new window instead of reusing existing windows depending on the paths to open.

devMode

A Boolean, true to open the window in development mode. Development mode loads the Atom source from the locally cloned repository and also loads all the packages in ~/.atom/dev/packages

safeMode

A Boolean, true to open the window in safe mode. Safe mode prevents all packages installed to ~/.atom/packages from loading.

::close()

Close the current window.

::getSize()

Get the size of current window.

Return values

Returns an Object in the format {width: 1000, height: 700}

::setSize(width, height)

Set the size of current window.

Argument Description

width

The Number of pixels.

height

The Number of pixels.

::getPosition()

Get the position of current window.

Return values

Returns an Object in the format {x: 10, y: 20}

::setPosition(x, y)

Set the position of current window.

Argument Description

x

The Number of pixels.

y

The Number of pixels.

Extended Methods

::pickFolder(callback)

Prompt the user to select one or more folders.

Argument Description

callback

A Function to call once the user has confirmed the selection.

paths

An Array of String paths that the user selected, or null if the user dismissed the dialog.

::getCurrentWindow()

Get the current window

::center()

Move current window to the center of the screen.

::focus()

Focus the current window.

::show()

Show the current window.

::hide()

Hide the current window.

::reload()

Reload the current window.

::restartApplication()

Relaunch the entire application.

::isMaximized()

Return values

Returns a Boolean that is true if the current window is maximized.

::isFullScreen()

Return values

Returns a Boolean that is true if the current window is in full screen mode.

::setFullScreen()

Set the full screen state of the current window.

::toggleFullScreen()

Toggle the full screen state of the current window.

Messaging the User

::beep()

Visually and audibly trigger a beep.

::confirm(options, callback)

A flexible way to open a dialog akin to an alert dialog.

While both async and sync versions are provided, it is recommended to use the async version such that the renderer process is not blocked while the dialog box is open.

The async version accepts the same options as Electron’s dialog.showMessageBox. For convenience, it sets type to 'info' and normalizeAccessKeys to true by default.

If the dialog is closed (via Esc key or X in the top corner) without selecting a button the first button will be clicked unless a “Cancel” or “No” button is provided.

Argument Description

options

An options Object. If the callback argument is also supplied, see the documentation at https://electronjs.org/docs/api/dialog#dialogshowmessageboxbrowserwindow-options-callback for the list of available options. Otherwise, only the following keys are accepted:

message

The String message to display.

detailedMessage

optional

The String detailed message to display.

buttons

optional

Either an Array of Strings or an Object where keys are button names and the values are callback Functions to invoke when clicked.

callback

optional

A Function that will be called with the index of the chosen option. If a callback is supplied, the dialog will be non-blocking. This argument is recommended.

Return values

Returns the chosen button index Number if the buttons option is an array or the return value of the callback if the buttons option is an object. If a callback function is supplied, returns undefined.

Managing the Dev Tools

This section only has Extended methods.

Extended Methods

::openDevTools()

Open the dev tools for the current window.

Return values

Returns a Promise that resolves when the DevTools have been opened.

::toggleDevTools()

Toggle the visibility of the dev tools for the current window.

Return values

Returns a Promise that resolves when the DevTools have been opened or closed.

::executeJavaScriptInDevTools()

Execute code in dev tools.