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

fix:修复全局浮窗对activity的依赖 #193

Merged
merged 4 commits into from
Jan 2, 2025
Merged

Conversation

Petterpx
Copy link
Owner

@Petterpx Petterpx commented Jan 2, 2025

Summary by Sourcery

更新浮动窗口实现,以移除对活动的依赖并添加开机启动支持。

新功能:

  • 添加在启动时自动启动浮动窗口的支持。

测试:

  • 更新测试以反映活动依赖和开机启动功能的变更。
Original summary in English

Summary by Sourcery

Update the floating window implementation to remove the dependency on activities and add support for starting on boot.

New Features:

  • Add support for automatically starting the floating window on boot.

Tests:

  • Update tests to reflect the changes in activity dependency and boot start functionality.

@Petterpx Petterpx added this to the 2.3.3 milestone Jan 2, 2025
Copy link
Contributor

sourcery-ai bot commented Jan 2, 2025

审阅者指南 by Sourcery

这个拉取请求移除了全局浮动窗口对活动生命周期的依赖。它引入了一个新的服务和广播接收器来管理浮动窗口的生命周期。同时还更新了权限检查逻辑和视图初始化过程。

更新后的浮动窗口初始化流程序列图

sequenceDiagram
    participant App
    participant FxSystemPlatformProvider
    participant WindowManager
    participant PermissionChecker

    App->>FxSystemPlatformProvider: checkOrInit()
    alt internalView exists
        FxSystemPlatformProvider-->>App: return true
    else internalView is null
        FxSystemPlatformProvider->>FxSystemPlatformProvider: checkOrRegisterActivityLifecycle()
        FxSystemPlatformProvider->>PermissionChecker: checkAgreePermission(context)
        alt has permission
            PermissionChecker-->>FxSystemPlatformProvider: true
            FxSystemPlatformProvider->>WindowManager: getSystemService
            FxSystemPlatformProvider->>FxSystemPlatformProvider: create FxSystemContainerView
            FxSystemPlatformProvider-->>App: return true
        else no permission
            PermissionChecker-->>FxSystemPlatformProvider: false
            FxSystemPlatformProvider->>FxSystemPlatformProvider: internalAskAutoPermission
            FxSystemPlatformProvider-->>App: return false
        end
    end
Loading

浮动窗口生命周期状态图

stateDiagram-v2
    [*] --> Initialized: 启动完成
    Initialized --> CheckingPermission: 显示请求
    CheckingPermission --> RequestingPermission: 无权限
    CheckingPermission --> Creating: 有权限
    RequestingPermission --> Creating: 权限已授予
    Creating --> Showing: 创建视图
    Showing --> Hidden: 隐藏请求
    Hidden --> Showing: 显示请求
    Hidden --> [*]: 销毁
Loading

文件级别变更

变更 详情 文件
将浮动窗口与活动生命周期解耦
  • FxSystemPlatformProvider 中移除了对活动的直接依赖。
  • 引入 checkOrRegisterActivityLifecycle 来管理生命周期回调。
  • 更新 checkOrInit 以独立于活动处理权限检查和视图初始化。
  • 修改 FxBasisControlImp 以更新启用状态并检查显示条件。
floatingx/src/main/java/com/petterp/floatingx/imp/system/FxSystemPlatformProvider.kt
floatingx/src/main/java/com/petterp/floatingx/imp/FxBasisControlImp.kt
引入新的服务和广播接收器来管理浮动窗口
  • 添加 LauncherService 处理浮动窗口的生命周期。
  • 添加 LauncherReceiver 在启动时启动服务。
  • 在清单文件中声明服务和接收器。
app/src/main/AndroidManifest.xml
app/src/main/java/com/petterp/floatingx/app/service/LauncherService.kt
app/src/main/java/com/petterp/floatingx/app/service/LauncherReceiver.kt
更新权限检查逻辑
  • 修改 checkAgreePermission 使用应用程序上下文而非活动上下文。
floatingx/src/main/java/com/petterp/floatingx/imp/system/FxSystemPlatformProvider.kt
改进视图初始化和更新过程
  • 添加逻辑以防止在大小未改变时进行不必要的视图更新。
floatingx/src/main/java/com/petterp/floatingx/view/helper/FxViewLocationHelper.kt
更新文档中的库版本
  • 将版本号更新到 2.3.3。
README.md
README_EN.md

可能关联的问题

  • #0:PR 修复了在活动 A 中隐藏后,在活动 B 中无法正确显示浮动窗口的问题。PR 更新 checkOrInit 函数以正确处理活动生命周期和权限检查。
  • Create detekt-analysis.yml #1:PR 通过移除显示浮动菜单对活动生命周期的依赖来修复问题,解决了应用启动时菜单无法显示的 bug。

提示和命令

与 Sourcery 交互

  • **触发新的审阅:**在拉取请求中评论 @sourcery-ai review
  • **继续讨论:**直接回复 Sourcery 的审阅评论。
  • **从审阅评论生成 GitHub 问题:**通过回复评论要求 Sourcery 创建问题。
  • **生成拉取请求标题:**在拉取请求标题中的任何位置写 @sourcery-ai 以随时生成标题。
  • **生成拉取请求摘要:**在拉取请求正文中的任何位置写 @sourcery-ai summary 以随时生成 PR 摘要。您还可以使用此命令指定摘要的插入位置。

自定义您的体验

访问您的仪表板以:

  • 启用或禁用审阅功能,如 Sourcery 生成的拉取请求摘要、审阅者指南等。
  • 更改审阅语言。
  • 添加、删除或编辑自定义审阅说明。
  • 调整其他审阅设置。

获取帮助

Original review guide in English

Reviewer's Guide by Sourcery

This pull request removes the dependency of the global floating window on the activity lifecycle. It introduces a new service and broadcast receiver to manage the floating window's lifecycle. It also updates the permission check logic and view initialization process.

Sequence diagram for updated floating window initialization flow

sequenceDiagram
    participant App
    participant FxSystemPlatformProvider
    participant WindowManager
    participant PermissionChecker

    App->>FxSystemPlatformProvider: checkOrInit()
    alt internalView exists
        FxSystemPlatformProvider-->>App: return true
    else internalView is null
        FxSystemPlatformProvider->>FxSystemPlatformProvider: checkOrRegisterActivityLifecycle()
        FxSystemPlatformProvider->>PermissionChecker: checkAgreePermission(context)
        alt has permission
            PermissionChecker-->>FxSystemPlatformProvider: true
            FxSystemPlatformProvider->>WindowManager: getSystemService
            FxSystemPlatformProvider->>FxSystemPlatformProvider: create FxSystemContainerView
            FxSystemPlatformProvider-->>App: return true
        else no permission
            PermissionChecker-->>FxSystemPlatformProvider: false
            FxSystemPlatformProvider->>FxSystemPlatformProvider: internalAskAutoPermission
            FxSystemPlatformProvider-->>App: return false
        end
    end
Loading

State diagram for floating window lifecycle

stateDiagram-v2
    [*] --> Initialized: Boot Completed
    Initialized --> CheckingPermission: Show Request
    CheckingPermission --> RequestingPermission: No Permission
    CheckingPermission --> Creating: Has Permission
    RequestingPermission --> Creating: Permission Granted
    Creating --> Showing: Create View
    Showing --> Hidden: Hide Request
    Hidden --> Showing: Show Request
    Hidden --> [*]: Destroy
Loading

File-Level Changes

Change Details Files
Decoupled the floating window from the activity lifecycle.
  • Removed the direct dependency on activity in FxSystemPlatformProvider.
  • Introduced checkOrRegisterActivityLifecycle to manage lifecycle callbacks.
  • Updated checkOrInit to handle permission checks and view initialization independently of the activity.
  • Modified FxBasisControlImp to update the enable status and check for show conditions.
floatingx/src/main/java/com/petterp/floatingx/imp/system/FxSystemPlatformProvider.kt
floatingx/src/main/java/com/petterp/floatingx/imp/FxBasisControlImp.kt
Introduced a new service and broadcast receiver to manage the floating window.
  • Added LauncherService to handle the floating window's lifecycle.
  • Added LauncherReceiver to start the service on boot.
  • Declared the service and receiver in the manifest.
app/src/main/AndroidManifest.xml
app/src/main/java/com/petterp/floatingx/app/service/LauncherService.kt
app/src/main/java/com/petterp/floatingx/app/service/LauncherReceiver.kt
Updated the permission check logic.
  • Modified checkAgreePermission to use the application context instead of the activity context.
floatingx/src/main/java/com/petterp/floatingx/imp/system/FxSystemPlatformProvider.kt
Improved view initialization and update process.
  • Added logic to prevent unnecessary view updates if the size hasn't changed.
floatingx/src/main/java/com/petterp/floatingx/view/helper/FxViewLocationHelper.kt
Updated library version in documentation.
  • Updated version number to 2.3.3.
README.md
README_EN.md

Possibly linked issues

  • #0: The PR fixes the issue where the floating window in Activity B could not be displayed correctly after being hidden in Activity A. The PR updates the checkOrInit function to handle activity lifecycle and permission checks correctly.
  • Create detekt-analysis.yml #1: The PR fixes the issue by removing the dependency on activity lifecycle for displaying the floating menu, addressing the bug where the menu wouldn't show on app start.

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.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a 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. You can also use
    this command to specify where the summary should be inserted.

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

Copy link
Contributor

@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.

@Petterpx - 我已经审查了你的更改 - 以下是一些反馈:

整体评论

  • 有一个 FIXME 注释表明可能存在多次 show() 调用 - 在合并之前应解决这个竞争条件。考虑添加适当的同步或事件去重。
以下是我在审查期间查看的内容
  • 🟡 一般性问题:发现 2 个问题
  • 🟢 安全性:一切看起来都很好
  • 🟢 测试:一切看起来都很好
  • 🟢 复杂性:一切看起来都很好
  • 🟢 文档:一切看起来都很好

Sourcery 对开源项目是免费的 - 如果你喜欢我们的评论,请考虑分享 ✨
帮助我变得更有用!请在每条评论上点击 👍 或 👎,我将使用这些反馈来改进你的评论。
Original comment in English

Hey @Petterpx - I've reviewed your changes - here's some feedback:

Overall Comments:

  • There's a FIXME comment indicating potential multiple show() calls - this race condition should be addressed before merging. Consider adding proper synchronization or event deduplication.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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.

README_EN.md Outdated Show resolved Hide resolved
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@Petterpx Petterpx merged commit f11d98f into main Jan 2, 2025
2 of 3 checks passed
@Petterpx Petterpx deleted the fix_system_scope_rule branch January 2, 2025 14:58
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.

1 participant