Skip to content

feat: persist and restore window layout on Windows - #2601

Open
ssghlou wants to merge 2 commits into
Predidit:mainfrom
ssghlou:windows-window-state
Open

ssghlou wants to merge 2 commits into
Predidit:mainfrom
ssghlou:windows-window-state

Conversation

@ssghlou

@ssghlou ssghlou commented Sep 30, 2026 •

Copy link
Copy Markdown

描述

在 Windows 平台增加窗口布局记忆功能,启动时恢复上次正常窗口的大小、位置及最大化状态。

关联的 Issues

#1080 #1316 #2147

PR 类型

  • Bug 修复
  • 添加新功能
  • 重构实现
  • 文档或格式
  • 其它

AI 辅助开发

  • 没有使用 AI 辅助
  • AI 辅助开发了部分功能,但是我已检查并理解 AI 所写的代码
  • 基本上都由 AI 实现,但是我非常了解 AI 的代码与写完的产物

AI 辅助模型:

OpenAI GPT-6.1 Sol

提交前检查

  • 我已经填写了 PR 模板中的所有内容
  • 我已经阅读了 贡献指引 ,并遵守指引进行开发
  • 这个 PR 的功能已经经过我的测试,并且我完全理解我(或 AI)做出的改动

附注

本次窗口布局记忆功能仅针对 Windows 实现。由于缺少 Linux 和 macOS 的实机测试环境,暂未将该功能扩展到这两个平台。

为了统一,三个桌面平台共用的桌面 PiP 比例更新流程和默认尺寸函数有所调整。

Comment thread lib/main.dart
bool restored = false;
if (windowState != null) {
if (savedState != null) {
restored = await windowState.restoreNormalLayout(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

WARNING: If layout restoration throws, the window stays hidden

The window is hidden until windowManager.show() on line 103, and nothing guards the restoration code before it. restoreNormalLayout catches errors from its first attempt, but its fallback _restoreDefaultLayout (_prepareNormalWindow, setSize, center) runs inside the catch block with no guard of its own. If any of those plugin calls throws, for example isMinimized or isMaximized failing a second time, the exception escapes this callback. show(), focus() and startListening() then never run. waitUntilReadyToShow doesn't await the callback, so the process keeps running with no visible window. Before this PR the callback only called show/focus, so this failure mode is new.

Put the restoration in a try and call show()/focus()/startListening() in a finally, or catch errors from the default-layout fallback inside restoreNormalLayout.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

@kilo-code-bot

kilo-code-bot Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
lib/main.dart 94 The startup callback doesn't guard layout restoration. If the default-layout fallback throws, show()/focus()/startListening() never run and the window stays hidden.
Files Reviewed (12 files)
  • lib/app_widget.dart - 0 issues
  • lib/main.dart - 1 issue
  • lib/pages/player/player_item.dart - 0 issues
  • lib/pages/player/player_item_panel.dart - 0 issues
  • lib/services/platform/window_state_service.dart - 0 issues
  • lib/services/player/pip_utils.dart - 0 issues
  • lib/services/storage/settings_keys.dart - 0 issues
  • lib/utils/device.dart - 0 issues
  • windows/runner/flutter_window.cpp - 0 issues
  • windows/runner/flutter_window.h - 0 issues
  • windows/runner/win32_window.cpp - 0 issues
  • windows/runner/win32_window.h - 0 issues

Fix these issues in Kilo Cloud


Reviewed by claude-opus-5.5 · Input: 0 · Output: 0 · Cached: 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant