Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desktop: fix window dimensions and position when the application start #2514

Merged
merged 5 commits into from
Feb 27, 2020
Merged

Desktop: fix window dimensions and position when the application start #2514

merged 5 commits into from
Feb 27, 2020

Conversation

daukadolt
Copy link
Contributor

Addresses #2476

  1. BrowserWindow set up to have a minimum width and height of 100 px. This is addressed by setting minWidth, minHeight properties of BrowserWindow.
  2. Centered position on a primary display is enforced if BrowserWindow rectangle doesn't match any display.

Electron app doesn't allow scaling any lower than minHeight and minWidth, which I've checked. However, I could not enforce the application to have a position outside my only display both through setting x, y manually here or through BrowserWindow.setPosition(). Hence, I could not check my solution on this one.

I initially wanted to discuss my approach (like setting arbitrary 100px for minHeight/minWidth) in the issue, but (sorry if I'm wrong) I thought that since pull request would either way be reviewed discussion could be set here.

Looking forward for comments.

@tessus tessus linked an issue Feb 17, 2020 that may be closed by this pull request
@tessus tessus added the desktop All desktop platforms label Feb 17, 2020
Copy link
Collaborator

@tessus tessus left a comment

Choose a reason for hiding this comment

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

I think we could try to corrupt the window-state-prod.json on purpose. On macOS, this file is in ~/Library/Application Support/Joplin. Not sure about Linux and Windows.

@tessus
Copy link
Collaborator

tessus commented Feb 17, 2020

This is a great start, but to bring it to the next level, I'd suggest the following: make the default size and position dependent of the screen size. e.g. that it takes 80%-85% of the width and height and that it is centered. This is just an idea and not necessary.
This is just a workaround for people who run into the weird problem of a 1x1 sized window or a window off screen (due to multiple monitors).

@gasolin
Copy link
Contributor

gasolin commented Feb 18, 2020

set minWidth/minHeight also solves the user occasionally scale the window to a minimum line issue.

https://discourse.joplinapp.org/t/installing-joplin-1-0-174-on-macos-catalina-results-in-no-visible-window/4425/10

@daukadolt I suggest to set the minWidth: 480, minHeight: 320 to keep the Joplin window barely workable

@daukadolt
Copy link
Contributor Author

daukadolt commented Feb 20, 2020

@tessus I've made default width and height dependent on the primary screen, since that is the screen that the app is spawned on for the first time. However, Travis build has failed and I wonder why. After a quick run through the logs and repo it seems that the first line intended for eslint is the culprit, but how come did the master repo build successfully? Or my commit somehow messes with it. And why is the build performed on laurent22/master instead of my master branch?

Additionally, I tried playing around with window-state.json file, but it's BrowserWindow constructor that is safeguarding against spawning outside any display, I believe.
electron-window-state package too has some safeguards against spawning outside any window, but I've even modified it's code in node_modules by hardcoding return of 4000 here for x and y, which is why I believe that BrowserWindow blocks spawning outside window.

@tessus
Copy link
Collaborator

tessus commented Feb 20, 2020

Right now all builds fail in Travis. We have to fix that. So don't worry about it right now.

I'll have a look at your new commit either tonight or tomorrow.

@daukadolt
Copy link
Contributor Author

@gasolin I like your suggestion, I will commit updated minimum dimensions after all other issues will be resolved

@tessus
Copy link
Collaborator

tessus commented Feb 22, 2020

Please rebase, so that the conflicts are resolved. This will also solve the Travis builds. The build process has changed, so everything should be fine now. Please have a look at the updated BUILD.md file.

daukadolt added 3 commits February 23, 2020 18:21
Hardcoded minimum width and height of 100 px.

Signed-off-by: daukadolt <daulet.amirkhanov.official@gmail.com>
Set Electron window at the center of primaryDisplay if BrowserWindow is not on any displays.

Signed-off-by: daukadolt <daulet.amirkhanov.official@gmail.com>
Set Electron window defaultWidth, defaultHeight to 80% of primary display workArea width, height, respectively.

Signed-off-by: daukadolt <daulet.amirkhanov.official@gmail.com>
@daukadolt
Copy link
Contributor Author

Please rebase, so that the conflicts are resolved. This will also solve the Travis builds. The build process has changed, so everything should be fine now. Please have a look at the updated BUILD.md file.

Got it. I've checked the updated test steps. What do you think about @gasolin 's suggestion on minWidth/minHeight? I can change them if everything else is fine.

Hotfix of a typo that calculates Electron app's default height at first run using primary screen's width, not height.

Signed-off-by: daukadolt <daulet.amirkhanov.official@gmail.com>
@daukadolt
Copy link
Contributor Author

Found a typo in my code, sorry for the sloppiness. However, here again, BrowserWindow safeguards against too big of a height. Doing 2*currentWorkArea.heightstill renders app within my mac's desktop, not going any lower than the dock and not higher than the menu bar. Tried resizing dock as well.

@daukadolt
Copy link
Contributor Author

@PackElend could you please tag this PR as gsoc-2020 as well?

Copy link
Collaborator

@tessus tessus left a comment

Choose a reason for hiding this comment

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

LGTM, but I'd change the defaultWidth and defaultHeight to something more sane.
Or depending on the actual screen size.

@daukadolt
Copy link
Contributor Author

LGTM, but I'd change the defaultWidth and defaultHeight to something more sane.
Or depending on the actual screen size.

@tessus you mean using screen size instead of workArea?

@tessus
Copy link
Collaborator

tessus commented Feb 26, 2020

I meant that if your screen is e.g. 1024x768, use ca 80-85% of that for the window size. Maybe 800x600 and position it (1024-800)/2 , (800-600)/2 so that it is in the middle of the screen.

This should of course only be done, if there's a problem with the size or the position in the first place. If the data in window-state-prod.json is correct, you don't have to do anything.

@@ -43,9 +43,12 @@ class ElectronAppWrapper {

const windowStateKeeper = require('electron-window-state');

const currentWorkArea = screen.getPrimaryDisplay().workArea;
const [defaultWidth, defaultHeight] = [0.8*currentWorkArea.width, 0.8*currentWorkArea.height];
Copy link
Owner

Choose a reason for hiding this comment

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

Please round the values. Also I don't see a need to create these separate values, so if you could set the properties on stateOptions directly that would be best.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@laurent22 can you take a look at the changes?

@laurent22
Copy link
Owner

Just left one comments. @tessus, is there something more that needs to be changed? I see he already uses 80% of the space or did I miss something?

@tessus
Copy link
Collaborator

tessus commented Feb 26, 2020

No, @laurent22, all is good. The OP has already changed the code according to my suggestion.

@laurent22
Copy link
Owner

Perfect, then there's just this one minor change to make and we can merge.

Setting defaultWidth/defaultHeight directly without extra variables.
Rounding defaultWidth/defaultHeight.

Signed-off-by: daukadolt <daulet.amirkhanov.official@gmail.com>
@laurent22 laurent22 merged commit ec64bf2 into laurent22:master Feb 27, 2020
@scotrod
Copy link

scotrod commented Jan 29, 2022

Bump. This is still happening with Joplin 2.6.10 (prod, win32)

Client ID: cf27eb0272a5451ca45a96eaa6351910
Sync Version: 3
Profile Version: 41
Keychain Supported: Yes

Revision: 98fba37

This issue appeared only on my multi-monitor setup - after I deleted the folder in C:\Users\USER\AppData\Roaming\Joplin\ it worked like a charm.

@tormung83
Copy link

@scotrod and all, this is still happening on Multi monitor and laptop's main display, docked and undocked.
Deleting the C:\Users\USER\AppData\Roaming\Joplin\ did not make any difference.

OS: Windows 11 22H2 (OS Build 22621.1555)
Joplin version: 2.9.17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
desktop All desktop platforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Check and fix window dimensions and position when the application start
7 participants