Skip to content

Conversation

@dengzhongyuan365-dev
Copy link

…ion shutdown

  • Updated destruction logic in TreelandCaptureManager and TreelandCaptureContext to skip operations when the application is closing down, preventing potential crashes.
  • Introduced a new destroySession method to safely handle session destruction with appropriate checks for initialization and manager activity.
  • Improved logging to provide clearer insights during the destruction process, ensuring better debugging and stability in Wayland environments.

fix: 在应用退出时增强捕获管理的销毁安全性

  • 更新 TreelandCaptureManager 和 TreelandCaptureContext 的销毁逻辑:应用关闭时跳过相关操作,避免潜在崩溃。
  • 新增 destroySession 方法:在会话销毁前检查初始化状态与管理器活跃度,确保安全退出。
  • 改进日志:在销毁流程中提供更清晰的日志,便于 Wayland 环境下的调试和稳定性分析。

bug: https://pms.uniontech.com/bug-view-342837.html

…ion shutdown

- Updated destruction logic in TreelandCaptureManager and TreelandCaptureContext to skip operations when the application is closing down, preventing potential crashes.
- Introduced a new destroySession method to safely handle session destruction with appropriate checks for initialization and manager activity.
- Improved logging to provide clearer insights during the destruction process, ensuring better debugging and stability in Wayland environments.

fix: 在应用退出时增强捕获管理的销毁安全性
- 更新 TreelandCaptureManager 和 TreelandCaptureContext 的销毁逻辑:应用关闭时跳过相关操作,避免潜在崩溃。
- 新增 destroySession 方法:在会话销毁前检查初始化状态与管理器活跃度,确保安全退出。
- 改进日志:在销毁流程中提供更清晰的日志,便于 Wayland 环境下的调试和稳定性分析。

bug: https://pms.uniontech.com/bug-view-342837.html
@deepin-ci-robot
Copy link

deepin pr auto review

我来对这段代码进行审查:

  1. 代码逻辑改进:

在 TreelandCaptureManager 析构函数中:

  • 优点:增加了 QCoreApplication::closingDown() 检查,避免在应用关闭时访问可能已销毁的对象
  • 建议:可以将 isActive() 和 waylandDisplay() 的检查合并到一个条件中,提高可读性

在 TreelandCaptureContext 析构函数中:

  • 优点:将 session 销毁逻辑抽取到独立方法 destroySession() 中,提高了代码复用性
  • 建议:在 destroySession() 方法中,可以考虑在删除 session 对象前先确保所有相关的资源都已经释放
  1. 代码质量改进:

在 main_window.cpp 中的 onTreelandSwitchToRecordUI() 方法:

  • 优点:简化了工具栏的显示逻辑,移除了不必要的 RecorderRegionShow 窗口
  • 建议:可以将工具栏的初始化和配置代码抽取到一个独立的方法中,提高代码组织性
  1. 性能优化:
  • 建议:在多次访问 TreelandCaptureManager::instance() 时,可以将其缓存到局部变量中
  • 建议:在 destroySession() 中,可以考虑使用智能指针来管理 session 对象的生命周期
  1. 安全性改进:
  • 优点:增加了多处 QCoreApplication::closingDown() 检查,避免在应用关闭时访问已销毁对象
  • 建议:在访问 waylandDisplay() 之前,应该检查其有效性

具体改进建议:

// 在 TreelandCaptureManager 析构函数中
if (QCoreApplication::closingDown()) {
    qCWarning(dsrApp) << "Skip TreelandCaptureManager::destroy because app closing down";
} else if (isActive() && waylandDisplay()) {
    destroy();
    // 销毁 Wayland 扩展
} else {
    qCWarning(dsrApp) << "Skip TreelandCaptureManager::destroy - inactive or invalid display";
}

// 在 destroySession() 中
void TreelandCaptureContext::destroySession()
{
    if (!m_session) {
        return;
    }

    qCDebug(dsrApp) << "Log: TreelandCaptureContext::destroySession - destroying session object.";
    
    if (QCoreApplication::closingDown()) {
        qCWarning(dsrApp) << "Skip session destroy because app closing down";
    } else {
        auto manager = TreelandCaptureManager::instance();
        if (manager && manager->isActive() && m_session->isInitialized()) {
            m_session->destroy();
        } else {
            qCWarning(dsrApp) << "Skip session destroy because not initialized or manager inactive";
        }
    }
    
    // 先释放资源再删除对象
    m_session->cleanup(); // 如果有清理资源的方法
    delete m_session;
    m_session = nullptr;
    Q_EMIT sessionChanged();
}

// 在 main_window.cpp 中抽取工具栏配置方法
void MainWindow::setupToolBarForTreeland()
{
    if (!m_toolBar) {
        return;
    }

    m_toolBar->setAttribute(Qt::WA_ShowWithoutActivating, true);
    m_toolBar->setFocusPolicy(Qt::NoFocus);
    m_toolBar->setWindowFlags(Qt::FramelessWindowHint | Qt::Tool | 
                            Qt::WindowStaysOnTopHint | Qt::BypassWindowManagerHint);
    
    if (m_toolBar->windowHandle()) {
        m_toolBar->windowHandle()->setParent(nullptr);
    }
}

这些改进主要关注于:

  1. 增强代码的健壮性和安全性
  2. 提高代码的可维护性和可读性
  3. 优化资源管理
  4. 改进错误处理和日志记录

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: dengzhongyuan365-dev, lzwind

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

@dengzhongyuan365-dev
Copy link
Author

/merge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Dec 11, 2025

This pr cannot be merged! (status: unstable)

@dengzhongyuan365-dev
Copy link
Author

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Dec 11, 2025

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit d18e6fa into linuxdeepin:develop/snipe Dec 11, 2025
6 of 7 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