Skip to content

重启后窗口大小恢复默认问题 #7755

Closed
@paiooocn

Description

@paiooocn

该问题是否已经被报告过了? Is there an existing issue for this?

  • 我已经搜索了 Issues,没有发现类似问题
    I have searched the existing issues

该问题是否能够在默认主题(daylight/midnight)下重现? Can the issue be reproduced with the default theme (daylight/midnight)?

  • 我能够在默认主题下重现该问题
    I was able to reproduce the issue with the default theme

该问题是否可能是由于扩展功能导致? Could the issue be due to extensions?

  • 我已经排除了扩展导致问题的可能性
    I've ruled out the possibility that the extension is causing the problem.

描述问题 Describe the problem

如下两行代码一直使用screen的width和height, 没有将windowState的width和height读入使用.

siyuan/app/electron/main.js

Lines 189 to 190 in f83a07f

defaultWidth = screen.getPrimaryDisplay().size.width;
defaultHeight = screen.getPrimaryDisplay().workAreaSize.height;

将代码改为下面的形式, 能够在下次打开程序时套用上次的windowState的width和height.

        defaultWidth = oldWindowState ? oldWindowState.width : screen.getPrimaryDisplay().size.width;
        defaultHeight = oldWindowState ? oldWindowState.height: screen.getPrimaryDisplay().workAreaSize.height;

期待的结果 Expected result

请在后续版本修正此问题, 谢谢.

截屏或者录屏演示 Screenshot or screen recording presentation

No response

版本环境 Version environment

- Version: 2.8.0
- Operating System: Windows 10
- Browser (if used):

日志文件 Log file

app.log

更多信息 More information

No response

Activity

88250

88250 commented on Mar 23, 2023

@88250
Member

我这里重现不了问题,后面的代码会进行覆盖:

image

88250

88250 commented on Mar 23, 2023

@88250
Member

另外,对于修改方案的实现:

        defaultWidth = oldWindowState ? oldWindowState.width : screen.getPrimaryDisplay().size.width;
        defaultHeight = oldWindowState ? oldWindowState.height: screen.getPrimaryDisplay().workAreaSize.height;

oldWindowState 这个变量应该一直会存在的,上面已经初始化过了 {},但是这样不能保证里面有 widthheight 两个字段。

88250

88250 commented on Mar 23, 2023

@88250
Member

这是增加两句调试日志的输出:

image

所以我觉得问题可能不是出在读取上。

你那里可以试下退出以后打开 windowState.json 看下是否已经持久化。

我先关闭了,如果还有问题请继续跟帖,谢谢 🙏

paiooocn

paiooocn commented on Mar 24, 2023

@paiooocn
Author

我输出了windowState, 和你说的一样, windowState加载了oldWindowState的数据.
发现在下面的代码里, 条件为真时使用了defaultWidth, defaultHeight

siyuan/app/electron/main.js

Lines 207 to 212 in f83a07f

if (workArea) {
// 窗口大小等同于或大于 workArea 时,缩小会隐藏到左下角
if (windowState.width >= workArea.width || windowState.height >= workArea.height) {
windowState.width = Math.min(defaultWidth, workArea.width);
windowState.height = Math.min(defaultHeight, workArea.height);
}

我输出了workArea和windowState的width, height

    const windowState = Object.assign({}, {
        isMaximized: true,
        fullscreen: false,
        isDevToolsOpened: false,
        x: 0,
        y: 0,
        width: defaultWidth,
        height: defaultHeight,
    }, oldWindowState);
    writeLog("windowStat: width " + windowState.width + ", height: " + windowState.height)
    writeLog("workArea: width " + workArea.width + ", height " + workArea.height)
2023-03-24 01:56:54 got kernel port [58392]
2023-03-24 01:56:54 ui version [2.8.0], booting kernel [C:\Users\Yimo\AppData\Local\Programs\SiYuan\resources\kernel\SiYuan-Kernel.exe --port 58392 --wd C:\Users\Yimo\AppData\Local\Programs\SiYuan\resources]
2023-03-24 01:56:54 booted kernel process [pid=7716, port=58392]
2023-03-24 01:56:54 checking kernel version
2023-03-24 01:56:54 got kernel version [2.8.0]
2023-03-24 01:56:55 windowStat: width 1152, height: 1040
2023-03-24 01:56:55 workArea: width 1920, height 1040
2023-03-24 01:57:06 exited ui

返回的workArea.height==windowState.height,
此条件生效if (windowState.width >= workArea.width || windowState.height >= workArea.height),
导致windowState.width, windowState.height被赋值defaultWidth, defaultHeight.

你可以将窗口高度拉到最大试试看能否重现. 我调小高度到1000后, 窗口大小正常了.

条件改为>后, 可以修正这个问题.

if (windowState.width > workArea.width || windowState.height > workArea.height) { 
self-assigned this
on Mar 24, 2023
changed the title [-]window 10下调整窗口大小后, 重新打开时还是1920x1040大小[/-] [+]重启后窗口大小恢复默认问题[/+] on Mar 24, 2023
added this to the 2.8.1 milestone on Mar 24, 2023
88250

88250 commented on Mar 24, 2023

@88250
Member

确实是这个问题,感谢指正,下个版本修复。

reopened this on Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @88250@paiooocn

      Issue actions

        重启后窗口大小恢复默认问题 · Issue #7755 · siyuan-note/siyuan