desktop-app.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. // SPDX-FileCopyrightText: 2012-2023 MOD Audio UG
  2. // SPDX-License-Identifier: AGPL-3.0-or-later
  3. /*
  4. * MOD Desktop ("desktop-app") seam.
  5. *
  6. * Everything specific to the MOD Desktop application lives here. Note that
  7. * desktop.js, despite the name, is the shared web GUI controller and runs on
  8. * the hardware too -- "desktop" there is the pedalboard workspace metaphor,
  9. * and the file predates MOD Desktop by years.
  10. *
  11. * This file is only served when mod-ui runs with MOD_DESKTOP=1: index.html
  12. * links it, its stylesheet and the desktop_app_* mustache templates behind
  13. * {% if desktop_app %}, so a MOD device never downloads any of it. The two
  14. * shared files that still mention DesktopApp (index.html, hardware.js) only do
  15. * so on paths that cannot run on a device -- see test/js/desktop-app.test.js.
  16. *
  17. * What MOD Desktop has: the Constructor (pedalboard editor) and the Pedalboard
  18. * Library, Tone3000 included. The set of plugins is fixed at build time.
  19. *
  20. * What it does not have, and how that shows:
  21. *
  22. * - Plugin Store, Banks, File Manager: the icon stays in the main menu,
  23. * greyed out, as is the Share button. Clicking one opens ONE shared overlay -- a Dwarf press shot,
  24. * the feature name, one sentence on what it does on a MOD device and a
  25. * button to the website -- instead of the feature's own window. No store
  26. * preview, no store queries, no "locked" plugin cards.
  27. * - Hardware addressing: the same card inside the addressing form, where the
  28. * hardware-only options would be.
  29. * - Control Chain: not advertised at all, icon and window hidden.
  30. * - Settings, status and RAM readouts, MIDI-port toggle, snapshot "assign
  31. * all": hidden, no card. They are absent for unrelated reasons, and
  32. * advertising hardware for them would mislead.
  33. */
  34. var DesktopApp = {
  35. /* Where the overlay and the cards send people: the MOD Dwarf product page
  36. * (Gianfranco, 2026-10-11; it was the retailers page, 2026-10-07). */
  37. STORE_URL: 'https://mod.audio/dwarf/',
  38. /* Press photo from mod.audio/dwarf, bundled rather than hotlinked: MOD
  39. * Desktop runs offline, and fetching it would tell mod.audio who is
  40. * looking at these panels. It is shot on black, so it sits inside the dark
  41. * UI without a seam. */
  42. IMAGE_URL: 'img/desktop-app/dwarf-front.jpg',
  43. /* The addressing dialog is a white form, where a photo shot on black would
  44. * be the same mismatch the other way round. This is the press shot on
  45. * white, cropped to the pedal. */
  46. IMAGE_URL_LIGHT: 'img/desktop-app/dwarf-light.jpg',
  47. CTA: 'Discover the MOD Dwarf',
  48. /* Device-only features that keep their main-menu icon, greyed out. Keyed by
  49. * the icon's id; clicking one opens the shared overlay with this copy. */
  50. EXCLUSIVE: {
  51. 'mod-cloud-plugins': {
  52. feature: 'Plugin Store',
  53. message: 'The Plugin Store downloads new plugins from the MOD cloud straight ' +
  54. 'into a MOD device, in one click and with no computer in between. ' +
  55. 'MOD Desktop ships with a fixed set of plugins.',
  56. },
  57. 'mod-bank': {
  58. feature: 'Banks',
  59. message: 'Banks group your pedalboards so you can step through them with the ' +
  60. 'footswitches on a MOD device, hands-free and without a screen.',
  61. },
  62. 'mod-file-manager': {
  63. feature: 'File Manager',
  64. message: 'The File Manager puts IRs, NAM captures, audio loops and MIDI files on ' +
  65. 'a MOD device\'s own storage, where its plugins use them on stage with ' +
  66. 'no computer attached.',
  67. },
  68. },
  69. /* The Share button on the pedalboard title bar: not an icon with an id, but
  70. * the same treatment -- greyed, overlay on click. */
  71. SHARE: {
  72. feature: 'Share',
  73. message: 'Sharing publishes a pedalboard to your MOD account, where it joins the ' +
  74. 'pedalboards other MOD device owners browse and load straight onto their ' +
  75. 'device. Pedalboards made on MOD Desktop stay on this computer.',
  76. },
  77. active: false,
  78. isActive: function () {
  79. return DesktopApp.active
  80. },
  81. // Render helpers ------------------------------------------------------
  82. render: function (template, feature, message, extra) {
  83. return Mustache.render(TEMPLATES[template], $.extend({
  84. feature: feature,
  85. message: message,
  86. cta: DesktopApp.CTA,
  87. store_url: DesktopApp.STORE_URL,
  88. image_url: DesktopApp.IMAGE_URL,
  89. variant: '',
  90. }, extra || {}))
  91. },
  92. /* The card: eyebrow, feature, one sentence, one button, over the photo.
  93. * Dark and full-window; used inside the Control Chain window and the
  94. * overlay. */
  95. panel: function (feature, message) {
  96. return DesktopApp.render('desktop_app_exclusive_panel', feature, message)
  97. },
  98. /* Same card, laid out wide and light, for use inside the addressing form. */
  99. formPanel: function (feature, message) {
  100. return DesktopApp.render('desktop_app_exclusive_panel', feature, message, {
  101. image_url: DesktopApp.IMAGE_URL_LIGHT,
  102. variant: 'desktop-app-exclusive-form',
  103. })
  104. },
  105. // Overlay -------------------------------------------------------------
  106. /* One overlay for the three greyed icons, created on first use and reused.
  107. * Closes on its button, on a click outside the card, and on Escape. */
  108. overlay: function () {
  109. var overlay = $('#desktop-app-exclusive-overlay')
  110. if (overlay.length === 0) {
  111. overlay = $(Mustache.render(TEMPLATES['desktop_app_exclusive_overlay'], {}))
  112. overlay.hide().appendTo('body')
  113. overlay.find('.js-close').click(function () {
  114. DesktopApp.hideUpsell()
  115. return false
  116. })
  117. // Anywhere outside the card is backdrop: the panel wrapper fills
  118. // the overlay, so the target is rarely the overlay element itself.
  119. overlay.click(function (e) {
  120. if ($(e.target).closest('.desktop-app-exclusive-card').length === 0) {
  121. DesktopApp.hideUpsell()
  122. }
  123. })
  124. $(document).keydown(function (e) {
  125. if (e.keyCode == 27 && overlay.css('display') !== 'none') {
  126. DesktopApp.hideUpsell()
  127. }
  128. })
  129. }
  130. return overlay
  131. },
  132. showUpsell: function (feature, message) {
  133. var overlay = DesktopApp.overlay()
  134. overlay.find('.desktop-app-exclusive-overlay-content').html(DesktopApp.panel(feature, message))
  135. overlay.show()
  136. },
  137. hideUpsell: function () {
  138. $('#desktop-app-exclusive-overlay').hide()
  139. },
  140. // Setup ---------------------------------------------------------------
  141. /* Called from index.html, after `desktop` is constructed, only when
  142. * mod-ui runs as MOD Desktop. */
  143. setup: function (desktop) {
  144. DesktopApp.active = true
  145. $('body').addClass('desktop-app')
  146. if (desktop) {
  147. // Shared code (hardware.js through the hardwareManager's isApp
  148. // option, installMissingPlugins) still asks the controller.
  149. desktop.isApp = true
  150. // No analytics on MOD Desktop: the Matomo tag manager is never
  151. // loaded, whatever the acceptance preference says. The terms
  152. // popup itself is untouched.
  153. desktop.setupMatomo = function () {}
  154. }
  155. // Not available on desktop, and not a reason to buy hardware.
  156. $('#mod-settings').hide()
  157. $('#mod-status').hide()
  158. $('#mod-ram').hide()
  159. $('#mod-show-midi-port').hide()
  160. $('#pedalboards-library').find('a').hide()
  161. DesktopApp.setupExclusiveIcons()
  162. DesktopApp.setupShare()
  163. DesktopApp.hideControlChain()
  164. DesktopApp.setupAddressing()
  165. },
  166. /* Plugin Store, Banks, File Manager: greyed icon, overlay on click, and the
  167. * feature's own window never opens. window.js bound each window's toggle
  168. * to its icon when `desktop` constructed the boxes, so that handler goes. */
  169. setupExclusiveIcons: function () {
  170. $.each(DesktopApp.EXCLUSIVE, function (id, copy) {
  171. var icon = $('#' + id)
  172. icon.off('click')
  173. icon.addClass('desktop-app-greyed')
  174. // The store icon is hidden by the non-device branch in index.html,
  175. // which runs before us.
  176. icon.show()
  177. icon.click(function () {
  178. DesktopApp.showUpsell(copy.feature, copy.message)
  179. return false
  180. })
  181. })
  182. },
  183. /* The Share button: desktop.js bound the share window to it; that handler
  184. * goes, the button stays visible but greyed and opens the overlay. */
  185. setupShare: function () {
  186. var button = $('#pedalboard-info').find('.js-cloud')
  187. button.off('click')
  188. button.addClass('desktop-app-greyed')
  189. button.show()
  190. button.click(function () {
  191. DesktopApp.showUpsell(DesktopApp.SHARE.feature, DesktopApp.SHARE.message)
  192. return false
  193. })
  194. },
  195. /* Control Chain is not advertised on MOD Desktop (Gianfranco, 2026-10-08):
  196. * the status-bar icon and its window are simply gone. cc-manager.js keeps
  197. * its tooltip on the hidden icon, harmless. */
  198. hideControlChain: function () {
  199. $('#mod-devices').hide()
  200. $('#mod-devices-window').hide()
  201. },
  202. setupAddressing: function () {
  203. // The snapshot "assign all" button drives hardware addressing.
  204. $('#pedal-presets-window').find('.js-assign-all').hide()
  205. },
  206. /* Hardware-only addressing targets stay selectable in the dialog. Picking one
  207. * puts this card where its addressing options would have been, rather than
  208. * greying the button out and explaining the refusal somewhere else.
  209. *
  210. * There is nothing to save in that state, so the Save button goes with them.
  211. */
  212. showAddressingUpsell: function (form) {
  213. var container = form.find('.main-form-container')
  214. var card = container.find('.desktop-app-exclusive')
  215. if (card.length === 0) {
  216. card = $(DesktopApp.formPanel('Hardware addressing',
  217. 'Assign this parameter to a knob or footswitch and control it with ' +
  218. 'your hands, eyes up, without touching the computer.'))
  219. container.append(card)
  220. }
  221. container.find('.dynamic-field').hide()
  222. card.show()
  223. form.find('.js-save').hide()
  224. // The advanced pane holds label, range, LED colour and sensitivity: all
  225. // settings of an addressing that cannot be made here. Collapse it through
  226. // its own toggle, which owns the dialog-width animation.
  227. var advanced = form.find('.advanced-toggle')
  228. if (form.find('.advanced-container').is(':visible')) {
  229. advanced.trigger('click')
  230. }
  231. advanced.hide()
  232. },
  233. hideAddressingUpsell: function (form) {
  234. if (! DesktopApp.active) {
  235. return
  236. }
  237. form.find('.main-form-container').find('.desktop-app-exclusive').hide()
  238. form.find('.js-save').show()
  239. form.find('.advanced-toggle').show()
  240. },
  241. }