Repository: Foundry376/Mailspring (language: javascript)

Issue:
Bug: Can launch minimized in Notification Area
I don't know if this is a bug or maybe a request for a new feature. 

I want Mailspring to launch at startup and minimized (in the background) to the notification area in Windows 10. At the moment it always starts open in my screen. I then have to click 'x' to send it to the notification area.

I've tried 'run minimized' in the properties of the shortcut but that doesn't work. I've also created a task in Task Scheduler to '\background' but still it doesn't stop it launching.

I may be missing something but it would be nice for it to go straight to the notification area at startup. 

Thanks for a great email client!

Running: Mailspring 1.7.6 (latest version)
Windows 10 Home





Discussion / hints:
Hello. Try "-background" in the properties of the shortcut startup.
I'm on Linux, but here I had the same problem and it only worked with this command in the auto-start shortcut (but with "--" before, on Windows only "-")
Thank you for replying but I've tried that and it didn't work for me. I've also tried "\background" but to no avail. Task scheduler too failed.

I **think** that the problem may be that if you set mailspring to run at Windows startup this overrides anything else that you might do.

 [**off topic!**] 
I eventually returned to emClient which was far quicker to update my inbox in mailspring (even after notifying me that there was a new email). It too had a problem with launching minimized but a google of their support forum solved this by unchecking the 'Run at system startup' in the program settings then put a bat file in the startup folder: 

cd "c:\Program Files (x86)\eM Client"
start /min MailClient.exe

Reboot, worked a treat! Maybe something like this would work with mailspring?
In Ubuntu 20.04 works for me on StarUp Applications

`mailspring -b %U`

Hope to help!
Hey folks! It looks like the `--background` / `-b` option doesn't help much on Windows... there doesn't seem to be a way to pass command line flags to the applications listed in `Task Manager > Startup`, which is what you'd need to do. I wonder if you could create a `cmd` / `bat` file of some sort that just launched Mailspring and passed the `--background` flag? I'm not much of a Windows user unfortunately.

If anyone has a better solution here I'd be happy to try to incorporate it into the app. I think similar to your eMClient example, you could do:

```
cd "~\AppData\Local\Mailspring"
start mailspring.exe --background
```
This `--background` simply doesn't work on Windows - when I execute above in the shell, it still didnt minimize.
This has nothing to do with Windows startup features (ofc there is a way to pass args to the startup entry on Windows)

The only way I found is to automate it via Autohotkey script:

```
Run, mailspring.exe
WinWaitActive, ahk_exe mailspring.exe
WinMinimize
```

This can be compiled to small exe and could be added to startup instead of mailspring itself. This can be easily replicated inside mailspring itself upon startup, although one may need to call WIN32 API directly.

Other way would be to actually start with hidden window (not minimized) and unhide it once user clicks tray icon.
Check my bug: https://github.com/Foundry376/Mailspring/issues/2231

This is a dead project and dead product unfortunately, and we need to find an alternative. Any suggestions?
This issue has been mentioned on **Mailspring Community**. There might be relevant details there:

https://community.getmailspring.com/t/run-as-minimized-on-startup/57/2

We are in the process of migrating issues to Discourse, which can better facilitate discussion and discovery, and so GitHub Issues can focus on issues that are confirmed and slated for resolution in the near term. [Learn more about the changes here.](https://community.getmailspring.com/t/mailspring-community-transition/38)

This issue appears to be related to one we've already migrated to Discourse:

https://community.getmailspring.com/t/run-as-minimized-on-startup/57

We're closing and locking the issue here as part of this migration. Rest assured, this doesn't mean the issue is being discarded or ignored. Please consider joining the Discourse community and continuing the discussion there.

We hope to see you on Discourse soon!

-The Mailspring Team

P.S. @majkinetor @paulhypno particularly, if you comment on that thread, I'll credit your migrated post(s) to you.

Fix patch:
diff --git a/app/src/app-env.ts b/app/src/app-env.ts
index 19824f0827..f553052f8a 100644
--- a/app/src/app-env.ts
+++ b/app/src/app-env.ts
@@ -558,12 +558,13 @@ export default class AppEnvConstructor {
   }
 
   restoreWindowDimensions() {
+    const settings = this.getLoadSettings();
     let dimensions = this.savedState.windowDimensions;
     if (!this.isValidDimensions(dimensions)) {
       dimensions = this.getDefaultWindowDimensions();
     }
     this.setWindowDimensions(dimensions);
-    if (dimensions.maximized && process.platform !== 'darwin') {
+    if (dimensions.maximized && !settings.initializeInBackground) {
       this.maximize();
     }
     if (dimensions.fullScreen) {


Test patch: