Skip to content

Add Platform.System.os_description/0#74

Merged
dominicletz merged 3 commits into
mainfrom
feat/platform-os-description
Jul 21, 2026
Merged

Add Platform.System.os_description/0#74
dominicletz merged 3 commits into
mainfrom
feat/platform-os-description

Conversation

@dominicletz

Copy link
Copy Markdown
Collaborator

Summary

  • Adds Desktop.Platform.System.os_description/0 as the backend-safe replacement for :wx_misc.getOsDescription/0
  • Implements it on Wx (:wx_misc), Json (Desktop.Bridge.Protocol), and Browser (nil)
  • Mock returns ~c"Mock OS"; facade normalizes charlist/binary and trims empty → nil
  • Guard + tests so apps do not call :wx_misc.getOsDescription/0 directly

Needed by diode-drive: after the mobile bridge embed (#73), OS.model/0 still called :wx_misc.getOsDescription/0, which targeted the removed Hex Bridge GenServer and crashed Android device linking.

Test plan

  • NO_WX=1 mix test test/desktop/backend/json_test.exs test/desktop/backend/browser_test.exs test/desktop/regression/beam_wx_calls_test.exs --exclude wx
  • mix test.guard
  • xvfb-run mix test.wx (or local wx) for T-WX: os_description via Platform.System

Made with Cursor

Replace direct :wx_misc.getOsDescription/0 usage so apps can read a
device/OS description on Wx, Json/mobile bridge, and Browser backends
without depending on the Hex Bridge GenServer.

Co-authored-by: Cursor <cursoragent@cursor.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces Desktop.Platform.System.os_description/0 as a backend-safe replacement for :wx_misc.getOsDescription/0 across different backends (Wx, Json bridge, and Browser). It includes corresponding backend implementations, tests, documentation updates, and a guard rule to prevent direct calls to :wx_misc.getOsDescription/0. Feedback suggests refactoring os_description/0 in lib/desktop/platform/system.ex to avoid piping a block directly into a case statement, which is an Elixir anti-pattern, and instead bind the block's result to a local variable first.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +42 to +61
def os_description do
Helpers.with_wx_env(fn ->
case impl().os_description() do
nil -> nil
desc when is_list(desc) -> List.to_string(desc)
desc when is_binary(desc) -> desc
_ -> nil
end
end)
|> case do
nil ->
nil

str ->
case String.trim(str) do
"" -> nil
other -> other
end
end
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Piping the result of a block directly into a case statement is generally considered an anti-pattern in Elixir (as highlighted by tools like Credo). It can make the code harder to read and debug.

Instead, bind the result of Helpers.with_wx_env/1 to a local variable first, and then perform the case match on that variable.

  def os_description do
    raw_desc =
      Helpers.with_wx_env(fn ->
        case impl().os_description() do
          desc when is_binary(desc) -> desc
          desc when is_list(desc) -> List.to_string(desc)
          _ -> nil
        end
      end)

    case raw_desc do
      nil ->
        nil

      str ->
        case String.trim(str) do
          "" -> nil
          trimmed -> trimmed
        end
    end
  end
References
  1. Avoid piping into control flow structures like case, if, or cond to maintain readability and idiomatic Elixir style. (link)

@dominicletz dominicletz added the cursor-waiting Cursor issue-workflow (cursor-automation.com) label Jul 21, 2026
@cursor-automation

Copy link
Copy Markdown

@gemini review this PR

@cursor-automation cursor-automation Bot added cursor-waiting-for-ci Cursor issue-workflow (cursor-automation.com) and removed cursor-waiting Cursor issue-workflow (cursor-automation.com) labels Jul 21, 2026
Bind Helpers.with_wx_env/1 before matching so we avoid piping into case,
and add Platform.System tests for charlist/binary and blank → nil.

Co-authored-by: Dominic Letz <dominicletz@users.noreply.github.com>
wx_use_env/0 calls Platform.System.set_env/1 when Desktop.Env is running,
so the os_description stub must no-op set_env/1 for host wx tests.

Co-authored-by: Dominic Letz <dominicletz@users.noreply.github.com>
@cursor-automation cursor-automation Bot added cursor-demo Cursor issue-workflow (cursor-automation.com) cursor-waiting-for-human Cursor issue-workflow (cursor-automation.com) and removed cursor-waiting-for-ci Cursor issue-workflow (cursor-automation.com) cursor-demo Cursor issue-workflow (cursor-automation.com) labels Jul 21, 2026
@dominicletz
dominicletz merged commit feeb68f into main Jul 21, 2026
4 checks passed
@dominicletz
dominicletz deleted the feat/platform-os-description branch July 21, 2026 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cursor-waiting-for-human Cursor issue-workflow (cursor-automation.com)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants