diff --git a/Gemfile b/Gemfile index 64a32d01a..1d8d39cd7 100644 --- a/Gemfile +++ b/Gemfile @@ -27,6 +27,7 @@ gem "rqrcode" gem "redcarpet" gem "rouge" gem "jbuilder" +gem "platform_agent" # Telemetry and logging gem "sentry-ruby" diff --git a/Gemfile.lock b/Gemfile.lock index 3965d502b..7353afc2c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -272,6 +272,9 @@ GEM parser (3.3.8.0) ast (~> 2.4.1) racc + platform_agent (1.0.1) + activesupport (>= 5.2.0) + useragent (~> 0.16.3) pp (0.6.2) prettyprint prettyprint (0.2.0) @@ -456,6 +459,7 @@ DEPENDENCIES importmap-rails jbuilder kamal + platform_agent propshaft puma (>= 5.0) rails! diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4f75453ff..20385eda0 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,5 @@ class ApplicationController < ActionController::Base - include Authentication, CurrentTimezone + include Authentication, CurrentTimezone, SetPlatform stale_when_importmap_changes allow_browser versions: :modern diff --git a/app/controllers/concerns/set_platform.rb b/app/controllers/concerns/set_platform.rb new file mode 100644 index 000000000..54e77d517 --- /dev/null +++ b/app/controllers/concerns/set_platform.rb @@ -0,0 +1,12 @@ +module SetPlatform + extend ActiveSupport::Concern + + included do + helper_method :platform + end + + private + def platform + @platform ||= ApplicationPlatform.new(request.user_agent) + end +end diff --git a/app/helpers/hotkeys_helper.rb b/app/helpers/hotkeys_helper.rb new file mode 100644 index 000000000..a1894104c --- /dev/null +++ b/app/helpers/hotkeys_helper.rb @@ -0,0 +1,19 @@ +module HotkeysHelper + def hotkey_label(hotkey) + hotkey.split(",").first if hotkey + case hotkey + when Array + hotkey.map { |key| + if key == "ctrl" && platform.mac? + "⌘" + elsif key == "enter" + platform.mac? ? "return" : "enter" + else + key + end + }.join("+") + else + hotkey.split(",").first if hotkey + end + end +end diff --git a/app/models/application_platform.rb b/app/models/application_platform.rb new file mode 100644 index 000000000..c8c24a50b --- /dev/null +++ b/app/models/application_platform.rb @@ -0,0 +1,29 @@ +class ApplicationPlatform < PlatformAgent + def ios? + match? /iPhone|iPad/ + end + + def android? + match? /Android/ + end + + def mac? + match? /Macintosh/ + end + + def chrome? + user_agent.browser.match? /Chrome/ + end + + def safari? + user_agent.browser.match? /Safari/ + end + + def mobile? + ios? || android? + end + + def desktop? + !mobile? + end +end diff --git a/app/views/cards/index/_header.html.erb b/app/views/cards/index/_header.html.erb index 7ec915b4d..499e70b45 100644 --- a/app/views/cards/index/_header.html.erb +++ b/app/views/cards/index/_header.html.erb @@ -7,7 +7,7 @@
<%= tag.button class: "txt-align-center input input--select borderless txt-medium", data: { - action: "click->dialog#open:stop keydown.meta+j@document->hotkey#click", + action: "click->dialog#open:stop keydown.meta+j@document->hotkey#click keydown.ctrl+j@document->hotkey#click", controller: "hotkey" } do %>

<%= filter_title filter %> @@ -38,7 +38,7 @@ <%= render "cards/index/collections_filter", filter: filter %>

- Press ⌘j anytime to open this, esc to close. + Press <%= hotkey_label(["ctrl", "J"]) -%> anytime to open this, esc to close.

<% end %>

diff --git a/app/views/commands/_form.html.erb b/app/views/commands/_form.html.erb index d10a919d8..c01705fe7 100644 --- a/app/views/commands/_form.html.erb +++ b/app/views/commands/_form.html.erb @@ -4,7 +4,7 @@ data: { controller: "form", terminal_target: "form", - action: "turbo:submit-start->terminal#commandSubmitted turbo:submit-end->terminal#focus keydown.meta+k@document->terminal#focus keydown.enter->terminal#executeCommand keydown.esc->terminal#hideMenus turbo:submit-end->terminal#handleCommandResponse" + action: "turbo:submit-start->terminal#commandSubmitted turbo:submit-end->terminal#focus keydown.meta+k@document->terminal#focus keydown.ctrl+k@document->terminal#focus keydown.enter->terminal#executeCommand keydown.esc->terminal#hideMenus turbo:submit-end->terminal#handleCommandResponse" } do %> @@ -17,7 +17,7 @@ terminal_target: "input", action: "keydown.up->toggle-class#add:prevent keydown.up->navigable-list#selectCurrentOrLast terminal#hideError" }, - placeholder: "Press ⌘+K to search or type commands…", + placeholder: "Press #{ hotkey_label(["ctrl", "K"]) } to search or type commands…", spellcheck: "false" %> <%= hidden_field_tag "confirmed", nil, data: { terminal_target: "confirmation" } %> diff --git a/app/views/events/_filter.html.erb b/app/views/events/_filter.html.erb index 9f46f826f..38f13feb0 100644 --- a/app/views/events/_filter.html.erb +++ b/app/views/events/_filter.html.erb @@ -2,7 +2,7 @@ data-controller="dialog" data-action="keydown.esc->dialog#close click@document->dialog#closeOnClickOutside"> <%= tag.button class:"events__filter-btn input input--select flex-inline center min-width max-width txt-small", data: { - action: "click->dialog#open:stop keydown.meta+j@document->hotkey#click", + action: "click->dialog#open:stop keydown.meta+j@document->hotkey#click keydown.ctrl+j@document->hotkey#click", controller: "hotkey" } do %> <%= filter_selected_collections_label(filter) %> @@ -35,7 +35,7 @@ <% end %>

- Press ⌘j anytime to open this, esc to close. + Press <%= hotkey_label(["ctrl", "K"]) -%> anytime to open this, esc to close.

<% end %>