Skip to content

Linux: Launching app again while minimized doesn't restore the window #15

Closed

Description

@khaira777

Description

On Linux/Ubuntu, when the app is minimized to the system tray, launching the app again (running the executable) does not bring the existing window to the front. The app stays minimized. A second launch appears to start a new instance instead of restoring the first one.

Steps to Reproduce

  1. Launch Flo Cafe on Linux/Ubuntu
  2. Close the window — app minimizes to system tray
  3. Run the app executable again
  4. The existing window stays minimized — nothing comes to front

Expected Behavior

Launching the app again should detect the running instance and restore/focus the existing window.

Current Behavior

The window stays minimized. It seems like the second instance either starts a new process or the second-instance event fires but restore() + focus() don't work on Linux.

Investigation Notes

The single-instance lock is implemented in main/index.ts:

gotSingleInstanceLock = app.requestSingleInstanceLock();
if (!gotSingleInstanceLock) {
  app.quit();
}

if (gotSingleInstanceLock) {
  app.on('second-instance', () => {
    if (mainWindow) {
      if (mainWindow.isMinimized()) mainWindow.restore();
      mainWindow.show();
      mainWindow.focus();
    }
  });
}

Known Electron/Linux issues:

  • BrowserWindow.restore() may not work on some Linux compositors (especially when minimized to tray via minimize() rather than hide())
  • focus() may be blocked by the window manager — need to use mainWindow.setAlwaysOnTop(true); mainWindow.setAlwaysOnTop(false) or call app.focus() as a workaround
  • When running unpacked (not installed via AppImage/deb), the single-instance lock file path may differ, causing a race condition

Possible fixes:

  • On Linux, use app.focus() in the second-instance handler in addition to restore()/focus()
  • Alternatively, destroy and recreate the window on second-instance if restore fails
  • Consider using minimizeToTray pattern (hide instead of minimize) so restore() is more reliable

Environment

  • OS: Linux/Ubuntu (unpacked from GitHub Actions build, not installed)
  • Electron system tray via Tray + Menu
  • Window close is intercepted to minimize on Linux

Activity

  1. added theissue type on Jul 6, 2026
  2. changed the issue type fromtoon Jul 6, 2026
  3. khaira777 commented on Jul 10, 2026

    @khaira777
    ContributorAuthor

    This issue was caused by a custom PID lock implemented for Linux that bypassed Electron's native requestSingleInstanceLock(). Because the custom lock forcefully quit the second instance instead of using Electron's IPC, the primary instance never received the second-instance event to restore the window. We removed the redundant custom lock (since userData was already correctly hardcoded for AppImage stability) and relied entirely on the native lock. We also added a Linux-specific focus workaround (setAlwaysOnTop) to overcome window manager focus-stealing prevention. Fixed via PR #73.

  4. added a commit that references this issue on Jul 11, 2026
    0d3cc94
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issue

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions