From 152914365aa906fc639cc43ceed620698f5cc976 Mon Sep 17 00:00:00 2001 From: 1024x2 Date: Sat, 11 Aug 2018 17:08:29 +0100 Subject: w --- pkg93.js | 61 ++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 23 deletions(-) (limited to 'pkg93.js') diff --git a/pkg93.js b/pkg93.js index 3f241ab..c1f0232 100644 --- a/pkg93.js +++ b/pkg93.js @@ -29,7 +29,7 @@ async function wrap(f) { var originalPrompt = this.cli.prompt.innerHTML; var originalOnenter = this.cli.onenter; - try { + try { this.cli.prompt.innerHTML = ""; this.cli.onenter = () => false; var lastLog = $log(""); @@ -42,6 +42,10 @@ async function wrap(f) { }, arg: this.arg }); + } catch (err) { + console.error(err); + this.cli.prompt.innerHTML = originalPrompt; + this.cli.onenter = originalOnenter; } finally { this.cli.prompt.innerHTML = originalPrompt; this.cli.onenter = originalOnenter; @@ -65,19 +69,15 @@ try { $alert({ title: "Couldn't load pkg93!", msg: "
" + (err.stack || err.toString()) + "
", - btnOk: "Send a bug report", btnCancel: "OK" - }, function(ok) { - if (ok) { - window.open("https://github.com/pkg93/pkg93/issues/new" + - "?title=" + encodeURIComponent(err.toString()) + - "&body=Type what you were doing here...%0A%0A```%0A" + encodeURIComponent(err.stack) + "%0A```", - "_blank"); - } + img: "/c/sys/skins/w93/error.png", + icon: "//cdn.rawgit.com/1024x2/pkg93/70039c02/pkg.png" }); } console.log("%c[pkg93]%c Done!", "font-weight:bold", "font-weight:normal"); console.groupEnd(); + +var errbar = "[---------------------------------------------------] ERR! !"; // thanks robbie! sauce: https://gist.github.com/robbie0630/e1386fb10676598e7d60d4f406a41042 // NOTE: this is a modified version var _abarpkg93uses = (width, percent) => { @@ -131,7 +131,11 @@ var pkg93 = { bardiv.innerHTML = _abarpkg93uses(60, e.loaded / e.total); }; xhr.onerror = () => { + bardiv.innerHTML = errbar; cli.log("ERR Fatal error while retriving package.json."); + if (xhr.status != 0) { + cli.log("ERR " + xhr.status + " " + xhr.statusText); + } }; xhr.onload = () => { try { @@ -164,8 +168,9 @@ var pkg93 = { res(); }); }, - get: async function(pkg, cli) { + get: async function(pkg, version, cli) { cli = cli || {log: (i) => {$log(i);}}; + version = version || "latest"; var config = pkg93.getConfig(); cli.log("SRCH " + pkg); var index = config.pkglist.findIndex(function(string) { @@ -193,18 +198,24 @@ var pkg93 = { }; return new Promise((res, rej) => { xhr.onerror = () => { + bardiv.innerHTML = errbar; cli.log("ERR Fatal error while retriving package.json."); + if (xhr.status == 0) { + cli.log("ERR " + xhr.status + " " + xhr.statusText); + } rej(); }; xhr.onload = () => { try { - if (xhr.status != 200) { - throw new Error("Got status " + xhr.status + " from server."); - } cli.log("DONE " + dest); var json = JSON.parse(xhr.responseText); localStorage[".pkg93/packages/" + pkgname + ".json"] = JSON.stringify(json); - var dest2 = pkgsource + "/" + pkgname + "/" + json.inject; + if (!json.versions) { + cli.log("WARN This package does not support versioning, using latest\n version instead."); + } else { + version = (version == "latest") ? json.versions[0] : version; + } + var dest2 = pkgsource + "/" + pkgname + "/" + (json.versions ? version + "/" : "") + json.inject; cli.log("GET " + dest2); var bardiv2 = cli.log(_abarpkg93uses(60, 0)); var xhr2 = new XMLHttpRequest(); @@ -218,7 +229,11 @@ var pkg93 = { } }; xhr2.onerror = () => { + bardiv2.innerHTML = errbar; cli.log("ERR Fatal error while retriving " + dest2); + if (xhr2.status != 0) { + cli.log("ERR " + xhr2.status + " " + xhr2.statusText); + } rej(); }; xhr2.onload = async () => { @@ -232,10 +247,9 @@ var pkg93 = { eval(script); if (json.uninstall) { // no xhr this time - var uninst = await (await (fetch(pkgsource + "/" + pkgname + "/" + json.uninstall))).text(); + var uninst = await (await (fetch(pkgsource + "/" + pkgname + "/" + (json.versions ? version + "/" : "") + json.uninstall))).text(); localStorage[".pkg93/packages/" + pkgname + ".rm.js"] = uninst; } - cli.log("OK Injected package!"); if (!config.installed.includes(pkgname)) { config.installed.push(pkgname); } @@ -344,7 +358,6 @@ async function _pkg93execdonotcallplsusetheapi(cli) { info [pkg] Gets information on a package ls [pkgs|installed|repos] Lists packages, installed packages or repositories. -credits Displays the credits Color meanings Executing OK Error Warning Info @@ -369,7 +382,9 @@ If you find my software useful, consider donating ERR You're trying to modify a pre-installed Windows93 app.\n Don't do that!"); } else { - await pkg93.get(args[1], cli); + var name = args[1].split("@")[0]; + var version = args[1].split("@")[1]; + await pkg93.get(name, version, cli); } } else if (args[0] == "rm") { if (args.length < 2) { @@ -430,11 +445,11 @@ If you find my software useful, consider donating ERR Package not found."); } else { - var depends = pkgInfo.dependencies ? pkgInfo.dependencies.join(" , ") : "None!"; var description = pkgInfo.description ? pkgInfo.description : "None!"; - cli.log(`${pkgInfo.name} - Description: ${description} - Dependencies: ${depends}`); + var vers = pkgInfo.versions ? pkgInfo.versions.join(", ") : "None!"; + cli.log(`${args[1]} +Description: ${description} +Versions: ${vers}`); } } catch (err) { cli.log("ERR Error while getting package info.\n" + err.stack); @@ -454,7 +469,7 @@ If you find my software useful, consider donating