From b71a9bb010b98befc1e1bfbb832ea29dd6181c74 Mon Sep 17 00:00:00 2001 From: Anatoli Date: Tue, 7 Mar 2017 04:56:10 -0300 Subject: [PATCH] Make an option to *always* restore the last session, no matter how Atom is invoked (#9643) --- src/config-schema.js | 5 +++++ src/main-process/atom-application.coffee | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/config-schema.js b/src/config-schema.js index 41b5ecbb6..1d41aeb9d 100644 --- a/src/config-schema.js +++ b/src/config-schema.js @@ -262,6 +262,11 @@ const configSchema = { type: 'boolean', default: true }, + restorePreviousWindowsOnStartAlways: { + description: 'When checked *ALWAYS* restores the last state of all Atom windows.', + type: 'boolean', + default: false + }, reopenProjectMenuCount: { description: 'How many recent projects to show in the Reopen Project menu.', type: 'integer', diff --git a/src/main-process/atom-application.coffee b/src/main-process/atom-application.coffee index 93e9e3395..27f337cfe 100644 --- a/src/main-process/atom-application.coffee +++ b/src/main-process/atom-application.coffee @@ -111,6 +111,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.restorePreviousWindowsOnStartAlways') + @loadState(clone(options)) @openWithOptions(options) else @loadState(options) or @openPath(options) @@ -558,6 +560,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 @@ -598,8 +601,7 @@ class AtomApplication @storageFolder.storeSync('application.json', states) loadState: (options) -> - restorePreviousState = @config.get('core.restorePreviousWindowsOnStart') ? true - if restorePreviousState and (states = @storageFolder.load('application.json'))?.length > 0 + if (@config.get('core.restorePreviousWindowsOnStartAlways') or @config.get('core.restorePreviousWindowsOnStart')) and (states = @storageFolder.load('application.json'))?.length > 0 for state in states @openWithOptions(Object.assign(options, { initialPaths: state.initialPaths @@ -812,3 +814,10 @@ class AtomApplication args.push("--resource-path=#{@resourcePath}") app.relaunch({args}) app.quit() + + clone = (obj) -> + return obj if obj is null or typeof (obj) isnt "object" + temp = new obj.constructor() + for key of obj + temp[key] = clone(obj[key]) + temp