diff options
author | Wojtek Kosior <koszko@koszko.org> | 2022-01-25 09:37:34 +0100 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2022-01-25 09:37:34 +0100 |
commit | b75a5717a084c9e5a727c2e960f2b910abcb5ace (patch) | |
tree | a9dcd00c428aeba011e9a445b96aacad962a1f3d /html/install.js | |
parent | 7218849ae2f43aee6b3462a30e07caf5bac3d22b (diff) | |
download | browser-extension-b75a5717a084c9e5a727c2e960f2b910abcb5ace.tar.gz browser-extension-b75a5717a084c9e5a727c2e960f2b910abcb5ace.zip |
add a repo querying HTML interface
Diffstat (limited to 'html/install.js')
-rw-r--r-- | html/install.js | 73 |
1 files changed, 28 insertions, 45 deletions
diff --git a/html/install.js b/html/install.js index dbc490d..e972924 100644 --- a/html/install.js +++ b/html/install.js @@ -46,8 +46,9 @@ #IMPORT html/item_preview.js AS ip #FROM common/browser.js IMPORT browser -#FROM html/DOM_helpers.js IMPORT clone_template -#FROM common/entities.js IMPORT item_id_string, version_string, get_files +#FROM html/DOM_helpers.js IMPORT clone_template, Showable +#FROM common/entities.js IMPORT item_id_string, version_string, get_files, \ + is_valid_version #FROM common/misc.js IMPORT sha256_async AS sha256 const coll = new Intl.Collator(); @@ -78,7 +79,7 @@ function ItemEntry(install_view, item) { } let preview_cb = () => install_view.preview_item(item.def); - preview_cb = dialog.when_hidden(install_view.dialog_ctx, preview_cb); + preview_cb = install_view.dialog_ctx.when_hidden(preview_cb); this.details_but.addEventListener("click", preview_cb); } @@ -114,8 +115,9 @@ async function init_work() { } function InstallView(tab_id, on_view_show, on_view_hide) { + Showable.call(this, on_view_show, on_view_hide); + Object.assign(this, clone_template("install_view")); - this.shown = false; const show_container = name => { for (const cid of container_ids) { @@ -154,8 +156,8 @@ function InstallView(tab_id, on_view_show, on_view_hide) { this[container_name].prepend(preview_ctx.main_div); } - const back_cb = dialog.when_hidden(this.dialog_ctx, - () => show_container("install_preview")); + let back_cb = () => show_container("install_preview"); + back_cb = this.dialog_ctx.when_hidden(back_cb); for (const type of ["resource", "mapping"]) this[`${type}_back_but`].addEventListener("click", back_cb); @@ -189,17 +191,18 @@ function InstallView(tab_id, on_view_show, on_view_hide) { "Repository's response is not valid JSON :("); } - if (response.json.api_schema_version > [1]) { - let api_ver = ""; - try { - api_ver = - ` (${version_string(response.json.api_schema_version)})`; - } catch(e) { - console.warn(e); - } + if (!is_valid_version(response.json.api_schema_version)) { + var bad_api_ver = ""; + } else if (response.json.api_schema_version > [1]) { + var bad_api_ver = + ` (${version_string(response.json.api_schema_version)})`; + } else { + var bad_api_ver = false; + } + if (bad_api_ver !== false) { const captype = item_type[0].toUpperCase() + item_type.substring(1); - const msg = `${captype} ${item_id_string(id, ver)} was served using unsupported Hydrilla API version${api_ver}. You might need to update Haketilo.`; + const msg = `${captype} ${item_id_string(id, ver)} was served using unsupported Hydrilla API version${bad_api_ver}. You might need to update Haketilo.`; return work.err(null, msg); } @@ -256,23 +259,16 @@ function InstallView(tab_id, on_view_show, on_view_hide) { return items; } + const show_super = this.show; this.show = async (repo_url, item_type, item_id, item_ver) => { - if (this.shown) + if (!show_super()) return; - this.shown = true; - this.repo_url = repo_url; dialog.loader(this.dialog_ctx, "Fetching data from repository..."); try { - on_view_show(); - } catch(e) { - console.error(e); - } - - try { var items = await compute_deps(item_type, item_id, item_ver); } catch(e) { var dialog_prom = dialog.error(this.dialog_ctx, e); @@ -288,7 +284,7 @@ function InstallView(tab_id, on_view_show, on_view_hide) { await dialog_prom; - hide(); + this.hide(); return; } @@ -419,35 +415,22 @@ function InstallView(tab_id, on_view_show, on_view_hide) { await dialog_prom; - hide(); + this.hide(); } - const hide = () => { - if (!this.shown) + const hide_super = this.hide; + this.hide = () => { + if (!hide_super()) return; - this.shown = false; delete this.item_entries; [...this.to_install_list.children].forEach(n => n.remove()); - - try { - on_view_hide(); - } catch(e) { - console.error(e); - } - } - - this.when_hidden = cb => { - const wrapped_cb = (...args) => { - if (!this.shown) - return cb(...args); - } - return wrapped_cb; } - const hide_cb = dialog.when_hidden(this.dialog_ctx, hide); + const hide_cb = this.dialog_ctx.when_hidden(this.hide); this.cancel_but.addEventListener("click", hide_cb); - const install_cb = dialog.when_hidden(this.dialog_ctx, perform_install); + const install_cb = this.dialog_ctx.when_hidden(perform_install); this.install_but.addEventListener("click", install_cb); } +#EXPORT InstallView |