Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #13947 from anatoli26/master
Browse files Browse the repository at this point in the history
Make an option to always restore the last session
  • Loading branch information
Bryant Ung committed May 8, 2017
2 parents f9117fc + a6e6076 commit f464bb3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions spec/main-process/atom-application.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ describe('AtomApplication', function () {
assert.deepEqual(await getTreeViewRootDirectories(app2Window2), [tempDirPath2])
})

it('does not reopen any previously opened windows when launched with no path and `core.restorePreviousWindowsOnStart` is false', async function () {
it('does not reopen any previously opened windows when launched with no path and `core.restorePreviousWindowsOnStart` is no', async function () {
const atomApplication1 = buildAtomApplication()
const app1Window1 = atomApplication1.launch(parseCommandLine([makeTempDir()]))
await focusWindow(app1Window1)
Expand All @@ -379,7 +379,7 @@ describe('AtomApplication', function () {
const configPath = path.join(process.env.ATOM_HOME, 'config.cson')
const config = season.readFileSync(configPath)
if (!config['*'].core) config['*'].core = {}
config['*'].core.restorePreviousWindowsOnStart = false
config['*'].core.restorePreviousWindowsOnStart = 'no'
season.writeFileSync(configPath, config)

const atomApplication2 = buildAtomApplication()
Expand Down
7 changes: 4 additions & 3 deletions src/config-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,10 @@ const configSchema = {
default: true
},
restorePreviousWindowsOnStart: {
description: 'When checked restores the last state of all Atom windows when started from the icon or `atom` by itself from the command line; otherwise a blank environment is loaded.',
type: 'boolean',
default: true
type: 'string',
enum: ['no', 'yes', 'always'],
default: 'yes',
description: "When selected 'no', a blank environment is loaded. When selected 'yes' and Atom is started from the icon or `atom` by itself from the command line, restores the last state of all Atom windows; otherwise a blank environment is loaded. When selected 'always', restores the last state of all Atom windows always, no matter how Atom is started."
},
reopenProjectMenuCount: {
description: 'How many recent projects to show in the Reopen Project menu.',
Expand Down
6 changes: 4 additions & 2 deletions src/main-process/atom-application.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class AtomApplication

launch: (options) ->
if options.pathsToOpen?.length > 0 or options.urlsToOpen?.length > 0 or options.test or options.benchmark or options.benchmarkTest
if @config.get('core.restorePreviousWindowsOnStart') is 'always'
@loadState(_.deepClone(options))
@openWithOptions(options)
else
@loadState(options) or @openPath(options)
Expand Down Expand Up @@ -575,6 +577,7 @@ class AtomApplication
windowDimensions ?= @getDimensionsForNewWindow()
openedWindow = new AtomWindow(this, @fileRecoveryService, {initialPaths, locationsToOpen, windowInitializationScript, resourcePath, devMode, safeMode, windowDimensions, profileStartup, clearWindowState, env})
openedWindow.focus()
@lastFocusedWindow = openedWindow

if pidToKillWhenClosed?
@pidsToOpenWindows[pidToKillWhenClosed] = openedWindow
Expand Down Expand Up @@ -616,8 +619,7 @@ class AtomApplication
@emit('application:did-save-state')

loadState: (options) ->
restorePreviousState = @config.get('core.restorePreviousWindowsOnStart') ? true
if restorePreviousState and (states = @storageFolder.load('application.json'))?.length > 0
if (@config.get('core.restorePreviousWindowsOnStart') in ['yes', 'always']) and (states = @storageFolder.load('application.json'))?.length > 0
for state in states
@openWithOptions(Object.assign(options, {
initialPaths: state.initialPaths
Expand Down

0 comments on commit f464bb3

Please sign in to comment.