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

feat(desktop): save and restore window state #1852

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

ni00
Copy link
Contributor

@ni00 ni00 commented Jan 3, 2025

PR Checklist

What is the current behavior?

Won't save and restore window position and size.

Issue Number

#1849

What is the new behavior?

Save and restore window position and size.

Does this PR introduce a breaking change?

  • Yes
  • No

Specific Instructions

Other information

reference: electron/electron#526

@Red-Asuka Red-Asuka added feature This pr is a feature desktop MQTTX Desktop labels Jan 13, 2025
Comment on lines +189 to +202
// Restore window state
const savedBounds = electronStore.get('bounds')
if (savedBounds !== undefined) {
const screenArea = screen.getDisplayMatching(savedBounds).workArea
// Check if the window is within the bounds of the screen
if (
savedBounds.x >= screenArea.x &&
savedBounds.x <= screenArea.x + screenArea.width &&
savedBounds.y >= screenArea.y &&
savedBounds.y <= screenArea.y + screenArea.height
) {
win.setBounds(savedBounds)
}
}
Copy link
Member

@ysfscream ysfscream Jan 13, 2025

Choose a reason for hiding this comment

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

Could you please write to the main folder independently of the background file (Extra the module)?

@ysfscream
Copy link
Member

ysfscream commented Jan 13, 2025

So many thanks for implementing the window state persistence feature!

The implementation looks thoughtful and handles the multi-monitor scenario well. Here are some thoughts that might be helpful:

  1. We might want to consider adding maximized state handling?
// Example approach:
electronStore.set('windowState', {
  bounds: win.getBounds(),
  isMaximized: win.isMaximized()
})
  1. Would it make sense to add some error handling? Something like:
try {
  win.setBounds(savedBounds)
} catch (error) {
  // log some error here
  console.error('Failed to restore window bounds:', error)
  // Handle fallback
}
  1. Can we sync the latest window size values to the database for better persistence?
image

Only when we open it for the first time do we use 1025 * 749 as the default value?

const defaultBounds = {
  width: 1024,
  height: 768,
  x: 0,
  y: 0
}

@ysfscream ysfscream closed this Jan 13, 2025
@ysfscream ysfscream reopened this Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
desktop MQTTX Desktop feature This pr is a feature
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants