cloudplugin.js 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136
  1. // SPDX-FileCopyrightText: 2012-2023 MOD Audio UG
  2. // SPDX-License-Identifier: AGPL-3.0-or-later
  3. // add this to plugin data when cloud fails
  4. function getDummyPluginData() {
  5. return $.extend(true, {}, {
  6. ports: {
  7. control: {
  8. input: []
  9. },
  10. },
  11. })
  12. }
  13. JqueryClass('cloudPluginBox', {
  14. init: function (options) {
  15. var self = $(this)
  16. options = $.extend({
  17. resultCanvas: self.find('.js-cloud-plugins'),
  18. removePluginBundles: function (bundles, callback) {
  19. callback({})
  20. },
  21. installPluginURI: function (uri, callback) {
  22. callback({}, "")
  23. },
  24. upgradePluginURI: function (uri, callback) {
  25. callback({}, "")
  26. },
  27. info: null,
  28. fake: false,
  29. isMainWindow: true,
  30. windowName: "Plugin Store",
  31. pluginsData: {},
  32. }, options)
  33. self.data(options)
  34. var searchbox = self.find('input[type=search]')
  35. // make sure searchbox is empty on init
  36. searchbox.val("")
  37. self.data('searchbox', searchbox)
  38. searchbox.cleanableInput()
  39. self.data('category', null)
  40. self.cloudPluginBox('setCategory', "All")
  41. var lastKeyTimeout = null
  42. searchbox.keydown(function (e) {
  43. if (e.keyCode == 13) { // detect enter
  44. if (lastKeyTimeout != null) {
  45. clearTimeout(lastKeyTimeout)
  46. lastKeyTimeout = null
  47. }
  48. self.cloudPluginBox('search')
  49. return false
  50. }
  51. else if (e.keyCode == 8 || e.keyCode == 46) { // detect delete and backspace
  52. if (lastKeyTimeout != null) {
  53. clearTimeout(lastKeyTimeout)
  54. }
  55. lastKeyTimeout = setTimeout(function () {
  56. self.cloudPluginBox('search')
  57. }, 400);
  58. }
  59. })
  60. searchbox.keypress(function (e) { // keypress won't detect delete and backspace but will only allow inputable keys
  61. if (e.which == 13)
  62. return
  63. if (lastKeyTimeout != null) {
  64. clearTimeout(lastKeyTimeout)
  65. }
  66. lastKeyTimeout = setTimeout(function () {
  67. self.cloudPluginBox('search')
  68. }, 400);
  69. })
  70. searchbox.on('cut', function(e) {
  71. if (lastKeyTimeout != null) {
  72. clearTimeout(lastKeyTimeout)
  73. }
  74. lastKeyTimeout = setTimeout(function () {
  75. self.cloudPluginBox('search')
  76. }, 400);
  77. })
  78. searchbox.on('paste', function(e) {
  79. if (lastKeyTimeout != null) {
  80. clearTimeout(lastKeyTimeout)
  81. }
  82. lastKeyTimeout = setTimeout(function () {
  83. self.cloudPluginBox('search')
  84. }, 400);
  85. })
  86. // three filter rows, one choice each: install state, release (beta) and price
  87. self.find('.filter-segments input:radio').change(function (e) {
  88. self.cloudPluginBox('search')
  89. })
  90. $('#cloud_install_all').click(function (e) {
  91. if (! $(this).hasClass("disabled")) {
  92. $(this).addClass("disabled").css({color:'#444'})
  93. self.cloudPluginBox('installAllPlugins', false)
  94. }
  95. })
  96. $('#cloud_update_all').click(function (e) {
  97. if (! $(this).hasClass("disabled")) {
  98. $(this).addClass("disabled").css({color:'#444'})
  99. self.cloudPluginBox('installAllPlugins', true)
  100. }
  101. })
  102. var results = {}
  103. self.data('results', results)
  104. self.data('firstLoad', true)
  105. self.find('ul.categories li').click(function () {
  106. var category = $(this).attr('id').replace(/^cloud-plugin-tab-/, '')
  107. self.cloudPluginBox('setCategory', category)
  108. })
  109. options.open = function () {
  110. self.data('firstLoad', true)
  111. $('#cloud_install_all').addClass("disabled").css({color:'#444'})
  112. $('#cloud_update_all').addClass("disabled").css({color:'#444'})
  113. // the filters keep their choice while the page is open
  114. self.cloudPluginBox('search')
  115. return false
  116. }
  117. self.window(options)
  118. return self
  119. },
  120. setCategory: function (category) {
  121. var self = $(this)
  122. self.find('ul.categories li').removeClass('selected')
  123. self.find('.plugins-wrapper').hide()
  124. self.find('#cloud-plugin-tab-' + category).addClass('selected')
  125. self.find('#cloud-plugin-content-' + category).show().css('display', 'inline-block')
  126. self.data('category', category)
  127. },
  128. cleanResults: function () {
  129. var self = $(this)
  130. self.find('.plugins-wrapper').html('')
  131. self.find('ul.categories li').each(function () {
  132. var content = $(this).html().split(/\s/)
  133. if (content.length >= 2 && content[1] == "Utility") {
  134. $(this).html(content[0] + " Utility")
  135. } else {
  136. $(this).html(content[0])
  137. }
  138. });
  139. },
  140. checkLocalScreenshot: function (plugin) {
  141. if (plugin.status == 'installed') {
  142. if (plugin.gui) {
  143. var uri = escape(plugin.uri)
  144. var ver = plugin.installedVersion.join('_')
  145. plugin.screenshot_href = "/effect/image/screenshot.png?uri=" + uri + "&v=" + ver
  146. plugin.thumbnail_href = "/effect/image/thumbnail.png?uri=" + uri + "&v=" + ver
  147. } else {
  148. plugin.screenshot_href = "/resources/pedals/default-screenshot.png"
  149. plugin.thumbnail_href = "/resources/pedals/default-thumbnail.png"
  150. }
  151. }
  152. else {
  153. //if (!plugin.screenshot_available && !plugin.thumbnail_available) {
  154. if (!plugin.screenshot_href && !plugin.thumbnail_href) {
  155. plugin.screenshot_href = "/resources/pedals/default-screenshot.png"
  156. plugin.thumbnail_href = "/resources/pedals/default-thumbnail.png"
  157. }
  158. }
  159. },
  160. // search all or installed, depending on selected option
  161. search: function (customRenderCallback) {
  162. var self = $(this)
  163. var query = {
  164. text: self.data('searchbox').val(),
  165. summary: "true",
  166. image_version: VERSION,
  167. bin_compat: BIN_COMPAT,
  168. }
  169. // betas only when enabled in Settings; otherwise the release row is hidden and official it is
  170. var release = self.cloudPluginBox('filterValue', 'release-filter', 'official')
  171. if (PREFERENCES['show-unstable-plugins'] != "true" || self.data('fake')) {
  172. release = 'official'
  173. }
  174. self.data('releaseFilter', release)
  175. self.data('priceFilter', self.cloudPluginBox('filterValue', 'price-filter', 'both'))
  176. // the full list is fetched and the release choice applied here, so an installed beta
  177. // is recognised as beta too (asking the store for stable only would hide that)
  178. if (self.data('fake')) {
  179. query.stable = true
  180. }
  181. var install = self.cloudPluginBox('filterValue', 'install-filter', 'all')
  182. if (install == 'installed')
  183. return self.cloudPluginBox('searchInstalled', query, customRenderCallback)
  184. if (install == 'non-installed')
  185. return self.cloudPluginBox('searchAll', false, query, customRenderCallback)
  186. return self.cloudPluginBox('searchAll', true, query, customRenderCallback)
  187. },
  188. filterValue: function (name, fallback) {
  189. return $(this).find('input:radio[name=' + name + ']:checked').val() || fallback
  190. },
  191. // keep the plugins that match the release (beta) and price choices of the last search
  192. applyFilters: function (plugins) {
  193. var self = $(this)
  194. var release = self.data('releaseFilter')
  195. var price = self.data('priceFilter')
  196. return plugins.filter(function (plugin) {
  197. if (release == 'beta' && plugin.stable !== false) {
  198. return false
  199. }
  200. if (release == 'official' && plugin.stable === false) {
  201. return false
  202. }
  203. if (price != 'both') {
  204. // store data says paid_perpetual; a local plugin the store does not list still
  205. // carries its licence state (0 = free, 1/-1 or true/false once converted = paid)
  206. var paid = plugin.mod_license === 'paid_perpetual' ||
  207. (plugin.licensed != null && plugin.licensed !== 0)
  208. if ((price == 'paid') != paid) {
  209. return false
  210. }
  211. }
  212. return true
  213. })
  214. },
  215. synchronizePluginData: function (plugin) {
  216. var index = $(this).data('pluginsData')
  217. indexed = index[plugin.uri]
  218. if (indexed == null) {
  219. indexed = {}
  220. index[plugin.uri] = indexed
  221. }
  222. // Let's store all data safely, while modifying the given object
  223. // to have all available data
  224. $.extend(indexed, plugin)
  225. $.extend(plugin, indexed)
  226. if (window.devicePixelRatio && window.devicePixelRatio >= 2) {
  227. plugin.thumbnail_href = plugin.thumbnail_href.replace("thumbnail","screenshot")
  228. }
  229. },
  230. rebuildSearchIndex: function () {
  231. var plugins = Object.values($(this).data('pluginsData'))
  232. desktop.resetPluginIndexer(plugins.filter(function(plugin) { return !!plugin.installedVersion }))
  233. },
  234. // search cloud and local plugins, prefer cloud
  235. searchAll: function (showInstalled, query, customRenderCallback) {
  236. var self = $(this)
  237. var results = {}
  238. var cplugin, lplugin,
  239. cloudReached = false
  240. renderResults = function () {
  241. if (results.local == null || results.cloud == null || results.shopify == null)
  242. return
  243. var plugins = []
  244. for (var i in results.cloud) {
  245. cplugin = results.cloud[i]
  246. lplugin = results.local[cplugin.uri]
  247. if (!showInstalled && lplugin) {
  248. continue
  249. }
  250. cplugin.latestVersion = [cplugin.builder_version || 0, cplugin.minorVersion, cplugin.microVersion, cplugin.release_number]
  251. if (desktop.licenseManager && cplugin.mod_license === 'paid_perpetual') {
  252. cplugin.commercial = true
  253. if (results.shopify[cplugin.uri]) {
  254. cplugin.shopify_id = results.shopify[cplugin.uri].id
  255. cplugin.licensed = desktop.licenseManager.licensed(cplugin.uri)
  256. if (!cplugin.licensed)
  257. cplugin.price = results.shopify[cplugin.uri].price
  258. } else {
  259. // Plugin is commercial but it's not at shopify.
  260. // Trial available, commercial version coming soon
  261. cplugin.licensed = desktop.licenseManager.licensed(cplugin.uri)
  262. }
  263. }
  264. cplugin.demo = lplugin && cplugin.commercial && !cplugin.licensed
  265. if (cplugin.shopify_id) {
  266. if (!cplugin.licensed)
  267. cplugin.price = results.shopify[cplugin.uri].price;
  268. if (lplugin && cplugin.licensed && !lplugin.licensed) {
  269. // Should not happen
  270. new Notification('warn', 'License for '+cplugin.label+' not downloaded, please reload interface', 4000);
  271. }
  272. } else if (cplugin.commercial) {
  273. cplugin.coming = true;
  274. }
  275. if (lplugin) {
  276. if (!lplugin.installedVersion) {
  277. console.log("local plugin is missing version info:", lplugin.uri)
  278. lplugin.installedVersion = [0, 0, 0, 0]
  279. }
  280. cplugin.installedVersion = lplugin.installedVersion
  281. delete results.local[cplugin.uri]
  282. if (compareVersions(cplugin.installedVersion, cplugin.latestVersion) >= 0) {
  283. cplugin.status = 'installed'
  284. } else {
  285. cplugin.status = 'outdated'
  286. }
  287. // overwrite build environment if local plugin
  288. cplugin.buildEnvironment = lplugin.buildEnvironment
  289. self.cloudPluginBox('checkLocalScreenshot', cplugin)
  290. } else {
  291. cplugin.installedVersion = null // if set to [0, 0, 0, 0], it appears as intalled on cloudplugininfo
  292. cplugin.status = 'blocked'
  293. }
  294. if (self.data('fake') && cplugin.mod_license === 'paid_perpetual') {
  295. cplugin.licensed = true;
  296. }
  297. if (!cplugin.screenshot_available && !cplugin.thumbnail_available) {
  298. if (!cplugin.screenshot_href && !cplugin.thumbnail_href) {
  299. cplugin.screenshot_href = "/resources/pedals/default-screenshot.png"
  300. cplugin.thumbnail_href = "/resources/pedals/default-thumbnail.png"
  301. }
  302. }
  303. self.cloudPluginBox('synchronizePluginData', cplugin)
  304. plugins.push(cplugin)
  305. }
  306. // for all the other plugins that are not in the cloud
  307. if (showInstalled) {
  308. for (var uri in results.local) {
  309. lplugin = results.local[uri]
  310. lplugin.status = 'installed'
  311. lplugin.latestVersion = null
  312. self.cloudPluginBox('checkLocalScreenshot', lplugin)
  313. if (lplugin.licensed) {
  314. if (lplugin.licensed > 0) {
  315. lplugin.licensed = true;
  316. } else {
  317. lplugin.licensed = false;
  318. lplugin.demo = true;
  319. }
  320. }
  321. self.cloudPluginBox('synchronizePluginData', lplugin)
  322. plugins.push(lplugin)
  323. }
  324. }
  325. plugins = self.cloudPluginBox('applyFilters', plugins)
  326. if (customRenderCallback) {
  327. customRenderCallback(plugins)
  328. } else {
  329. self.cloudPluginBox('showPlugins', plugins, cloudReached)
  330. }
  331. if (self.data('firstLoad')) {
  332. self.data('firstLoad', false)
  333. $('#cloud_install_all').removeClass("disabled").css({color:'white'})
  334. $('#cloud_update_all').removeClass("disabled").css({color:'white'})
  335. }
  336. self.cloudPluginBox('rebuildSearchIndex')
  337. }
  338. // get list of shopify commercial plugins
  339. desktop.fetchShopProducts().then(function(products) {
  340. results.shopify = {};
  341. for (var i in products) {
  342. var uri = products[i].selectedVariant.attrs.variant.sku;
  343. results.shopify[uri] = {
  344. id: products[i].id,
  345. price: products[i].selectedVariant.price
  346. }
  347. }
  348. renderResults();
  349. }, function() {
  350. if (desktop.cloudAccessToken)
  351. new Notification('error', "Our commercial plugin store is offline now, sorry for the inconvenience")
  352. results.shopify = {}
  353. renderResults();
  354. });
  355. // cloud search
  356. var cloudResults
  357. $.ajax({
  358. method: 'GET',
  359. url: SITEURL + "/lv2/plugins",
  360. data: query,
  361. success: function (plugins) {
  362. cloudReached = true
  363. cloudResults = plugins
  364. },
  365. error: function () {
  366. cloudResults = []
  367. },
  368. complete: function () {
  369. results.cloud = cloudResults;
  370. renderResults()
  371. },
  372. cache: false,
  373. dataType: 'json'
  374. })
  375. if (self.data('fake')) {
  376. results.local = {}
  377. renderResults()
  378. return;
  379. }
  380. // local search
  381. if (query.text)
  382. {
  383. var lplugins = {}
  384. var ret = desktop.pluginIndexer.search(query.text)
  385. for (var i in ret) {
  386. var uri = ret[i].ref
  387. var pluginData = self.data('pluginsData')[uri]
  388. if (! pluginData) {
  389. console.log("ERROR: Plugin '" + uri + "' was not previously cached, cannot show it")
  390. continue
  391. }
  392. lplugins[uri] = pluginData
  393. }
  394. results.local = $.extend(true, {}, lplugins) // deep copy instead of link/reference
  395. renderResults()
  396. }
  397. else
  398. {
  399. $.ajax({
  400. method: 'GET',
  401. url: '/effect/list',
  402. success: function (plugins) {
  403. var i, plugin, allplugins = {}
  404. for (i in plugins) {
  405. plugin = plugins[i]
  406. plugin.installedVersion = [plugin.builder, plugin.minorVersion, plugin.microVersion, plugin.release]
  407. allplugins[plugin.uri] = plugin
  408. }
  409. results.local = $.extend(true, {}, allplugins) // deep copy instead of link/reference
  410. renderResults()
  411. },
  412. error: function () {
  413. results.local = {}
  414. renderResults()
  415. },
  416. cache: false,
  417. dataType: 'json'
  418. })
  419. }
  420. },
  421. // search cloud and local plugins, show installed only
  422. searchInstalled: function (query, customRenderCallback) {
  423. var self = $(this)
  424. var results = {}
  425. var cplugin, lplugin,
  426. cloudReached = false
  427. renderResults = function () {
  428. var plugins = []
  429. for (var i in results.local) {
  430. lplugin = results.local[i]
  431. cplugin = results.cloud[lplugin.uri]
  432. if (!lplugin.installedVersion) {
  433. console.log("local plugin is missing version info:", lplugin.uri)
  434. lplugin.installedVersion = [0, 0, 0, 0]
  435. }
  436. if (cplugin) {
  437. lplugin.stable = cplugin.stable
  438. lplugin.latestVersion = [cplugin.builder_version || 0, cplugin.minorVersion, cplugin.microVersion, cplugin.release_number]
  439. if (compareVersions(lplugin.installedVersion, lplugin.latestVersion) >= 0) {
  440. lplugin.status = 'installed'
  441. } else {
  442. lplugin.status = 'outdated'
  443. }
  444. if (cplugin.shopify_id && !lplugin.licensed) {
  445. lplugin.demo = true
  446. }
  447. } else {
  448. lplugin.latestVersion = null
  449. lplugin.status = 'installed'
  450. }
  451. if (lplugin.licensed) {
  452. if (lplugin.licensed > 0) {
  453. lplugin.licensed = true;
  454. } else {
  455. lplugin.licensed = false;
  456. lplugin.demo = true;
  457. }
  458. }
  459. // we're showing installed only, so prefer to show installed modgui screenshot
  460. if (lplugin.gui) {
  461. var uri = escape(lplugin.uri)
  462. var ver = [lplugin.builder, lplugin.microVersion, lplugin.minorVersion, lplugin.release].join('_')
  463. lplugin.screenshot_href = "/effect/image/screenshot.png?uri=" + uri + "&v=" + ver
  464. lplugin.thumbnail_href = "/effect/image/thumbnail.png?uri=" + uri + "&v=" + ver
  465. } else {
  466. lplugin.screenshot_href = "/resources/pedals/default-screenshot.png"
  467. lplugin.thumbnail_href = "/resources/pedals/default-thumbnail.png"
  468. }
  469. self.cloudPluginBox('synchronizePluginData', lplugin)
  470. plugins.push(lplugin)
  471. }
  472. plugins = self.cloudPluginBox('applyFilters', plugins)
  473. if (customRenderCallback) {
  474. customRenderCallback(plugins)
  475. } else {
  476. self.cloudPluginBox('showPlugins', plugins, cloudReached)
  477. }
  478. if (self.data('firstLoad')) {
  479. self.data('firstLoad', false)
  480. $('#cloud_install_all').removeClass("disabled").css({color:'white'})
  481. $('#cloud_update_all').removeClass("disabled").css({color:'white'})
  482. }
  483. self.cloudPluginBox('rebuildSearchIndex')
  484. }
  485. // cloud search
  486. $.ajax({
  487. method: 'GET',
  488. url: SITEURL + "/lv2/plugins",
  489. data: query,
  490. success: function (plugins) {
  491. // index by uri, needed later to check its latest version
  492. var cplugins = {}
  493. for (var i in plugins) {
  494. delete plugins[i].installedVersion
  495. delete plugins[i].bundles
  496. cplugins[plugins[i].uri] = plugins[i]
  497. }
  498. cloudReached = true
  499. results.cloud = cplugins
  500. if (results.local != null)
  501. renderResults()
  502. },
  503. error: function () {
  504. results.cloud = {}
  505. if (results.local != null)
  506. renderResults()
  507. },
  508. cache: false,
  509. dataType: 'json'
  510. })
  511. // local search
  512. if (query.text)
  513. {
  514. var lplugins = []
  515. var ret = desktop.pluginIndexer.search(query.text)
  516. for (var i in ret) {
  517. var uri = ret[i].ref
  518. var pluginData = self.data('pluginsData')[uri]
  519. if (! pluginData) {
  520. console.log("ERROR: Plugin '" + uri + "' was not previously cached, cannot show it")
  521. continue
  522. }
  523. lplugins.push(pluginData)
  524. }
  525. results.local = $.extend(true, {}, lplugins) // deep copy instead of link/reference
  526. if (results.cloud != null)
  527. renderResults()
  528. }
  529. else
  530. {
  531. $.ajax({
  532. method: 'GET',
  533. url: '/effect/list',
  534. success: function (plugins) {
  535. var i, plugin
  536. for (i in plugins) {
  537. plugin = plugins[i]
  538. plugin.installedVersion = [plugin.builder || 0, plugin.minorVersion, plugin.microVersion, plugin.release]
  539. }
  540. results.local = plugins
  541. if (results.cloud != null)
  542. renderResults()
  543. },
  544. cache: false,
  545. dataType: 'json'
  546. })
  547. }
  548. },
  549. showPlugins: function (plugins, cloudReached) {
  550. var self = $(this)
  551. self.cloudPluginBox('cleanResults')
  552. // sort plugins by label
  553. plugins.sort(function (a, b) {
  554. a = a.label.toLowerCase()
  555. b = b.label.toLowerCase()
  556. if (a > b) {
  557. return 1
  558. }
  559. if (a < b) {
  560. return -1
  561. }
  562. return 0
  563. })
  564. var category = {}
  565. var categories = {
  566. 'All': plugins.length,
  567. 'ControlVoltage': 0,
  568. 'Delay': 0,
  569. 'Distortion': 0,
  570. 'Dynamics': 0,
  571. 'Filter': 0,
  572. 'Generator': 0,
  573. 'MIDI': 0,
  574. 'Modulator': 0,
  575. 'Reverb': 0,
  576. 'Simulator': 0,
  577. 'Spatial': 0,
  578. 'Spectral': 0,
  579. 'Utility': 0,
  580. }
  581. var cachedContentCanvas = {
  582. 'All': self.find('#cloud-plugin-content-All')
  583. }
  584. var pluginsDict = {}
  585. var getCategory = function(plugin) {
  586. category = plugin.category[0]
  587. if (category == 'Utility' && plugin.category.length == 2 && plugin.category[1] == 'MIDI') {
  588. return 'MIDI';
  589. }
  590. return category
  591. }
  592. var plugin, render
  593. for (var i in plugins) {
  594. plugin = plugins[i]
  595. category = getCategory(plugin)
  596. render = self.cloudPluginBox('renderPlugin', plugin, cloudReached)
  597. pluginsDict[plugin.uri] = plugin
  598. if (category && category != 'All' && categories[category] != null) {
  599. categories[category] += 1
  600. if (cachedContentCanvas[category] == null) {
  601. cachedContentCanvas[category] = self.find('#cloud-plugin-content-' + category)
  602. }
  603. render.clone(true).appendTo(cachedContentCanvas[category])
  604. }
  605. render.appendTo(cachedContentCanvas['All'])
  606. }
  607. self.data('pluginsDict', pluginsDict)
  608. // display plugin count
  609. self.cloudPluginBox('setCategoryCount', categories)
  610. },
  611. setCategoryCount: function (categories) {
  612. var self = $(this)
  613. self.data('categoryCount', categories)
  614. for (var category in categories) {
  615. var tab = self.find('#cloud-plugin-tab-' + category)
  616. if (tab.length == 0) {
  617. continue
  618. }
  619. var content = tab.html().split(/\s/)
  620. if (content.length >= 2 && content[1] == "Utility") {
  621. content = content[0] + " Utility"
  622. } else {
  623. content = content[0]
  624. }
  625. tab.html(content + ' <span class="plugin_count">(' + categories[category] + ')</span>')
  626. }
  627. },
  628. renderPlugin: function (plugin, cloudReached, featured) {
  629. var self = $(this)
  630. var uri = escape(plugin.uri)
  631. var comment = plugin.comment.trim()
  632. var has_comment = ""
  633. if(!comment) {
  634. comment = "No description available";
  635. has_comment = "no_description";
  636. }
  637. var plugin_data = {
  638. uri: uri,
  639. screenshot_href: plugin.screenshot_href,
  640. thumbnail_href: plugin.thumbnail_href,
  641. has_comment: has_comment,
  642. comment: comment,
  643. status: plugin.status,
  644. brand : plugin.brand,
  645. label : plugin.label,
  646. demo: !!plugin.demo,
  647. price: plugin.price,
  648. licensed: plugin.licensed,
  649. featured: plugin.featured,
  650. coming: plugin.coming,
  651. unstable: plugin.stable === false,
  652. build_env: plugin.buildEnvironment,
  653. }
  654. var template = featured ? TEMPLATES.featuredplugin : TEMPLATES.cloudplugin
  655. var rendered = $(Mustache.render(template, plugin_data))
  656. rendered.click(function () {
  657. self.cloudPluginBox('showPluginInfo', plugin.uri)
  658. })
  659. return rendered
  660. },
  661. installAllPlugins: function (updateOnly) {
  662. var self = $(this)
  663. self.cloudPluginBox('search', function (plugins) {
  664. // sort plugins by label
  665. var alower, blower
  666. plugins.sort(function (a, b) {
  667. alower = a.label.toLowerCase()
  668. blower = b.label.toLowerCase()
  669. if (alower > blower)
  670. return 1
  671. if (alower < blower)
  672. return -1
  673. return 0
  674. })
  675. var bundle_id, bundle_ids = []
  676. var currentCategory = $("#cloud-plugins-library .categories .selected").attr('id').replace(/^cloud-plugin-tab-/, '') || "All"
  677. var plugin
  678. for (var i in plugins) {
  679. plugin = plugins[i]
  680. if (! plugin.bundle_id || ! plugin.latestVersion) {
  681. continue
  682. }
  683. if (plugin.installedVersion) {
  684. if (compareVersions(plugin.latestVersion, plugin.installedVersion) <= 0) {
  685. continue
  686. }
  687. } else if (updateOnly) {
  688. continue
  689. }
  690. var category = plugin.category[0]
  691. if (category == 'Utility' && plugin.category.length == 2 && plugin.category[1] == 'MIDI') {
  692. category = 'MIDI'
  693. }
  694. // FIXME for midi
  695. if (bundle_ids.indexOf(plugin.bundle_id) < 0 && (currentCategory == "All" || currentCategory == category)) {
  696. bundle_ids.push(plugin.bundle_id)
  697. }
  698. }
  699. if (bundle_ids.length == 0) {
  700. $('#cloud_install_all').removeClass("disabled").css({color:'white'})
  701. $('#cloud_update_all').removeClass("disabled").css({color:'white'})
  702. new Notification('warn', 'All plugins are '+(updateOnly?'updated':'installed')+', nothing to do', 8000)
  703. return
  704. }
  705. var count = 0
  706. var finished = function (resp, bundlename) {
  707. self.cloudPluginBox('postInstallAction', resp.installed, resp.removed, bundlename)
  708. count += 1
  709. if (count == bundle_ids.length) {
  710. $('#cloud_install_all').removeClass("disabled").css({color:'white'})
  711. $('#cloud_update_all').removeClass("disabled").css({color:'white'})
  712. new Notification('warn', 'All plugins are now '+(updateOnly?'updated':'installed'), 8000)
  713. }
  714. if (resp.ok) {
  715. self.cloudPluginBox('search')
  716. }
  717. }
  718. for (var i in bundle_ids) {
  719. desktop.installationQueue.installUsingBundle(bundle_ids[i], finished)
  720. }
  721. })
  722. },
  723. postInstallAction: function (installed, removed, bundlename) {
  724. var self = $(this)
  725. var bundle = LV2_PLUGIN_DIR + bundlename
  726. var category, categories = self.data('categoryCount')
  727. var uri, plugin, oldElem, newElem
  728. for (var i in installed) {
  729. uri = installed[i]
  730. plugin = self.data('pluginsData')[uri]
  731. if (! plugin) {
  732. continue
  733. }
  734. plugin.status = 'installed'
  735. if (plugin.commercial && !plugin.licensed)
  736. plugin.demo = true;
  737. plugin.bundles = [bundle]
  738. plugin.installedVersion = plugin.latestVersion
  739. oldElem = self.find('.cloud-plugin[mod-uri="'+escape(uri)+'"]')
  740. newElem = self.cloudPluginBox('renderPlugin', plugin, true)
  741. oldElem.replaceWith(newElem)
  742. }
  743. for (var i in removed) {
  744. uri = removed[i]
  745. if (installed.indexOf(uri) >= 0) {
  746. continue
  747. }
  748. var favoriteIndex = FAVORITES.indexOf(uri)
  749. if (favoriteIndex >= 0) {
  750. FAVORITES.splice(favoriteIndex, 1)
  751. $('#effect-content-Favorites').find('[mod-uri="'+escape(uri)+'"]').remove()
  752. $('#effect-tab-Favorites').html('Favorites (' + FAVORITES.length + ')')
  753. }
  754. plugin = self.data('pluginsData')[uri]
  755. oldElem = self.find('.cloud-plugin[mod-uri="'+escape(uri)+'"]')
  756. if (plugin.latestVersion) {
  757. // removing a plugin available on cloud, keep its store item
  758. plugin.status = 'blocked'
  759. plugin.demo = false
  760. plugin.bundle_name = bundle
  761. delete plugin.bundles
  762. plugin.installedVersion = null
  763. newElem = self.cloudPluginBox('renderPlugin', plugin, true)
  764. oldElem.replaceWith(newElem)
  765. } else {
  766. // removing local plugin means the number of possible plugins goes down
  767. category = plugin.category[0]
  768. if (category && category != 'All') {
  769. if (category == 'Utility' && plugin.category.length == 2 && plugin.category[1] == 'MIDI') {
  770. category = 'MIDI'
  771. }
  772. categories[category] -= 1
  773. }
  774. categories['All'] -= 1
  775. // remove it from store
  776. delete self.data('pluginsData')[uri]
  777. oldElem.remove()
  778. }
  779. }
  780. self.cloudPluginBox('setCategoryCount', categories)
  781. },
  782. showPluginInfo: function (uri) {
  783. var self = $(this)
  784. var plugin = self.data('pluginsData')[uri]
  785. if (!plugin) {
  786. if (self.data('fake'))
  787. new Notification('error', "Requested plugin is not available")
  788. return
  789. }
  790. var cloudChecked = false
  791. var localChecked = false
  792. var showInfo = function() {
  793. if (!cloudChecked || !localChecked)
  794. return
  795. // formating numbers and flooring ranges up to two decimal cases
  796. for (var i = 0; i < plugin.ports.control.input.length; i++) {
  797. plugin.ports.control.input[i].formatted = format(plugin.ports.control.input[i])
  798. }
  799. if (plugin.ports.cv && plugin.ports.cv.input) {
  800. for (var i = 0; i < plugin.ports.cv.input.length; i++) {
  801. plugin.ports.cv.input[i].formatted = format(plugin.ports.cv.input[i])
  802. }
  803. }
  804. if (plugin.ports.cv && plugin.ports.cv.output) {
  805. for (var i = 0; i < plugin.ports.cv.output.length; i++) {
  806. plugin.ports.cv.output[i].formatted = format(plugin.ports.cv.output[i])
  807. }
  808. }
  809. var category = plugin.category[0]
  810. if (category == 'Utility' && plugin.category.length == 2 && plugin.category[1] == 'MIDI') {
  811. category = 'MIDI'
  812. }
  813. // Plugin might have been licensed after plugin data was bound to event,
  814. // so let's check
  815. if (desktop.licenseManager && desktop.licenseManager.licensed(plugin.uri)) {
  816. plugin.licensed = true;
  817. plugin.demo = false;
  818. plugin.coming = false;
  819. plugin.price = null;
  820. }
  821. var metadata = {
  822. author: plugin.author,
  823. uri: plugin.uri,
  824. escaped_uri: escape(plugin.uri),
  825. thumbnail_href: plugin.thumbnail_href,
  826. screenshot_href: plugin.screenshot_href,
  827. category: category || "None",
  828. installed_version: version(plugin.installedVersion),
  829. latest_version: version(plugin.latestVersion),
  830. package_name: (plugin.bundle_name || plugin.bundles[0]).replace(/\.lv2$/, ''),
  831. comment: plugin.comment.trim() || "No description available",
  832. brand : plugin.brand,
  833. name : plugin.name,
  834. label : plugin.label,
  835. ports : plugin.ports,
  836. plugin_href: PLUGINS_URL + '/' + btoa(plugin.uri),
  837. pedalboard_href: desktop.getPedalboardHref(plugin.uri, plugin.stable === false),
  838. shopify_id: plugin.shopify_id,
  839. price: plugin.price,
  840. trial: plugin.commercial && !plugin.licensed && status != 'blocked',
  841. demo : !!plugin.demo,
  842. licensed: plugin.licensed,
  843. coming: plugin.coming,
  844. build_env_uppercase: plugin.buildEnvironment ? plugin.buildEnvironment.toUpperCase()
  845. : (plugin.stable === false ? "BETA" : "LOCAL"),
  846. show_build_env: plugin.buildEnvironment !== "prod",
  847. };
  848. var info = self.data('info')
  849. if (info) {
  850. info.remove()
  851. self.data('info', null)
  852. }
  853. info = $(Mustache.render(TEMPLATES.cloudplugin_info, metadata))
  854. // hide control ports table if none available
  855. if (plugin.ports.control.input.length == 0) {
  856. info.find('.plugin-controlports').hide()
  857. }
  858. // hide cv inputs table if none available
  859. if (!plugin.ports.cv || (plugin.ports.cv && plugin.ports.cv.input && plugin.ports.cv.input.length == 0)) {
  860. info.find('.plugin-cvinputs').hide()
  861. }
  862. // hide cv ouputs ports table if none available
  863. if (!plugin.ports.cv || (plugin.ports.cv && plugin.ports.cv.output && plugin.ports.cv.output.length == 0)) {
  864. info.find('.plugin-cvoutputs').hide()
  865. }
  866. var canInstall = false,
  867. canUpgrade = false
  868. // The remove button will remove the plugin, close window and re-render the plugins
  869. // without the removed one
  870. if (plugin.installedVersion) {
  871. info.find('.js-install').hide()
  872. info.find('.js-remove').show().click(function () {
  873. // Remove plugin
  874. self.data('removePluginBundles')(plugin.bundles, function (resp) {
  875. var bundlename = plugin.bundles[0].split('/').filter(function(el){return el.length!=0}).pop(0)
  876. self.cloudPluginBox('postInstallAction', [], resp.removed, bundlename)
  877. info.window('close')
  878. // remove-only action, need to manually update plugins
  879. desktop.updatePluginList([], resp.removed)
  880. })
  881. })
  882. } else {
  883. canInstall = true
  884. info.find('.js-remove').hide()
  885. info.find('.js-installed-version').hide()
  886. info.find('.js-install').show().click(function () {
  887. // Install plugin
  888. self.data('installPluginURI')(plugin.uri, function (resp, bundlename) {
  889. self.cloudPluginBox('postInstallAction', resp.installed, resp.removed, bundlename)
  890. info.window('close')
  891. })
  892. })
  893. }
  894. if (plugin.installedVersion && plugin.latestVersion && compareVersions(plugin.latestVersion, plugin.installedVersion) > 0) {
  895. canUpgrade = true
  896. info.find('.js-upgrade').show().click(function () {
  897. // Upgrade plugin
  898. self.data('upgradePluginURI')(plugin.uri, function (resp, bundlename) {
  899. self.cloudPluginBox('postInstallAction', resp.installed, resp.removed, bundlename)
  900. info.window('close')
  901. })
  902. })
  903. } else {
  904. info.find('.js-upgrade').hide()
  905. }
  906. if (! plugin.latestVersion) {
  907. info.find('.js-latest-version').hide()
  908. }
  909. info.appendTo($('body'))
  910. info.window({
  911. windowName: "Cloud Plugin Info"
  912. })
  913. if (metadata.shopify_id && !metadata.licensed) {
  914. desktop.createBuyButton(metadata.shopify_id)
  915. }
  916. info.window('open')
  917. self.data('info', info)
  918. }
  919. // get full plugin info if plugin has a local version
  920. if ((plugin.bundles && plugin.bundles.length > 0) || ! plugin.installedVersion) {
  921. localChecked = true
  922. } else {
  923. var renderedVersion = [plugin.builder,
  924. plugin.microVersion,
  925. plugin.minorVersion,
  926. plugin.release].join('_');
  927. $.ajax({
  928. url: "/effect/get",
  929. data: {
  930. uri: plugin.uri,
  931. version: VERSION,
  932. plugin_version: renderedVersion,
  933. },
  934. success: function (pluginData) {
  935. // delete cloud specific fields just in case
  936. delete pluginData.bundle_name
  937. delete pluginData.latestVersion
  938. // ready to merge
  939. plugin = $.extend(pluginData, plugin)
  940. localChecked = true
  941. showInfo()
  942. },
  943. error: function () {
  944. // assume not installed
  945. plugin.installedVersion = null
  946. plugin.installed_version = null
  947. localChecked = true
  948. showInfo()
  949. },
  950. cache: !!plugin.buildEnvironment,
  951. dataType: 'json'
  952. })
  953. }
  954. // always get cloud plugin info
  955. $.ajax({
  956. url: SITEURL + "/lv2/plugins",
  957. data: {
  958. uri: plugin.uri,
  959. image_version: VERSION,
  960. bin_compat: BIN_COMPAT,
  961. },
  962. success: function (pluginData) {
  963. if (pluginData && pluginData.length > 0) {
  964. pluginData = pluginData[0]
  965. // delete local specific fields just in case
  966. delete pluginData.bundles
  967. delete pluginData.installedVersion
  968. // ready to merge
  969. plugin = $.extend(pluginData, plugin)
  970. plugin.latestVersion = [plugin.builder_version || 0, plugin.minorVersion, plugin.microVersion, plugin.release_number]
  971. } else {
  972. plugin = $.extend(getDummyPluginData(), plugin)
  973. plugin.latestVersion = null
  974. }
  975. cloudChecked = true
  976. showInfo()
  977. },
  978. error: function () {
  979. plugin = $.extend(getDummyPluginData(), plugin)
  980. plugin.latestVersion = null
  981. cloudChecked = true
  982. showInfo()
  983. },
  984. cache: false,
  985. dataType: 'json'
  986. })
  987. },
  988. })