アプリ再起動後に前回のウィンドウサイズを維持したまま起動する#46
Hidden character warning
Conversation
|
@codex review |
There was a problem hiding this comment.
Code Review
This pull request implements window state persistence by saving and restoring the window's dimensions and position. Feedback was provided to debounce the save operation to prevent excessive disk I/O during resizing or moving and to include a safety check ensuring the window is not destroyed before saving.
| const saveBounds = () => { | ||
| if (!mainWindow.isMinimized() && !mainWindow.isMaximized()) { | ||
| store.set("windowBounds", mainWindow.getBounds()); | ||
| } | ||
| }; |
There was a problem hiding this comment.
ウィンドウの resize や move イベントはドラッグやリサイズ中に頻繁に発生するため、そのたびに store.set(ディスク I/O)を呼び出すとパフォーマンスに悪影響を与える可能性があります。setTimeout を使用して処理をデバウンス(間引き)することをお勧めします。また、タイマー実行時にウィンドウが既に閉じられている場合の例外を防ぐため、!mainWindow.isDestroyed() のチェックを追加するのが安全です。
let saveTimeout: ReturnType<typeof setTimeout>;
const saveBounds = () => {
clearTimeout(saveTimeout);
saveTimeout = setTimeout(() => {
if (!mainWindow.isDestroyed() && !mainWindow.isMinimized() && !mainWindow.isMaximized()) {
store.set("windowBounds", mainWindow.getBounds());
}
}, 500);
};
Deploying switchbotcontroller with
|
| Latest commit: |
5e69ea2
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://e2450b8e.switchbotcontroller.pages.dev |
| Branch Preview URL: | https://45.switchbotcontroller.pages.dev |
|
@codex review |
b4eddee to
5e69ea2
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5e69ea28c4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| x: savedBounds?.x, | ||
| y: savedBounds?.y, |
There was a problem hiding this comment.
Validate restored window position against active displays
Restoring x/y unconditionally can make the app reopen off-screen when the monitor layout changes (for example, a laptop was last used with an external display and then restarted without it). In that case Electron will honor the stale coordinates and users may see no window at startup, which is a functional regression from the previous centered default behavior.
Useful? React with 👍 / 👎.
fix #45