Skip to content

Conversation

@lichaofan2008
Copy link
Contributor

@lichaofan2008 lichaofan2008 commented Nov 25, 2025

不保留标签页功能未生效,因为历史上的一条提交引入了错误代码导致提前返回了,导致历史文件记录没有被清空。 revert 9ce896a.

Bug: https://pms.uniontech.com/bug-view-341299.html

Summary by Sourcery

Fix tab history handling so temporary file records are always updated and respect the "Do not keep tabs" behavior.

Bug Fixes:

  • Always load and update browsing history temporary files on startup instead of only when saving tabs before close.
  • Ensure automatic backup updates history even when no editor windows are open, and log the number of history entries written.

不保留标签页功能未生效,因为历史上的一条提交引入了错误代码导致提前返回了,导致历史文件记录没有被清空。
revert 9ce896a.

Bug: https://pms.uniontech.com/bug-view-341299.html
@sourcery-ai
Copy link

sourcery-ai bot commented Nov 25, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR fixes the "Do not keep tabs" feature by always loading and persisting the browsing history list regardless of the startup setting, and by removing an early return that prevented clearing/saving history when no windows were open, plus adding logging for easier debugging.

Sequence diagram for updated autoBackupFile history persistence

sequenceDiagram
  participant StartManager
  participant Settings
  participant QSettings

  StartManager->>StartManager: autoBackupFile()
  StartManager->>StartManager: m_qlistTemFile.clear()
  StartManager->>Settings: instance()
  Settings-->>StartManager: settings
  StartManager->>QSettings: option(advance.editor.browsing_history_temfile)
  QSettings-->>StartManager: current_history_list
  StartManager->>StartManager: iterate m_windows and build m_qlistTemFile
  StartManager->>StartManager: qInfo history file counts
  StartManager->>QSettings: setValue(m_qlistTemFile)
  StartManager->>StartManager: saveBookmark()
Loading

Sequence diagram for loading history in StartManager constructor

sequenceDiagram
  participant StartManager
  participant Settings
  participant QSettings

  StartManager->>StartManager: StartManager(parent)
  StartManager->>Settings: instance()
  Settings-->>StartManager: settings
  StartManager->>QSettings: option(advance.editor.browsing_history_temfile)
  QSettings-->>StartManager: saved_history_list
  StartManager->>StartManager: m_qlistTemFile = saved_history_list
  StartManager->>StartManager: initBookmark()
Loading

Updated class diagram for StartManager history handling

classDiagram
class StartManager {
  -QStringList m_qlistTemFile
  -QList_Window_ m_windows
  +StartManager(parent: QObject)
  +autoBackupFile()
  +initBookmark()
  +saveBookmark()
}

class Settings {
  +static Settings instance()
  +QSettings settings
}

StartManager --> Settings : uses
StartManager --> QSettings : reads_and_writes_history
Loading

File-Level Changes

Change Details Files
Always load the browsing history temp file list at startup instead of only when the "save tab before close" setting is enabled.
  • Removed the conditional check on the startup save-tab setting before reading the browsing history list from settings.
  • Unconditionally assign the browsing history temp file list from configuration into the internal member list during StartManager construction.
src/startmanager.cpp
Ensure browsing history is updated and cleared correctly even when there are no open windows, and add logging for history persistence.
  • Removed an early return in autoBackupFile that exited when there were no open windows so that the history list can still be cleared or updated in settings.
  • Added an informational log statement in autoBackupFile to record the number of history entries being written to settings before saving.
  • Kept the logic that clears and rebuilds the internal history list, ensuring it is saved back to configuration correctly.
src/startmanager.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot
Copy link

deepin pr auto review

我来对这个git diff进行代码审查:

  1. 代码逻辑审查:
    主要修改了两处:
  • 移除了打开上次关闭前文件的判断条件,直接获取历史文件列表
  • 移除了autoBackupFile()中的窗口空检查
  • 添加了日志输出记录历史文件数量
  1. 代码质量分析:
  • 第一处修改(移除openSavedTab判断)可能会影响程序行为,现在无论设置如何都会加载历史文件列表。这可能是预期行为,但建议在注释中说明原因。
  • 移除窗口空检查(m_windows.isEmpty())可能会导致潜在问题,如果没有任何窗口打开时,后续的循环操作可能不必要。
  1. 性能影响:
  • 直接加载历史文件列表的性能影响很小
  • 移除窗口空检查实际上可能会带来轻微的性能提升(减少了一次条件判断),但这是以潜在的逻辑风险为代价的
  1. 安全性考虑:
  • 修改没有直接引入安全风险
  • 但移除窗口空检查可能会导致在特定边界条件下的未预期行为

改进建议:

  1. 对于第一处修改,建议:
// 直接加载历史文件列表,因为后续逻辑中会根据实际需要判断是否使用这些文件
m_qlistTemFile = Settings::instance()->settings->option("advance.editor.browsing_history_temfile")->value().toStringList();
  1. 对于autoBackupFile()中的窗口检查,建议保留或改为:
// 如果没有窗口打开,直接保存空列表
if (m_windows.isEmpty()) {
    Settings::instance()->settings->option("advance.editor.browsing_history_temfile")->setValue(QStringList());
    return;
}
  1. 日志输出是好的实践,建议添加更多上下文信息:
qInfo() << __func__ << "Saving" << m_qlistTemFile.size() << "files to browsing history";
  1. 考虑添加错误处理:
// 在访问设置时添加错误处理
auto settingsOption = Settings::instance()->settings->option("advance.editor.browsing_history_temfile");
if (!settingsOption) {
    qWarning() << __func__ << "Failed to access browsing history setting";
    return;
}

这些修改建议主要是为了提高代码的健壮性和可维护性,同时保持代码的性能和安全性。

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `src/startmanager.cpp:222` </location>
<code_context>
     }

     //将json串列表写入配置文件
+    qInfo() << __func__ << "history file counts:" << m_qlistTemFile.size();
     Settings::instance()->settings->option("advance.editor.browsing_history_temfile")->setValue(m_qlistTemFile);
     // 备份书签信息
</code_context>

<issue_to_address>
**suggestion:** Consider reducing verbosity or using a more appropriate log level for frequent backup logs.

If autoBackupFile() is called frequently, logging with qInfo() every time can clutter production logs. Prefer a debug category (e.g. qCDebug(...)) so it’s disabled in release, or only log when the count changes or is non-zero to keep logs useful but concise.

Suggested implementation:

```cpp
    //将json串列表写入配置文件
    // 使用调试日志并仅在有历史文件时输出,避免频繁备份时生产日志过于冗长
    if (!m_qlistTemFile.isEmpty()) {
        qDebug() << __func__ << "history file counts:" << m_qlistTemFile.size();
    }
    Settings::instance()->settings->option("advance.editor.browsing_history_temfile")->setValue(m_qlistTemFile);

```

- Ensure that qDebug() is acceptable in your logging policy for debug/diagnostic output. In many Qt projects, qDebug is either compiled out or filtered in release builds, which helps keep production logs concise.
- If your codebase uses QLoggingCategory for more granular control, you may want to replace qDebug() here with qCDebug(yourCategory) and define/configure that category consistently with the rest of the project.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lichaofan2008, max-lvs

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@lichaofan2008
Copy link
Contributor Author

/merge

@deepin-bot deepin-bot bot merged commit 1ac3c8f into linuxdeepin:release/eagle Nov 25, 2025
21 checks passed
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.

3 participants