report.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. // SPDX-FileCopyrightText: 2026 MOD Audio UG
  2. // SPDX-License-Identifier: AGPL-3.0-or-later
  3. /*
  4. * "Report a problem"
  5. *
  6. * Collects what the Web UI knows about this device and the current session
  7. * into a block of text, and points the user at the forum topic for the
  8. * running release so they can paste it there as a reply.
  9. *
  10. * Nothing is sent anywhere by itself: the user copies the text and posts it.
  11. * The device serial and full logs are deliberately not included; QA can ask for
  12. * them in the thread. On a computer (MOD Desktop) the system information
  13. * answers with a "host" block: operating system, CPU, memory, audio setup and
  14. * the problem lines of the launcher log, with the home folder shortened to ~.
  15. *
  16. * Used by index.html (with pedalboard and DSP stats) and settings.html
  17. * (system details only).
  18. */
  19. function ProblemReport(options) {
  20. var self = this
  21. options = $.extend({
  22. version: '', // OS version string as shown in Settings
  23. feedbackUrl: '', // forum topic (or category) for this release
  24. getPedalboard: null, // function () -> { title: '', plugins: [uri, ...] } or null
  25. getStats: null, // function () -> { xruns: n, cpuLoad: n } or null
  26. }, options)
  27. this.window = null
  28. this.textarea = null
  29. var TEMPLATE = [
  30. '**What happened**',
  31. '',
  32. '',
  33. '**Steps to reproduce**',
  34. '1. ',
  35. '',
  36. '**Expected**',
  37. '',
  38. '',
  39. ].join('\n')
  40. this.build = function () {
  41. if (self.window) {
  42. return
  43. }
  44. var win = $('<div id="report-window" class="save-popup mod-hidden"></div>')
  45. var box = $('<div class="box"></div>').appendTo(win)
  46. box.append('<h1 class="pull-left">Report a problem</h1><span class="js-cancel close">&times;</span>')
  47. box.append('<div class="clearfix"></div>')
  48. box.append('<p>Describe the problem in the text below, then copy it and paste it as a reply in the forum topic for this release. ' +
  49. 'The system details are filled in for you.</p>')
  50. self.textarea = $('<textarea id="report-text" rows="18" spellcheck="false"></textarea>').appendTo(box)
  51. var actions = $('<div class="actions"></div>').appendTo(box)
  52. actions.append('<span id="report-copied" class="mod-hidden">Copied to clipboard</span> ')
  53. actions.append('<input type="button" id="report-copy" value="Copy to clipboard"> ')
  54. actions.append('<a id="report-open-forum" target="_blank" rel="noopener">Open the forum topic</a> ')
  55. actions.append('<input type="button" class="js-cancel" value="Close">')
  56. win.find('#report-open-forum').attr('href', options.feedbackUrl)
  57. win.find('.js-cancel').click(function () {
  58. self.close()
  59. return false
  60. })
  61. win.find('#report-copy').click(function () {
  62. self.copy()
  63. return false
  64. })
  65. $('body').keydown(function (e) {
  66. if (e.keyCode == 27) {
  67. self.close()
  68. }
  69. })
  70. $('body').append(win)
  71. self.window = win
  72. }
  73. this.open = function () {
  74. self.build()
  75. self.textarea.val(TEMPLATE + '\n\nCollecting system details...')
  76. self.window.show()
  77. $.ajax({
  78. url: '/system/info',
  79. method: 'GET',
  80. cache: false,
  81. global: false,
  82. dataType: 'json',
  83. success: function (info) {
  84. self.textarea.val(TEMPLATE + '\n' + self.render(info))
  85. },
  86. error: function () {
  87. self.textarea.val(TEMPLATE + '\n' + self.render(null))
  88. },
  89. })
  90. }
  91. this.close = function () {
  92. if (self.window) {
  93. self.window.hide()
  94. }
  95. }
  96. this.copy = function () {
  97. self.textarea.select()
  98. var ok
  99. try {
  100. ok = document.execCommand('copy')
  101. } catch (err) {
  102. ok = false
  103. }
  104. var note = self.window.find('#report-copied')
  105. note.text(ok ? 'Copied to clipboard' : 'Press Ctrl/Cmd + C to copy').show()
  106. setTimeout(function () { note.hide() }, 2500)
  107. }
  108. function formatUptime(seconds) {
  109. if (seconds === null || seconds === undefined) {
  110. return 'unknown'
  111. }
  112. var h = Math.floor(seconds / 3600)
  113. var m = Math.floor((seconds % 3600) / 60)
  114. return h + 'h ' + m + 'm'
  115. }
  116. this.render = function (info) {
  117. info = info || {}
  118. var lines = []
  119. lines.push('```')
  120. var host = info.host || null
  121. lines.push('MOD release: ' + (info.release || options.version || 'unknown') +
  122. (info.sysdate && info.sysdate !== 'Unknown' ? ' (built ' + info.sysdate + ')' : ''))
  123. if (host) {
  124. // a computer: describe the computer, not a device
  125. lines.push('Product: ' + (info.model || 'MOD Desktop') + ' / ' + (info.bin_compat || '?'))
  126. lines.push('Computer OS: ' + (host.os || 'unknown'))
  127. lines.push('CPU: ' + (host.cpu || 'unknown'))
  128. lines.push('Memory: ' + (host.memory_gb ? host.memory_gb + ' GB' : 'unknown'))
  129. lines.push('Up for: ' + formatUptime(host.uptime))
  130. lines.push('Audio engine: ' + (host.sample_rate ? Math.round(host.sample_rate) + ' Hz' : '? Hz') +
  131. ', buffer ' + (host.buffer_size || '?') + ' frames')
  132. var launcher = host.launcher || null
  133. if (launcher && launcher.jackd) {
  134. lines.push('Audio start: ' + launcher.jackd)
  135. } else {
  136. lines.push('Audio start: unknown (no launcher log found)')
  137. }
  138. } else {
  139. lines.push('Device: ' + (info.hwname || 'unknown') +
  140. ' / ' + (info.platform || '?') + ' / ' + (info.bin_compat || '?') +
  141. (info.model ? ' / ' + info.model : ''))
  142. lines.push('Controller fw: ' + (info.controller || 'unknown'))
  143. if (info.uname) {
  144. lines.push('Kernel: ' + info.uname.release)
  145. }
  146. lines.push('Uptime: ' + formatUptime(info.uptime))
  147. }
  148. var stats = options.getStats ? options.getStats() : null
  149. if (stats) {
  150. lines.push('Xruns: ' + (stats.xruns === null ? 'unknown' : stats.xruns) +
  151. ' DSP load: ' + (stats.cpuLoad === null ? 'unknown' : stats.cpuLoad + '%'))
  152. }
  153. var pb = options.getPedalboard ? options.getPedalboard() : null
  154. if (pb) {
  155. lines.push('Pedalboard: "' + pb.title + '" (' + pb.plugins.length + ' plugins)')
  156. for (var i = 0; i < pb.plugins.length; i++) {
  157. lines.push(' - ' + pb.plugins[i])
  158. }
  159. }
  160. lines.push('Web UI at: ' + window.location.host)
  161. lines.push('Browser: ' + navigator.userAgent)
  162. lines.push('```')
  163. if (host && host.launcher && host.launcher.problems && host.launcher.problems.length) {
  164. lines.push('')
  165. lines.push('Launcher log, lines about problems since the last start (' + host.launcher.path + '):')
  166. lines.push('```')
  167. lines = lines.concat(host.launcher.problems)
  168. lines.push('```')
  169. }
  170. return lines.join('\n')
  171. }
  172. }