From f8ab3c0e83eb47eea2b1c9a1aab4e3010bcff052 Mon Sep 17 00:00:00 2001
From: Gabriel Handford <gabrielh@gmail.com>
Date: Tue, 30 Aug 2016 12:50:05 -0700
Subject: [PATCH] Tweak show window rule again (#4076)

---
 desktop/app/main-window.js | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/desktop/app/main-window.js b/desktop/app/main-window.js
index 629e820cf16d..da2f5ae12121 100644
--- a/desktop/app/main-window.js
+++ b/desktop/app/main-window.js
@@ -33,15 +33,21 @@ export default function () {
     mainWindow.window.setPosition(forceMainWindowPosition.x, forceMainWindowPosition.y)
   }
 
+  const openedAtLogin = app.getLoginItemSettings().wasOpenedAtLogin
   const isRestore = getenv.boolish('KEYBASE_RESTORE_UI', false) || app.getLoginItemSettings().restoreState
   const openHidden = (getenv.string('KEYBASE_START_UI', '') === 'hideWindow') || app.getLoginItemSettings().wasOpenedAsHidden
+  console.log('Opened at login:', openedAtLogin)
+  console.log('Is restore:', isRestore)
+  console.log('Open hidden:', openHidden)
 
-  // We show the main window on startup if:
-  //  - We are restoring UI and the window was previously visible (in app state)
-  //  - and, we are not set to open hidden
-  const showMainWindow = (isRestore && !appState.state.windowHidden) && !openHidden
-  console.log('Show main window: %s', showMainWindow)
-  if (showMainWindow) {
+  // Don't show main window:
+  // - If we are set to open hidden,
+  // - or, if we are restoring and window was hidden
+  // - or, if we were opened from login (but not restoring)
+  const hideMainWindow = openHidden || (isRestore && appState.state.windowHidden) || (openedAtLogin && !isRestore)
+
+  console.log('Hide main window:', hideMainWindow)
+  if (!hideMainWindow) {
     // On Windows we can try showing before Windows is ready
     // This will result in a dropped .show request
     // We add a listener to `did-finish-load` so we can show it when
@@ -52,11 +58,11 @@ export default function () {
     })
   }
 
-  // Hide the dock icon if:
-  // - We are not restoring
-  // - or, we are restoring and dock was hidden
-  // - or, we are set to open hidden
-  const shouldHideDockIcon = !isRestore || (isRestore && appState.state.dockHidden) || openHidden
+  // Don't show dock:
+  // - If we are set to open hidden,
+  // - or, if we are restoring and dock was hidden
+  // - or, if we were opened from login (but not restoring)
+  const shouldHideDockIcon = openHidden || (isRestore && appState.state.dockHidden) || (openedAtLogin && !isRestore)
   console.log('Hide dock icon: %s', shouldHideDockIcon)
   if (shouldHideDockIcon) {
     hideDockIcon()