From cb7f322f09fb8ed9be95978db82f99a2e8a4661b Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 3 Mar 2021 19:07:39 +0300 Subject: add basic plugin installer (uses tt-rss.org) --- js/PrefHelpers.js | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 119 insertions(+), 1 deletion(-) (limited to 'js/PrefHelpers.js') diff --git a/js/PrefHelpers.js b/js/PrefHelpers.js index fc59ebb70..5658ce9b0 100644 --- a/js/PrefHelpers.js +++ b/js/PrefHelpers.js @@ -349,10 +349,128 @@ const Helpers = { } }); }, + install: function() { + const dialog = new fox.SingleUseDialog({ + PI_RES_ALREADY_INSTALLED: "PI_RES_ALREADY_INSTALLED", + PI_RES_SUCCESS: "PI_RES_SUCCESS", + PI_ERR_NO_CLASS: "PI_ERR_NO_CLASS", + PI_ERR_NO_INIT_PHP: "PI_ERR_NO_INIT_PHP", + PI_ERR_EXEC_FAILED: "PI_ERR_EXEC_FAILED", + PI_ERR_NO_TEMPDIR: "PI_ERR_NO_TEMPDIR", + PI_ERR_PLUGIN_NOT_FOUND: "PI_ERR_PLUGIN_NOT_FOUND", + PI_ERR_NO_WORKDIR: "PI_ERR_NO_WORKDIR", + title: __("List of plugins"), + need_refresh: false, + onHide: function() { + if (this.need_refresh) { + Helpers.Prefs.refresh(); + } + }, + performInstall: function(plugin) { + + const install_dialog = new fox.SingleUseDialog({ + title: __("Plugin installer"), + content: ` + + + ` + }); + + const tmph = dojo.connect(install_dialog, 'onShow', function () { + dojo.disconnect(tmph); + + const container = install_dialog.domNode.querySelector(".contents"); + + xhr.json("backend.php", {op: "pref-prefs", method: "installPlugin", plugin: plugin}, (reply) => { + if (!reply) { + container.innerHTML = `
  • ${__("Operation failed: check event log.")}
  • `; + } else { + switch (reply.result) { + case dialog.PI_RES_SUCCESS: + container.innerHTML = `
  • ${__("Plugin has been installed.")}
  • ` + dialog.need_refresh = true; + break; + case dialog.PI_RES_ALREADY_INSTALLED: + container.innerHTML = `
  • ${__("Plugin is already installed.")}
  • ` + break; + default: + container.innerHTML = ` +
  • +

    ${plugin}

    + ${reply.stderr ? `
    ${reply.stderr}
    ` : ''} + ${reply.stdour ? `
    ${reply.stdout}
    ` : ''} +

    + ${App.FormFields.icon("error_outline") + " " + __("Exited with RC: %d").replace("%d", reply.git_status)} +

    +
  • + `; + } + } + }); + }); + + install_dialog.show(); + + }, + refresh: function() { + const container = dialog.domNode.querySelector(".contents"); + container.innerHTML = `
  • ${__("Looking for plugins...")}
  • `; + + xhr.json("backend.php", {op: "pref-prefs", method: "getAvailablePlugins"}, (reply) => { + + if (!reply) { + container.innerHTML = `
  • ${__("Operation failed: check event log.")}
  • `; + } else { + container.innerHTML = ""; + + reply.forEach((plugin) => { + container.innerHTML += ` +
  • +

    ${plugin.name} + + ${App.FormFields.icon("open_in_new_window")} + +

    + +

    ${plugin.description}

    + + ${App.FormFields.button_tag(__('Install plugin'), "", {class: 'alt-primary', + onclick: `App.dialogOf(this).performInstall("${App.escapeHtml(plugin.name)}")`})} + +
    +
  • + ` + }); + + dojo.parser.parse(container); + } + }); + }, + content: ` + + + + `, + }); + + const tmph = dojo.connect(dialog, 'onShow', function () { + dojo.disconnect(tmph); + dialog.refresh(); + }); + + dialog.show(); + }, update: function(name = null) { const dialog = new fox.SingleUseDialog({ - title: __("Plugin Updater"), + title: __("Update plugins"), need_refresh: false, plugins_to_update: [], onHide: function() { -- cgit v1.2.3-54-g00ecf