Search code examples
elixirwxwidgets

Failed to unregister class Chrome_WidgetWin_0. Error


Background

I am using Elixir Desktop to make an elixir desktop application: https://github.com/elixir-desktop/desktop

And I am successfully able to launch and manage my app. However, when I close it I always get this error:

[1224/050609.437:ERROR:window_impl.cc(115)] Failed to unregister class Chrome_WidgetWin_0. Error = 203

enter image description here

Problems

There are actually two issues here

  1. The application takes a very long time to close after I press Quit. The message is received by Phoenix (see the Ì AM LEAVING log) but for some reason the window takes several seconds to close.
  2. I get the previously mentioned error

Code

At this point 90% of this HelloWorld project is code generated by mix. There are only 2 files I changes that might be relevant here:

menubar.ex

defmodule WebInterface.MenuBar do
  @moduledoc """
    Menubar that is shown as part of the main Window on Windows/Linux. In
    MacOS this Menubar appears at the very top of the screen.
  """
  import WebInterface.Gettext
  use Desktop.Menu
  alias Desktop.Window

  @impl Desktop.Menu
  def render(assigns) do
    ~H"""
    <menubar>
      <menu label={gettext("File")}>
          <hr/>
          <item onclick="quit"><%= gettext "Quit" %></item>
      </menu>
      <menu label={gettext("Extra")}>
          <item onclick="browser"><%= gettext "Open Browser" %></item>
      </menu>
    </menubar>
    """
  end

  @impl Desktop.Menu
  def handle_event("quit", menu) do
    IO.puts("I AM LEAVING")
    Window.quit()
    {:noreply, menu}
  end

  def handle_event("browser", menu) do
    WebInterface.Endpoint.url()
    |> Window.prepare_url()
    |> :wx_misc.launchDefaultBrowser()

    {:noreply, menu}
  end

  @impl Desktop.Menu
  def mount(menu) do
    {:ok, menu}
  end

  @impl Desktop.Menu
  def handle_info(:changed, menu) do
    {:noreply, menu}
  end
end

applications.ex

defmodule WebInterface.Application do
  # See https://hexdocs.pm/elixir/Application.html
  # for more information on OTP Applications
  @moduledoc false

  use Application

    alias Desktop

  @impl true
  def start(_type, _args) do
    children = [
      WebInterface.Telemetry,
      {Phoenix.PubSub, name: WebInterface.PubSub},
      WebInterface.Endpoint,
      {Desktop.Window,
       [
         app: :web_interface,
         id: WebInterface,
         title: "Web Interface",
         size: {600, 500},
         menubar: WebInterface.MenuBar,
         url: &WebInterface.Endpoint.url/0
       ]}
    ]

    opts = [strategy: :one_for_one, name: WebInterface.Supervisor]
    Supervisor.start_link(children, opts)
  end

  @impl true
  def config_change(changed, _new, removed) do
    WebInterface.Endpoint.config_change(changed, removed)
    :ok
  end
end

I am hoping this error is caused by either a miss configuration or some function I am not implementing correctly.

How can I fix this error?


Solution

  • Answer

    At the time of this writing, the author pushed a fix to Master in Github. This fix addresses the issue of the application taking a long time to close, however it does not address the Chrome_WidgetWin_0. Error issue.

    This issue is a known one and has already been reported, but there are no signs of fixing it from the Chrome project, so I guess we just have to live with it for the time being: https://bugs.chromium.org/p/chromium/issues/detail?id=113008

    Another issue is the crash. Is likely happens because of the previous issue, and therefore there is little one can do here.

    Since the main problem was fixed, I am marking this as solved.