CARTAvis / carta

To CARTA users, this repo holds the CARTA release packages. Please use this repo to log bugs and feature requests. These will be triaged by the development team and prioritised as necessary in the development cycles.
19 stars 0 forks source link

macOS electron app window is too small when there is an external monitor #157

Closed kswang1029 closed 1 year ago

kswang1029 commented 1 year ago

Describe the bug This is an issue reported by users twice via the Helpdesk. Occasionally, when we launch the electron app, there is no application window showing up. The root cause is for some reason the window state configuration went wrong like the following example:

~/Library/Application Support/CARTA-v3.0.0-beta.3/windowStates.json

CbP2FU7GRqRZIPkKxj7L2uJIM_yXYVP0cQ

The two users are all with an external monitor attached to their Mac.

It would be good if the electron app starting script can check for such situation and overwrite the config if necessary to avoid this "no app window" issue.

To Reproduce Unknown so far.

Expected behavior Have a guard to prevent the issue happening.

Platform info (please complete the following information):

kswang1029 commented 1 year ago

@ajm-asiaa would you be able to apply a check and fix in the electron app script?

ajm-ska commented 1 year ago

I am unable to reproduce this issue myself, but we can try the following attempted fix and see if the problem ever gets reported again:

Add minWidth and minHeight variables to the CARTA Electron main.js file.

    const newWindow = new BrowserWindow({
    width: mainWindowState.width,
    height: mainWindowState.height,
    minWidth: 640,
    minHeight: 480,
    x: x,
    y: y,
    show: false
    });

It prevents you from resizing the window any smaller than 640x480 pixels by hand. I am hoping that it would also prevent whatever process automatically resizes the window to the size of a few pixels.

I tried to test it by modifying the main.js and windowStates.json files in order to manually reduce the window size to a few pixels. Unfortunately, the window still becomes a few pixels in size. But I assume that happens because I am forcing the size modification by manually changing the values by hand. Hopefully, it would not be able to occur in whatever process seemingly automatically reduces the size.

ajm-ska commented 1 year ago

I added the fix to the carta-package repo It will be implemented in any future CARTA Electron releases.

kswang1029 commented 1 year ago

wonder if this works using ternary operator?

width: mainWindowState.width > 640 ? mainWindowState.width : 640,

could you give it a try and manually modify windowStates.json to emulate the issue and launch CARTA to see if it fixes the window size?

ajm-ska commented 1 year ago

@kswang1029 You are right! It works! I modified main.js to

    const newWindow = new BrowserWindow({
    width: mainWindowState.width > 640 ? mainWindowState.width : 640,
    height: mainWindowState.height > 480 ? mainWindowState.height : 640,
    x: x,
    y: y,
    show: false
  });

Then I modified the windowStates.json to

        "dimensions": {
          "width": 1,
          "height": 29
        },

When I opened CARTA, the window was 640x480!

If I close CARTA when the window is bigger than 640x480, the WindowStateManager still behaves properly and remembers the previous size and position. If I manually drag the CARTA window smaller than 640x480, then close and re-open, the window becomes 640x480.

So this is a better solution that seems to be working!

Hang on, I'll do a proper PR now.