diff --git a/app/javascript/retrospring/controllers/capabilities_controller.ts b/app/javascript/retrospring/controllers/capabilities_controller.ts new file mode 100644 index 00000000..3d21039f --- /dev/null +++ b/app/javascript/retrospring/controllers/capabilities_controller.ts @@ -0,0 +1,21 @@ +import { Controller } from '@hotwired/stimulus'; + +export default class extends Controller { + connect(): void { + const capabilities = []; + + if ('share' in navigator) { + capabilities.push('cap-web-share'); + } + + if ('serviceWorker' in navigator) { + capabilities.push('cap-service-worker'); + } + + if ('Notification' in window) { + capabilities.push('cap-notification'); + } + + this.element.classList.add(...capabilities); + } +} diff --git a/app/javascript/retrospring/initializers/stimulus.ts b/app/javascript/retrospring/initializers/stimulus.ts index 56e27d7f..3159b75a 100644 --- a/app/javascript/retrospring/initializers/stimulus.ts +++ b/app/javascript/retrospring/initializers/stimulus.ts @@ -5,6 +5,7 @@ import CharacterCountController from "retrospring/controllers/character_count_co import CharacterCountWarningController from "retrospring/controllers/character_count_warning_controller"; import FormatPopupController from "retrospring/controllers/format_popup_controller"; import CollapseController from "retrospring/controllers/collapse_controller"; +import CapabilitiesController from "retrospring/controllers/capabilities_controller"; /** * This module sets up Stimulus and our controllers @@ -17,6 +18,7 @@ export default function (): void { window['Stimulus'] = Application.start(); window['Stimulus'].register('announcement', AnnouncementController); window['Stimulus'].register('autofocus', AutofocusController); + window['Stimulus'].register('capabilities', CapabilitiesController); window['Stimulus'].register('character-count', CharacterCountController); window['Stimulus'].register('character-count-warning', CharacterCountWarningController); window['Stimulus'].register('collapse', CollapseController); diff --git a/app/views/layouts/base.html.haml b/app/views/layouts/base.html.haml index 8b05a3b8..d1d7d54a 100644 --- a/app/views/layouts/base.html.haml +++ b/app/views/layouts/base.html.haml @@ -23,7 +23,7 @@ = csrf_meta_tags = yield(:og) = yield(:meta) - %body{ class: user_signed_in? ? '' : 'not-logged-in' } + %body{ class: user_signed_in? ? nil : 'not-logged-in', data: { controller: "capabilities" } } - if user_signed_in? = render 'navigation/main' - else