From 1ccae245ccfd9447597b916a3be92342fce37c04 Mon Sep 17 00:00:00 2001 From: Kyza Date: Wed, 13 Oct 2021 12:49:49 -0400 Subject: [PATCH] Huge changes - Renderer loading, better build script --- package.json | 10 +- pnpm-lock.yaml | 315 +++--------------- scripts/build.mjs | 36 +- src/core/EventListener.ts | 8 + src/core/injectRendererModule.ts | 2 +- src/core/packageLoader/PackageInfo.ts | 1 + src/core/packageLoader/_startPackage.ts | 5 +- src/core/packageLoader/_stopPackage.ts | 4 +- src/core/packageLoader/getPackages.ts | 12 +- src/core/packageLoader/loadPackage.ts | 16 +- src/core/packageLoader/loadedPackages.ts | 9 +- src/core/packageLoader/startPackage.ts | 10 +- src/core/packageLoader/stopPackage.ts | 10 +- src/index.ts | 12 +- src/patchBrowserWindow.ts | 2 +- src/preload/index.ts | 4 +- .../bridge}/index.ts | 11 +- .../renderer/bridge/packageListener.ts | 3 + .../bridge}/packages.ts | 24 +- src/preload/rendererBridge/packageListener.ts | 3 - 20 files changed, 163 insertions(+), 334 deletions(-) rename src/preload/{rendererBridge => renderer/bridge}/index.ts (69%) create mode 100644 src/preload/renderer/bridge/packageListener.ts rename src/preload/{rendererBridge => renderer/bridge}/packages.ts (50%) delete mode 100644 src/preload/rendererBridge/packageListener.ts diff --git a/package.json b/package.json index 21e915f..bce276e 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,16 @@ { "main": "index.js", "scripts": { - "build": "pnpx zx ./scripts/build.mjs", - "build-dev": "pnpx zx ./scripts/build.mjs --dev" + "build": "node ./scripts/build.mjs", + "build-dev": "node ./scripts/build.mjs --dev" }, "devDependencies": { - "@swc/cli": "^0.1.49", - "@swc/core": "^1.2.85", + "@swc/cli": "^0.1.51", + "@swc/core": "^1.2.95", "asar": "^3.1.0", "electron": "^13.3.0", "fs-extra": "^10.0.0", "glob": "^7.2.0", - "zx": "^4.2.0" + "minimist": "^1.2.5" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 75be6c0..afa8fd5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,22 +1,22 @@ lockfileVersion: 5.3 specifiers: - '@swc/cli': ^0.1.49 - '@swc/core': ^1.2.85 + '@swc/cli': ^0.1.51 + '@swc/core': ^1.2.95 asar: ^3.1.0 electron: ^13.3.0 fs-extra: ^10.0.0 glob: ^7.2.0 - zx: ^4.2.0 + minimist: ^1.2.5 devDependencies: - '@swc/cli': 0.1.49_@swc+core@1.2.85 - '@swc/core': 1.2.85 + '@swc/cli': 0.1.51_@swc+core@1.2.95 + '@swc/core': 1.2.95 asar: 3.1.0 electron: 13.3.0 fs-extra: 10.0.0 glob: 7.2.0 - zx: 4.2.0 + minimist: 1.2.5 packages: @@ -74,8 +74,8 @@ packages: engines: {node: '>=6'} dev: true - /@swc/cli/0.1.49_@swc+core@1.2.85: - resolution: {integrity: sha512-r1m8C+4YoAmV+xfzPTvjsfOvOaFuCoyFTT3W/8mLoJMgx7CL4wu5/nCVVLHHC1JCJFbwSXvHTfkuHWRNcnOjtg==} + /@swc/cli/0.1.51_@swc+core@1.2.95: + resolution: {integrity: sha512-7eqZGpkI4QOYfF+9FV4xpT/V/LSRDs5OMJcm4Z46JnPMvv+sxumAFdCe1hHRzHgnzwis9OtjI8Tt3Srf9JudQw==} engines: {node: '>= 12.13'} hasBin: true peerDependencies: @@ -85,15 +85,15 @@ packages: chokidar: optional: true dependencies: - '@swc/core': 1.2.85 + '@swc/core': 1.2.95 commander: 7.2.0 fast-glob: 3.2.7 slash: 3.0.0 source-map: 0.7.3 dev: true - /@swc/core-android-arm64/1.2.85: - resolution: {integrity: sha512-XhRCVKrjwZBq7ubTnUtN8klCf/2V/MQNy18S4Z7xEdKhf2a0b1+DXd25bePF00WvFLGZbcLZGrm7l/SQBsPeEg==} + /@swc/core-android-arm64/1.2.95: + resolution: {integrity: sha512-5sG4om9aP60DRDrP2/nIHS34oSCmvu4U41jQuF0bwULp45WTIKF4DJpXzPLVV8ikfpgwgWSdMJv8AQJlSmlq+g==} engines: {node: '>=10'} cpu: [arm64] os: [android] @@ -101,8 +101,8 @@ packages: dev: true optional: true - /@swc/core-darwin-arm64/1.2.85: - resolution: {integrity: sha512-N4PSx48knDWmhvo2vNVBKye+8II9/lPgOTh2BL7OzYQEa6zV7ZkSCYu77mJs1ZdDdfV96FUKgN3mLeKOAhyWUg==} + /@swc/core-darwin-arm64/1.2.95: + resolution: {integrity: sha512-3b0EK8shRKPiv0ZjDGm6JXVdZsuySoq6d3PDIw50/98/dtnDTNVdMuAPutXladXGUajN/HbeEyf/xFl3iaTkUA==} engines: {node: '>=10'} cpu: [arm64] os: [darwin] @@ -110,8 +110,8 @@ packages: dev: true optional: true - /@swc/core-darwin-x64/1.2.85: - resolution: {integrity: sha512-pXkwGs+mbsUyHa2Pbhxvl0ADgenlDlxy883DEY9pBpaLDf6KBd8kG/T3lNQJAq8rKAk9aW17VJTyMsEBHhpwLw==} + /@swc/core-darwin-x64/1.2.95: + resolution: {integrity: sha512-AAmqhj6TmrP7mXtxFnQdN1uYlzsCTUba2oxx07rlIzpDxZ+dylCaR1pzYPt22Dz/hSv1ZS318RVYDQgSNpqZkA==} engines: {node: '>=10'} cpu: [x64] os: [darwin] @@ -119,8 +119,8 @@ packages: dev: true optional: true - /@swc/core-freebsd-x64/1.2.85: - resolution: {integrity: sha512-pA5GKyBE7fH1VRdnUJK9deh8s/A9FswO5Yp3g/inKyPu13r5C+5KM8GGwByLgqV/tMG+hO+/LkAaqAGOPmHDRQ==} + /@swc/core-freebsd-x64/1.2.95: + resolution: {integrity: sha512-iAGoddNwGSHzwTN+d1nfmru+lSSVy/TR/CbGUDm08Abga17b5rBXMt8xscoSX1rU3XwqzfUuODlc8rNFDdzroA==} engines: {node: '>=10'} cpu: [x64] os: [freebsd] @@ -128,8 +128,8 @@ packages: dev: true optional: true - /@swc/core-linux-arm-gnueabihf/1.2.85: - resolution: {integrity: sha512-YIetNUGh1IYqVo4u1+0qu41NFFfpiRhILqUO294bCqLTpV6N/zLTEqI+KV8RU90rCEOBJ9BOjjJXT+CpRoEH4Q==} + /@swc/core-linux-arm-gnueabihf/1.2.95: + resolution: {integrity: sha512-3OUdmrF016bON1fTMp4C8yQiz7ViF5j3NZ+3wpG4FLmJpUKWQn98BvGubQoBxHOsT2HxwOOcjSG9aiN4j53q0Q==} engines: {node: '>=10'} cpu: [arm] os: [linux] @@ -137,8 +137,8 @@ packages: dev: true optional: true - /@swc/core-linux-arm64-gnu/1.2.85: - resolution: {integrity: sha512-GgJ0/wXmryIgFsEWIEoxnDkDi+acChflB0qZcDckjrLJ2/BCuvaRlN9BBMeXoGPSasccw9Zrc13XBOYiPQ/5Ow==} + /@swc/core-linux-arm64-gnu/1.2.95: + resolution: {integrity: sha512-jdAoiKUPrxUc0gZ76bXa3hH/RftBnZ9GFp8hHpVYw4v7LL5Vga7X3Vffjdj8ONgSO6YbVOp7k3TDS9jSeyRaDQ==} engines: {node: '>=10'} cpu: [arm64] os: [linux] @@ -146,8 +146,8 @@ packages: dev: true optional: true - /@swc/core-linux-arm64-musl/1.2.85: - resolution: {integrity: sha512-xby6egD1FMtZAvAdLOAzPx2Cna0FayD0S2K4o1ACRfDxmCKz8muFgmTgaMiUeCFQ4+U/Zc+ofm2DuboZCytk0Q==} + /@swc/core-linux-arm64-musl/1.2.95: + resolution: {integrity: sha512-hKB5GBmKKVYJtGaoRABEGH+ruGr5SdrmdS2p0kQmVUXLry4wburWcw1abr8f4RL118VT1lhqM0p6VxmnIsqLcw==} engines: {node: '>=10'} cpu: [arm64] os: [linux] @@ -155,8 +155,8 @@ packages: dev: true optional: true - /@swc/core-linux-x64-gnu/1.2.85: - resolution: {integrity: sha512-+xBmnXze1WfhoSrCOkXt7Zbm/x+Huwo9RGwU4ZkMfOHU2xgp/Obfj6pN28gJs6KN9QBoDAbQJqUuWqhkt7SLzA==} + /@swc/core-linux-x64-gnu/1.2.95: + resolution: {integrity: sha512-f7+/UD1d0cyOeMlLqgqhOpBdEUPBXrOWkv8tZXsLGpKdawcBv6QnoLfQPVmYYjFIt1bFZWMwalDU8N74QX93GQ==} engines: {node: '>=10'} cpu: [x64] os: [linux] @@ -164,8 +164,8 @@ packages: dev: true optional: true - /@swc/core-linux-x64-musl/1.2.85: - resolution: {integrity: sha512-F+VMphiPNTvoZ6pWOJk1b6P3VQBJPnStv1OKshy1po2L98vhqMt6O9Pa1UV8Ugd1KW263hje1K3vy7qzbbbQJQ==} + /@swc/core-linux-x64-musl/1.2.95: + resolution: {integrity: sha512-V+N5dhHNnHw0hS4aLjecYbcflUa+XKGUbDpFyNdHTTOk+/18Wf1Cr08SbD/6EGF0OfQW1a8OZPLRSi17D53biw==} engines: {node: '>=10'} cpu: [x64] os: [linux] @@ -173,8 +173,8 @@ packages: dev: true optional: true - /@swc/core-win32-arm64-msvc/1.2.85: - resolution: {integrity: sha512-tmYS1RT+3rCQI47KxWzoBKSv6kfSno98SznmmhjFJooxtcQwyxLNp/WEsbnCixQbUUQaA5vF0qZRJ57oJrf2ZQ==} + /@swc/core-win32-arm64-msvc/1.2.95: + resolution: {integrity: sha512-jsXw99Nes5VqgrJeYuPdwHwfwdoq38t1P4i/cxbqUjXYyGHgkSXBE0smlAd00LaNQ/rkuoysJr/FzjQHXF8WQg==} engines: {node: '>=10'} cpu: [arm64] os: [win32] @@ -182,8 +182,8 @@ packages: dev: true optional: true - /@swc/core-win32-ia32-msvc/1.2.85: - resolution: {integrity: sha512-ihXjkalqBJKsdvErfClVwq+viVOrGB/ZCB+lADmVO8Lw0iKEHG8cdN89MSK7ASAY8E4ek7MObDMoSTE52pksVg==} + /@swc/core-win32-ia32-msvc/1.2.95: + resolution: {integrity: sha512-PTxG852WOr2c3LLm0gphH6TwJYtewhYa7YbJYNoxHf14vdt+hMAoAJyhRUQ1OOdjKhYZ13sRC4Umpy67MqlWVw==} engines: {node: '>=10'} cpu: [ia32] os: [win32] @@ -191,8 +191,8 @@ packages: dev: true optional: true - /@swc/core-win32-x64-msvc/1.2.85: - resolution: {integrity: sha512-LmvpyEXL1q2Cq7TxCOX89oSHhgj29CMIk9jMmMJtng/1Ud75jU9POmzHN4sUyIRbO0hicjFwQ5TWOt0GTl+kQg==} + /@swc/core-win32-x64-msvc/1.2.95: + resolution: {integrity: sha512-biSwecUU8eI3i/jfZm/KiY3/Tp1B9bG6U07jNEvSQbJoTqx179+4gwKvCnO0DkDaGh19abGJVdeo8kR8YEVttA==} engines: {node: '>=10'} cpu: [x64] os: [win32] @@ -200,24 +200,24 @@ packages: dev: true optional: true - /@swc/core/1.2.85: - resolution: {integrity: sha512-P0yKca8CfKE+Kf4LlAmLDUGZ8W9wLvdnkeXo8SjG/vV21scAkoo1qVyWyAHsWNxNxHTxw2E/oqDWqI+yEn7qMg==} + /@swc/core/1.2.95: + resolution: {integrity: sha512-1uqBCVGjQ6IWAF+FewJI2HZOWMhUmh36lwdk2kmP4QeLlVPWk1AcX4o+d+4KsHZ2KGyEF08Ys4incO6kWIrnPw==} engines: {node: '>=10'} dependencies: '@node-rs/helper': 1.2.1 optionalDependencies: - '@swc/core-android-arm64': 1.2.85 - '@swc/core-darwin-arm64': 1.2.85 - '@swc/core-darwin-x64': 1.2.85 - '@swc/core-freebsd-x64': 1.2.85 - '@swc/core-linux-arm-gnueabihf': 1.2.85 - '@swc/core-linux-arm64-gnu': 1.2.85 - '@swc/core-linux-arm64-musl': 1.2.85 - '@swc/core-linux-x64-gnu': 1.2.85 - '@swc/core-linux-x64-musl': 1.2.85 - '@swc/core-win32-arm64-msvc': 1.2.85 - '@swc/core-win32-ia32-msvc': 1.2.85 - '@swc/core-win32-x64-msvc': 1.2.85 + '@swc/core-android-arm64': 1.2.95 + '@swc/core-darwin-arm64': 1.2.95 + '@swc/core-darwin-x64': 1.2.95 + '@swc/core-freebsd-x64': 1.2.95 + '@swc/core-linux-arm-gnueabihf': 1.2.95 + '@swc/core-linux-arm64-gnu': 1.2.95 + '@swc/core-linux-arm64-musl': 1.2.95 + '@swc/core-linux-x64-gnu': 1.2.95 + '@swc/core-linux-x64-musl': 1.2.95 + '@swc/core-win32-arm64-msvc': 1.2.95 + '@swc/core-win32-ia32-msvc': 1.2.95 + '@swc/core-win32-x64-msvc': 1.2.95 dev: true /@szmarczak/http-timer/1.1.2: @@ -227,12 +227,6 @@ packages: defer-to-connect: 1.1.3 dev: true - /@types/fs-extra/9.0.12: - resolution: {integrity: sha512-I+bsBr67CurCGnSenZZ7v94gd3tc3+Aj2taxMT4yu4ABLuOgOjeFxX3dokG24ztSRg5tnT00sL8BszO7gSMoIw==} - dependencies: - '@types/node': 16.9.1 - dev: true - /@types/glob/7.1.4: resolution: {integrity: sha512-w+LsMxKyYQm347Otw+IfBXOv9UWVjpHpCDdbBMt8Kz/xbvCYNjP+0qPh91Km3iKfSRLBB0P7fAMf0KHrPu+MyA==} requiresBuild: true @@ -247,17 +241,6 @@ packages: dev: true optional: true - /@types/minimist/1.2.2: - resolution: {integrity: sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==} - dev: true - - /@types/node-fetch/2.5.12: - resolution: {integrity: sha512-MKgC4dlq4kKNa/mYrwpKfzQMB5X3ee5U6fSprkKpToBqBmX4nFZL9cW5jl6sWn+xpRJ7ypWh2yyqqr8UUCstSw==} - dependencies: - '@types/node': 16.9.1 - form-data: 3.0.1 - dev: true - /@types/node/14.17.15: resolution: {integrity: sha512-D1sdW0EcSCmNdLKBGMYb38YsHUS6JcM7yQ6sLQ9KuZ35ck7LYCKE7kYFHOO59ayFOY3zobWVZxf4KXhYHcHYFA==} dev: true @@ -265,18 +248,7 @@ packages: /@types/node/16.9.1: resolution: {integrity: sha512-QpLcX9ZSsq3YYUUnD3nFDY8H7wctAhQj/TFKL8Ya8v5fMm3CFXxo8zStsLAl780ltoYoo1WvKUVGBQK+1ifr7g==} dev: true - - /ansi-styles/4.3.0: - resolution: {integrity: sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==} - engines: {node: '>=8'} - dependencies: - color-convert: 2.0.1 - dev: true - - /array-union/3.0.1: - resolution: {integrity: sha512-1OvF9IbWwaeiM9VhzYXVQacMibxpXOMYVNIvMtKRyX9SImBXpKcFr8XvFDeEslCyuH/t6KRt7HEO94AlP8Iatw==} - engines: {node: '>=12'} - dev: true + optional: true /asar/3.1.0: resolution: {integrity: sha512-vyxPxP5arcAqN4F/ebHd/HhwnAiZtwhglvdmc7BR2f0ywbVNTOpSeyhLDbGXtE/y58hv1oC75TaNIXutnsOZsQ==} @@ -291,10 +263,6 @@ packages: '@types/glob': 7.1.4 dev: true - /asynckit/0.4.0: - resolution: {integrity: sha1-x57Zf380y48robyXkLzDZkdLS3k=} - dev: true - /balanced-match/1.0.2: resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} dev: true @@ -339,14 +307,6 @@ packages: responselike: 1.0.2 dev: true - /chalk/4.1.2: - resolution: {integrity: sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==} - engines: {node: '>=10'} - dependencies: - ansi-styles: 4.3.0 - supports-color: 7.2.0 - dev: true - /chromium-pickle-js/0.2.0: resolution: {integrity: sha1-BKEGZywYsIWrd02YPfo+oTjyIgU=} dev: true @@ -357,24 +317,6 @@ packages: mimic-response: 1.0.1 dev: true - /color-convert/2.0.1: - resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==} - engines: {node: '>=7.0.0'} - dependencies: - color-name: 1.1.4 - dev: true - - /color-name/1.1.4: - resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==} - dev: true - - /combined-stream/1.0.8: - resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==} - engines: {node: '>= 0.8'} - dependencies: - delayed-stream: 1.0.0 - dev: true - /commander/5.1.0: resolution: {integrity: sha512-P0CysNDQ7rtVw4QIQtm+MRxV66vKFSvlsQvGYXZWR3qFU0jlMKHZZZgw8e+8DSah4UDKMqnknRDQz+xuQXQ/Zg==} engines: {node: '>= 6'} @@ -454,27 +396,11 @@ packages: dev: true optional: true - /delayed-stream/1.0.0: - resolution: {integrity: sha1-3zrhmayt+31ECqrgsp4icrJOxhk=} - engines: {node: '>=0.4.0'} - dev: true - /detect-node/2.1.0: resolution: {integrity: sha512-T0NIuQpnTvFDATNuHN5roPwSBG83rFsuO+MXXH9/3N1eFbn4wcPjttvjMLEPWJ0RGUYgQE7cGgS3tNxbqCGM7g==} dev: true optional: true - /dir-glob/3.0.1: - resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==} - engines: {node: '>=8'} - dependencies: - path-type: 4.0.0 - dev: true - - /duplexer/0.1.2: - resolution: {integrity: sha512-jtD6YG370ZCIi/9GTaJKQxWTZD045+4R4hTk/x1UyoqadyJ9x9CgSi1RlVDQF8U2sxLLSnFkCaMihqljHIWgMg==} - dev: true - /duplexer3/0.1.4: resolution: {integrity: sha1-7gHdHKwO08vH/b6jfcCo8c4ALOI=} dev: true @@ -520,18 +446,6 @@ packages: dev: true optional: true - /event-stream/3.3.4: - resolution: {integrity: sha1-SrTJoPWlTbkzi0w02Gv86PSzVXE=} - dependencies: - duplexer: 0.1.2 - from: 0.1.7 - map-stream: 0.1.0 - pause-stream: 0.0.11 - split: 0.3.3 - stream-combiner: 0.0.4 - through: 2.3.8 - dev: true - /extract-zip/1.7.0: resolution: {integrity: sha512-xoh5G1W/PB0/27lXgMQyIhP5DSY/LhoCsOyZgb+6iMmRtCwVBo55uKaMoEYrDCKQhWvqEip5ZPKAc6eFNyf/MA==} hasBin: true @@ -572,19 +486,6 @@ packages: to-regex-range: 5.0.1 dev: true - /form-data/3.0.1: - resolution: {integrity: sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==} - engines: {node: '>= 6'} - dependencies: - asynckit: 0.4.0 - combined-stream: 1.0.8 - mime-types: 2.1.32 - dev: true - - /from/0.1.7: - resolution: {integrity: sha1-g8YK/Fi5xWmXAH7Rp2izqzA6RP4=} - dev: true - /fs-extra/10.0.0: resolution: {integrity: sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ==} engines: {node: '>=12'} @@ -685,18 +586,6 @@ packages: dev: true optional: true - /globby/12.0.2: - resolution: {integrity: sha512-lAsmb/5Lww4r7MM9nCCliDZVIKbZTavrsunAsHLr9oHthrZP1qi7/gAnHOsUs9bLvEt2vKVJhHmxuL7QbDuPdQ==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dependencies: - array-union: 3.0.1 - dir-glob: 3.0.1 - fast-glob: 3.2.7 - ignore: 5.1.8 - merge2: 1.4.1 - slash: 4.0.0 - dev: true - /got/9.6.0: resolution: {integrity: sha512-R7eWptXuGYxwijs0eV+v3o6+XH1IqVK8dJOEecQfTmkncw9AV4dcw/Dhxi8MdlqPthxxpZyizMzyg8RTmEsG+Q==} engines: {node: '>=8.6'} @@ -718,20 +607,10 @@ packages: resolution: {integrity: sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==} dev: true - /has-flag/4.0.0: - resolution: {integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==} - engines: {node: '>=8'} - dev: true - /http-cache-semantics/4.1.0: resolution: {integrity: sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ==} dev: true - /ignore/5.1.8: - resolution: {integrity: sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==} - engines: {node: '>= 4'} - dev: true - /inflight/1.0.6: resolution: {integrity: sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=} dependencies: @@ -769,10 +648,6 @@ packages: resolution: {integrity: sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=} dev: true - /isexe/2.0.0: - resolution: {integrity: sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=} - dev: true - /json-buffer/3.0.0: resolution: {integrity: sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg=} dev: true @@ -825,10 +700,6 @@ packages: dev: true optional: true - /map-stream/0.1.0: - resolution: {integrity: sha1-5WqpTEyAVaFkBKBnS3jyFffI4ZQ=} - dev: true - /matcher/3.0.0: resolution: {integrity: sha512-OkeDaAZ/bQCxeFAozM55PKcKU0yJMPGifLwV4Qgjitu+5MoAfSQN4lsLJeXZ1b8w0x+/Emda6MZgXS1jvsapng==} engines: {node: '>=10'} @@ -850,18 +721,6 @@ packages: picomatch: 2.3.0 dev: true - /mime-db/1.49.0: - resolution: {integrity: sha512-CIc8j9URtOVApSFCQIF+VBkX1RwXp/oMMOrqdyXSBXq5RWNEsRfyj1kiRnQgmNXmHxPoFIxOroKA3zcU9P+nAA==} - engines: {node: '>= 0.6'} - dev: true - - /mime-types/2.1.32: - resolution: {integrity: sha512-hJGaVS4G4c9TSMYh2n6SQAGrC4RnfU+daP8G7cSCmaqNjiOoUY0VHCMS42pxnQmVF1GWwFhbHWn3RIxCqTmZ9A==} - engines: {node: '>= 0.6'} - dependencies: - mime-db: 1.49.0 - dev: true - /mimic-response/1.0.1: resolution: {integrity: sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==} engines: {node: '>=4'} @@ -892,11 +751,6 @@ packages: resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} dev: true - /node-fetch/2.6.2: - resolution: {integrity: sha512-aLoxToI6RfZ+0NOjmWAgn9+LEd30YCkJKFSyWacNZdEKTit/ZMcKjGkTRo8uWEsnIb/hfKecNPEbln02PdWbcA==} - engines: {node: 4.x || >=6.0.0} - dev: true - /normalize-url/4.5.1: resolution: {integrity: sha512-9UZCFRHQdNrfTpGg8+1INIg93B6zE0aXMVFkw1WFwvO4SlZywU6aLg5Of0Ap/PgcbSw4LNxvMWXMeugwMCX0AA==} engines: {node: '>=8'} @@ -933,17 +787,6 @@ packages: engines: {node: '>=0.10.0'} dev: true - /path-type/4.0.0: - resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==} - engines: {node: '>=8'} - dev: true - - /pause-stream/0.0.11: - resolution: {integrity: sha1-/lo0sMvOErWqaitAPuLnO2AvFEU=} - dependencies: - through: 2.3.8 - dev: true - /pend/1.2.0: resolution: {integrity: sha1-elfrVQpng/kRUzH89GY9XI4AelA=} dev: true @@ -978,14 +821,6 @@ packages: dev: true optional: true - /ps-tree/1.2.0: - resolution: {integrity: sha512-0VnamPPYHl4uaU/nSFeZZpR21QAWRz+sRv4iW9+v/GS/J5U5iZB5BNN6J0RMoOvdx2gWM2+ZFMIm58q24e4UYA==} - engines: {node: '>= 0.10'} - hasBin: true - dependencies: - event-stream: 3.3.4 - dev: true - /pump/3.0.0: resolution: {integrity: sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==} dependencies: @@ -1075,33 +910,16 @@ packages: engines: {node: '>=8'} dev: true - /slash/4.0.0: - resolution: {integrity: sha512-3dOsAHXXUkQTpOYcoAxLIorMTp4gIQr5IW3iVb7A7lFIp0VHhnynm9izx6TssdrIcVIESAlVjtnO2K8bg+Coew==} - engines: {node: '>=12'} - dev: true - /source-map/0.7.3: resolution: {integrity: sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==} engines: {node: '>= 8'} dev: true - /split/0.3.3: - resolution: {integrity: sha1-zQ7qXmOiEd//frDwkcQTPi0N0o8=} - dependencies: - through: 2.3.8 - dev: true - /sprintf-js/1.1.2: resolution: {integrity: sha512-VE0SOVEHCk7Qc8ulkWw3ntAzXuqf7S2lvwQaDLRnUeIEaKNQJzV6BwmLKhOqT61aGhfUMrXeaBk+oDGCzvhcug==} dev: true optional: true - /stream-combiner/0.0.4: - resolution: {integrity: sha1-TV5DPBhSYd3mI8o/RMWGvPXErRQ=} - dependencies: - duplexer: 0.1.2 - dev: true - /string_decoder/1.1.1: resolution: {integrity: sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==} dependencies: @@ -1117,17 +935,6 @@ packages: - supports-color dev: true - /supports-color/7.2.0: - resolution: {integrity: sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==} - engines: {node: '>=8'} - dependencies: - has-flag: 4.0.0 - dev: true - - /through/2.3.8: - resolution: {integrity: sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=} - dev: true - /to-readable-stream/1.0.0: resolution: {integrity: sha512-Iq25XBt6zD5npPhlLVXGFN3/gyR2/qODcKNNyTMd4vbm39HUaOiAM4PMq0eMVC/Tkxz+Zjdsc55g9yyz+Yq00Q==} engines: {node: '>=6'} @@ -1177,14 +984,6 @@ packages: resolution: {integrity: sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=} dev: true - /which/2.0.2: - resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==} - engines: {node: '>= 8'} - hasBin: true - dependencies: - isexe: 2.0.0 - dev: true - /wrappy/1.0.2: resolution: {integrity: sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=} dev: true @@ -1200,21 +999,3 @@ packages: buffer-crc32: 0.2.13 fd-slicer: 1.1.0 dev: true - - /zx/4.2.0: - resolution: {integrity: sha512-/4f7FaJecA9I655KXKXIHO3CFNYjAz2uSmTz6v2eNlKdrQKyz4VyF3RjqFuP6nQG+Hd3+NjOvrVNBkv8Ne9d4Q==} - engines: {node: '>= 14.13.0'} - hasBin: true - dependencies: - '@types/fs-extra': 9.0.12 - '@types/minimist': 1.2.2 - '@types/node': 16.9.1 - '@types/node-fetch': 2.5.12 - chalk: 4.1.2 - fs-extra: 10.0.0 - globby: 12.0.2 - minimist: 1.2.5 - node-fetch: 2.6.2 - ps-tree: 1.2.0 - which: 2.0.2 - dev: true diff --git a/scripts/build.mjs b/scripts/build.mjs index 8dceadc..4bc74a1 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -6,6 +6,14 @@ import swc from "@swc/core"; import { promisify } from "util"; import glob from "glob"; import asar from "asar"; +import { exec } from "child_process"; +import minimist from "minimist"; +import { dirname } from "path"; +import { fileURLToPath } from "url"; + +const __dirname = dirname(fileURLToPath(import.meta.url)); + +const argv = minimist(process.argv.slice(2)); try { await fs.emptyDir("./dist"); @@ -51,7 +59,7 @@ for (const file of sourceFiles) { externalHelpers: false, keepClassNames: true, minify: { - compress: production, + compress: false, // TODO: Figure out why this breaks package loading in main. mangle: production, }, // paths: { @@ -75,6 +83,7 @@ for (const file of sourceFiles) { }); } +// Save this for possibly using it in the future. // await fs.copy( // "./node_modules/@swc/helpers", // "./transpiled/node_modules/@swc/helpers", @@ -90,21 +99,24 @@ for (const file of sourceFiles) { const baseDir = path.join(__dirname, ".."); // Build the renderer and copy it over. -cd(path.join(baseDir, "..", "browser")); -await $`pnpm run build`; +await new Promise((resolve) => + exec( + `cd ${path.join(baseDir, "..", "browser")} && pnpm run build`, + (err, stdout, stderr) => { + if (err) { + console.error(err); + return; + } + console.log(stdout); + resolve(); + } + ) +); await fs.copyFile( path.join(baseDir, "..", "browser", "dist", "index.js"), - path.join(baseDir, "transpiled", "preload", "renderer.js") + path.join(baseDir, "transpiled", "preload", "renderer", "index.js") ); -// Build the core and copy it over. -// cd(path.join(baseDir, "..", "core")); -// await $`npm run build`; -// await fs.copyFile( -// path.join(baseDir, "..", "core", "dist", "index.js"), -// path.join(baseDir, "transpiled", "core.js") -// ); - console.time("Successfully packed"); await asar.createPackage( path.join(__dirname, "..", "transpiled"), diff --git a/src/core/EventListener.ts b/src/core/EventListener.ts index 236f942..b689bdc 100644 --- a/src/core/EventListener.ts +++ b/src/core/EventListener.ts @@ -8,6 +8,14 @@ class EventListener { this.#listeners[eventName].push(listener); } + once(eventName: string, listener: (...args: any[]) => any) { + const onceListener = (...args: any[]) => { + listener(...args); + this.off(eventName, onceListener); + }; + this.on(eventName, onceListener); + } + off(eventName: string, listener: (...args: any[]) => any) { if (this.#listeners[eventName] == undefined) { return; diff --git a/src/core/injectRendererModule.ts b/src/core/injectRendererModule.ts index 000f50e..356b2a2 100644 --- a/src/core/injectRendererModule.ts +++ b/src/core/injectRendererModule.ts @@ -21,7 +21,7 @@ export default async function injectRendererModule({ { type: "module", async: (!sync).toString(), - src: `import${sync ? "-sync" : ""}://${resolve(script)}`, + src: `kernel${sync ? "-sync" : ""}://${resolve(script)}`, } ); diff --git a/src/core/packageLoader/PackageInfo.ts b/src/core/packageLoader/PackageInfo.ts index 751aa7c..75533ac 100644 --- a/src/core/packageLoader/PackageInfo.ts +++ b/src/core/packageLoader/PackageInfo.ts @@ -4,4 +4,5 @@ export default interface PackageInfo { path: string; version?: string; dependencies?: string[]; + enabled?: boolean; } diff --git a/src/core/packageLoader/_startPackage.ts b/src/core/packageLoader/_startPackage.ts index bf0ccc4..ce34be9 100644 --- a/src/core/packageLoader/_startPackage.ts +++ b/src/core/packageLoader/_startPackage.ts @@ -1,8 +1,5 @@ import loadedPackages from "./loadedPackages"; export default function _startPackage(packageID: string) { - - if (loadedPackages.get(packageID)) { - loadedPackages.get(packageID).instance?.start?.(); - } + loadedPackages[packageID]?.instance?.start?.(); } diff --git a/src/core/packageLoader/_stopPackage.ts b/src/core/packageLoader/_stopPackage.ts index 0141da9..c2c4f22 100644 --- a/src/core/packageLoader/_stopPackage.ts +++ b/src/core/packageLoader/_stopPackage.ts @@ -1,7 +1,5 @@ import loadedPackages from "./loadedPackages"; export default function _stopPackage(packageID: string) { - if (loadedPackages.get(packageID)) { - loadedPackages.get(packageID).instance?.stop?.(); - } + loadedPackages[packageID]?.instance?.stop?.(); } diff --git a/src/core/packageLoader/getPackages.ts b/src/core/packageLoader/getPackages.ts index 2d48c1c..16e9975 100644 --- a/src/core/packageLoader/getPackages.ts +++ b/src/core/packageLoader/getPackages.ts @@ -4,6 +4,7 @@ import PackageInfo from "./PackageInfo"; import getPackagesPath from "./getPackagesPath"; import processLocation from "../processLocation"; import { ipcMain, ipcRenderer } from "electron"; +import loadedPackages from "./loadedPackages"; switch (processLocation()) { case "MAIN": @@ -30,12 +31,21 @@ export default function getPackages(): { const packageInfo: PackageInfo = JSON.parse( fs.readFileSync(path.join(packagePath, "index.json"), "utf8") ); + + // Automatically start new packages. + packageInfo.enabled = loadedPackages[packageInfo.id]?.hasOwnProperty( + "enabled" + ) + ? !!loadedPackages[packageInfo.id].enabled + : true; + packageInfo.path = packagePath; packages[packageInfo.id] = packageInfo; } return packages; - } catch { + } catch (e) { + console.error(e); return {}; } case "PRELOAD": diff --git a/src/core/packageLoader/loadPackage.ts b/src/core/packageLoader/loadPackage.ts index dc4792a..d0fc9c1 100644 --- a/src/core/packageLoader/loadPackage.ts +++ b/src/core/packageLoader/loadPackage.ts @@ -17,18 +17,18 @@ export default function loadPackage( const packageScript = path.join(pack.path, `${context}.js`); if (fs.existsSync(packageScript)) { - const packageClass = require(packageScript); - const packageInstance = new ( - packageClass.default ? packageClass.default : packageClass - )(); + const packageExport = require(packageScript); + const packageInstance = packageExport.default + ? packageExport.default + : packageExport; - loadedPackages.set(packageID, { - enabled: true, + loadedPackages[packageID] = { ...pack, + enabled: true, instance: packageInstance, - }); + }; - if (loadedPackages.get(packageID).enabled) { + if (loadedPackages[packageID].enabled) { if (broadcast) { startPackage(packageID); } else { diff --git a/src/core/packageLoader/loadedPackages.ts b/src/core/packageLoader/loadedPackages.ts index 5e0477b..5e19781 100644 --- a/src/core/packageLoader/loadedPackages.ts +++ b/src/core/packageLoader/loadedPackages.ts @@ -1,10 +1,3 @@ let loadedPackages = {}; -export default { - get: (key: string) => { - return loadedPackages[key] ?? loadedPackages; - }, - set: (key: string, value: any) => { - loadedPackages[key] = value; - }, -}; +export default loadedPackages; diff --git a/src/core/packageLoader/startPackage.ts b/src/core/packageLoader/startPackage.ts index 563f251..8e2bcd0 100644 --- a/src/core/packageLoader/startPackage.ts +++ b/src/core/packageLoader/startPackage.ts @@ -1,4 +1,5 @@ import broadcast from "../broadcast"; +import loadedPackages from "./loadedPackages"; import _startPackage from "./_startPackage"; broadcast.on("startPackage", (packageID: string) => { @@ -6,5 +7,12 @@ broadcast.on("startPackage", (packageID: string) => { }); export default function startPackage(packageID: string) { - broadcast.emit("startPackage", packageID); + const pack = loadedPackages[packageID]; + if (!pack.enabled) { + loadedPackages[packageID] = { + ...pack, + enabled: true, + }; + broadcast.emit("startPackage", packageID); + } } diff --git a/src/core/packageLoader/stopPackage.ts b/src/core/packageLoader/stopPackage.ts index 829328e..33b796f 100644 --- a/src/core/packageLoader/stopPackage.ts +++ b/src/core/packageLoader/stopPackage.ts @@ -1,4 +1,5 @@ import broadcast from "../broadcast"; +import loadedPackages from "./loadedPackages"; import _stopPackage from "./_stopPackage"; broadcast.on("stopPackage", (packageID: string) => { @@ -6,5 +7,12 @@ broadcast.on("stopPackage", (packageID: string) => { }); export default function stopPackage(packageID: string) { - broadcast.emit("stopPackage", packageID); + const pack = loadedPackages[packageID]; + if (pack.enabled) { + loadedPackages[packageID] = { + ...pack, + enabled: false, + }; + broadcast.emit("stopPackage", packageID); + } } diff --git a/src/index.ts b/src/index.ts index 2cd9dbc..24e6233 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,9 +6,9 @@ console.time("Loaded before app ready in"); console.log("Loading Kernel."); protocol.registerSchemesAsPrivileged([ - { scheme: "import", privileges: { bypassCSP: true } }, + { scheme: "kernel", privileges: { bypassCSP: true } }, { - scheme: "import-sync", + scheme: "kernel-sync", privileges: { bypassCSP: true }, }, ]); @@ -23,12 +23,12 @@ console.timeEnd("Loaded before app ready in"); app.on("ready", async () => { console.time("Loaded after app ready in"); - protocol.registerFileProtocol("import", (request, callback) => { - const url = request.url.substr(9); + protocol.registerFileProtocol("kernel", (request, callback) => { + const url = request.url.substr(8); callback({ path: url }); }); - protocol.registerFileProtocol("import-sync", (request, callback) => { - const url = request.url.substr(14); + protocol.registerFileProtocol("kernel-sync", (request, callback) => { + const url = request.url.substr(12); callback({ path: url }); }); diff --git a/src/patchBrowserWindow.ts b/src/patchBrowserWindow.ts index 02b0bff..926a1e7 100644 --- a/src/patchBrowserWindow.ts +++ b/src/patchBrowserWindow.ts @@ -33,7 +33,7 @@ const electronProxy = new Proxy(electron, { // @ts-ignore window.webContents.kernelWindowData = { originalPreload: originalPreload, - windowOptions: options + windowOptions: options, }; window.webContents.openDevTools(); diff --git a/src/preload/index.ts b/src/preload/index.ts index 46aacd7..1b53048 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -6,12 +6,12 @@ import * as packageLoader from "../core/packageLoader"; ipcRenderer.sendSync("KERNEL_SETUP_RENDERER_HOOK"); // Initialize the renderer bridge. -require("./rendererBridge"); +require("./renderer/bridge/index.js"); packageLoader.loadPackages(packageLoader.getOgre(), false); injectRendererModule({ - script: path.join(__dirname, "renderer.js"), + script: path.join(__dirname, "renderer", "index.js"), }); // const packagesPath = packageLoader.getPackagesPath(); diff --git a/src/preload/rendererBridge/index.ts b/src/preload/renderer/bridge/index.ts similarity index 69% rename from src/preload/rendererBridge/index.ts rename to src/preload/renderer/bridge/index.ts index 10d9f6d..404a923 100644 --- a/src/preload/rendererBridge/index.ts +++ b/src/preload/renderer/bridge/index.ts @@ -1,6 +1,13 @@ +declare global { + const kernel: typeof api; + interface Window { + kernel: typeof kernel; + } +} + import { contextBridge, ipcRenderer } from "electron"; import packages from "./packages"; -import broadcast from "../../core/broadcast"; +import broadcast from "../../../core/broadcast"; const preloadData = ipcRenderer.sendSync("KERNEL_WINDOW_DATA"); @@ -10,12 +17,12 @@ const api = { sendFinished: () => { return ipcRenderer.sendSync("KERNEL_FINISH_RENDERER_HOOK"); }, + importProtocol: "kernel", }; if (!!preloadData.windowOptions.webPreferences?.contextIsolation) { contextBridge.exposeInMainWorld("kernel", api); } else { - // @ts-ignore window.kernel = api; } diff --git a/src/preload/renderer/bridge/packageListener.ts b/src/preload/renderer/bridge/packageListener.ts new file mode 100644 index 0000000..649147c --- /dev/null +++ b/src/preload/renderer/bridge/packageListener.ts @@ -0,0 +1,3 @@ +import EventListener from "../../../core/EventListener"; + +export default new EventListener(); diff --git a/src/preload/rendererBridge/packages.ts b/src/preload/renderer/bridge/packages.ts similarity index 50% rename from src/preload/rendererBridge/packages.ts rename to src/preload/renderer/bridge/packages.ts index 913b0a6..a74ccea 100644 --- a/src/preload/rendererBridge/packages.ts +++ b/src/preload/renderer/bridge/packages.ts @@ -1,5 +1,6 @@ -import * as packageLoader from "../../core/packageLoader"; -import broadcast from "../../core/broadcast"; +import * as packageLoader from "../../../core/packageLoader"; +import broadcast from "../../../core/broadcast"; +import fs from "fs"; export default { getPackages(): { @@ -7,13 +8,18 @@ export default { } { return packageLoader.getPackages(); }, - getOgre(packages: { - [id: string]: packageLoader.PackageInfo; - }): packageLoader.Ogre { - // Hot. - packages ??= packageLoader.getPackages(); + getOgre( + packages: { + [id: string]: packageLoader.PackageInfo; + } = packageLoader.getPackages() + ): packageLoader.Ogre { return packageLoader.getOgre(packages); }, + hasRendererScript(packageID: string) { + return fs.existsSync( + `${packageLoader.getPackages()[packageID].path}/renderer.js` + ); + }, startPackage(packageID: string) { broadcast.emit("startPackage", packageID); }, @@ -21,10 +27,10 @@ export default { broadcast.emit("stopPackage", packageID); }, events: { - on(event: string, callback: (pack: packageLoader.PackageInfo) => void) { + on(event: string, callback: (...data: any) => void) { broadcast.on(event, callback); }, - once(event: string, callback: (pack: packageLoader.PackageInfo) => void) { + once(event: string, callback: (...data: any) => void) { broadcast.once(event, callback); }, off(event: string, callback: (pack: packageLoader.PackageInfo) => void) { diff --git a/src/preload/rendererBridge/packageListener.ts b/src/preload/rendererBridge/packageListener.ts deleted file mode 100644 index c321fd3..0000000 --- a/src/preload/rendererBridge/packageListener.ts +++ /dev/null @@ -1,3 +0,0 @@ -import EventListener from "../../core/EventListener"; - -export default new EventListener();