Skip to content

Commit

Permalink
Wrapper for :wx_misc.launchDefaultBrowser
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicletz committed Nov 1, 2023
1 parent 9b4197b commit 502c2af
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/desktop/fallback.ex
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ defmodule Desktop.Fallback do
end

def webview_show(%Desktop.Window{webview: nil}, url, _) do
:wx_misc.launchDefaultBrowser(url)
OS.launch_default_browser(url)
end

def webview_show(
Expand Down
2 changes: 1 addition & 1 deletion lib/desktop/menu.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule Desktop.Menu do
case command do
<<"open">> -> :not_implemented
<<"quit">> -> Desktop.Window.quit()
<<"help">> -> :wx_misc.launchDefaultBrowser(\'https://google.com\')
<<"help">> -> Desktop.OS.launch_default_browser(\'https://google.com\')
<<"about">> -> :not_implemented
end
Expand Down
13 changes: 13 additions & 0 deletions lib/desktop/os.ex
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,17 @@ defmodule Desktop.OS do
Path.expand(path)
end
end

@doc """
Replacement for the :wx_misc.launchDefaultBrowser function
"""
def launch_default_browser(file) do
spawn(fn ->
case type() do
MacOS -> System.cmd("open", [file], stderr_to_stdout: true, parallelism: true)
Linux -> System.cmd("xdg-open", [file], stderr_to_stdout: true, parallelism: true)
_other -> :wx_misc.launchDefaultBrowser(file)
end
end)
end
end
2 changes: 1 addition & 1 deletion lib/desktop/window.ex
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ defmodule Desktop.Window do

@doc false
def handle_event(wx(event: {:wxWebView, :webview_newwindow, _, _, _target, url}), ui) do
:wx_misc.launchDefaultBrowser(url)
OS.launch_default_browser(url)
{:noreply, ui}
end

Expand Down

0 comments on commit 502c2af

Please sign in to comment.