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

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

Closed
3 tasks done
paiooocn opened this issue Mar 23, 2023 · 5 comments
Closed
3 tasks done

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

paiooocn opened this issue Mar 23, 2023 · 5 comments
Assignees
Labels
Milestone

Comments

@paiooocn
Copy link

该问题是否已经被报告过了? 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

@88250
Copy link
Member

88250 commented Mar 23, 2023

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

image

@88250
Copy link
Member

88250 commented Mar 23, 2023

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

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

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

@88250
Copy link
Member

88250 commented Mar 23, 2023

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

image

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

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

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

@88250 88250 closed this as completed Mar 23, 2023
@paiooocn
Copy link
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) { 

@88250 88250 self-assigned this Mar 24, 2023
@88250 88250 changed the title window 10下调整窗口大小后, 重新打开时还是1920x1040大小 重启后窗口大小恢复默认问题 Mar 24, 2023
@88250 88250 added the Bug label Mar 24, 2023
@88250 88250 added this to the 2.8.1 milestone Mar 24, 2023
@88250
Copy link
Member

88250 commented Mar 24, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants