From a051aace376492a48c10615106dda222a7136300 Mon Sep 17 00:00:00 2001 From: 1024x2 Date: Thu, 1 Nov 2018 21:16:16 +0000 Subject: new fancy webpack stuff --- src/pkg93.js | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/pkg93.js (limited to 'src/pkg93.js') diff --git a/src/pkg93.js b/src/pkg93.js new file mode 100644 index 0000000..725d447 --- /dev/null +++ b/src/pkg93.js @@ -0,0 +1,62 @@ +import { pkg93 } from "./api.js"; +import { _pkg93execdonotcallplsusetheapi } from "./cli.js"; + +window.pkg93 = pkg93; + +async function wrap(f) { + var originalPrompt = this.cli.prompt.innerHTML; + var originalOnenter = this.cli.onenter; + try { + this.cli.prompt.innerHTML = ""; + this.cli.onenter = () => false; + var lastLog = $log(""); + await f({ + log: (...args) => { + var newLog = $log(...args); + newLog.parentElement.insertBefore(newLog, lastLog.nextSibling); + lastLog = newLog; + return newLog; + }, + 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; + } +} + +console.group("[pkg93]"); +console.log("%c[pkg93]%c Injecting packages...", "font-weight:bold", "font-weight:normal"); +try { + if (localStorage[".pkg93/config.json"] === undefined) { + console.log("%c[pkg93]%c You seem new. Creating config...", "font-weight:bold", "font-weight:normal"); + localStorage[".pkg93/config.json"] = `{"repos": ["https://1024x2.xyz/main-repo"], "installed": [], "pkglist": []}`; + } + var config = JSON.parse(localStorage[".pkg93/config.json"]); + for (let pkg of config.installed) { + eval(localStorage[".pkg93/packages/" + pkg + ".js"]); + } +} catch (err) { + console.error("%c[pkg93]%c Couldn't load pkg93!", "font-weight:bold", "font-weight:normal"); + console.error("%c[pkg93]%c %o", "font-weight:bold", "font-weight:normal", err); + $alert({ + title: "Couldn't load pkg93!", + msg: "
" + (err.stack || err.toString()) + "
", + 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(); + +le._apps.pkg93 = { + exec: function() { wrap.call(this, _pkg93execdonotcallplsusetheapi); }, + icon: "//cdn.rawgit.com/pkg93/pkg93/70039c02/pkg.png", + terminal: true, + hascli: true, + categories: "Network;Utility;Settings;PackageManager" +}; -- cgit v1.2.3