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

add option to choose whether atom rememebers your last windows and project folders - #9042

Closed
jordanbtucker wants to merge 3 commits into
atom:masterfrom
jordanbtucker:config-save-state
Closed

jordanbtucker wants to merge 3 commits into
atom:masterfrom
jordanbtucker:config-save-state

Conversation

@jordanbtucker

Copy link
Copy Markdown
Contributor

A new Core Setting: Restore Previous Windows On Start

Enabled by default, so it's backward compatible.

Fixes #6605

@thedaniel

Copy link
Copy Markdown
Contributor

👎 on loading config twice. Is there a way you could achieve the same goal without this? We have to be tediously strict about counting milliseconds on window load.

@thedaniel

Copy link
Copy Markdown
Contributor

Also, what's your use case here? I'm personally not convinced this is a common enough need to warrant another checkbox in core settings. cc @atom/feedback

@winstliu

winstliu commented Oct 4, 2015

Copy link
Copy Markdown
Contributor

👎 on loading config twice.

Ditto. My window load time is long enough as it is 😉.

As for use case, a lot of people have been asking for this in #6605.

@m1ga

m1ga commented Oct 4, 2015

Copy link
Copy Markdown

@jordanbtucker wouldn't it be enough just to save an empty state when closing atom and the setting is switched on. So you won't need to change to opening part at all.

@jordanbtucker

Copy link
Copy Markdown
Contributor Author

@thedaniel @50Wliu I totally agree with you on the loading config issue, but I haven't come up with a better solution, and config option is what 99% of the users wanted in their comments. I'm okay with removing the checkbox and making it config file only.

I'm against having a command that disables saving on exit that you have to call every time. This should be a set-and-forget setting.

Honestly, I feel this is on par with the "open empty editor" config setting. Seems odd to give that a checkbox, but not this one.

Please leave any suggestions to improve this. I'll be so glad when this is fixed.

@m1ga

m1ga commented Oct 4, 2015

Copy link
Copy Markdown

I'm against having a command that disables saving on exit that you have to call every time. This should be a set-and-forget setting.

I meant in your example you are returning out of the save function when your new setting is switched on and you have the same for the opening function. If you just change the saving part to save [] if your setting is switched on you don't need to do any changes on the loading part (less code to test, less side-effects). saveState/loadState do their work normally but you end up with a clean session every time.

@jordanbtucker

Copy link
Copy Markdown
Contributor Author

@m1ga I hadn't responded to your comment yet. With my method, you can modify the config file with the editor closed and it will honor your setting when it starts. If we go with your method, the option should be changed to "Save Your Previously Opened Windows" or something like that. Or maybe I'm just nitpicking. I'm not opposed to your method, but I just want everyone to be aware before we decide which way to go.

One thing that needs to be said is that your method would eliminate the extra load time if I move all of the config logic into the saveState function.

@samis

samis commented Oct 6, 2015

Copy link
Copy Markdown

I am personally fine with it not being a checkbox. However, there should be some way that the user can find out about the option if they want to. Perhaps the main settings page links to a 'Configuration Reference' saying it contains additional options not displayed here?

@jordanbtucker

Copy link
Copy Markdown
Contributor Author

I removed the checkbox and it now only loads the config file when saving. I'm not sure the best way to use a config option that doesn't have a UI. Do I set the default in the code like I did on line 438? What other examples are there of settings that do not have a UI?

Comment thread spec/integration/startup-spec.coffee Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work adding this integration test. The assertion doesn't seem right to me though; this is saying that there should be two Atom windows, each with no project paths. If we've chosen to not restore the session though, shouldn't there just be one Atom window with no project paths?

@maxbrunsfeld

Copy link
Copy Markdown
Contributor

@jordanbtucker Thanks for diving in and taking a look at this. I'm 👍 on this change; a number of people have asked for it. I agree w/ @thedaniel that we don't need to add UI for it yet. I left some small pieces of feedback above.

@jordanbtucker

Copy link
Copy Markdown
Contributor Author

Good catch on the integration test. I can't actually get integration tests to work on my Ubuntu box, but hopefully the test is correct now.

Comment thread src/browser/atom-application.coffee Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, I believe this will throw an exception when the user's config is invalid, because it will try to reference atom.notifications, which won't be defined in the browser process. If we're going to use the Config class here, I think we'll need to remove its dependency on the NotificationManager.

That code is also going to change a little bit when #8968 lands. Maybe instead of creating the notification inside of Config, we should add a method ::onDidFailToLoad(callback), and we can use that method in the renderer process to set up a callback that creates the notification.

@docrinehart

Copy link
Copy Markdown

+1 Bump! I'd really like to have Atom open clean every time and stop saving my session when I close it

@maxbrunsfeld

Copy link
Copy Markdown
Contributor

@jordanbtucker Are you still interested in doing this? It has actually become a little bit easier since we last talked, because of #9990. We are now using the Config class in the browser process for other purposes.

@jordanbtucker

Copy link
Copy Markdown
Contributor Author

Sure! I'll take a look at #9990 and start working on this again. Thanks.

@docrinehart

Copy link
Copy Markdown

@jordanbtucker Yay! You rock! And thanks for the quick reply and review @maxbrunsfeld

@jordanbtucker

Copy link
Copy Markdown
Contributor Author

@maxbrunsfeld I looked through #9990, and the relevant code looks almost identical to what I've already written. Sorry if I'm missing something, but what do I still need to change to get this merged?

@maxbrunsfeld

Copy link
Copy Markdown
Contributor

@jordanbtucker We just need to avoid loading the config twice in the browser process. Currently, it's loaded inside of auto-update-manager, so I think we need to move that code out into atom-application, passing the config into the AutoUpdateManager.

@jacobgraf

Copy link
Copy Markdown

Excited for this! Personally, I want a clean slate every time Iaunch Atom.

@mikechabot

Copy link
Copy Markdown

+1 Chomping at the bit for this change....needing to always close a mass of files on every startup is super not fun.

@mehcode

mehcode commented Mar 8, 2016

Copy link
Copy Markdown
Contributor

You can shim this in atom right now with project-plus and the following line in init.coffee (as long as you only use one atom window):

atom.commands.dispatch(atom.views.getView(atom.workspace), 'project-plus:close')

@jordanbtucker

Copy link
Copy Markdown
Contributor Author

@maxbrunsfeld I made some changes that I think satisfy your requirements. Please take a look and let me know. Thanks.

@lee-dohm lee-dohm added the atom label Mar 14, 2016
@lee-dohm

Copy link
Copy Markdown
Contributor

@jordanbtucker Max is on parental leave currently. I've added this to the queue to review but I don't have an ETA on when someone will be able to get to it.

@as-cii

as-cii commented Mar 29, 2016

Copy link
Copy Markdown
Contributor

Thanks for the patience and the hard work on this, @jordanbtucker. ✨

I have started reviewing this and I think right now we may not be handling the scenario where the restorePreviousWindowsOnStart setting is set to false outside of Atom (e.g. nano ~/.atom/config.cson). In that case, we'd still reopen the previous windows even if the configuration explicitly states we shouldn't.

So, what do you think about moving that if clause down to the loadState method? Basically, we'd always store the currently open windows, but we open them on the next launch only if the configuration states so. If we do that, we might also want to change the integration test to reflect this behavior; in particular, we could move this piece of code down, so that it gets executed before opening the second instance:

configPath = path.join(atomHome, 'config.cson')
config = CSON.readFileSync(configPath)
config['*'].core = {restorePreviousWindowsOnStart: false}
CSON.writeFileSync(configPath, config)

What do you think? /cc: @atom/core

@jacobgraf

Copy link
Copy Markdown

I don't know much about the technicalities of this, but based on your comments, why does this have to be so difficult? Why save the previously opened windows at all unless explicitly told to do so? From the people I have talked to, none of them want the windows saved when they fully close the editor. Frankly, it's a pain in the butt that it does that currently.

@mnquintana

Copy link
Copy Markdown
Contributor

@jacobgraf This was a highly requested feature by the community: #1603

FWIW, Sublime also remembers its open windows and files by default, so this is actually expected behavior for those coming from Sublime, and is also consistent with the defaults of native document-based OS X apps.

Once this PR lands then you'll be able to disable this.

@jordanbtucker

Copy link
Copy Markdown
Contributor Author

@as-cii Thanks for the feedback. You make a good point.

I've pushed the changes you suggested.

@jordanbtucker

Copy link
Copy Markdown
Contributor Author

One thing I want to make clear to everyone (in case there is any confusion). This only applies to opening Atom without a path argument.

If your config file looks like this:

'*'
  core:
    restorePreviousWindowsOnStart: false

Then the following command will not open the previous session:

$ atom    # will not restore previous session

However, the following commands will restore the previous session for that directory.

# this will restore the state for this directory (if it was
# recently opened) regardless of restorePreviousWindowsOnStart
$ atom /home/me/project

# this will restore the state for the parent directory (if it was recently
# opened) of this file regardless of restorePreviousWindowsOnStart
$ atom /home/me/project/package.json

configPath = path.join(atomHome, 'config.cson')
config = CSON.readFileSync(configPath)
config['*'].core = {restorePreviousWindowsOnStart: false}
CSON.writeFileSync(configPath, config)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about moving this section before this LOC? This way we make sure that the setting works independently of when we change the configuration.

@as-cii

as-cii commented Mar 30, 2016

Copy link
Copy Markdown
Contributor

Just left one comment, I think we can :shipit: after addressing it and specs are 💚. 🎆

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.