Skip to content

Commit

Permalink
Credo fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicletz committed Oct 15, 2024
1 parent de38c02 commit 4fc6ea3
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lib/desktop/fallback.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ defmodule Desktop.Fallback do
do_webview_new(frame, backend: String.to_charlist(webview_backend_env()))

backend_available?("wxWebViewChromium") ->
do_webview_new(frame, backend: 'wxWebViewChromium')
do_webview_new(frame, backend: ~c"wxWebViewChromium")

backend_available?("wxWebViewEdge") ->
do_webview_new(frame, backend: 'wxWebViewEdge')
do_webview_new(frame, backend: ~c"wxWebViewEdge")

OS.type() == Windows ->
error_missing_edge(frame)
Expand Down
9 changes: 6 additions & 3 deletions lib/desktop/menu.ex
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ defmodule Desktop.Menu do

@doc false
defmacro __using__(opts) do
Module.register_attribute(__CALLER__.module, :is_menu_server, persist: true, accumulate: false)
Module.register_attribute(__CALLER__.module, :is_menu_server,
persist: true,
accumulate: false
)

Module.put_attribute(__CALLER__.module, :is_menu_server, Keyword.get(opts, :server, true))

Expand Down Expand Up @@ -310,7 +313,7 @@ defmodule Desktop.Menu do
}
|> do_mount()

if is_module_server?(module) do
if module_server?(module) do
Process.register(menu_pid, module)
end

Expand Down Expand Up @@ -480,7 +483,7 @@ defmodule Desktop.Menu do
end
end

defp is_module_server?(module) do
defp module_server?(module) do
try do
case Keyword.get(module.__info__(:attributes), :is_menu_server, false) do
[true] -> true
Expand Down
6 changes: 3 additions & 3 deletions lib/desktop/menu/adapters/wx.ex
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,10 @@ defmodule Desktop.Menu.Adapter.Wx do
:wxMenu.append(parent_menu, item)

if attr[:checked] != nil do
:wxMenuItem.check(item, check: is_true(attr[:checked]))
:wxMenuItem.check(item, check: true?(attr[:checked]))
end

if is_true(attr[:disabled]) do
if true?(attr[:disabled]) do
:wxMenu.enable(parent_menu, id, false)
end

Expand Down Expand Up @@ -347,7 +347,7 @@ defmodule Desktop.Menu.Adapter.Wx do
parent_menu
end

defp is_true(value) do
defp true?(value) do
value != nil and value != "false" and value != "0" and value != ""
end
end
4 changes: 2 additions & 2 deletions lib/desktop/menu/html_tokenizer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ defmodule Desktop.Menu.HTMLTokenizer do
# unfortunately the token/4 API changed into token/6 so copying it inplace...

@moduledoc false
@space_chars '\s\t\f'
@name_stop_chars @space_chars ++ '>/=\r\n'
@space_chars ~c"\s\t\f"
@name_stop_chars @space_chars ++ ~c">/=\r\n"

defmodule ParseError do
defexception [:file, :line, :column, :description]
Expand Down
8 changes: 6 additions & 2 deletions lib/desktop/window.ex
Original file line number Diff line number Diff line change
Expand Up @@ -638,13 +638,17 @@ defmodule Desktop.Window do

def prepare_url(url) when is_function(url), do: prepare_url(url.())
def prepare_url(nil), do: nil

def prepare_url(url) when is_binary(url) do
query = %{"k" => Desktop.Auth.login_key()}
uri = URI.parse(url)

case uri do
%URI{query: nil} -> %URI{uri | query: URI.encode_query(query)}
%URI{query: other} -> %URI{uri | query: URI.encode_query(Map.merge(URI.decode_query(other), query))}
%URI{query: nil} ->
%URI{uri | query: URI.encode_query(query)}

%URI{query: other} ->
%URI{uri | query: URI.encode_query(Map.merge(URI.decode_query(other), query))}
end
|> URI.to_string()
end
Expand Down
6 changes: 3 additions & 3 deletions lib/desktop/wx/task_bar_icon.ex
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ defmodule Desktop.Wx.TaskBarIcon do
if supports_method?(:new, 1) do
# Supports :wxTaskBarIcon.new(opts)

if is_module?(:wxWebView) do
if module?(:wxWebView) do
# Proper OTP24 release
create_taskbar_icon(createPopupMenu: fn_create_popup)
else
Expand Down Expand Up @@ -186,14 +186,14 @@ defmodule Desktop.Wx.TaskBarIcon do
end

defp supports_method?(method, arity) do
if is_module?(:wxTaskBarIcon) do
if module?(:wxTaskBarIcon) do
Kernel.function_exported?(:wxTaskBarIcon, method, arity)
else
false
end
end

defp is_module?(module) do
defp module?(module) do
Code.ensure_loaded?(module)
end
end

0 comments on commit 4fc6ea3

Please sign in to comment.