Skip to content

fix: suppress splash for singleton apps with existing instances#329

Open
wineee wants to merge 1 commit intolinuxdeepin:masterfrom
wineee:singleton
Open

fix: suppress splash for singleton apps with existing instances#329
wineee wants to merge 1 commit intolinuxdeepin:masterfrom
wineee:singleton

Conversation

@wineee
Copy link
Member

@wineee wineee commented Feb 5, 2026

The change modifies the splash screen logic to skip showing the splash screen for singleton applications that already have running instances. Previously, splash screens were only suppressed for system autostart launches. Now, when a singleton application (marked with X-Deepin- Singleton=true) is launched while another instance is already running, the splash screen will be skipped to prevent redundant visual feedback.

Technical details:

  1. Added detection for singleton applications using the X-Deepin- Singleton desktop entry key
  2. Added check for existing application instances using m_Instances.isEmpty()
  3. Combined both conditions to determine when to skip splash screen
  4. Added appropriate logging for the new skip condition

Log: Skip splash screen when launching singleton applications with existing instances

Influence:

  1. Test launching singleton applications when no instance is running - should show splash
  2. Test launching singleton applications when instance is already running - should skip splash
  3. Verify system autostart launches still skip splash as before
  4. Test non-singleton applications behavior remains unchanged
  5. Check logging output for proper splash skip messages

fix: 为已有实例的单例应用跳过启动闪屏

修改了启动闪屏逻辑,对于已有运行实例的单例应用跳过显示启动闪屏。之前
仅对系统自启动的应用程序跳过闪屏显示。现在当单例应用(标记为X-Deepin-
Singleton=true)在已有实例运行时再次启动,将跳过闪屏以避免冗余的视觉
反馈。

技术细节:

  1. 添加了对单例应用的检测,使用X-Deepin-Singleton桌面条目键
  2. 添加了对现有应用实例的检查,使用m_Instances.isEmpty()
  3. 结合两个条件来确定何时跳过闪屏显示
  4. 为新的跳过条件添加了适当的日志记录

Log: 当启动已有实例的单例应用时跳过启动闪屏

Influence:

  1. 测试在无实例运行时启动单例应用 - 应显示闪屏
  2. 测试在已有实例运行时启动单例应用 - 应跳过闪屏
  3. 验证系统自启动应用仍按原有方式跳过闪屏
  4. 测试非单例应用的行为保持不变
  5. 检查日志输出中正确的闪屏跳过消息

Summary by Sourcery

Bug Fixes:

  • Prevent redundant splash screens when launching singleton applications that already have an active instance.

The change modifies the splash screen logic to skip showing the splash
screen for singleton applications that already have running instances.
Previously, splash screens were only suppressed for system autostart
launches. Now, when a singleton application (marked with X-Deepin-
Singleton=true) is launched while another instance is already running,
the splash screen will be skipped to prevent redundant visual feedback.

Technical details:
1. Added detection for singleton applications using the X-Deepin-
Singleton desktop entry key
2. Added check for existing application instances using
m_Instances.isEmpty()
3. Combined both conditions to determine when to skip splash screen
4. Added appropriate logging for the new skip condition

Log: Skip splash screen when launching singleton applications with
existing instances

Influence:
1. Test launching singleton applications when no instance is running -
should show splash
2. Test launching singleton applications when instance is already
running - should skip splash
3. Verify system autostart launches still skip splash as before
4. Test non-singleton applications behavior remains unchanged
5. Check logging output for proper splash skip messages

fix: 为已有实例的单例应用跳过启动闪屏

修改了启动闪屏逻辑,对于已有运行实例的单例应用跳过显示启动闪屏。之前
仅对系统自启动的应用程序跳过闪屏显示。现在当单例应用(标记为X-Deepin-
Singleton=true)在已有实例运行时再次启动,将跳过闪屏以避免冗余的视觉
反馈。

技术细节:
1. 添加了对单例应用的检测,使用X-Deepin-Singleton桌面条目键
2. 添加了对现有应用实例的检查,使用m_Instances.isEmpty()
3. 结合两个条件来确定何时跳过闪屏显示
4. 为新的跳过条件添加了适当的日志记录

Log: 当启动已有实例的单例应用时跳过启动闪屏

Influence:
1. 测试在无实例运行时启动单例应用 - 应显示闪屏
2. 测试在已有实例运行时启动单例应用 - 应跳过闪屏
3. 验证系统自启动应用仍按原有方式跳过闪屏
4. 测试非单例应用的行为保持不变
5. 检查日志输出中正确的闪屏跳过消息
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: wineee

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

@sourcery-ai
Copy link

sourcery-ai bot commented Feb 5, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts prelaunch splash behavior so that singleton applications with existing instances skip the splash, extending the previous autostart-only suppression and adding logging for the new condition.

Sequence diagram for prelaunch splash decision in ApplicationService::Launch

sequenceDiagram
    actor User
    participant Launcher
    participant ApplicationService
    participant SplashHelper

    User->>Launcher: request app launch
    Launcher->>ApplicationService: Launch(action, fields, options)

    ApplicationService->>ApplicationService: isAutostartLaunch = optionsMap.contains(_autostart)
    ApplicationService->>ApplicationService: isSingleton = findEntryValue(X_Deepin_Singleton)
    ApplicationService->>ApplicationService: singletonWithInstance = isSingleton && !m_Instances.isEmpty()

    alt isAutostartLaunch
        ApplicationService->>ApplicationService: log Skip prelaunch splash (autostart)
        ApplicationService-->>Launcher: continue launch without splash
    else singletonWithInstance
        ApplicationService->>ApplicationService: log Skip prelaunch splash (singleton with existing instance)
        ApplicationService-->>Launcher: continue launch without splash
    else normal_launch
        ApplicationService->>ApplicationService: am = parent()
        ApplicationService->>SplashHelper: splashHelper() and show splash with icon
        SplashHelper-->>ApplicationService: splash shown
        ApplicationService-->>Launcher: continue launch with splash
    end
Loading

File-Level Changes

Change Details Files
Extend splash suppression logic to singleton applications that already have running instances.
  • Introduce detection of singleton applications via X-Deepin-Singleton desktop entry key
  • Check for existing instances using the non-emptiness of m_Instances
  • Combine singleton and instance checks into a singletonWithInstance flag used in splash suppression branching
  • Add logging message when skipping splash for singleton applications with existing instances while preserving existing autostart behavior
src/dbus/applicationservice.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

这段代码修改主要针对在 Wayland 会话下启动应用时的启动画面(splash screen)显示逻辑进行了优化。以下是对该 git diff 的详细审查意见,包括语法逻辑、代码质量、代码性能和代码安全四个方面:

1. 语法逻辑

审查结果:通过

  • 逻辑清晰:代码逻辑非常直观。首先判断是否为自启动(isAutostartLaunch),其次判断是否为单例应用且已有实例运行(singletonWithInstance)。如果满足任一条件,则跳过启动画面。
  • 变量命名准确isSingletonsingletonWithInstance 准确地描述了变量的用途,符合布尔变量的命名规范。
  • 日志完善:新增的 qCInfo 日志能够帮助开发者清晰地追踪启动画面被跳过的具体原因(单例且有实例),便于调试。

2. 代码质量

审查结果:良好,有优化建议

  • 可读性:代码片段使用了 const 修饰局部变量,且命名具有自解释性,符合现代 C++ 编码规范。
  • 解耦性:引入了 isSingleton 变量,将“是否是单例应用”的判断与“是否已有实例”的判断分离开来,逻辑更加独立。
  • 改进建议
    • 魔法字符串:代码中使用了字符串字面量 "X-Deepin-Singleton"。建议将其定义为类内的静态常量字符串(例如 static const char kDeepinSingleton[]),以避免拼写错误,并便于未来统一维护或修改配置项名称。

3. 代码性能

审查结果:良好

  • 开销分析
    • findEntryValue:这是一个查找操作,通常涉及解析 .desktop 文件或查询缓存。在启动流程中调用一次是必要的开销。
    • m_Instances.isEmpty():这是一个 O(1) 的操作,性能开销极低。
  • 结论:新增的几行代码逻辑简单,没有引入循环、递归或阻塞操作,对性能的影响微乎其微。

4. 代码安全

审查结果:通过

  • 空指针检查:原代码中已有对 parent()splashHelper() 的检查,修改部分未引入新的空指针风险。
  • 类型安全:使用了 .toBool() 进行类型转换,Qt 的 QVariant 能够安全处理各种基础类型转换。
  • 逻辑安全:对于单例应用,如果已有实例运行,通常意味着不会创建新的主窗口,因此跳过针对新窗口的启动画面显示是符合逻辑且安全的,避免了资源浪费或界面闪烁。

总结与建议

这段代码修改是正确且必要的,它解决了单例应用在已有实例运行时仍显示启动画面的逻辑冗余问题。

建议优化后的代码片段(主要针对魔法字符串的改进):

// 建议在类头文件中定义常量,例如:
// static const char kDeepinSingletonKey[] = "X-Deepin-Singleton";

// Notify the compositor to show a splash screen if in a Wayland session.
// Suppress splash for system autostart launches or singleton apps with existing instances.
const bool isAutostartLaunch = optionsMap.contains("_autostart") && optionsMap.value("_autostart").toBool();
// 使用常量替代字符串字面量
const bool isSingleton = findEntryValue(DesktopFileEntryKey, kDeepinSingletonKey, EntryValueType::Boolean).toBool();
const bool singletonWithInstance = isSingleton && !m_Instances.isEmpty();

if (isAutostartLaunch) {
    qCInfo(amPrelaunchSplash) << "Skip prelaunch splash (autostart)" << id();
} else if (singletonWithInstance) {
    qCInfo(amPrelaunchSplash) << "Skip prelaunch splash (singleton with existing instance)" << id();
} else if (auto *am = parent()) {
    // ... 后续逻辑

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 - I've left some high level feedback:

  • Consider whether m_Instances.isEmpty() is safe from races in this context (e.g., if a new instance can be registered concurrently with this Launch call) and, if needed, document or guard against any potential timing issues.
  • The isSingleton lookup via findEntryValue is now on the hot path for every launch; if this value is static per desktop file, consider caching it at a higher level to avoid repeated lookups.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider whether `m_Instances.isEmpty()` is safe from races in this context (e.g., if a new instance can be registered concurrently with this Launch call) and, if needed, document or guard against any potential timing issues.
- The `isSingleton` lookup via `findEntryValue` is now on the hot path for every launch; if this value is static per desktop file, consider caching it at a higher level to avoid repeated lookups.

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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances the splash screen logic to suppress splash screens for singleton applications that already have running instances. Previously, splash suppression only applied to system autostart launches.

Changes:

  • Added detection of singleton applications via the X-Deepin-Singleton desktop entry key
  • Added logic to skip splash screens when a singleton app with existing instances is launched
  • Updated comments and logging to reflect the new behavior

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// Suppress splash for system autostart launches.
// Suppress splash for system autostart launches or singleton apps with existing instances.
const bool isAutostartLaunch = optionsMap.contains("_autostart") && optionsMap.value("_autostart").toBool();
const bool isSingleton = findEntryValue(DesktopFileEntryKey, "X-Deepin-Singleton", EntryValueType::Boolean).toBool();
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

Consider adding a null check before calling toBool() for consistency with the existing pattern used in noDisplay() (line 541-547). While calling toBool() on a null QVariant safely returns false, the codebase convention appears to explicitly check for null first. For example:

auto val = findEntryValue(DesktopFileEntryKey, "X-Deepin-Singleton", EntryValueType::Boolean);
const bool isSingleton = val.isNull() ? false : val.toBool();

This matches the pattern at line 541 where noDisplay() checks val.isNull() before calling val.toBool().

Copilot uses AI. Check for mistakes.
@deepin-bot
Copy link

deepin-bot bot commented Feb 5, 2026

TAG Bot

New tag: 1.2.45
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #330

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.

2 participants