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

Persist window location when opening the app #171

Closed
groundbirdaircat opened this issue Jan 18, 2024 · 2 comments
Closed

Persist window location when opening the app #171

groundbirdaircat opened this issue Jan 18, 2024 · 2 comments
Labels
enhancement New feature or enhancement

Comments

@groundbirdaircat
Copy link

Currently the application always opens in the center of the primary monitor.

This request is for the window to open up wherever it was when it was last closed.

@heyman heyman added the enhancement New feature or enhancement label Jan 18, 2024
@heyman heyman changed the title Feature request: Persist window location when opening the app Persist window location when opening the app Jan 18, 2024
@ImKaashif
Copy link
Contributor

ImKaashif commented Jan 19, 2024

Hi, @heyman, I was looking into this enhancement request and this can be achieved by adding this to config while creating new BrowserWindow

let windowConfig = {
    width: CONFIG.get("windowConfig.width", 900) as number,
    height: CONFIG.get("windowConfig.height", 680) as number,
    x: CONFIG.get("windowConfig.x") as number,
    y: CONFIG.get("windowConfig.y") as number,
    isMaximized: CONFIG.get("windowConfig.isMaximized", false) as boolean,
    isFullScreen: CONFIG.get("windowConfig.isFullScreen", false) as boolean,
}

but the problem here is a default value in case x and y are not found in config, we cant just pass any arbitrary value as we would like to center the window in that case, I can technically do the following to avoid passing the x and y value in case they are not present and window will automatically be centered,

let window_offset = {};
if(CONFIG.get("windowConfig.x") && CONFIG.get("windowConfig.y")) window_offset = {
  x: CONFIG.get("windowConfig.x") as number,
  y: CONFIG.get("windowConfig.y") as number,
}
let windowConfig = {
  width: CONFIG.get("windowConfig.width", 900) as number,
  height: CONFIG.get("windowConfig.height", 680) as number,
  isMaximized: CONFIG.get("windowConfig.isMaximized", false) as boolean,
  isFullScreen: CONFIG.get("windowConfig.isFullScreen", false) as boolean,
  ...window_offset
}

this will get the job done but I am not sure if it's the right way of doing this. Could you share your opinions on this?

@heyman
Copy link
Owner

heyman commented Jan 25, 2024

Fixed by #171

@heyman heyman closed this as completed Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants