diff --git a/.eslintrc.json b/.eslintrc.json index e45e446fc..2ee24e8b3 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -4,7 +4,7 @@ "ignorePatterns": ["dist", "browser"], "plugins": [ "@typescript-eslint", - "header", + "simple-header", "simple-import-sort", "unused-imports", "path-alias" @@ -26,35 +26,12 @@ // Since it's only been a month and Vencord has already been stolen // by random skids who rebranded it to "AlphaCord" and erased all license // information - "header/header": [ - 2, - "block", - [ - { - "pattern": "!?", - "template": " " - }, - " * Vencord, a modification for Discord's desktop app", - { - "pattern": " \\* Copyright \\(c\\) \\d{4}", - "template": " * Copyright (c) 2023 Vendicated and contributors" - }, - " *", - " * This program is free software: you can redistribute it and/or modify", - " * it under the terms of the GNU General Public License as published by", - " * the Free Software Foundation, either version 3 of the License, or", - " * (at your option) any later version.", - " *", - " * This program is distributed in the hope that it will be useful,", - " * but WITHOUT ANY WARRANTY; without even the implied warranty of", - " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the", - " * GNU General Public License for more details.", - " *", - " * You should have received a copy of the GNU General Public License", - " * along with this program. If not, see .", - "" - ], - 2 + "simple-header/header": [ + "error", + { + "files": ["scripts/header-new.txt", "scripts/header-old.txt"], + "templates": { "author": [".*", "Vendicated and contributors"] } + } ], "quotes": ["error", "double", { "avoidEscape": true }], "jsx-quotes": ["error", "prefer-double"], @@ -74,7 +51,10 @@ "eqeqeq": ["error", "always", { "null": "ignore" }], "spaced-comment": ["error", "always", { "markers": ["!"] }], "yoda": "error", - "prefer-destructuring": ["error", { "object": true, "array": false }], + "prefer-destructuring": ["error", { + "VariableDeclarator": { "array": false, "object": true }, + "AssignmentExpression": { "array": false, "object": false } + }], "operator-assignment": ["error", "always"], "no-useless-computed-key": "error", "no-unneeded-ternary": ["error", { "defaultAssignment": false }], diff --git a/.github/ISSUE_TEMPLATE/blank.yml b/.github/ISSUE_TEMPLATE/blank.yml index 9887db99f..e8ca246de 100644 --- a/.github/ISSUE_TEMPLATE/blank.yml +++ b/.github/ISSUE_TEMPLATE/blank.yml @@ -1,14 +1,23 @@ -name: Blank Template -description: Use this only if your issue does not fit into another template. **DO NOT ASK FOR SUPPORT OR REQUEST PLUGINS** -labels: [] +name: Blank Issue +description: Create a blank issue. ALWAYS FIRST USE OUR SUPPORT CHANNEL! ONLY USE THIS FORM IF YOU ARE A CONTRIBUTOR OR WERE TOLD TO DO SO IN THE SUPPORT CHANNEL. body: - - type: textarea - id: info-sec + - type: markdown attributes: - label: Tell us all about it. - description: Go nuts, let us know what you're wanting to bring attention to. - placeholder: ... + value: | + # READ THIS BEFORE OPENING AN ISSUE + + This form is ONLY FOR DEVELOPERS. YOUR ISSUE WILL BE CLOSED AND YOU WILL POSSIBLY BE BLOCKED FROM THE REPOSITORY IF YOU IGNORE THIS. + + DO NOT USE THIS FORM, unless + - you are a vencord contributor + - you were given explicit permission to use this form by a moderator in our support server + - you are filing a security related report + + - type: textarea + id: content + attributes: + label: Content validations: required: true @@ -16,7 +25,6 @@ body: id: agreement-check attributes: label: Request Agreement - description: DO NOT USE THIS TEMPLATE FOR SUPPORT OR PLUGIN REQUESTS!!! For Support, **join our Discord**. For plugin requests, **use discussions** options: - - label: This is not a support or plugin request + - label: I have read the requirements for opening an issue above required: true diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 734bbaca8..d79f5e490 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -1,9 +1,22 @@ name: Bug/Crash Report -description: Create a bug or crash report for Vencord +description: Create a bug or crash report for Vencord. ALWAYS FIRST USE OUR SUPPORT CHANNEL! ONLY USE THIS FORM IF YOU ARE A CONTRIBUTOR OR WERE TOLD TO DO SO IN THE SUPPORT CHANNEL. labels: [bug] title: "[Bug] " body: + - type: markdown + attributes: + value: | + # READ THIS BEFORE OPENING AN ISSUE + + This form is ONLY FOR DEVELOPERS. YOUR ISSUE WILL BE CLOSED AND YOU WILL POSSIBLY BE BLOCKED FROM THE REPOSITORY IF YOU IGNORE THIS. + + DO NOT USE THIS FORM, unless + - you are a vencord contributor + - you were given explicit permission to use this form by a moderator in our support server + + DO NOT USE THIS FORM FOR SECURITY RELATED ISSUES. [CREATE A SECURITY ADVISORY INSTEAD.](https://github.com/Vendicated/Vencord/security/advisories/new) + - type: input id: discord attributes: @@ -64,3 +77,5 @@ body: options: - label: I am using Discord Stable or tried on Stable and this bug happens there as well required: true + - label: I have read the requirements for opening an issue above + required: true diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml deleted file mode 100644 index 115f7f700..000000000 --- a/.github/ISSUE_TEMPLATE/feature_request.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Feature Request -description: Create a feature request for Vencord. To request new plugins, please use the Discussions tab -labels: [enhancement] -title: "[Feature Request] <title>" - -body: - - type: input - id: discord - attributes: - label: Discord Account - description: Who on Discord is making this request? Not required but encouraged for easier follow-up - placeholder: username#0000 - validations: - required: false - - - type: textarea - id: feature-basic-description - attributes: - label: What is it that you'd like to see? - description: Describe the feature you want added as detailed as possible - placeholder: I think ... would be a cool feature to add. This would be awesome, thanks! - validations: - required: true - - - type: checkboxes - id: agreement-check - attributes: - label: Request Agreement - description: DO NOT USE THIS TEMPLATE FOR PLUGIN REQUESTS!!! For plugin requests, **use discussions** - options: - - label: This is not a plugin request - required: true diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 46645ad8a..9ed7d5ca7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,41 +38,43 @@ jobs: run: pnpm build --standalone - name: Generate plugin list - run: pnpm generatePluginJson dist/plugins.json + run: pnpm generatePluginJson dist/plugins.json dist/plugin-readmes.json - name: Clean up obsolete files run: | - rm -rf dist/*-unpacked Vencord.user.css vencordDesktopRenderer.css vencordDesktopRenderer.css.map + rm -rf dist/*-unpacked dist/monaco Vencord.user.css vencordDesktopRenderer.css vencordDesktopRenderer.css.map - name: Get some values needed for the release id: release_values run: | - echo "release_tag=$(git rev-parse --short HEAD)" >> $GITHUB_ENV + echo "release_tag=$(git rev-parse --short HEAD)" >> $GITHUB_ENV - name: Upload DevBuild as release + if: github.repository == 'Vendicated/Vencord' run: | - gh release upload devbuild --clobber dist/* - gh release edit devbuild --title "DevBuild $RELEASE_TAG" + gh release upload devbuild --clobber dist/* + gh release edit devbuild --title "DevBuild $RELEASE_TAG" env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - RELEASE_TAG: ${{ env.release_tag }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RELEASE_TAG: ${{ env.release_tag }} - name: Upload DevBuild to builds repo + if: github.repository == 'Vendicated/Vencord' run: | - git config --global user.name "$USERNAME" - git config --global user.email actions@github.com + git config --global user.name "$USERNAME" + git config --global user.email actions@github.com - git clone https://$USERNAME:$API_TOKEN@github.com/$GH_REPO.git upload - cd upload + git clone https://$USERNAME:$API_TOKEN@github.com/$GH_REPO.git upload + cd upload - GLOBIGNORE=.git:.gitignore:README.md:LICENSE - rm -rf * - cp -r ../dist/* . + GLOBIGNORE=.git:.gitignore:README.md:LICENSE + rm -rf * + cp -r ../dist/* . - git add -A - git commit -m "Builds for https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA" - git push --force https://$USERNAME:$API_TOKEN@github.com/$GH_REPO.git + git add -A + git commit -m "Builds for https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA" + git push --force https://$USERNAME:$API_TOKEN@github.com/$GH_REPO.git env: - API_TOKEN: ${{ secrets.BUILDS_TOKEN }} - GH_REPO: Vencord/builds - USERNAME: GitHub-Actions + API_TOKEN: ${{ secrets.BUILDS_TOKEN }} + GH_REPO: Vencord/builds + USERNAME: GitHub-Actions diff --git a/.github/workflows/codeberg-mirror.yml b/.github/workflows/codeberg-mirror.yml new file mode 100644 index 000000000..1b2266ee7 --- /dev/null +++ b/.github/workflows/codeberg-mirror.yml @@ -0,0 +1,22 @@ +name: Sync to Codeberg +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true +on: + push: + workflow_dispatch: + schedule: + - cron: "0 */6 * * *" + +jobs: + codeberg: + if: github.repository == 'Vendicated/Vencord' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: pixta-dev/repository-mirroring-action@674e65a7d483ca28dafaacba0d07351bdcc8bd75 # v1.1.1 + with: + target_repo_url: "git@codeberg.org:Vee/cord.git" + ssh_private_key: ${{ secrets.CODEBERG_SSH_PRIVATE_KEY }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f9ddf608d..83236c11e 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,6 +6,7 @@ on: jobs: Publish: + if: github.repository == 'Vendicated/Vencord' runs-on: ubuntu-latest steps: @@ -13,11 +14,11 @@ jobs: - name: check that tag matches package.json version run: | - pkg_version="v$(jq -r .version < package.json)" - if [[ "${{ github.ref_name }}" != "$pkg_version" ]]; then - echo "Tag ${{ github.ref_name }} does not match package.json version $pkg_version" >&2 - exit 1 - fi + pkg_version="v$(jq -r .version < package.json)" + if [[ "${{ github.ref_name }}" != "$pkg_version" ]]; then + echo "Tag ${{ github.ref_name }} does not match package.json version $pkg_version" >&2 + exit 1 + fi - uses: pnpm/action-setup@v2 # Install pnpm using packageManager key in package.json @@ -35,26 +36,10 @@ jobs: - name: Publish extension run: | - # Do not fail so that even if chrome fails, firefox gets a shot. But also store exit code to fail workflow later - EXIT_CODE=0 - - # Chrome - cd dist/chromium-unpacked - pnpx chrome-webstore-upload-cli@2.1.0 upload --auto-publish || EXIT_CODE=$? - - # Firefox - cd ../firefox-unpacked - npm i -g web-ext@7.4.0 web-ext-submit@7.4.0 - web-ext-submit || EXIT_CODE=$? - - exit $EXIT_CODE + cd dist/chromium-unpacked + pnpx chrome-webstore-upload-cli@2.1.0 upload --auto-publish env: - # Chrome - EXTENSION_ID: ${{ secrets.CHROME_EXTENSION_ID }} - CLIENT_ID: ${{ secrets.CHROME_CLIENT_ID }} - CLIENT_SECRET: ${{ secrets.CHROME_CLIENT_SECRET }} - REFRESH_TOKEN: ${{ secrets.CHROME_REFRESH_TOKEN }} - - # Firefox - WEB_EXT_API_KEY: ${{ secrets.WEBEXT_USER }} - WEB_EXT_API_SECRET: ${{ secrets.WEBEXT_SECRET }} + EXTENSION_ID: ${{ secrets.CHROME_EXTENSION_ID }} + CLIENT_ID: ${{ secrets.CHROME_CLIENT_ID }} + CLIENT_SECRET: ${{ secrets.CHROME_CLIENT_SECRET }} + REFRESH_TOKEN: ${{ secrets.CHROME_REFRESH_TOKEN }} diff --git a/.github/workflows/reportBrokenPlugins.yml b/.github/workflows/reportBrokenPlugins.yml index 6dcc09d38..4b09463e0 100644 --- a/.github/workflows/reportBrokenPlugins.yml +++ b/.github/workflows/reportBrokenPlugins.yml @@ -2,15 +2,22 @@ name: Test Patches on: workflow_dispatch: schedule: - # Every day at midnight - - cron: 0 0 * * * + # Every day at midnight + - cron: 0 0 * * * jobs: TestPlugins: + if: github.repository == 'Vendicated/Vencord' runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + if: ${{ github.event_name == 'schedule' }} + with: + ref: dev + + - uses: actions/checkout@v3 + if: ${{ github.event_name == 'workflow_dispatch' }} - uses: pnpm/action-setup@v2 # Install pnpm using packageManager key in package.json @@ -22,36 +29,36 @@ jobs: - name: Install dependencies run: | - pnpm install --frozen-lockfile - pnpm add puppeteer + pnpm install --frozen-lockfile + pnpm add puppeteer - sudo apt-get install -y chromium-browser + sudo apt-get install -y chromium-browser - name: Build web - run: pnpm buildWeb --standalone + run: pnpm buildWeb --standalone --dev - name: Create Report timeout-minutes: 10 run: | - export PATH="$PWD/node_modules/.bin:$PATH" - export CHROMIUM_BIN=$(which chromium-browser) + export PATH="$PWD/node_modules/.bin:$PATH" + export CHROMIUM_BIN=$(which chromium-browser) - esbuild scripts/generateReport.ts > dist/report.mjs - node dist/report.mjs >> $GITHUB_STEP_SUMMARY + esbuild scripts/generateReport.ts > dist/report.mjs + node dist/report.mjs >> $GITHUB_STEP_SUMMARY env: - DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }} - DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} + DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }} + DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} - name: Create Report (Canary) timeout-minutes: 10 if: success() || failure() # even run if previous one failed run: | - export PATH="$PWD/node_modules/.bin:$PATH" - export CHROMIUM_BIN=$(which chromium-browser) - export USE_CANARY=true + export PATH="$PWD/node_modules/.bin:$PATH" + export CHROMIUM_BIN=$(which chromium-browser) + export USE_CANARY=true - esbuild scripts/generateReport.ts > dist/report.mjs - node dist/report.mjs >> $GITHUB_STEP_SUMMARY + esbuild scripts/generateReport.ts > dist/report.mjs + node dist/report.mjs >> $GITHUB_STEP_SUMMARY env: - DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }} - DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} + DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }} + DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 46d564184..d4746d673 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,11 +1,10 @@ name: test on: push: - branches: - - main pull_request: branches: - main + - dev jobs: test: runs-on: ubuntu-latest diff --git a/.vscode/settings.json b/.vscode/settings.json index c0b2045c8..fa543b38c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,7 @@ { "editor.formatOnSave": true, "editor.codeActionsOnSave": { - "source.fixAll.eslint": true + "source.fixAll.eslint": "explicit" }, "[typescript]": { "editor.defaultFormatter": "vscode.typescript-language-features" @@ -12,5 +12,12 @@ "javascript.format.semicolons": "insert", "typescript.format.semicolons": "insert", "typescript.preferences.quoteStyle": "double", - "javascript.preferences.quoteStyle": "double" + "javascript.preferences.quoteStyle": "double", + + "gitlens.remotes": [ + { + "domain": "codeberg.org", + "type": "Gitea" + } + ] } diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 000000000..5b160cb84 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,25 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Build", + "type": "shell", + "command": "pnpm build", + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "Watch", + "type": "shell", + "command": "pnpm watch", + "problemMatcher": [], + "group": { + "kind": "build" + } + } + ] +} \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 792fa40f1..680f8375e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -65,7 +65,7 @@ Also pay attention to the following: - Match any but a guaranteed terminating character: `[^;]+`, for example to match the entire assigned value in `var a=b||c||func();`, `var .{1,2}=([^;]+);` - If you don't care about that part, just match a bunch of chars: `.{0,50}`, for example to extract the variable "b" in `createElement("div",{a:"foo",c:"bar"},b)`, `createElement\("div".{0,30},(.{1,2})\),`. Note the `.{0,30}`, this is essentially the same as `.+`, but safer as you can't end up accidently eating thousands of characters -- Additionally, as you might have noticed, all of the appove approaches use regex groups (`(...)`) to capture the variable name. You can then use those groups in your replacement to access those variables dynamically +- Additionally, as you might have noticed, all of the above approaches use regex groups (`(...)`) to capture the variable name. You can then use those groups in your replacement to access those variables dynamically #### "replace" diff --git a/README.md b/README.md index e1a70c6be..a43c9f834 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,12 @@ # Vencord +[![Codeberg Mirror](https://img.shields.io/static/v1?style=for-the-badge&label=Codeberg%20Mirror&message=codeberg.org/Vee/cord&color=2185D0&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABmJLR0QA/wD/AP+gvaeTAAAKbUlEQVR4nNVae3AV5RX/nW/3Pva+b24e5HHzIICQKGoiYiW8NFBFgohaa6ctglpbFSujSGurzUinohWsOij/gGX6R2fqOK0d1FYTEZXaTrWCBbEikJCEyCvkeXNvkrunf+zdkJDkPnex/c3cmd29+53v/M6e73znnF2Cydj4Tntldzi6qrN/qKqzf2jy6b7BnL4B1dI7oMp9AyoRAIdVsNMqhlxWMZjtspzyK/Jhr036OMsm//bh2vzPzNSPzBD6xFutd7R0Dq758ky4orkjYuc05RCAkixbeEq2/UCJ1/LczxcX/c5IPfU5DMHmxpbCpu7o1k/b+xc1n43YjJI7EqV+W2RmvuPt0oDjB2vn5bQbITNjAzzdeKK8qTO0bU9T77zucNQUjzofHrvENWWu3aUBZfW6+ZOOZiIrbYXrmUXo9daX3v6i667O/iGRiRLpwqtIvKDc+0efJ3hb/UIaSkdGWgZ4sqGt9r2m3lc/P9HvSWe80ZiRp3TPL/UsX1+bvyvVsSkb4NE3WjbuPNj5SM8Fcvdk4bAKrqvwv7DxhuCPUxmXNIn6XSy3nWr6R8OhrqrU1btwqJ3m/bgwu/SqZJdEUgbYsuuka09b9/4Pm3tLMlPvwuAbpe6m+RcplfdcURBKdG9CA2zZddLV2Nx1+JO2vlxj1LswqCpynlxc6SxLZIS40bueWfy9vXvv/xt5APhXa1/u7v+EPqvfxXK8++IaoO2Vpn9+cLS33FjVLhw+bOotOX7q6N/i3TOhAX7y+rHN/+sBLxm8fah71k93tjw/0f/jGuDJxtZrdh7setA8tS4sdn7eef+v3mmfP95/Ywxw6x9Yev9I35/6Iubv83WVfl5a6Uu3VkoavZEo7TnS/Vo98xi+Yy6UKC3bDp7sd5ut1OWFDjyzNMib6oq5Oug0ezp8dqLfG3r92Nbzr48ywNONJ8obDnV/z2xlAk4ZW1aUqhaJIAvCb5YVqwFn3GBtCBoO9dz5TOPxUbnMKAM0dYa2d5lc2AgCNi8r5klui3aBgWynjE11QZbI3FV3NjQkjnYNbB+lj36wubGlcE9T71xTNQDw0Px8nlvmHl73GmfCrKCL19Tkmh4P9jT1LHz2vVP5+vmwAZq71a1m1/PXTPXwD68eS5KIEVUZd1yZwwumeEw1Qld/lJrPhF7Sz4cNsO+rUK2ZExd6rfj10iCPZ2GJCCoAZuCJxQUc9FvNVAX72kPX6ccC0Hp4zR0Ru1kT2mTCSzeXqn5l/EAniMAqoDLDYZWwqa5EVSzmhaKmsxHbLxvbbgdiBmjpHFxj2mwANlxXxBdPUib8nwgQgqAyEFUZxT4L1i/MN3UpHDsTWQvEDHDoTLjCrIluuyzAt8zMSkhGFhp5hrYUFk3z8IqZftOMcKRj4GIAEM80tFccM8n9Z+Qq+MXigqRIWCQCMzQvYIbKwH1X53FFnjkr88iZsLKpoXWa6BiIrjbDzF67hK23lKp2Obm1LAstPEZVjTwDkAio/2ZQ9dolw/VjAB0DfKfoCg9WGy2cADy1NMhBX2rR3CIRGICq8rAhAg4Jj9UWsDBhg+4MR6vF2VC0zGjB99fk8eJp3pQdyyrRMHF9KURVxswCB6+alWO4o3b2RyeLU32D2UYKnVPm5gfm5qWlrF0Wo4hzbCmoDNw0089XlboNNcLpvsFc0RtRDXuNle+x4Lkbi9PO6WWJIBFGEY+qjGjswtq5eVzosRilLnoiUavoH1INiTCyIDy/vETNcmRW1dl0L4gRVxmx3YFhlwnrry1QrZIxASE0yJIIDaiGSHt8UQFXF2Ve1zusYgzxkXGhyGvFvePUE+mgfyAqhGqAqKWVPv5udbYhSjmtkpYWq6OJqzFjqCpjTpmbl1Rk3klSGRBWmTISNC3Hjo1LgoYFJ0GA1aIVR+cTVxlQoS2Pb18a4PLszMKXzSJYuCySmq4Al03CiytKVYfBhYvLKk1IXE+XLRLhwZp81WlNf26HTFHhd0jhdAYTgKduCPLkgPHfQjitYkLiAIEZBDBlu2R6aF7euCV2Mgg45bDw2qWOdAavnp3D109PPdlJBvpTnYg4kVY3MDMuylVw62WJi63x4LHLZ0TAIR9OdWBVodPUclUQwWmT4hLXfgCIUDfDi6oiR8rzBJzyl8LnkD9KZVCOU8aLN5eoshnJ+Qh4bFJC4gztmEjgrtk5anaKnWWfXfpIuBTLjmSpSILw/E0laq7LuGxsIngVCYmIa96hLRG3TaZ1C/KTfjAEQLFIO8TPFk7aH/RZI8kMWrdgEs8udqXLKSUoMkEW4ETEQTRsoHyPlVZfmVw+Uuy3hR9bVHBQAMD0XPu/Ew24dqqH777K/La1DiKCxyYlRRzQymgG4+oyDxZOTdxZnp5r3wvEWmJ5btuL8W4uzbJh87LitLebdOFVpKSJx4IlwIzbL81CcYLO8iSX/IImGQCYae6Wg/2tXQNjNnW7LPDKyilqZd7ETU2zEBlifNTSS4i9PNFIx44x4jh2nZlBsUr0dN8QP/6XVhEaHJvnlfhtkXd/NF0BUextKRFXFznfGk+JDdcX8tdBHtDa6YpFsB4I9ac88omf8wbEgqa2XAIOme6bM35foqrQ+QZIKwGG80ifVbrXZZNGDfhOVYBvviS9JMMoaP3AEcQpPnHdOxiMGXkKbrx4dGfZY5c4T8H9+vmwAeqXFLXOKXW9r59fWuDA44sKv1byAOBzyCkTH+kdS2f4MLPgXJI0p9T17vrFxcf181GVxEUB+0qfIqt+RcKWFSWGNR4ygd4RTpW4HiCJgFWzstmnSPA7ZLU827pypPwxDB/687GXl1X6Vs6bbGz/LRN80hZCT+yLFZ0cgHED4egACeiXm89GsP9EePuzy4rvGil7jAGYmQDsBjDHUBYZ4GhHBMfORigd4rpnyIS9u6d4rqgnGrUtjCmmSYuOqwB0GcwjbWh9xviurpNnxnDA1IspMPe6bOL755MHJvhKjIgOA7jbJD4pw22Thj+kSIW47h2KRaydVezeP57sCdspRPQqgGeNJJIuBAE+ReJUiOv32mXaXjPZs21C2QnmXgdghyEsMoRfkVMiDgCywF/by9z3xJMb1wCxeHAPgDczZpAh/Iq+HSYmDjCsstgThmf5t4ii8eQm7CgS0SCA5QBezoRApnBaBSyCEhIHCLJEb4ZUd+2SqZSwzE+qpUpEQ9CC4qb01M8cRIQsh8zxiKsMtsn08nvlnrpkyAPj5AGJwMw3AtgGwJ/q2ExxvHsQB74KxfKBMblAyGmTHq4pc4/5GjQeUm6qE9FrAK4E8H6ie41GlkN/jTk6F5Ak2ueUpNmpkgfSMAAAENERAAsB3AHgZDoy0oFdFnBYpXPEBfU4beLRD6Z4qmumug+kIzPjaoeZfQDWAHgAQFam8hLh4MkwWjsHemyS2OF08IYrCjynzZ4zKTCzi5nXMvOnzBw16bevIxR95JOj7DNKb1PqXWa+HMDtAGoBXII0lxq0N2OfAmgA8Hsi2muMhudgesHPzNkA5gKoADADwFRoS8UHQO+x9wLoBNAB4AsAnwM4AOADIjLVxf8L9kdXUOE0IskAAAAASUVORK5CYII=)](https://codeberg.org/Vee/cord) + The cutest Discord client mod - -![](https://user-images.githubusercontent.com/45497981/235015332-0453d3eb-1da6-4601-963e-ef5e454123a1.png) -*A screenshot of Vencord featuring the [ClearVision-v6 theme](https://github.com/ClearVision/ClearVision-v6) (Vencord does not come with it pre-installed, it is only an example)* +| ![image](https://github.com/Vendicated/Vencord/assets/45497981/706722b1-32de-4d99-bee9-93993b504334) | +|:--:| +| A screenshot of vencord showcasing the [vencord-theme](https://github.com/synqat/vencord-theme) | ## Features @@ -22,34 +24,29 @@ The cutest Discord client mod ## Installing / Uninstalling -Click the below button to install Vencord to the Discord Desktop app - -[![Download and run the Installer](https://img.shields.io/github/v/release/Vencord/Installer?label=Download%20Vencord%20Installer&style=for-the-badge)](https://github.com/Vencord/Installer#vencord-installer) - -## Installing on Browser - -[![Get it on the Firefox Webstore](https://blog.mozilla.org/addons/files/2015/11/get-the-addon.png)](https://addons.mozilla.org/en-GB/firefox/addon/vencord-web/) [![Get it on the Chrome Webstore](https://storage.googleapis.com/web-dev-uploads/image/WlD8wC6g8khYWPJUsQceQkhXSlv1/UV4C4ybeBTsZt43U4xis.png)](https://chrome.google.com/webstore/detail/vencord-web/cbghhgpcnddeihccjmnadmkaejncjndb) - -Or use the [UserScript](https://raw.githubusercontent.com/Vencord/builds/main/Vencord.user.js) - Please note that the CSS Editor, Themes loaded from remote sources and co. will not work in the UserScript. Use the extension if you need any of those - -<details> -<summary>Alternative Downloads</summary> - -## Vencord Desktop - -> **Warning** -> This is an alternative app. It currently doesn't support screensharing or keybinds. If you just want to install to the normal Discord Desktop app, scroll up - - -As an alternative to the Discord Desktop app, Vencord also has its own standalone Desktop app that is snappier and lighter than Discord's official Desktop app. It is currently in beta and we have yet to implement some features like screensharing, but you can try the beta nonetheless - -[![Download Vencord Desktop](https://img.shields.io/github/v/release/Vencord/Desktop?label=Download%20Vencord%20Desktop&style=for-the-badge)](https://github.com/Vencord/Desktop#vencord-desktop) - -</details> +Visit https://vencord.dev/download ## Join our Support/Community Server -[![Vencord Discord Server](https://invidget.switchblade.xyz/D9uwnFnqmd?theme=dark)](https://discord.gg/D9uwnFnqmd) +https://discord.gg/D9uwnFnqmd + +## Sponsors + +| **Thanks a lot to all Vencord [sponsors](https://github.com/sponsors/Vendicated)!!** | +|:--:| +| [![](https://meow.vendicated.dev/sponsors.png)](https://github.com/sponsors/Vendicated) | +| *generated using [github-sponsor-graph](https://github.com/Vendicated/github-sponsor-graph)* | + + +## Star History + +<a href="https://star-history.com/#Vendicated/Vencord&Timeline"> + <picture> + <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=Vendicated/Vencord&type=Timeline&theme=dark" /> + <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=Vendicated/Vencord&type=Timeline" /> + <img alt="Star History Chart" src="https://api.star-history.com/svg?repos=Vendicated/Vencord&type=Timeline" /> + </picture> +</a> ## Disclaimer diff --git a/browser/GMPolyfill.js b/browser/GMPolyfill.js index f8801551e..387389ce6 100644 --- a/browser/GMPolyfill.js +++ b/browser/GMPolyfill.js @@ -62,7 +62,7 @@ function GM_fetch(url, opt) { resp.arrayBuffer = () => blobTo("arrayBuffer", blob); resp.text = () => blobTo("text", blob); resp.json = async () => JSON.parse(await blobTo("text", blob)); - resp.headers = new Headers(parseHeaders(resp.responseHeaders)); + resp.headers = parseHeaders(resp.responseHeaders); resp.ok = resp.status >= 200 && resp.status < 300; resolve(resp); }; diff --git a/browser/VencordNativeStub.ts b/browser/VencordNativeStub.ts index 515ccc3fc..77c72369c 100644 --- a/browser/VencordNativeStub.ts +++ b/browser/VencordNativeStub.ts @@ -19,10 +19,14 @@ /// <reference path="../src/modules.d.ts" /> /// <reference path="../src/globals.d.ts" /> -import monacoHtml from "~fileContent/../src/components/monacoWin.html"; +import monacoHtmlLocal from "~fileContent/monacoWin.html"; +import monacoHtmlCdn from "~fileContent/../src/main/monacoWin.html"; import * as DataStore from "../src/api/DataStore"; import { debounce } from "../src/utils"; +import { EXTENSION_BASE_URL } from "../src/utils/web-metadata"; import { getTheme, Theme } from "../src/utils/discord"; +import { getThemeInfo } from "../src/main/themes"; +import { Settings } from "../src/Vencord"; // Discord deletes this so need to store in variable const { localStorage } = window; @@ -34,8 +38,21 @@ const NOOP_ASYNC = async () => { }; const setCssDebounced = debounce((css: string) => VencordNative.quickCss.set(css)); +const themeStore = DataStore.createStore("VencordThemes", "VencordThemeData"); + // probably should make this less cursed at some point window.VencordNative = { + themes: { + uploadTheme: (fileName: string, fileData: string) => DataStore.set(fileName, fileData, themeStore), + deleteTheme: (fileName: string) => DataStore.del(fileName, themeStore), + getThemesDir: async () => "", + getThemesList: () => DataStore.entries(themeStore).then(entries => + entries.map(([name, css]) => getThemeInfo(css, name.toString())) + ), + getThemeData: (fileName: string) => DataStore.get(fileName, themeStore), + getSystemValues: async () => ({}), + }, + native: { getVersions: () => ({}), openExternal: async (url) => void open(url, "_blank") @@ -57,6 +74,7 @@ window.VencordNative = { addChangeListener(cb) { cssListeners.add(cb); }, + addThemeChangeListener: NOOP, openFile: NOOP_ASYNC, async openEditor() { const features = `popup,width=${Math.min(window.innerWidth, 1000)},height=${Math.min(window.innerHeight, 1000)}`; @@ -66,6 +84,7 @@ window.VencordNative = { return; } + win.baseUrl = EXTENSION_BASE_URL; win.setCss = setCssDebounced; win.getCurrentCss = () => VencordNative.quickCss.get(); win.getTheme = () => @@ -73,13 +92,22 @@ window.VencordNative = { ? "vs-light" : "vs-dark"; - win.document.write(monacoHtml); + win.document.write(IS_EXTENSION ? monacoHtmlLocal : monacoHtmlCdn); }, }, settings: { - get: () => localStorage.getItem("VencordSettings") || "{}", - set: async (s: string) => localStorage.setItem("VencordSettings", s), + get: () => { + try { + return JSON.parse(localStorage.getItem("VencordSettings") || "{}"); + } catch (e) { + console.error("Failed to parse settings from localStorage: ", e); + return {}; + } + }, + set: async (s: Settings) => localStorage.setItem("VencordSettings", JSON.stringify(s)), getSettingsDir: async () => "LocalStorage" - } + }, + + pluginHelpers: {} as any, }; diff --git a/browser/content.js b/browser/content.js index e47ef8377..4810fe3c8 100644 --- a/browser/content.js +++ b/browser/content.js @@ -4,6 +4,11 @@ if (typeof browser === "undefined") { const script = document.createElement("script"); script.src = browser.runtime.getURL("dist/Vencord.js"); +script.id = "vencord-script"; +Object.assign(script.dataset, { + extensionBaseUrl: browser.runtime.getURL(""), + version: browser.runtime.getManifest().version +}); const style = document.createElement("link"); style.type = "text/css"; diff --git a/browser/manifest.json b/browser/manifest.json index cb7ecc71e..69bf0cec0 100644 --- a/browser/manifest.json +++ b/browser/manifest.json @@ -28,7 +28,7 @@ "web_accessible_resources": [ { - "resources": ["dist/Vencord.js", "dist/Vencord.css"], + "resources": ["dist/*", "third-party/*"], "matches": ["*://*.discord.com/*"] } ], @@ -41,12 +41,5 @@ "path": "modifyResponseHeaders.json" } ] - }, - - "browser_specific_settings": { - "gecko": { - "id": "vencord-firefox@vendicated.dev", - "strict_min_version": "109.0" - } } } diff --git a/browser/monaco.ts b/browser/monaco.ts new file mode 100644 index 000000000..ead061d65 --- /dev/null +++ b/browser/monaco.ts @@ -0,0 +1,43 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2023 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import "./patch-worker"; + +import * as monaco from "monaco-editor/esm/vs/editor/editor.main.js"; + +declare global { + const baseUrl: string; + const getCurrentCss: () => Promise<string>; + const setCss: (css: string) => void; + const getTheme: () => string; +} + +const BASE = "/dist/monaco/vs"; + +self.MonacoEnvironment = { + getWorkerUrl(_moduleId: unknown, label: string) { + const path = label === "css" ? "/language/css/css.worker.js" : "/editor/editor.worker.js"; + return new URL(BASE + path, baseUrl).toString(); + } +}; + +getCurrentCss().then(css => { + const editor = monaco.editor.create( + document.getElementById("container")!, + { + value: css, + language: "css", + theme: getTheme(), + } + ); + editor.onDidChangeModelContent(() => + setCss(editor.getValue()) + ); + window.addEventListener("resize", () => { + // make monaco re-layout + editor.layout(); + }); +}); diff --git a/browser/monacoWin.html b/browser/monacoWin.html new file mode 100644 index 000000000..a55b0e547 --- /dev/null +++ b/browser/monacoWin.html @@ -0,0 +1,37 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="utf-8" /> + <title>Vencord QuickCSS Editor + + + + +
+ + + + diff --git a/browser/patch-worker.js b/browser/patch-worker.js new file mode 100644 index 000000000..428ea6cc0 --- /dev/null +++ b/browser/patch-worker.js @@ -0,0 +1,135 @@ +/* +Copyright 2013 Rob Wu +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +// Target: Chrome 20+ + +// W3-compliant Worker proxy. +// This module replaces the global Worker object. +// When invoked, the default Worker object is called. +// If this call fails with SECURITY_ERR, the script is fetched +// using async XHR, and transparently proxies all calls and +// setters/getters to the new Worker object. +// Note: This script does not magically circumvent the Same origin policy. + +(function () { + 'use strict'; + var Worker_ = window.Worker; + var URL = window.URL || window.webkitURL; + // Create dummy worker for the following purposes: + // 1. Don't override the global Worker object if the fallback isn't + // going to work (future API changes?) + // 2. Use it to trigger early validation of postMessage calls + // Note: Blob constructor is supported since Chrome 20, but since + // some of the used Chrome APIs are only supported as of Chrome 20, + // I don't bother adding a BlobBuilder fallback. + var dummyWorker = new Worker_( + URL.createObjectURL(new Blob([], { type: 'text/javascript' }))); + window.Worker = function Worker(scriptURL) { + if (arguments.length === 0) { + throw new TypeError('Not enough arguments'); + } + try { + return new Worker_(scriptURL); + } catch (e) { + if (e.code === 18/*DOMException.SECURITY_ERR*/) { + return new WorkerXHR(scriptURL); + } else { + throw e; + } + } + }; + // Bind events and replay queued messages + function bindWorker(worker, workerURL) { + if (worker._terminated) { + return; + } + worker.Worker = new Worker_(workerURL); + worker.Worker.onerror = worker._onerror; + worker.Worker.onmessage = worker._onmessage; + var o; + while ((o = worker._replayQueue.shift())) { + worker.Worker[o.method].apply(worker.Worker, o.arguments); + } + while ((o = worker._messageQueue.shift())) { + worker.Worker.postMessage.apply(worker.Worker, o); + } + } + function WorkerXHR(scriptURL) { + var worker = this; + var x = new XMLHttpRequest(); + x.responseType = 'blob'; + x.onload = function () { + // http://stackoverflow.com/a/10372280/938089 + var workerURL = URL.createObjectURL(x.response); + bindWorker(worker, workerURL); + }; + x.open('GET', scriptURL); + x.send(); + worker._replayQueue = []; + worker._messageQueue = []; + } + WorkerXHR.prototype = { + constructor: Worker_, + terminate: function () { + if (!this._terminated) { + this._terminated = true; + if (this.Worker) + this.Worker.terminate(); + } + }, + postMessage: function (message, transfer) { + if (!(this instanceof WorkerXHR)) + throw new TypeError('Illegal invocation'); + if (this.Worker) { + this.Worker.postMessage.apply(this.Worker, arguments); + } else { + // Trigger validation: + dummyWorker.postMessage(message); + // Alright, push the valid message to the queue. + this._messageQueue.push(arguments); + } + } + }; + // Implement the EventTarget interface + [ + 'addEventListener', + 'removeEventListener', + 'dispatchEvent' + ].forEach(function (method) { + WorkerXHR.prototype[method] = function () { + if (!(this instanceof WorkerXHR)) { + throw new TypeError('Illegal invocation'); + } + if (this.Worker) { + this.Worker[method].apply(this.Worker, arguments); + } else { + this._replayQueue.push({ method: method, arguments: arguments }); + } + }; + }); + Object.defineProperties(WorkerXHR.prototype, { + onmessage: { + get: function () { return this._onmessage || null; }, + set: function (func) { + this._onmessage = typeof func === 'function' ? func : null; + } + }, + onerror: { + get: function () { return this._onerror || null; }, + set: function (func) { + this._onerror = typeof func === 'function' ? func : null; + } + } + }); +})(); \ No newline at end of file diff --git a/docs/1_INSTALLING.md b/docs/1_INSTALLING.md index 5bce6b79d..edeed4eb5 100644 --- a/docs/1_INSTALLING.md +++ b/docs/1_INSTALLING.md @@ -1,5 +1,6 @@ -> **Warning** +> [!WARNING] > These instructions are only for advanced users. If you're not a Developer, you should use our [graphical installer](https://github.com/Vendicated/VencordInstaller#usage) instead. +> No support will be provided for installing in this fashion. If you cannot figure it out, you should just stick to a regular install. # Installation Guide @@ -62,7 +63,7 @@ Then fully close Discord from your taskbar or task manager, and restart it. Venc If you're using Discord already, go into the `Updater` tab in settings. -Sometimes it may be neccessary to manually update if the GUI updater fails. +Sometimes it may be necessary to manually update if the GUI updater fails. To pull latest changes: @@ -94,5 +95,3 @@ Simply run: ```shell pnpm uninject ``` - -If you need more help, ask in the support channel in our [Discord Server](https://discord.gg/D9uwnFnqmd). diff --git a/package.json b/package.json index 2f9aacc47..025fa13d4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "vencord", "private": "true", - "version": "1.2.4", + "version": "1.7.3", "description": "The cutest Discord client mod", "homepage": "https://github.com/Vendicated/Vencord#readme", "bugs": { @@ -11,33 +11,38 @@ "type": "git", "url": "git+https://github.com/Vendicated/Vencord.git" }, - "license": "GPL-3.0", + "license": "GPL-3.0-or-later", "author": "Vendicated", "directories": { "doc": "docs" }, "scripts": { - "build": "node scripts/build/build.mjs", + "build": "node --require=./scripts/suppressExperimentalWarnings.js scripts/build/build.mjs", "buildWeb": "node --require=./scripts/suppressExperimentalWarnings.js scripts/build/buildWeb.mjs", "generatePluginJson": "tsx scripts/generatePluginList.ts", "inject": "node scripts/runInstaller.mjs", "lint": "eslint . --ext .js,.jsx,.ts,.tsx --ignore-pattern src/userplugins", "lint-styles": "stylelint \"src/**/*.css\" --ignore-pattern src/userplugins", "lint:fix": "pnpm lint --fix", - "test": "pnpm build && pnpm lint && pnpm lint-styles && pnpm testTsc", + "test": "pnpm build && pnpm lint && pnpm lint-styles && pnpm testTsc && pnpm generatePluginJson", "testWeb": "pnpm lint && pnpm buildWeb && pnpm testTsc", "testTsc": "tsc --noEmit", "uninject": "node scripts/runInstaller.mjs", - "watch": "node scripts/build/build.mjs --watch" + "watch": "node --require=./scripts/suppressExperimentalWarnings.js scripts/build/build.mjs --watch" }, "dependencies": { + "@sapphi-red/web-noise-suppressor": "0.3.3", "@vap/core": "0.0.12", "@vap/shiki": "0.10.5", + "eslint-plugin-simple-header": "^1.0.2", "fflate": "^0.7.4", + "gifenc": "github:mattdesl/gifenc#64842fca317b112a8590f8fef2bf3825da8f6fe3", + "monaco-editor": "^0.43.0", "nanoid": "^4.0.2", "virtual-merge": "^1.0.1" }, "devDependencies": { + "@types/chrome": "^0.0.246", "@types/diff": "^5.0.3", "@types/lodash": "^4.14.194", "@types/node": "^18.16.3", @@ -49,9 +54,8 @@ "diff": "^5.1.0", "discord-types": "^1.3.26", "esbuild": "^0.15.18", - "eslint": "^8.28.0", + "eslint": "^8.46.0", "eslint-import-resolver-alias": "^1.1.2", - "eslint-plugin-header": "^3.1.1", "eslint-plugin-path-alias": "^1.0.0", "eslint-plugin-simple-import-sort": "^10.0.0", "eslint-plugin-unused-imports": "^2.0.0", @@ -63,13 +67,15 @@ "stylelint-config-standard": "^33.0.0", "tsx": "^3.12.7", "type-fest": "^3.9.0", - "typescript": "^5.0.4" + "typescript": "^5.0.4", + "zip-local": "^0.3.5", + "zustand": "^3.7.2" }, - "packageManager": "pnpm@8.1.1", + "packageManager": "pnpm@8.10.2", "pnpm": { "patchedDependencies": { "eslint-plugin-path-alias@1.0.0": "patches/eslint-plugin-path-alias@1.0.0.patch", - "eslint@8.28.0": "patches/eslint@8.28.0.patch" + "eslint@8.46.0": "patches/eslint@8.46.0.patch" }, "peerDependencyRules": { "ignoreMissing": [ @@ -89,7 +95,7 @@ "build": { "overwriteDest": true }, - "sourceDir": "./dist/extension-v2-unpacked" + "sourceDir": "./dist/firefox-unpacked" }, "engines": { "node": ">=18", diff --git a/patches/eslint@8.28.0.patch b/patches/eslint@8.46.0.patch similarity index 50% rename from patches/eslint@8.28.0.patch rename to patches/eslint@8.46.0.patch index 994481b91..c91e45d56 100644 --- a/patches/eslint@8.28.0.patch +++ b/patches/eslint@8.46.0.patch @@ -1,11 +1,11 @@ diff --git a/lib/rules/no-useless-escape.js b/lib/rules/no-useless-escape.js -index 2046a148a17fd1d5f3a4bbc9f45f7700259d11fa..f4898c6b57355a4fd72c43a9f32bf1a36a6ccf4a 100644 +index 0e0f6f09f2c35f3276173c08f832cde9f2cf56a0..7dc22851715f3574d935f513c1b5e35552985711 100644 --- a/lib/rules/no-useless-escape.js +++ b/lib/rules/no-useless-escape.js -@@ -97,12 +97,30 @@ module.exports = { +@@ -65,13 +65,31 @@ module.exports = { escapeBackslash: "Replace the `\\` with `\\\\` to include the actual backslash character." }, - + - schema: [] + schema: [{ + type: "object", @@ -22,24 +22,28 @@ index 2046a148a17fd1d5f3a4bbc9f45f7700259d11fa..f4898c6b57355a4fd72c43a9f32bf1a3 + additionalProperties: false + }] }, - + create(context) { + const options = context.options[0] || {}; -+ const { extra, extraCharClass } = options || '' - const sourceCode = context.getSourceCode(); - -+ const NON_CHARCLASS_ESCAPES = union(REGEX_NON_CHARCLASS_ESCAPES, new Set(extra)) -+ const CHARCLASS_ESCAPES = union(REGEX_GENERAL_ESCAPES, new Set(extraCharClass)) ++ const { extra, extraCharClass } = options; + const sourceCode = context.sourceCode; + const parser = new RegExpParser(); + ++ const NON_CHARCLASS_ESCAPES = union(REGEX_NON_CHARCLASS_ESCAPES, new Set(extra)); ++ const CHARCLASS_ESCAPES = union(REGEX_GENERAL_ESCAPES, new Set(extraCharClass)); + /** * Reports a node * @param {ASTNode} node The node to report -@@ -238,7 +256,7 @@ module.exports = { - .filter(charInfo => charInfo.escaped) - - // Filter out characters that are valid to escape, based on their position in the regular expression. -- .filter(charInfo => !(charInfo.inCharClass ? REGEX_GENERAL_ESCAPES : REGEX_NON_CHARCLASS_ESCAPES).has(charInfo.text)) -+ .filter(charInfo => !(charInfo.inCharClass ? CHARCLASS_ESCAPES : NON_CHARCLASS_ESCAPES).has(charInfo.text)) - - // Report all the remaining characters. - .forEach(charInfo => report(node, charInfo.index, charInfo.text)); \ No newline at end of file +@@ -200,9 +218,9 @@ module.exports = { + let allowedEscapes; + + if (characterClassStack.length) { +- allowedEscapes = unicodeSets ? REGEX_CLASSSET_CHARACTER_ESCAPES : REGEX_GENERAL_ESCAPES; ++ allowedEscapes = unicodeSets ? REGEX_CLASSSET_CHARACTER_ESCAPES : CHARCLASS_ESCAPES; + } else { +- allowedEscapes = REGEX_NON_CHARCLASS_ESCAPES; ++ allowedEscapes = NON_CHARCLASS_ESCAPES; + } + if (allowedEscapes.has(escapedChar)) { + return; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c43737109..43866f50b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,20 +4,32 @@ patchedDependencies: eslint-plugin-path-alias@1.0.0: hash: m6sma4g6bh67km3q6igf6uxaja path: patches/eslint-plugin-path-alias@1.0.0.patch - eslint@8.28.0: - hash: 7wc6icvgtg3uswirb5tpsbjnbe - path: patches/eslint@8.28.0.patch + eslint@8.46.0: + hash: xm46kqcmdgzlmm4aifkfpxaho4 + path: patches/eslint@8.46.0.patch dependencies: + '@sapphi-red/web-noise-suppressor': + specifier: 0.3.3 + version: 0.3.3 '@vap/core': specifier: 0.0.12 version: 0.0.12 '@vap/shiki': specifier: 0.10.5 version: 0.10.5 + eslint-plugin-simple-header: + specifier: ^1.0.2 + version: 1.0.2 fflate: specifier: ^0.7.4 version: 0.7.4 + gifenc: + specifier: github:mattdesl/gifenc#64842fca317b112a8590f8fef2bf3825da8f6fe3 + version: github.com/mattdesl/gifenc/64842fca317b112a8590f8fef2bf3825da8f6fe3 + monaco-editor: + specifier: ^0.43.0 + version: 0.43.0 nanoid: specifier: ^4.0.2 version: 4.0.2 @@ -26,6 +38,9 @@ dependencies: version: 1.0.1 devDependencies: + '@types/chrome': + specifier: ^0.0.246 + version: 0.0.246 '@types/diff': specifier: ^5.0.3 version: 5.0.3 @@ -46,10 +61,10 @@ devDependencies: version: 2.4.2 '@typescript-eslint/eslint-plugin': specifier: ^5.59.1 - version: 5.59.1(@typescript-eslint/parser@5.59.1)(eslint@8.28.0)(typescript@5.0.4) + version: 5.59.1(@typescript-eslint/parser@5.59.1)(eslint@8.46.0)(typescript@5.0.4) '@typescript-eslint/parser': specifier: ^5.59.1 - version: 5.59.1(eslint@8.28.0)(typescript@5.0.4) + version: 5.59.1(eslint@8.46.0)(typescript@5.0.4) diff: specifier: ^5.1.0 version: 5.1.0 @@ -60,23 +75,20 @@ devDependencies: specifier: ^0.15.18 version: 0.15.18 eslint: - specifier: ^8.28.0 - version: 8.28.0(patch_hash=7wc6icvgtg3uswirb5tpsbjnbe) + specifier: ^8.46.0 + version: 8.46.0(patch_hash=xm46kqcmdgzlmm4aifkfpxaho4) eslint-import-resolver-alias: specifier: ^1.1.2 version: 1.1.2 - eslint-plugin-header: - specifier: ^3.1.1 - version: 3.1.1(eslint@8.28.0) eslint-plugin-path-alias: specifier: ^1.0.0 - version: 1.0.0(patch_hash=m6sma4g6bh67km3q6igf6uxaja)(eslint@8.28.0) + version: 1.0.0(patch_hash=m6sma4g6bh67km3q6igf6uxaja)(eslint@8.46.0) eslint-plugin-simple-import-sort: specifier: ^10.0.0 - version: 10.0.0(eslint@8.28.0) + version: 10.0.0(eslint@8.46.0) eslint-plugin-unused-imports: specifier: ^2.0.0 - version: 2.0.0(@typescript-eslint/eslint-plugin@5.59.1)(eslint@8.28.0) + version: 2.0.0(@typescript-eslint/eslint-plugin@5.59.1)(eslint@8.46.0) highlight.js: specifier: 10.6.0 version: 10.6.0 @@ -104,9 +116,20 @@ devDependencies: typescript: specifier: ^5.0.4 version: 5.0.4 + zip-local: + specifier: ^0.3.5 + version: 0.3.5 + zustand: + specifier: ^3.7.2 + version: 3.7.2 packages: + /@aashutoshrathi/word-wrap@1.2.6: + resolution: {integrity: sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA==} + engines: {node: '>=0.10.0'} + dev: true + /@babel/code-frame@7.21.4: resolution: {integrity: sha512-LYvhNKfwWSPpocw8GI7gpK2nq3HSDuEPC/uSYaALSJu9xjsalaaYFOq0Pwt5KmVqwEbZlDu81aLXwBOmD/Fv9g==} engines: {node: '>=6.9.0'} @@ -399,7 +422,7 @@ packages: dev: true optional: true - /@eslint-community/eslint-utils@4.4.0(eslint@8.28.0): + /@eslint-community/eslint-utils@4.4.0(eslint@8.46.0): resolution: {integrity: sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -408,8 +431,8 @@ packages: eslint: optional: true dependencies: - eslint: 8.28.0(patch_hash=7wc6icvgtg3uswirb5tpsbjnbe) - eslint-visitor-keys: 3.4.0 + eslint: 8.46.0(patch_hash=xm46kqcmdgzlmm4aifkfpxaho4) + eslint-visitor-keys: 3.4.2 dev: true /@eslint-community/regexpp@4.5.1: @@ -417,15 +440,20 @@ packages: engines: {node: ^12.0.0 || ^14.0.0 || >=16.0.0} dev: true - /@eslint/eslintrc@1.3.3: - resolution: {integrity: sha512-uj3pT6Mg+3t39fvLrj8iuCIJ38zKO9FpGtJ4BBJebJhEwjoT+KLVNCcHT5QC9NGRIEi7fZ0ZR8YRb884auB4Lg==} + /@eslint-community/regexpp@4.6.2: + resolution: {integrity: sha512-pPTNuaAG3QMH+buKyBIGJs3g/S5y0caxw0ygM3YyE6yJFySwiGGSzA+mM3KJ8QQvzeLh3blwgSonkFjgQdxzMw==} + engines: {node: ^12.0.0 || ^14.0.0 || >=16.0.0} + dev: true + + /@eslint/eslintrc@2.1.1: + resolution: {integrity: sha512-9t7ZA7NGGK8ckelF0PQCfcxIUzs1Md5rrO6U/c+FIQNanea5UZC0wqKXH4vHBccmu4ZJgZ2idtPeW7+Q2npOEA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: ajv: 6.12.6 debug: 4.3.4 - espree: 9.4.1 - globals: 13.17.0 - ignore: 5.2.0 + espree: 9.6.1 + globals: 13.20.0 + ignore: 5.2.4 import-fresh: 3.3.0 js-yaml: 4.1.0 minimatch: 3.1.2 @@ -434,8 +462,13 @@ packages: - supports-color dev: true - /@humanwhocodes/config-array@0.11.7: - resolution: {integrity: sha512-kBbPWzN8oVMLb0hOUYXhmxggL/1cJE6ydvjDIGi9EnAGUyA7cLVKQg+d/Dsm+KZwx2czGHrCmMVLiyg8s5JPKw==} + /@eslint/js@8.46.0: + resolution: {integrity: sha512-a8TLtmPi8xzPkCbp/OGFUo5yhRkHM2Ko9kOWP4znJr0WAhWyThaw3PnwX4vOTWOAMsV2uRt32PPDcEz63esSaA==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + dev: true + + /@humanwhocodes/config-array@0.11.10: + resolution: {integrity: sha512-KVVjQmNUepDVGXNuoRRdmmEjruj0KfiGSbS8LVc12LMsWDQzRXJ0qdhN8L8uUigKpfEHRhlaQFY0ib1tnUbNeQ==} engines: {node: '>=10.10.0'} dependencies: '@humanwhocodes/object-schema': 1.2.1 @@ -498,10 +531,35 @@ packages: - supports-color dev: true + /@sapphi-red/web-noise-suppressor@0.3.3: + resolution: {integrity: sha512-gAC33DCXYwNTI/k1PxOVHmbbzakUSMbb/DHpoV6rn4pKZtPI1dduULSmAAm/y1ipgIlArnk2JcnQzw4n2tCZHw==} + dev: false + + /@types/chrome@0.0.246: + resolution: {integrity: sha512-MxGxEomGxsJiL9xe/7ZwVgwdn8XVKWbPvxpVQl3nWOjrS0Ce63JsfzxUc4aU3GvRcUPYsfufHmJ17BFyKxeA4g==} + dependencies: + '@types/filesystem': 0.0.33 + '@types/har-format': 1.2.13 + dev: true + /@types/diff@5.0.3: resolution: {integrity: sha512-amrLbRqTU9bXMCc6uX0sWpxsQzRIo9z6MJPkH1pkez/qOxuqSZVuryJAWoBRq94CeG8JxY+VK4Le9HtjQR5T9A==} dev: true + /@types/filesystem@0.0.33: + resolution: {integrity: sha512-2KedRPzwu2K528vFkoXnnWdsG0MtUwPjuA7pRy4vKxlxHEe8qUDZibYHXJKZZr2Cl/ELdCWYqyb/MKwsUuzBWw==} + dependencies: + '@types/filewriter': 0.0.30 + dev: true + + /@types/filewriter@0.0.30: + resolution: {integrity: sha512-lB98tui0uxc7erbj0serZfJlHKLNJHwBltPnbmO1WRpL5T325GOHRiQfr2E29V2q+S1brDO63Fpdt6vb3bES9Q==} + dev: true + + /@types/har-format@1.2.13: + resolution: {integrity: sha512-PwBsCBD3lDODn4xpje3Y1di0aDJp4Ww7aSfMRVw6ysnxD4I7Wmq2mBkSKaDtN403hqH5sp6c9xQUvFYY3+lkBg==} + dev: true + /@types/json-schema@7.0.11: resolution: {integrity: sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==} dev: true @@ -569,7 +627,7 @@ packages: '@types/node': 18.16.3 dev: true - /@typescript-eslint/eslint-plugin@5.59.1(@typescript-eslint/parser@5.59.1)(eslint@8.28.0)(typescript@5.0.4): + /@typescript-eslint/eslint-plugin@5.59.1(@typescript-eslint/parser@5.59.1)(eslint@8.46.0)(typescript@5.0.4): resolution: {integrity: sha512-AVi0uazY5quFB9hlp2Xv+ogpfpk77xzsgsIEWyVS7uK/c7MZ5tw7ZPbapa0SbfkqE0fsAMkz5UwtgMLVk2BQAg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -583,12 +641,12 @@ packages: optional: true dependencies: '@eslint-community/regexpp': 4.5.1 - '@typescript-eslint/parser': 5.59.1(eslint@8.28.0)(typescript@5.0.4) + '@typescript-eslint/parser': 5.59.1(eslint@8.46.0)(typescript@5.0.4) '@typescript-eslint/scope-manager': 5.59.1 - '@typescript-eslint/type-utils': 5.59.1(eslint@8.28.0)(typescript@5.0.4) - '@typescript-eslint/utils': 5.59.1(eslint@8.28.0)(typescript@5.0.4) + '@typescript-eslint/type-utils': 5.59.1(eslint@8.46.0)(typescript@5.0.4) + '@typescript-eslint/utils': 5.59.1(eslint@8.46.0)(typescript@5.0.4) debug: 4.3.4 - eslint: 8.28.0(patch_hash=7wc6icvgtg3uswirb5tpsbjnbe) + eslint: 8.46.0(patch_hash=xm46kqcmdgzlmm4aifkfpxaho4) grapheme-splitter: 1.0.4 ignore: 5.2.4 natural-compare-lite: 1.4.0 @@ -599,7 +657,7 @@ packages: - supports-color dev: true - /@typescript-eslint/parser@5.59.1(eslint@8.28.0)(typescript@5.0.4): + /@typescript-eslint/parser@5.59.1(eslint@8.46.0)(typescript@5.0.4): resolution: {integrity: sha512-nzjFAN8WEu6yPRDizIFyzAfgK7nybPodMNFGNH0M9tei2gYnYszRDqVA0xlnRjkl7Hkx2vYrEdb6fP2a21cG1g==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -615,7 +673,7 @@ packages: '@typescript-eslint/types': 5.59.1 '@typescript-eslint/typescript-estree': 5.59.1(typescript@5.0.4) debug: 4.3.4 - eslint: 8.28.0(patch_hash=7wc6icvgtg3uswirb5tpsbjnbe) + eslint: 8.46.0(patch_hash=xm46kqcmdgzlmm4aifkfpxaho4) typescript: 5.0.4 transitivePeerDependencies: - supports-color @@ -629,7 +687,7 @@ packages: '@typescript-eslint/visitor-keys': 5.59.1 dev: true - /@typescript-eslint/type-utils@5.59.1(eslint@8.28.0)(typescript@5.0.4): + /@typescript-eslint/type-utils@5.59.1(eslint@8.46.0)(typescript@5.0.4): resolution: {integrity: sha512-ZMWQ+Oh82jWqWzvM3xU+9y5U7MEMVv6GLioM3R5NJk6uvP47kZ7YvlgSHJ7ERD6bOY7Q4uxWm25c76HKEwIjZw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -642,9 +700,9 @@ packages: optional: true dependencies: '@typescript-eslint/typescript-estree': 5.59.1(typescript@5.0.4) - '@typescript-eslint/utils': 5.59.1(eslint@8.28.0)(typescript@5.0.4) + '@typescript-eslint/utils': 5.59.1(eslint@8.46.0)(typescript@5.0.4) debug: 4.3.4 - eslint: 8.28.0(patch_hash=7wc6icvgtg3uswirb5tpsbjnbe) + eslint: 8.46.0(patch_hash=xm46kqcmdgzlmm4aifkfpxaho4) tsutils: 3.21.0(typescript@5.0.4) typescript: 5.0.4 transitivePeerDependencies: @@ -677,7 +735,7 @@ packages: - supports-color dev: true - /@typescript-eslint/utils@5.59.1(eslint@8.28.0)(typescript@5.0.4): + /@typescript-eslint/utils@5.59.1(eslint@8.46.0)(typescript@5.0.4): resolution: {integrity: sha512-MkTe7FE+K1/GxZkP5gRj3rCztg45bEhsd8HYjczBuYm+qFHP5vtZmjx3B0yUCDotceQ4sHgTyz60Ycl225njmA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -686,13 +744,13 @@ packages: eslint: optional: true dependencies: - '@eslint-community/eslint-utils': 4.4.0(eslint@8.28.0) + '@eslint-community/eslint-utils': 4.4.0(eslint@8.46.0) '@types/json-schema': 7.0.11 '@types/semver': 7.3.13 '@typescript-eslint/scope-manager': 5.59.1 '@typescript-eslint/types': 5.59.1 '@typescript-eslint/typescript-estree': 5.59.1(typescript@5.0.4) - eslint: 8.28.0(patch_hash=7wc6icvgtg3uswirb5tpsbjnbe) + eslint: 8.46.0(patch_hash=xm46kqcmdgzlmm4aifkfpxaho4) eslint-scope: 5.1.1 semver: 7.5.0 transitivePeerDependencies: @@ -722,16 +780,16 @@ packages: vscode-textmate: 5.2.0 dev: false - /acorn-jsx@5.3.2(acorn@8.8.0): + /acorn-jsx@5.3.2(acorn@8.10.0): resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==} peerDependencies: acorn: ^6.0.0 || ^7.0.0 || ^8.0.0 dependencies: - acorn: 8.8.0 + acorn: 8.10.0 dev: true - /acorn@8.8.0: - resolution: {integrity: sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w==} + /acorn@8.10.0: + resolution: {integrity: sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==} engines: {node: '>=0.4.0'} hasBin: true dev: true @@ -821,6 +879,10 @@ packages: engines: {node: '>=8'} dev: true + /async@1.5.2: + resolution: {integrity: sha512-nSVgobk4rv61R9PUSDtYt7mPVB2olxNR5RWJcAsH676/ef11bUZwvu7+RGYrYauVdDPcO519v68wRhXQtxsV9w==} + dev: true + /atob@2.1.2: resolution: {integrity: sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==} engines: {node: '>= 4.5.0'} @@ -1446,18 +1508,7 @@ packages: optional: true dev: true - /eslint-plugin-header@3.1.1(eslint@8.28.0): - resolution: {integrity: sha512-9vlKxuJ4qf793CmeeSrZUvVClw6amtpghq3CuWcB5cUNnWHQhgcqy5eF8oVKFk1G3Y/CbchGfEaw3wiIJaNmVg==} - peerDependencies: - eslint: '>=7.7.0' - peerDependenciesMeta: - eslint: - optional: true - dependencies: - eslint: 8.28.0(patch_hash=7wc6icvgtg3uswirb5tpsbjnbe) - dev: true - - /eslint-plugin-path-alias@1.0.0(patch_hash=m6sma4g6bh67km3q6igf6uxaja)(eslint@8.28.0): + /eslint-plugin-path-alias@1.0.0(patch_hash=m6sma4g6bh67km3q6igf6uxaja)(eslint@8.46.0): resolution: {integrity: sha512-FXus57yC+Zd3sMv46pbloXYwFeNVNHJqlACr9V68FG/IzGFBBokGJpmjDbEjpt8ZCeVSndUubeDWWl2A8sCNVQ==} peerDependencies: eslint: ^7 @@ -1465,14 +1516,18 @@ packages: eslint: optional: true dependencies: - eslint: 8.28.0(patch_hash=7wc6icvgtg3uswirb5tpsbjnbe) + eslint: 8.46.0(patch_hash=xm46kqcmdgzlmm4aifkfpxaho4) nanomatch: 1.2.13 transitivePeerDependencies: - supports-color dev: true patched: true - /eslint-plugin-simple-import-sort@10.0.0(eslint@8.28.0): + /eslint-plugin-simple-header@1.0.2: + resolution: {integrity: sha512-K1EJ/ueBIjPRA8qR44Ymo+GDmPYYmfoODtainGxVr7PSbX6QiaY+pTuGCrOhO+AtVsYJs8GLSVdGUTXyAxAtOA==} + dev: false + + /eslint-plugin-simple-import-sort@10.0.0(eslint@8.46.0): resolution: {integrity: sha512-AeTvO9UCMSNzIHRkg8S6c3RPy5YEwKWSQPx3DYghLedo2ZQxowPFLGDN1AZ2evfg6r6mjBSZSLxLFsWSu3acsw==} peerDependencies: eslint: '>=5.0.0' @@ -1480,10 +1535,10 @@ packages: eslint: optional: true dependencies: - eslint: 8.28.0(patch_hash=7wc6icvgtg3uswirb5tpsbjnbe) + eslint: 8.46.0(patch_hash=xm46kqcmdgzlmm4aifkfpxaho4) dev: true - /eslint-plugin-unused-imports@2.0.0(@typescript-eslint/eslint-plugin@5.59.1)(eslint@8.28.0): + /eslint-plugin-unused-imports@2.0.0(@typescript-eslint/eslint-plugin@5.59.1)(eslint@8.46.0): resolution: {integrity: sha512-3APeS/tQlTrFa167ThtP0Zm0vctjr4M44HMpeg1P4bK6wItarumq0Ma82xorMKdFsWpphQBlRPzw/pxiVELX1A==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -1495,8 +1550,8 @@ packages: eslint: optional: true dependencies: - '@typescript-eslint/eslint-plugin': 5.59.1(@typescript-eslint/parser@5.59.1)(eslint@8.28.0)(typescript@5.0.4) - eslint: 8.28.0(patch_hash=7wc6icvgtg3uswirb5tpsbjnbe) + '@typescript-eslint/eslint-plugin': 5.59.1(@typescript-eslint/parser@5.59.1)(eslint@8.46.0)(typescript@5.0.4) + eslint: 8.46.0(patch_hash=xm46kqcmdgzlmm4aifkfpxaho4) eslint-rule-composer: 0.3.0 dev: true @@ -1513,49 +1568,34 @@ packages: estraverse: 4.3.0 dev: true - /eslint-scope@7.1.1: - resolution: {integrity: sha512-QKQM/UXpIiHcLqJ5AOyIW7XZmzjkzQXYE54n1++wb0u9V/abW3l9uQnxX8Z5Xd18xyKIMTUAyQ0k1e8pz6LUrw==} + /eslint-scope@7.2.2: + resolution: {integrity: sha512-dOt21O7lTMhDM+X9mB4GX+DZrZtCUJPL/wlcTqxyrx5IvO0IYtILdtrQGQp+8n5S0gwSVmOf9NQrjMOgfQZlIg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: esrecurse: 4.3.0 estraverse: 5.3.0 dev: true - /eslint-utils@3.0.0(eslint@8.28.0): - resolution: {integrity: sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==} - engines: {node: ^10.0.0 || ^12.0.0 || >= 14.0.0} - peerDependencies: - eslint: '>=5' - peerDependenciesMeta: - eslint: - optional: true - dependencies: - eslint: 8.28.0(patch_hash=7wc6icvgtg3uswirb5tpsbjnbe) - eslint-visitor-keys: 2.1.0 - dev: true - - /eslint-visitor-keys@2.1.0: - resolution: {integrity: sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==} - engines: {node: '>=10'} - dev: true - - /eslint-visitor-keys@3.3.0: - resolution: {integrity: sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==} - engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} - dev: true - /eslint-visitor-keys@3.4.0: resolution: {integrity: sha512-HPpKPUBQcAsZOsHAFwTtIKcYlCje62XB7SEAcxjtmW6TD1WVpkS6i6/hOVtTZIl4zGj/mBqpFVGvaDneik+VoQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dev: true - /eslint@8.28.0(patch_hash=7wc6icvgtg3uswirb5tpsbjnbe): - resolution: {integrity: sha512-S27Di+EVyMxcHiwDrFzk8dJYAaD+/5SoWKxL1ri/71CRHsnJnRDPNt2Kzj24+MT9FDupf4aqqyqPrvI8MvQ4VQ==} + /eslint-visitor-keys@3.4.2: + resolution: {integrity: sha512-8drBzUEyZ2llkpCA67iYrgEssKDUu68V8ChqqOfFupIaG/LCVPUT+CoGJpT77zJprs4T/W7p07LP7zAIMuweVw==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + dev: true + + /eslint@8.46.0(patch_hash=xm46kqcmdgzlmm4aifkfpxaho4): + resolution: {integrity: sha512-cIO74PvbW0qU8e0mIvk5IV3ToWdCq5FYG6gWPHHkx6gNdjlbAYvtfHmlCMXxjcoVaIdwy/IAt3+mDkZkfvb2Dg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} hasBin: true dependencies: - '@eslint/eslintrc': 1.3.3 - '@humanwhocodes/config-array': 0.11.7 + '@eslint-community/eslint-utils': 4.4.0(eslint@8.46.0) + '@eslint-community/regexpp': 4.6.2 + '@eslint/eslintrc': 2.1.1 + '@eslint/js': 8.46.0 + '@humanwhocodes/config-array': 0.11.10 '@humanwhocodes/module-importer': 1.0.1 '@nodelib/fs.walk': 1.2.8 ajv: 6.12.6 @@ -1564,60 +1604,46 @@ packages: debug: 4.3.4 doctrine: 3.0.0 escape-string-regexp: 4.0.0 - eslint-scope: 7.1.1 - eslint-utils: 3.0.0(eslint@8.28.0) - eslint-visitor-keys: 3.3.0 - espree: 9.4.0 - esquery: 1.4.0 + eslint-scope: 7.2.2 + eslint-visitor-keys: 3.4.2 + espree: 9.6.1 + esquery: 1.5.0 esutils: 2.0.3 fast-deep-equal: 3.1.3 file-entry-cache: 6.0.1 find-up: 5.0.0 glob-parent: 6.0.2 - globals: 13.17.0 - grapheme-splitter: 1.0.4 - ignore: 5.2.0 - import-fresh: 3.3.0 + globals: 13.20.0 + graphemer: 1.4.0 + ignore: 5.2.4 imurmurhash: 0.1.4 is-glob: 4.0.3 is-path-inside: 3.0.3 - js-sdsl: 4.1.5 js-yaml: 4.1.0 json-stable-stringify-without-jsonify: 1.0.1 levn: 0.4.1 lodash.merge: 4.6.2 minimatch: 3.1.2 natural-compare: 1.4.0 - optionator: 0.9.1 - regexpp: 3.2.0 + optionator: 0.9.3 strip-ansi: 6.0.1 - strip-json-comments: 3.1.1 text-table: 0.2.0 transitivePeerDependencies: - supports-color dev: true patched: true - /espree@9.4.0: - resolution: {integrity: sha512-DQmnRpLj7f6TgN/NYb0MTzJXL+vJF9h3pHy4JhCIs3zwcgez8xmGg3sXHcEO97BrmO2OSvCwMdfdlyl+E9KjOw==} + /espree@9.6.1: + resolution: {integrity: sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: - acorn: 8.8.0 - acorn-jsx: 5.3.2(acorn@8.8.0) - eslint-visitor-keys: 3.3.0 + acorn: 8.10.0 + acorn-jsx: 5.3.2(acorn@8.10.0) + eslint-visitor-keys: 3.4.2 dev: true - /espree@9.4.1: - resolution: {integrity: sha512-XwctdmTO6SIvCzd9810yyNzIrOrqNYV9Koizx4C/mRhf9uq0o4yHoCEU/670pOxOL/MSraektvSAji79kX90Vg==} - engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} - dependencies: - acorn: 8.8.0 - acorn-jsx: 5.3.2(acorn@8.8.0) - eslint-visitor-keys: 3.3.0 - dev: true - - /esquery@1.4.0: - resolution: {integrity: sha512-cCDispWt5vHHtwMY2YrAQ4ibFkAL8RbH5YGBnZBc90MolvvfkkQcJro/aZiAQUlQ3qgrYS6D6v8Gc5G5CQsc9w==} + /esquery@1.5.0: + resolution: {integrity: sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg==} engines: {node: '>=0.10'} dependencies: estraverse: 5.3.0 @@ -1858,8 +1884,8 @@ packages: which: 1.3.1 dev: true - /globals@13.17.0: - resolution: {integrity: sha512-1C+6nQRb1GwGMKm2dH/E7enFAMxGTmGI7/dEdhy/DNelv85w9B72t3uc5frtMNXIbzrarJJ/lTCjcaZwbLJmyw==} + /globals@13.20.0: + resolution: {integrity: sha512-Qg5QtVkCy/kv3FUSlu4ukeZDVf9ee0iXLAUYX13gbR17bnejFTzr4iS9bY7kwCf1NztRNm1t91fjOiyx4CSwPQ==} engines: {node: '>=8'} dependencies: type-fest: 0.20.2 @@ -1881,10 +1907,18 @@ packages: resolution: {integrity: sha512-xYfnw62CKG8nLkZBfWbhWwDw02CHty86jfPcc2cr3ZfeuK9ysoVPPEUxf21bAD/rWAgk52SuBrLJlefNy8mvFg==} dev: true + /graceful-fs@4.2.11: + resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==} + dev: true + /grapheme-splitter@1.0.4: resolution: {integrity: sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==} dev: true + /graphemer@1.4.0: + resolution: {integrity: sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==} + dev: true + /hard-rejection@2.1.0: resolution: {integrity: sha512-VIZB+ibDhx7ObhAe7OVtoEbuP4h/MuOTHJ+J8h/eBXotJYl0fBgR72xDFCKgIh22OJZIOVNxBMWuhAr10r8HdA==} engines: {node: '>=6'} @@ -1972,11 +2006,6 @@ packages: resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==} dev: true - /ignore@5.2.0: - resolution: {integrity: sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==} - engines: {node: '>= 4'} - dev: true - /ignore@5.2.4: resolution: {integrity: sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==} engines: {node: '>= 4'} @@ -2168,10 +2197,6 @@ packages: engines: {node: '>=0.10.0'} dev: true - /js-sdsl@4.1.5: - resolution: {integrity: sha512-08bOAKweV2NUC1wqTtf3qZlnpOX/R2DU9ikpjOHs0H+ibQv3zpncVQg6um4uYtRtrwIX8M4Nh3ytK4HGlYAq7Q==} - dev: true - /js-tokens@4.0.0: resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} dev: true @@ -2203,6 +2228,12 @@ packages: resolution: {integrity: sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w==} dev: false + /jszip@2.7.0: + resolution: {integrity: sha512-JIsRKRVC3gTRo2vM4Wy9WBC3TRcfnIZU8k65Phi3izkvPH975FowRYtKGT6PxevA0XnJ/yO8b0QwV0ydVyQwfw==} + dependencies: + pako: 1.0.11 + dev: true + /kind-of@3.2.2: resolution: {integrity: sha512-NOW9QQXMoZGg/oqnVNoNTTIFEIid1627WCffUBJEdMxYApq7mNE7CpzucIPc+ZQg25Phej7IJSmX3hO+oblOtQ==} engines: {node: '>=0.10.0'} @@ -2373,6 +2404,10 @@ packages: resolution: {integrity: sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==} dev: true + /monaco-editor@0.43.0: + resolution: {integrity: sha512-cnoqwQi/9fml2Szamv1XbSJieGJ1Dc8tENVMD26Kcfl7xGQWp7OBKMjlwKVGYFJ3/AXJjSOGvcqK7Ry/j9BM1Q==} + dev: false + /ms@2.0.0: resolution: {integrity: sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==} dev: true @@ -2485,16 +2520,16 @@ packages: wrappy: 1.0.2 dev: true - /optionator@0.9.1: - resolution: {integrity: sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw==} + /optionator@0.9.3: + resolution: {integrity: sha512-JjCoypp+jKn1ttEFExxhetCKeJt9zhAgAve5FXHixTvFDW/5aEktX9bufBKLRRMdU7bNtpLfcGu94B3cdEJgjg==} engines: {node: '>= 0.8.0'} dependencies: + '@aashutoshrathi/word-wrap': 1.2.6 deep-is: 0.1.4 fast-levenshtein: 2.0.6 levn: 0.4.1 prelude-ls: 1.2.1 type-check: 0.4.0 - word-wrap: 1.2.3 dev: true /p-limit@2.3.0: @@ -2530,6 +2565,10 @@ packages: engines: {node: '>=6'} dev: true + /pako@1.0.11: + resolution: {integrity: sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==} + dev: true + /parent-module@1.0.1: resolution: {integrity: sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==} engines: {node: '>=6'} @@ -2681,6 +2720,11 @@ packages: - utf-8-validate dev: true + /q@1.5.1: + resolution: {integrity: sha512-kV/CThkXo6xyFEZUugw/+pIOywXcDbFYgSct5cT3gqlbkBE1SJdwy6UQoZvodiWF/ckQLZyDE/Bu1M6gVu5lVw==} + engines: {node: '>=0.6.0', teleport: '>=0.2.0'} + dev: true + /queue-microtask@1.2.3: resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} dev: true @@ -2734,11 +2778,6 @@ packages: safe-regex: 1.1.0 dev: true - /regexpp@3.2.0: - resolution: {integrity: sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg==} - engines: {node: '>=8'} - dev: true - /require-directory@2.1.1: resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==} engines: {node: '>=0.10.0'} @@ -3323,11 +3362,6 @@ packages: isexe: 2.0.0 dev: true - /word-wrap@1.2.3: - resolution: {integrity: sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==} - engines: {node: '>=0.10.0'} - dev: true - /wrap-ansi@7.0.0: resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==} engines: {node: '>=10'} @@ -3405,3 +3439,32 @@ packages: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} engines: {node: '>=10'} dev: true + + /zip-local@0.3.5: + resolution: {integrity: sha512-GRV3D5TJY+/PqyeRm5CYBs7xVrKTKzljBoEXvocZu0HJ7tPEcgpSOYa2zFIsCZWgKWMuc4U3yMFgFkERGFIB9w==} + dependencies: + async: 1.5.2 + graceful-fs: 4.2.11 + jszip: 2.7.0 + q: 1.5.1 + dev: true + + /zustand@3.7.2: + resolution: {integrity: sha512-PIJDIZKtokhof+9+60cpockVOq05sJzHCriyvaLBmEJixseQ1a5Kdov6fWZfWOu5SK9c+FhH1jU0tntLxRJYMA==} + engines: {node: '>=12.7.0'} + peerDependencies: + react: '>=16.8' + peerDependenciesMeta: + react: + optional: true + dev: true + + github.com/mattdesl/gifenc/64842fca317b112a8590f8fef2bf3825da8f6fe3: + resolution: {tarball: https://codeload.github.com/mattdesl/gifenc/tar.gz/64842fca317b112a8590f8fef2bf3825da8f6fe3} + name: gifenc + version: 1.0.3 + dev: false + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false diff --git a/scripts/build/build.mjs b/scripts/build/build.mjs index 45cda74ad..0c2a930a0 100755 --- a/scripts/build/build.mjs +++ b/scripts/build/build.mjs @@ -18,12 +18,19 @@ */ import esbuild from "esbuild"; +import { readdir } from "fs/promises"; +import { join } from "path"; -import { commonOpts, globPlugins, isStandalone, watch } from "./common.mjs"; +import { BUILD_TIMESTAMP, commonOpts, existsAsync, globPlugins, isDev, isStandalone, updaterDisabled, VERSION, watch } from "./common.mjs"; const defines = { IS_STANDALONE: isStandalone, - IS_DEV: JSON.stringify(watch) + IS_DEV: JSON.stringify(isDev), + IS_UPDATER_DISABLED: updaterDisabled, + IS_WEB: false, + IS_EXTENSION: false, + VERSION: JSON.stringify(VERSION), + BUILD_TIMESTAMP, }; if (defines.IS_STANDALONE === "false") // If this is a local build (not standalone), optimise @@ -38,26 +45,65 @@ const nodeCommonOpts = { format: "cjs", platform: "node", target: ["esnext"], - minify: true, - bundle: true, - external: ["electron", ...commonOpts.external], + external: ["electron", "original-fs", "~pluginNatives", ...commonOpts.external], define: defines, }; const sourceMapFooter = s => watch ? "" : `//# sourceMappingURL=vencord://${s}.js.map`; const sourcemap = watch ? "inline" : "external"; -await Promise.all([ - // common preload - esbuild.build({ - ...nodeCommonOpts, - entryPoints: ["src/preload.ts"], - outfile: "dist/preload.js", - footer: { js: "//# sourceURL=VencordPreload\n" + sourceMapFooter("preload") }, - sourcemap, - }), +/** + * @type {import("esbuild").Plugin} + */ +const globNativesPlugin = { + name: "glob-natives-plugin", + setup: build => { + const filter = /^~pluginNatives$/; + build.onResolve({ filter }, args => { + return { + namespace: "import-natives", + path: args.path + }; + }); - // Discord Desktop main & renderer + build.onLoad({ filter, namespace: "import-natives" }, async () => { + const pluginDirs = ["plugins", "userplugins"]; + let code = ""; + let natives = "\n"; + let i = 0; + for (const dir of pluginDirs) { + const dirPath = join("src", dir); + if (!await existsAsync(dirPath)) continue; + const plugins = await readdir(dirPath); + for (const p of plugins) { + const nativePath = join(dirPath, p, "native.ts"); + const indexNativePath = join(dirPath, p, "native/index.ts"); + + if (!(await existsAsync(nativePath)) && !(await existsAsync(indexNativePath))) + continue; + + const nameParts = p.split("."); + const namePartsWithoutTarget = nameParts.length === 1 ? nameParts : nameParts.slice(0, -1); + // pluginName.thing.desktop -> PluginName.thing + const cleanPluginName = p[0].toUpperCase() + namePartsWithoutTarget.join(".").slice(1); + + const mod = `p${i}`; + code += `import * as ${mod} from "./${dir}/${p}/native";\n`; + natives += `${JSON.stringify(cleanPluginName)}:${mod},\n`; + i++; + } + } + code += `export default {${natives}};`; + return { + contents: code, + resolveDir: "./src" + }; + }); + } +}; + +await Promise.all([ + // Discord Desktop main & renderer & preload esbuild.build({ ...nodeCommonOpts, entryPoints: ["src/main/index.ts"], @@ -67,8 +113,12 @@ await Promise.all([ define: { ...defines, IS_DISCORD_DESKTOP: true, - IS_VENCORD_DESKTOP: false - } + IS_VESKTOP: false + }, + plugins: [ + ...nodeCommonOpts.plugins, + globNativesPlugin + ] }), esbuild.build({ ...commonOpts, @@ -85,13 +135,24 @@ await Promise.all([ ], define: { ...defines, - IS_WEB: false, IS_DISCORD_DESKTOP: true, - IS_VENCORD_DESKTOP: false + IS_VESKTOP: false + } + }), + esbuild.build({ + ...nodeCommonOpts, + entryPoints: ["src/preload.ts"], + outfile: "dist/preload.js", + footer: { js: "//# sourceURL=VencordPreload\n" + sourceMapFooter("preload") }, + sourcemap, + define: { + ...defines, + IS_DISCORD_DESKTOP: true, + IS_VESKTOP: false } }), - // Vencord Desktop main & renderer + // Vencord Desktop main & renderer & preload esbuild.build({ ...nodeCommonOpts, entryPoints: ["src/main/index.ts"], @@ -101,8 +162,12 @@ await Promise.all([ define: { ...defines, IS_DISCORD_DESKTOP: false, - IS_VENCORD_DESKTOP: true - } + IS_VESKTOP: true + }, + plugins: [ + ...nodeCommonOpts.plugins, + globNativesPlugin + ] }), esbuild.build({ ...commonOpts, @@ -119,9 +184,20 @@ await Promise.all([ ], define: { ...defines, - IS_WEB: false, IS_DISCORD_DESKTOP: false, - IS_VENCORD_DESKTOP: true + IS_VESKTOP: true + } + }), + esbuild.build({ + ...nodeCommonOpts, + entryPoints: ["src/preload.ts"], + outfile: "dist/vencordDesktopPreload.js", + footer: { js: "//# sourceURL=VencordPreload\n" + sourceMapFooter("vencordDesktopPreload") }, + sourcemap, + define: { + ...defines, + IS_DISCORD_DESKTOP: false, + IS_VESKTOP: true } }), ]).catch(err => { diff --git a/scripts/build/buildWeb.mjs b/scripts/build/buildWeb.mjs index cc27ea8cd..b4c726064 100644 --- a/scripts/build/buildWeb.mjs +++ b/scripts/build/buildWeb.mjs @@ -17,16 +17,13 @@ * along with this program. If not, see . */ - import esbuild from "esbuild"; -import { zip } from "fflate"; import { readFileSync } from "fs"; -import { appendFile, mkdir, readFile, rm, writeFile } from "fs/promises"; +import { appendFile, mkdir, readdir, readFile, rm, writeFile } from "fs/promises"; import { join } from "path"; +import Zip from "zip-local"; -// wtf is this assert syntax -import PackageJSON from "../../package.json" assert { type: "json" }; -import { commonOpts, globPlugins, watch } from "./common.mjs"; +import { BUILD_TIMESTAMP, commonOpts, globPlugins, isDev, VERSION } from "./common.mjs"; /** * @type {esbuild.BuildOptions} @@ -44,30 +41,73 @@ const commonOptions = { target: ["esnext"], define: { IS_WEB: "true", + IS_EXTENSION: "false", IS_STANDALONE: "true", - IS_DEV: JSON.stringify(watch), + IS_DEV: JSON.stringify(isDev), IS_DISCORD_DESKTOP: "false", - IS_VENCORD_DESKTOP: "false" + IS_VESKTOP: "false", + IS_UPDATER_DISABLED: "true", + VERSION: JSON.stringify(VERSION), + BUILD_TIMESTAMP, } }; +const MonacoWorkerEntryPoints = [ + "vs/language/css/css.worker.js", + "vs/editor/editor.worker.js" +]; + +const RnNoiseFiles = [ + "dist/rnnoise.wasm", + "dist/rnnoise_simd.wasm", + "dist/rnnoise/workletProcessor.js", + "LICENSE" +]; + await Promise.all( [ + esbuild.build({ + entryPoints: MonacoWorkerEntryPoints.map(entry => `node_modules/monaco-editor/esm/${entry}`), + bundle: true, + minify: true, + format: "iife", + outbase: "node_modules/monaco-editor/esm/", + outdir: "dist/monaco" + }), + esbuild.build({ + entryPoints: ["browser/monaco.ts"], + bundle: true, + minify: true, + format: "iife", + outfile: "dist/monaco/index.js", + loader: { + ".ttf": "file" + } + }), esbuild.build({ ...commonOptions, outfile: "dist/browser.js", footer: { js: "//# sourceURL=VencordWeb" }, }), + esbuild.build({ + ...commonOptions, + outfile: "dist/extension.js", + define: { + ...commonOptions?.define, + IS_EXTENSION: "true", + }, + footer: { js: "//# sourceURL=VencordWeb" }, + }), esbuild.build({ ...commonOptions, inject: ["browser/GMPolyfill.js", ...(commonOptions?.inject || [])], define: { - "window": "unsafeWindow", - ...(commonOptions?.define) + ...(commonOptions?.define), + window: "unsafeWindow", }, outfile: "dist/Vencord.user.js", banner: { - js: readFileSync("browser/userscript.meta.js", "utf-8").replace("%version%", `${PackageJSON.version}.${new Date().getTime()}`) + js: readFileSync("browser/userscript.meta.js", "utf-8").replace("%version%", `${VERSION}.${new Date().getTime()}`) }, footer: { // UserScripts get wrapped in an iife, so define Vencord prop on window that returns our local @@ -78,17 +118,46 @@ await Promise.all( ); /** - * @type {(target: string, files: string[], shouldZip: boolean) => Promise} + * @type {(dir: string) => Promise} */ -async function buildPluginZip(target, files, shouldZip) { +async function globDir(dir) { + const files = []; + + for (const child of await readdir(dir, { withFileTypes: true })) { + const p = join(dir, child.name); + if (child.isDirectory()) + files.push(...await globDir(p)); + else + files.push(p); + } + + return files; +} + +/** + * @type {(dir: string, basePath?: string) => Promise>} + */ +async function loadDir(dir, basePath = "") { + const files = await globDir(dir); + return Object.fromEntries(await Promise.all(files.map(async f => [f.slice(basePath.length), await readFile(f)]))); +} + +/** + * @type {(target: string, files: string[]) => Promise} + */ +async function buildExtension(target, files) { const entries = { - "dist/Vencord.js": await readFile("dist/browser.js"), - "dist/Vencord.css": await readFile("dist/browser.css"), + "dist/Vencord.js": await readFile("dist/extension.js"), + "dist/Vencord.css": await readFile("dist/extension.css"), + ...await loadDir("dist/monaco"), + ...Object.fromEntries(await Promise.all(RnNoiseFiles.map(async file => + [`third-party/rnnoise/${file.replace(/^dist\//, "")}`, await readFile(`node_modules/@sapphi-red/web-noise-suppressor/${file}`)] + ))), ...Object.fromEntries(await Promise.all(files.map(async f => { let content = await readFile(join("browser", f)); if (f.startsWith("manifest")) { const json = JSON.parse(content.toString("utf-8")); - json.version = PackageJSON.version; + json.version = VERSION; content = new TextEncoder().encode(JSON.stringify(json)); } @@ -99,31 +168,15 @@ async function buildPluginZip(target, files, shouldZip) { }))), }; - if (shouldZip) { - return new Promise((resolve, reject) => { - zip(entries, {}, (err, data) => { - if (err) { - reject(err); - } else { - const out = join("dist", target); - writeFile(out, data).then(() => { - console.info("Extension written to " + out); - resolve(); - }).catch(reject); - } - }); - }); - } else { - await rm(target, { recursive: true, force: true }); - await Promise.all(Object.entries(entries).map(async ([file, content]) => { - const dest = join("dist", target, file); - const parentDirectory = join(dest, ".."); - await mkdir(parentDirectory, { recursive: true }); - await writeFile(dest, content); - })); + await rm(target, { recursive: true, force: true }); + await Promise.all(Object.entries(entries).map(async ([file, content]) => { + const dest = join("dist", target, file); + const parentDirectory = join(dest, ".."); + await mkdir(parentDirectory, { recursive: true }); + await writeFile(dest, content); + })); - console.info("Unpacked Extension written to dist/" + target); - } + console.info("Unpacked Extension written to dist/" + target); } const appendCssRuntime = readFile("dist/Vencord.user.css", "utf-8").then(content => { @@ -141,8 +194,12 @@ const appendCssRuntime = readFile("dist/Vencord.user.css", "utf-8").then(content await Promise.all([ appendCssRuntime, - buildPluginZip("extension.zip", ["modifyResponseHeaders.json", "content.js", "manifest.json", "icon.png"], true), - buildPluginZip("chromium-unpacked", ["modifyResponseHeaders.json", "content.js", "manifest.json", "icon.png"], false), - buildPluginZip("firefox-unpacked", ["background.js", "content.js", "manifestv2.json", "icon.png"], false), + buildExtension("chromium-unpacked", ["modifyResponseHeaders.json", "content.js", "manifest.json", "icon.png"]), + buildExtension("firefox-unpacked", ["background.js", "content.js", "manifestv2.json", "icon.png"]), ]); +Zip.sync.zip("dist/chromium-unpacked").compress().save("dist/extension-chrome.zip"); +console.info("Packed Chromium Extension written to dist/extension-chrome.zip"); + +Zip.sync.zip("dist/firefox-unpacked").compress().save("dist/extension-firefox.zip"); +console.info("Packed Firefox Extension written to dist/extension-firefox.zip"); diff --git a/scripts/build/common.mjs b/scripts/build/common.mjs index 7ff599aa5..5c34ad038 100644 --- a/scripts/build/common.mjs +++ b/scripts/build/common.mjs @@ -16,25 +16,44 @@ * along with this program. If not, see . */ +import "../suppressExperimentalWarnings.js"; +import "../checkNodeVersion.js"; + import { exec, execSync } from "child_process"; -import { existsSync, readFileSync } from "fs"; -import { readdir, readFile } from "fs/promises"; +import { constants as FsConstants, readFileSync } from "fs"; +import { access, readdir, readFile } from "fs/promises"; import { join, relative } from "path"; import { promisify } from "util"; +// wtf is this assert syntax +import PackageJSON from "../../package.json" assert { type: "json" }; +import { getPluginTarget } from "../utils.mjs"; + +export const VERSION = PackageJSON.version; +// https://reproducible-builds.org/docs/source-date-epoch/ +export const BUILD_TIMESTAMP = Number(process.env.SOURCE_DATE_EPOCH) || Date.now(); export const watch = process.argv.includes("--watch"); +export const isDev = watch || process.argv.includes("--dev"); export const isStandalone = JSON.stringify(process.argv.includes("--standalone")); -export const gitHash = execSync("git rev-parse --short HEAD", { encoding: "utf-8" }).trim(); +export const updaterDisabled = JSON.stringify(process.argv.includes("--disable-updater")); +export const gitHash = process.env.VENCORD_HASH || execSync("git rev-parse --short HEAD", { encoding: "utf-8" }).trim(); export const banner = { js: ` // Vencord ${gitHash} // Standalone: ${isStandalone} // Platform: ${isStandalone === "false" ? process.platform : "Universal"} +// Updater disabled: ${updaterDisabled} `.trim() }; const isWeb = process.argv.slice(0, 2).some(f => f.endsWith("buildWeb.mjs")); +export function existsAsync(path) { + return access(path, FsConstants.F_OK) + .then(() => true) + .catch(() => false); +} + // https://github.com/evanw/esbuild/issues/619#issuecomment-751995294 /** * @type {import("esbuild").Plugin} @@ -62,24 +81,24 @@ export const globPlugins = kind => ({ }); build.onLoad({ filter, namespace: "import-plugins" }, async () => { - const pluginDirs = ["plugins", "userplugins"]; + const pluginDirs = ["plugins/_api", "plugins/_core", "plugins", "userplugins"]; let code = ""; let plugins = "\n"; let i = 0; for (const dir of pluginDirs) { - if (!existsSync(`./src/${dir}`)) continue; + if (!await existsAsync(`./src/${dir}`)) continue; const files = await readdir(`./src/${dir}`); for (const file of files) { - if (file.startsWith(".")) continue; + if (file.startsWith("_") || file.startsWith(".")) continue; if (file === "index.ts") continue; - const fileBits = file.split("."); - if (fileBits.length > 2 && ["ts", "tsx"].includes(fileBits.at(-1))) { - const mod = fileBits.at(-2); - if (mod === "dev" && !watch) continue; - if (mod === "web" && kind === "discordDesktop") continue; - if (mod === "desktop" && kind === "web") continue; - if (mod === "discordDesktop" && kind !== "discordDesktop") continue; - if (mod === "vencordDesktop" && kind !== "vencordDesktop") continue; + + const target = getPluginTarget(file); + if (target) { + if (target === "dev" && !watch) continue; + if (target === "web" && kind === "discordDesktop") continue; + if (target === "desktop" && kind === "web") continue; + if (target === "discordDesktop" && kind !== "discordDesktop") continue; + if (target === "vencordDesktop" && kind !== "vencordDesktop") continue; } const mod = `p${i}`; @@ -124,11 +143,14 @@ export const gitRemotePlugin = { namespace: "git-remote", path: args.path })); build.onLoad({ filter, namespace: "git-remote" }, async () => { - const res = await promisify(exec)("git remote get-url origin", { encoding: "utf-8" }); - const remote = res.stdout.trim() - .replace("https://github.com/", "") - .replace("git@github.com:", "") - .replace(/.git$/, ""); + let remote = process.env.VENCORD_REMOTE; + if (!remote) { + const res = await promisify(exec)("git remote get-url origin", { encoding: "utf-8" }); + remote = res.stdout.trim() + .replace("https://github.com/", "") + .replace("git@github.com:", "") + .replace(/.git$/, ""); + } return { contents: `export default "${remote}"` }; }); diff --git a/scripts/genPluginList.js b/scripts/genPluginList.js deleted file mode 100644 index efe22ac4a..000000000 --- a/scripts/genPluginList.js +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Vencord, a modification for Discord's desktop app - * Copyright (c) 2022 Vendicated and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . -*/ - -// A script to automatically generate a list of all plugins. -// Just copy paste the entire file into a running Vencord install and it will prompt you -// to save the file - -// eslint-disable-next-line spaced-comment -/// - -(() => { - /** - * @type {typeof import("~plugins").default} - */ - const Plugins = Vencord.Plugins.plugins; - - const header = ` - - -# Vencord Plugins -`; - - let tableOfContents = "\n\n"; - - let list = "\n\n"; - - for (const p of Object.values(Plugins).sort((a, b) => a.name.localeCompare(b.name))) { - tableOfContents += `- [${p.name}](#${p.name.replaceAll(" ", "-")})\n`; - - list += `## ${p.name} - -${p.description} - -**Authors**: ${p.authors.map(a => a.name).join(", ")} -`; - - if (p.commands?.length) { - list += "\n\n#### Commands\n"; - for (const cmd of p.commands) { - list += `${cmd.name} - ${cmd.description}\n\n`; - } - } - list += "\n\n"; - } - - copy(header + tableOfContents + list); -})(); diff --git a/scripts/generatePluginList.ts b/scripts/generatePluginList.ts index 8442e4290..e8aa33a46 100644 --- a/scripts/generatePluginList.ts +++ b/scripts/generatePluginList.ts @@ -18,8 +18,11 @@ import { Dirent, readdirSync, readFileSync, writeFileSync } from "fs"; import { access, readFile } from "fs/promises"; -import { join } from "path"; -import { BigIntLiteral, createSourceFile, Identifier, isArrayLiteralExpression, isCallExpression, isExportAssignment, isIdentifier, isObjectLiteralExpression, isPropertyAccessExpression, isPropertyAssignment, isStringLiteral, isVariableStatement, NamedDeclaration, NodeArray, ObjectLiteralExpression, ScriptTarget, StringLiteral, SyntaxKind } from "typescript"; +import { join, sep } from "path"; +import { normalize as posixNormalize, sep as posixSep } from "path/posix"; +import { BigIntLiteral, createSourceFile, Identifier, isArrayLiteralExpression, isCallExpression, isExportAssignment, isIdentifier, isObjectLiteralExpression, isPropertyAccessExpression, isPropertyAssignment, isSatisfiesExpression, isStringLiteral, isVariableStatement, NamedDeclaration, NodeArray, ObjectLiteralExpression, ScriptTarget, StringLiteral, SyntaxKind } from "typescript"; + +import { getPluginTarget } from "./utils.mjs"; interface Dev { name: string; @@ -37,6 +40,7 @@ interface PluginData { required: boolean; enabledByDefault: boolean; target: "discordDesktop" | "vencordDesktop" | "web" | "dev"; + filePath: string; } const devs = {} as Record; @@ -66,9 +70,9 @@ function parseDevs() { const value = devsDeclaration.initializer.arguments[0]; - if (!isObjectLiteralExpression(value)) return; + if (!isSatisfiesExpression(value) || !isObjectLiteralExpression(value.expression)) throw new Error("Failed to parse devs: not an object literal"); - for (const prop of value.properties) { + for (const prop of value.expression.properties) { const name = (prop.name as Identifier).text; const value = isPropertyAssignment(prop) ? prop.initializer : prop; @@ -130,7 +134,9 @@ async function parseFile(fileName: string) { if (!isArrayLiteralExpression(value)) throw fail("authors is not an array literal"); data.authors = value.elements.map(e => { if (!isPropertyAccessExpression(e)) throw fail("authors array contains non-property access expressions"); - return devs[getName(e)!]; + const d = devs[getName(e)!]; + if (!d) throw fail(`couldn't look up author ${getName(e)}`); + return d; }); break; case "tags": @@ -149,28 +155,36 @@ async function parseFile(fileName: string) { case "required": case "enabledByDefault": data[key] = value.kind === SyntaxKind.TrueKeyword; - if (!data[key] && value.kind !== SyntaxKind.FalseKeyword) throw fail(`${key} is not a boolean literal`); break; } } if (!data.name || !data.description || !data.authors) throw fail("name, description or authors are missing"); - const fileBits = fileName.split("."); - if (fileBits.length > 2 && ["ts", "tsx"].includes(fileBits.at(-1)!)) { - const mod = fileBits.at(-2)!; - if (!["web", "discordDesktop", "vencordDesktop", "dev"].includes(mod)) throw fail(`invalid target ${fileBits.at(-2)}`); - data.target = mod as any; + const target = getPluginTarget(fileName); + if (target) { + if (!["web", "discordDesktop", "vencordDesktop", "desktop", "dev"].includes(target)) throw fail(`invalid target ${target}`); + data.target = target as any; } - return data; + data.filePath = posixNormalize(fileName) + .split(sep) + .join(posixSep) + .replace(/\/index\.([jt]sx?)$/, "") + .replace(/^src\/plugins\//, ""); + + let readme = ""; + try { + readme = readFileSync(join(fileName, "..", "README.md"), "utf-8"); + } catch { } + return [data, readme] as const; } throw fail("no default export called 'definePlugin' found"); } -async function getEntryPoint(dirent: Dirent) { - const base = join("./src/plugins", dirent.name); +async function getEntryPoint(dir: string, dirent: Dirent) { + const base = join(dir, dirent.name); if (!dirent.isDirectory()) return base; for (const name of ["index.ts", "index.tsx"]) { @@ -184,16 +198,32 @@ async function getEntryPoint(dirent: Dirent) { throw new Error(`${dirent.name}: Couldn't find entry point`); } +function isPluginFile({ name }: { name: string; }) { + if (name === "index.ts") return false; + return !name.startsWith("_") && !name.startsWith("."); +} + (async () => { parseDevs(); - const plugins = readdirSync("./src/plugins", { withFileTypes: true }).filter(d => d.name !== "index.ts"); - const promises = plugins.map(async dirent => parseFile(await getEntryPoint(dirent))); + const plugins = [] as PluginData[]; + const readmes = {} as Record; - const data = JSON.stringify(await Promise.all(promises)); + await Promise.all(["src/plugins", "src/plugins/_core"].flatMap(dir => + readdirSync(dir, { withFileTypes: true }) + .filter(isPluginFile) + .map(async dirent => { + const [data, readme] = await parseFile(await getEntryPoint(dir, dirent)); + plugins.push(data); + if (readme) readmes[data.name] = readme; + }) + )); - if (process.argv.length > 2) { + const data = JSON.stringify(plugins); + + if (process.argv.length > 3) { writeFileSync(process.argv[2], data); + writeFileSync(process.argv[3], JSON.stringify(readmes)); } else { console.log(data); } diff --git a/scripts/generateReport.ts b/scripts/generateReport.ts index 90449657c..41e384295 100644 --- a/scripts/generateReport.ts +++ b/scripts/generateReport.ts @@ -34,7 +34,7 @@ for (const variable of ["DISCORD_TOKEN", "CHROMIUM_BIN"]) { const CANARY = process.env.USE_CANARY === "true"; const browser = await pup.launch({ - headless: true, + headless: "new", executablePath: process.env.CHROMIUM_BIN }); @@ -58,16 +58,29 @@ const report = { plugin: string; error: string; }[], - otherErrors: [] as string[] + otherErrors: [] as string[], + badWebpackFinds: [] as string[] }; +const IGNORED_DISCORD_ERRORS = [ + "KeybindStore: Looking for callback action", + "Unable to process domain list delta: Client revision number is null", + "Downloading the full bad domains file", + /\[GatewaySocket\].{0,110}Cannot access '/, + "search for 'name' in undefined", + "Attempting to set fast connect zstd when unsupported" +] as Array; + function toCodeBlock(s: string) { s = s.replace(/```/g, "`\u200B`\u200B`"); return "```" + s + " ```"; } async function printReport() { + console.log(); + console.log("# Vencord Report" + (CANARY ? " (Canary)" : "")); + console.log(); console.log("## Bad Patches"); @@ -80,19 +93,43 @@ async function printReport() { console.log(); + console.log("## Bad Webpack Finds"); + report.badWebpackFinds.forEach(p => console.log("- " + p)); + + console.log(); + console.log("## Bad Starts"); report.badStarts.forEach(p => { console.log(`- ${p.plugin}`); console.log(` - Error: ${toCodeBlock(p.error)}`); }); + console.log(); + + const ignoredErrors = [] as string[]; + report.otherErrors = report.otherErrors.filter(e => { + if (IGNORED_DISCORD_ERRORS.some(regex => e.match(regex))) { + ignoredErrors.push(e); + return false; + } + return true; + }); + console.log("## Discord Errors"); report.otherErrors.forEach(e => { console.log(`- ${toCodeBlock(e)}`); }); + console.log(); + + console.log("## Ignored Discord Errors"); + ignoredErrors.forEach(e => { + console.log(`- ${toCodeBlock(e)}`); + }); + + console.log(); + if (process.env.DISCORD_WEBHOOK) { - // this code was written almost entirely by Copilot xD await fetch(process.env.DISCORD_WEBHOOK, { method: "POST", headers: { @@ -101,7 +138,7 @@ async function printReport() { body: JSON.stringify({ description: "Here's the latest Vencord Report!", username: "Vencord Reporter" + (CANARY ? " (Canary)" : ""), - avatar_url: "https://cdn.discordapp.com/icons/1015060230222131221/f0204a918c6c9c9a43195997e97d8adf.webp", + avatar_url: "https://cdn.discordapp.com/avatars/1017176847865352332/c312b6b44179ae6817de7e4b09e9c6af.webp?size=512", embeds: [ { title: "Bad Patches", @@ -116,6 +153,11 @@ async function printReport() { }).join("\n\n") || "None", color: report.badPatches.length ? 0xff0000 : 0x00ff00 }, + { + title: "Bad Webpack Finds", + description: report.badWebpackFinds.map(toCodeBlock).join("\n") || "None", + color: report.badWebpackFinds.length ? 0xff0000 : 0x00ff00 + }, { title: "Bad Starts", description: report.badStarts.map(p => { @@ -144,46 +186,64 @@ async function printReport() { page.on("console", async e => { const level = e.type(); - const args = e.args(); + const rawArgs = e.args(); - const firstArg = (await args[0]?.jsonValue()); - if (firstArg === "PUPPETEER_TEST_DONE_SIGNAL") { + const firstArg = await rawArgs[0]?.jsonValue(); + if (firstArg === "[PUPPETEER_TEST_DONE_SIGNAL]") { await browser.close(); await printReport(); process.exit(); } - const isVencord = (await args[0]?.jsonValue()) === "[Vencord]"; - const isDebug = (await args[0]?.jsonValue()) === "[PUP_DEBUG]"; + const isVencord = firstArg === "[Vencord]"; + const isDebug = firstArg === "[PUP_DEBUG]"; + const isWebpackFindFail = firstArg === "[PUP_WEBPACK_FIND_FAIL]"; + + if (isWebpackFindFail) { + process.exitCode = 1; + report.badWebpackFinds.push(await rawArgs[1].jsonValue() as string); + } if (isVencord) { - // make ci fail - process.exitCode = 1; + const args = await Promise.all(e.args().map(a => a.jsonValue())); - const jsonArgs = await Promise.all(args.map(a => a.jsonValue())); - const [, tag, message] = jsonArgs; - const cause = await maybeGetError(args[3]); + const [, tag, message] = args as Array; + const cause = await maybeGetError(e.args()[3]); switch (tag) { case "WebpackInterceptor:": - const [, plugin, type, id, regex] = (message as string).match(/Patch by (.+?) (had no effect|errored|found no module) \(Module id is (.+?)\): (.+)/)!; + const patchFailMatch = message.match(/Patch by (.+?) (had no effect|errored|found no module) \(Module id is (.+?)\): (.+)/)!; + if (!patchFailMatch) break; + + process.exitCode = 1; + + const [, plugin, type, id, regex] = patchFailMatch; report.badPatches.push({ plugin, type, id, - match: regex, + match: regex.replace(/\[A-Za-z_\$\]\[\\w\$\]\*/g, "\\i"), error: cause }); + break; case "PluginManager:": - const [, name] = (message as string).match(/Failed to start (.+)/)!; + const failedToStartMatch = message.match(/Failed to start (.+)/); + if (!failedToStartMatch) break; + + process.exitCode = 1; + + const [, name] = failedToStartMatch; report.badStarts.push({ plugin: name, error: cause }); + break; } - } else if (isDebug) { + } + + if (isDebug) { console.error(e.text()); } else if (level === "error") { const text = await Promise.all( @@ -197,8 +257,8 @@ page.on("console", async e => { ).then(a => a.join(" ").trim()); - if (text.length && !text.startsWith("Failed to load resource: the server responded with a status of")) { - console.error("Got unexpected error", text); + if (text.length && !text.startsWith("Failed to load resource: the server responded with a status of") && !text.includes("Webpack")) { + console.error("[Unexpected Error]", text); report.otherErrors.push(text); } } @@ -210,17 +270,16 @@ page.on("pageerror", e => console.error("[Page Error]", e)); await page.setBypassCSP(true); function runTime(token: string) { - console.error("[PUP_DEBUG]", "Starting test..."); + console.log("[PUP_DEBUG]", "Starting test..."); try { - // spoof languages to not be suspicious + // Spoof languages to not be suspicious Object.defineProperty(navigator, "languages", { get: function () { return ["en-US", "en"]; }, }); - // Monkey patch Logger to not log with custom css // @ts-ignore Vencord.Util.Logger.prototype._log = function (level, levelColor, args) { @@ -228,7 +287,7 @@ function runTime(token: string) { console[level]("[Vencord]", this.name + ":", ...args); }; - // force enable all plugins and patches + // Force enable all plugins and patches Vencord.Plugins.patches.length = 0; Object.values(Vencord.Plugins.plugins).forEach(p => { // Needs native server to run @@ -238,8 +297,15 @@ function runTime(token: string) { p.patches?.forEach(patch => { patch.plugin = p.name; delete patch.predicate; + delete patch.group; + if (!Array.isArray(patch.replacement)) patch.replacement = [patch.replacement]; + + patch.replacement.forEach(r => { + delete r.predicate; + }); + Vencord.Plugins.patches.push(patch); }); }); @@ -247,41 +313,159 @@ function runTime(token: string) { Vencord.Webpack.waitFor( "loginToken", m => { - console.error("[PUP_DEBUG]", "Logging in with token..."); + console.log("[PUP_DEBUG]", "Logging in with token..."); m.loginToken(token); } ); - // force load all chunks + // Force load all chunks Vencord.Webpack.onceReady.then(() => setTimeout(async () => { - console.error("[PUP_DEBUG]", "Webpack is ready!"); + console.log("[PUP_DEBUG]", "Webpack is ready!"); const { wreq } = Vencord.Webpack; - console.error("[PUP_DEBUG]", "Loading all chunks..."); - const ids = Function("return" + wreq.u.toString().match(/\{.+\}/s)![0])(); - for (const id in ids) { + console.log("[PUP_DEBUG]", "Loading all chunks..."); + + let chunks = null as Record | null; + const sym = Symbol("Vencord.chunksExtract"); + + Object.defineProperty(Object.prototype, sym, { + get() { + chunks = this; + }, + set() { }, + configurable: true, + }); + + await (wreq as any).el(sym); + delete Object.prototype[sym]; + + const validChunksEntryPoints = new Set(); + const validChunks = new Set(); + const invalidChunks = new Set(); + + if (!chunks) throw new Error("Failed to get chunks"); + + for (const entryPoint in chunks) { + const chunkIds = chunks[entryPoint]; + let invalidEntryPoint = false; + + for (const id of chunkIds) { + if (wreq.u(id) == null || wreq.u(id) === "undefined.js") continue; + + const isWasm = await fetch(wreq.p + wreq.u(id)) + .then(r => r.text()) + .then(t => t.includes(".module.wasm") || !t.includes("(this.webpackChunkdiscord_app=this.webpackChunkdiscord_app||[]).push")); + + if (isWasm) { + invalidChunks.add(id); + invalidEntryPoint = true; + continue; + } + + validChunks.add(id); + } + + if (!invalidEntryPoint) + validChunksEntryPoints.add(entryPoint); + } + + for (const entryPoint of validChunksEntryPoints) { + try { + // Loads all chunks required for an entry point + await (wreq as any).el(entryPoint); + } catch (err) { } + } + + // Matches "id" or id: + const chunkIdRegex = /(?:"(\d+?)")|(?:(\d+?):)/g; + const wreqU = wreq.u.toString(); + + const allChunks = [] as string[]; + let currentMatch: RegExpExecArray | null; + + while ((currentMatch = chunkIdRegex.exec(wreqU)) != null) { + const id = currentMatch[1] ?? currentMatch[2]; + if (id == null) continue; + + allChunks.push(id); + } + + if (allChunks.length === 0) throw new Error("Failed to get all chunks"); + const chunksLeft = allChunks.filter(id => { + return !(validChunks.has(id) || invalidChunks.has(id)); + }); + + for (const id of chunksLeft) { const isWasm = await fetch(wreq.p + wreq.u(id)) .then(r => r.text()) - .then(t => t.includes(".module.wasm")); + .then(t => t.includes(".module.wasm") || !t.includes("(this.webpackChunkdiscord_app=this.webpackChunkdiscord_app||[]).push")); - if (!isWasm) - await wreq.e(id as any); - - await new Promise(r => setTimeout(r, 150)); + // Loads a chunk + if (!isWasm) await wreq.e(id as any); } - console.error("[PUP_DEBUG]", "Finished loading chunks!"); + + // Make sure every chunk has finished loading + await new Promise(r => setTimeout(r, 1000)); + + for (const entryPoint of validChunksEntryPoints) { + try { + if (wreq.m[entryPoint]) wreq(entryPoint as any); + } catch (err) { + console.error(err); + } + } + + console.log("[PUP_DEBUG]", "Finished loading all chunks!"); for (const patch of Vencord.Plugins.patches) { if (!patch.all) { new Vencord.Util.Logger("WebpackInterceptor").warn(`Patch by ${patch.plugin} found no module (Module id is -): ${patch.find}`); } } - setTimeout(() => console.log("PUPPETEER_TEST_DONE_SIGNAL"), 1000); + + for (const [searchType, args] of Vencord.Webpack.lazyWebpackSearchHistory) { + let method = searchType; + + if (searchType === "findComponent") method = "find"; + if (searchType === "findExportedComponent") method = "findByProps"; + if (searchType === "waitFor" || searchType === "waitForComponent") { + if (typeof args[0] === "string") method = "findByProps"; + else method = "find"; + } + if (searchType === "waitForStore") method = "findStore"; + + try { + let result: any; + + if (method === "proxyLazyWebpack" || method === "LazyComponentWebpack") { + const [factory] = args; + result = factory(); + } else if (method === "extractAndLoadChunks") { + const [code, matcher] = args; + + const module = Vencord.Webpack.findModuleFactory(...code); + if (module) result = module.toString().match(Vencord.Util.canonicalizeMatch(matcher)); + } else { + // @ts-ignore + result = Vencord.Webpack[method](...args); + } + + if (result == null || ("$$vencordInternal" in result && result.$$vencordInternal() == null)) throw "a rock at ben shapiro"; + } catch (e) { + let logMessage = searchType; + if (method === "find" || method === "proxyLazyWebpack" || method === "LazyComponentWebpack") logMessage += `(${args[0].toString().slice(0, 147)}...)`; + else if (method === "extractAndLoadChunks") logMessage += `([${args[0].map(arg => `"${arg}"`).join(", ")}], ${args[1].toString()})`; + else logMessage += `(${args.map(arg => `"${arg}"`).join(", ")})`; + + console.log("[PUP_WEBPACK_FIND_FAIL]", logMessage); + } + } + + setTimeout(() => console.log("[PUPPETEER_TEST_DONE_SIGNAL]"), 1000); }, 1000)); } catch (e) { - console.error("[PUP_DEBUG]", "A fatal error occured"); - console.error("[PUP_DEBUG]", e); + console.log("[PUP_DEBUG]", "A fatal error occurred:", e); process.exit(1); } } diff --git a/scripts/header-new.txt b/scripts/header-new.txt new file mode 100644 index 000000000..0db705dbd --- /dev/null +++ b/scripts/header-new.txt @@ -0,0 +1,3 @@ +Vencord, a Discord client mod +Copyright (c) {year} {author} +SPDX-License-Identifier: GPL-3.0-or-later diff --git a/src/plugins/reviewDB/entities/Review.ts b/scripts/header-old.txt similarity index 67% rename from src/plugins/reviewDB/entities/Review.ts rename to scripts/header-old.txt index e1f8380cf..8bb40244e 100644 --- a/src/plugins/reviewDB/entities/Review.ts +++ b/scripts/header-old.txt @@ -1,6 +1,6 @@ /* * Vencord, a modification for Discord's desktop app - * Copyright (c) 2022 Vendicated and contributors + * Copyright (c) {year} {author} * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,21 +15,3 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - -import { Badge } from "./Badge"; - -export interface Sender { - id : number, - discordID: string, - username: string, - profilePhoto: string, - badges: Badge[] -} - -export interface Review { - comment: string, - id: number, - star: number, - sender: Sender, - timestamp: number -} diff --git a/scripts/runInstaller.mjs b/scripts/runInstaller.mjs index b35039f8a..145ea5a5e 100644 --- a/scripts/runInstaller.mjs +++ b/scripts/runInstaller.mjs @@ -35,11 +35,11 @@ const ETAG_FILE = join(FILE_DIR, "etag.txt"); function getFilename() { switch (process.platform) { case "win32": - return "VencordInstaller.exe"; + return "VencordInstallerCli.exe"; case "darwin": return "VencordInstaller.MacOS.zip"; case "linux": - return "VencordInstaller-" + (process.env.WAYLAND_DISPLAY ? "wayland" : "x11"); + return "VencordInstallerCli-linux"; default: throw new Error("Unsupported platform: " + process.platform); } @@ -118,11 +118,15 @@ const installerBin = await ensureBinary(); console.log("Now running Installer..."); -execFileSync(installerBin, { - stdio: "inherit", - env: { - ...process.env, - VENCORD_USER_DATA_DIR: BASE_DIR, - VENCORD_DEV_INSTALL: "1" - } -}); +try { + execFileSync(installerBin, { + stdio: "inherit", + env: { + ...process.env, + VENCORD_USER_DATA_DIR: BASE_DIR, + VENCORD_DEV_INSTALL: "1" + } + }); +} catch { + console.error("Something went wrong. Please check the logs above."); +} diff --git a/scripts/utils.mjs b/scripts/utils.mjs new file mode 100644 index 000000000..5b84c9878 --- /dev/null +++ b/scripts/utils.mjs @@ -0,0 +1,30 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2023 Vendicated and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +/** + * @param {string} filePath + * @returns {string | null} + */ +export function getPluginTarget(filePath) { + const pathParts = filePath.split(/[/\\]/); + if (/^index\.tsx?$/.test(pathParts.at(-1))) pathParts.pop(); + + const identifier = pathParts.at(-1).replace(/\.tsx?$/, ""); + const identiferBits = identifier.split("."); + return identiferBits.length === 1 ? null : identiferBits.at(-1); +} diff --git a/src/Vencord.ts b/src/Vencord.ts index a05ec5383..29e965fa0 100644 --- a/src/Vencord.ts +++ b/src/Vencord.ts @@ -27,6 +27,9 @@ export { PlainSettings, Settings }; import "./utils/quickCss"; import "./webpack/patchWebpack"; +import { StartAt } from "@utils/types"; + +import { get as dsGet } from "./api/DataStore"; import { showNotification } from "./api/Notifications"; import { PlainSettings, Settings } from "./api/Settings"; import { patches, PMLogger, startAllPlugins } from "./plugins"; @@ -38,6 +41,22 @@ import { onceReady } from "./webpack"; import { SettingsRouter } from "./webpack/common"; async function syncSettings() { + // pre-check for local shared settings + if ( + Settings.cloud.authenticated && + !await dsGet("Vencord_cloudSecret") // this has been enabled due to local settings share or some other bug + ) { + // show a notification letting them know and tell them how to fix it + showNotification({ + title: "Cloud Integrations", + body: "We've noticed you have cloud integrations enabled in another client! Due to limitations, you will " + + "need to re-authenticate to continue using them. Click here to go to the settings page to do so!", + color: "var(--yellow-360)", + onClick: () => SettingsRouter.open("VencordCloud") + }); + return; + } + if ( Settings.cloud.settingsSync && // if it's enabled Settings.cloud.authenticated // if cloud integrations are enabled @@ -62,7 +81,7 @@ async function syncSettings() { async function init() { await onceReady; - startAllPlugins(); + startAllPlugins(StartAt.WebpackReady); syncSettings(); @@ -113,13 +132,16 @@ async function init() { } } +startAllPlugins(StartAt.Init); init(); -if (IS_DISCORD_DESKTOP && Settings.winNativeTitleBar && navigator.platform.toLowerCase().startsWith("win")) { - document.addEventListener("DOMContentLoaded", () => { +document.addEventListener("DOMContentLoaded", () => { + startAllPlugins(StartAt.DOMContentLoaded); + + if (IS_DISCORD_DESKTOP && Settings.winNativeTitleBar && navigator.platform.toLowerCase().startsWith("win")) { document.head.append(Object.assign(document.createElement("style"), { id: "vencord-native-titlebar-style", - textContent: "[class*=titleBar-]{display: none!important}" + textContent: "[class*=titleBar]{display: none!important}" })); - }, { once: true }); -} + } +}, { once: true }); diff --git a/src/VencordNative.ts b/src/VencordNative.ts index 02de74f66..42e697452 100644 --- a/src/VencordNative.ts +++ b/src/VencordNative.ts @@ -1,23 +1,14 @@ /* - * Vencord, a modification for Discord's desktop app - * Copyright (c) 2022 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . -*/ + * Vencord, a Discord client mod + * Copyright (c) 2023 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ -import { IpcEvents } from "@utils/IpcEvents"; +import { PluginIpcMappings } from "@main/ipcPlugins"; +import type { UserThemeHeader } from "@main/themes"; +import { IpcEvents } from "@shared/IpcEvents"; import { IpcRes } from "@utils/types"; +import type { Settings } from "api/Settings"; import { ipcRenderer } from "electron"; function invoke(event: IpcEvents, ...args: any[]) { @@ -28,7 +19,26 @@ export function sendSync(event: IpcEvents, ...args: any[]) { return ipcRenderer.sendSync(event, ...args) as T; } +const PluginHelpers = {} as Record Promise>>; +const pluginIpcMap = sendSync(IpcEvents.GET_PLUGIN_IPC_METHOD_MAP); + +for (const [plugin, methods] of Object.entries(pluginIpcMap)) { + const map = PluginHelpers[plugin] = {}; + for (const [methodName, method] of Object.entries(methods)) { + map[methodName] = (...args: any[]) => invoke(method as IpcEvents, ...args); + } +} + export default { + themes: { + uploadTheme: (fileName: string, fileData: string) => invoke(IpcEvents.UPLOAD_THEME, fileName, fileData), + deleteTheme: (fileName: string) => invoke(IpcEvents.DELETE_THEME, fileName), + getThemesDir: () => invoke(IpcEvents.GET_THEMES_DIR), + getThemesList: () => invoke>(IpcEvents.GET_THEMES_LIST), + getThemeData: (fileName: string) => invoke(IpcEvents.GET_THEME_DATA, fileName), + getSystemValues: () => invoke>(IpcEvents.GET_THEME_SYSTEM_VALUES), + }, + updater: { getUpdates: () => invoke[]>>(IpcEvents.GET_UPDATES), update: () => invoke>(IpcEvents.UPDATE), @@ -37,8 +47,8 @@ export default { }, settings: { - get: () => sendSync(IpcEvents.GET_SETTINGS), - set: (settings: string) => invoke(IpcEvents.SET_SETTINGS, settings), + get: () => sendSync(IpcEvents.GET_SETTINGS), + set: (settings: Settings, pathToNotify?: string) => invoke(IpcEvents.SET_SETTINGS, settings, pathToNotify), getSettingsDir: () => invoke(IpcEvents.GET_SETTINGS_DIR), }, @@ -50,6 +60,10 @@ export default { ipcRenderer.on(IpcEvents.QUICK_CSS_UPDATE, (_, css) => cb(css)); }, + addThemeChangeListener(cb: () => void) { + ipcRenderer.on(IpcEvents.THEME_UPDATE, () => cb()); + }, + openFile: () => invoke(IpcEvents.OPEN_QUICKCSS), openEditor: () => invoke(IpcEvents.OPEN_MONACO_EDITOR), }, @@ -58,4 +72,6 @@ export default { getVersions: () => process.versions as Partial, openExternal: (url: string) => invoke(IpcEvents.OPEN_EXTERNAL, url) }, + + pluginHelpers: PluginHelpers }; diff --git a/src/api/Badges.ts b/src/api/Badges.ts index a0961c46d..b50016c5b 100644 --- a/src/api/Badges.ts +++ b/src/api/Badges.ts @@ -22,7 +22,7 @@ import { ComponentType, HTMLProps } from "react"; import Plugins from "~plugins"; -export enum BadgePosition { +export const enum BadgePosition { START, END } @@ -79,7 +79,7 @@ export function _getBadges(args: BadgeUserArgs) { : badges.push({ ...badge, ...args }); } } - const donorBadges = (Plugins.BadgeAPI as unknown as typeof import("../plugins/apiBadges").default).getDonorBadges(args.user.id); + const donorBadges = (Plugins.BadgeAPI as unknown as typeof import("../plugins/_api/badges").default).getDonorBadges(args.user.id); if (donorBadges) badges.unshift(...donorBadges); return badges; diff --git a/src/api/ChatButton.css b/src/api/ChatButton.css new file mode 100644 index 000000000..30869a846 --- /dev/null +++ b/src/api/ChatButton.css @@ -0,0 +1,4 @@ +.vc-chatbar-button { + display: flex; + align-items: center; +} diff --git a/src/api/ChatButtons.tsx b/src/api/ChatButtons.tsx new file mode 100644 index 000000000..fcb76fffc --- /dev/null +++ b/src/api/ChatButtons.tsx @@ -0,0 +1,128 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import "./ChatButton.css"; + +import ErrorBoundary from "@components/ErrorBoundary"; +import { Logger } from "@utils/Logger"; +import { waitFor } from "@webpack"; +import { Button, ButtonLooks, ButtonWrapperClasses, Tooltip } from "@webpack/common"; +import { Channel } from "discord-types/general"; +import { HTMLProps, MouseEventHandler, ReactNode } from "react"; + +let ChannelTextAreaClasses: Record<"button" | "buttonContainer", string>; +waitFor(["buttonContainer", "channelTextArea"], m => ChannelTextAreaClasses = m); + +export interface ChatBarProps { + channel: Channel; + disabled: boolean; + isEmpty: boolean; + type: { + analyticsName: string; + attachments: boolean; + autocomplete: { + addReactionShortcut: boolean, + forceChatLayer: boolean, + reactions: boolean; + }, + commands: { + enabled: boolean; + }, + drafts: { + type: number, + commandType: number, + autoSave: boolean; + }, + emojis: { + button: boolean; + }, + gifs: { + button: boolean, + allowSending: boolean; + }, + gifts: { + button: boolean; + }, + permissions: { + requireSendMessages: boolean; + }, + showThreadPromptOnReply: boolean, + stickers: { + button: boolean, + allowSending: boolean, + autoSuggest: boolean; + }, + users: { + allowMentioning: boolean; + }, + submit: { + button: boolean, + ignorePreference: boolean, + disableEnterToSubmit: boolean, + clearOnSubmit: boolean, + useDisabledStylesOnSubmit: boolean; + }, + uploadLongMessages: boolean, + upsellLongMessages: { + iconOnly: boolean; + }, + showCharacterCount: boolean, + sedReplace: boolean; + }; +} + +export type ChatBarButton = (props: ChatBarProps & { isMainChat: boolean; }) => JSX.Element | null; + +const buttonFactories = new Map(); +const logger = new Logger("ChatButtons"); + +export function _injectButtons(buttons: ReactNode[], props: ChatBarProps) { + if (props.disabled) return; + + for (const [key, Button] of buttonFactories) { + buttons.push( + logger.error(`Failed to render ${key}`, e.error)}> + + + )} + + ); +}, { noop: true }); diff --git a/src/api/Commands/commandHelpers.ts b/src/api/Commands/commandHelpers.ts index dd1196f9f..dc5ecfd67 100644 --- a/src/api/Commands/commandHelpers.ts +++ b/src/api/Commands/commandHelpers.ts @@ -17,15 +17,14 @@ */ import { mergeDefaults } from "@utils/misc"; -import { findByCodeLazy, findByPropsLazy } from "@webpack"; -import { SnowflakeUtils } from "@webpack/common"; +import { findByPropsLazy } from "@webpack"; +import { MessageActions, SnowflakeUtils } from "@webpack/common"; import { Message } from "discord-types/general"; import type { PartialDeep } from "type-fest"; import { Argument } from "./types"; -const createBotMessage = findByCodeLazy('username:"Clyde"'); -const MessageSender = findByPropsLazy("receiveMessage"); +const MessageCreator = findByPropsLazy("createBotMessage"); export function generateId() { return `-${SnowflakeUtils.fromTimestamp(Date.now())}`; @@ -38,9 +37,9 @@ export function generateId() { * @returns {Message} */ export function sendBotMessage(channelId: string, message: PartialDeep): Message { - const botMessage = createBotMessage({ channelId, content: "", embeds: [] }); + const botMessage = MessageCreator.createBotMessage({ channelId, content: "", embeds: [] }); - MessageSender.receiveMessage(channelId, mergeDefaults(message, botMessage)); + MessageActions.receiveMessage(channelId, mergeDefaults(message, botMessage)); return message as Message; } diff --git a/src/api/Commands/types.ts b/src/api/Commands/types.ts index 9acab664f..bd349e250 100644 --- a/src/api/Commands/types.ts +++ b/src/api/Commands/types.ts @@ -24,7 +24,7 @@ export interface CommandContext { guild?: Guild; } -export enum ApplicationCommandOptionType { +export const enum ApplicationCommandOptionType { SUB_COMMAND = 1, SUB_COMMAND_GROUP = 2, STRING = 3, @@ -38,7 +38,7 @@ export enum ApplicationCommandOptionType { ATTACHMENT = 11, } -export enum ApplicationCommandInputType { +export const enum ApplicationCommandInputType { BUILT_IN = 0, BUILT_IN_TEXT = 1, BUILT_IN_INTEGRATION = 2, @@ -64,7 +64,7 @@ export interface ChoicesOption { displayName?: string; } -export enum ApplicationCommandType { +export const enum ApplicationCommandType { CHAT_INPUT = 1, USER = 2, MESSAGE = 3, diff --git a/src/api/ContextMenu.ts b/src/api/ContextMenu.ts index 156ae209a..fdd4facf4 100644 --- a/src/api/ContextMenu.ts +++ b/src/api/ContextMenu.ts @@ -17,22 +17,20 @@ */ import { Logger } from "@utils/Logger"; +import { Menu, React } from "@webpack/common"; import type { ReactElement } from "react"; -type ContextMenuPatchCallbackReturn = (() => void) | void; /** * @param children The rendered context menu elements * @param args Any arguments passed into making the context menu, like the guild, channel, user or message for example - * @returns A callback which is only ran once used to modify the context menu elements (Use to avoid duplicates) */ -export type NavContextMenuPatchCallback = (children: Array, ...args: Array) => ContextMenuPatchCallbackReturn; +export type NavContextMenuPatchCallback = (children: Array, ...args: Array) => void; /** * @param navId The navId of the context menu being patched * @param children The rendered context menu elements * @param args Any arguments passed into making the context menu, like the guild, channel, user or message for example - * @returns A callback which is only ran once used to modify the context menu elements (Use to avoid duplicates) */ -export type GlobalContextMenuPatchCallback = (navId: string, children: Array, ...args: Array) => ContextMenuPatchCallbackReturn; +export type GlobalContextMenuPatchCallback = (navId: string, children: Array, ...args: Array) => void; const ContextMenuLogger = new Logger("ContextMenu"); @@ -69,7 +67,7 @@ export function addGlobalContextMenuPatch(patch: GlobalContextMenuPatchCallback) * Remove a context menu patch * @param navId The navId(s) for the context menu(s) to remove the patch * @param patch The patch to be removed - * @returns Wheter the patch was sucessfully removed from the context menu(s) + * @returns Whether the patch was successfully removed from the context menu(s) */ export function removeContextMenuPatch>(navId: T, patch: NavContextMenuPatchCallback): T extends string ? boolean : Array { const navIds = Array.isArray(navId) ? navId : [navId as string]; @@ -82,7 +80,7 @@ export function removeContextMenuPatch>(navId: /** * Remove a global context menu patch * @param patch The patch to be removed - * @returns Wheter the patch was sucessfully removed + * @returns Whether the patch was successfully removed */ export function removeGlobalContextMenuPatch(patch: GlobalContextMenuPatchCallback): boolean { return globalPatches.delete(patch); @@ -93,14 +91,19 @@ export function removeGlobalContextMenuPatch(patch: GlobalContextMenuPatchCallba * @param id The id of the child. If an array is specified, all ids will be tried * @param children The context menu children */ -export function findGroupChildrenByChildId(id: string | string[], children: Array, _itemsArray?: Array): Array | null { +export function findGroupChildrenByChildId(id: string | string[], children: Array): Array | null { for (const child of children) { if (child == null) continue; + if (Array.isArray(child)) { + const found = findGroupChildrenByChildId(id, child); + if (found !== null) return found; + } + if ( (Array.isArray(id) && id.some(id => child.props?.id === id)) || child.props?.id === id - ) return _itemsArray ?? null; + ) return children; let nextChildren = child.props?.children; if (nextChildren) { @@ -109,7 +112,7 @@ export function findGroupChildrenByChildId(id: string | string[], children: Arra child.props.children = nextChildren; } - const found = findGroupChildrenByChildId(id, nextChildren, nextChildren); + const found = findGroupChildrenByChildId(id, nextChildren); if (found !== null) return found; } } @@ -126,9 +129,12 @@ interface ContextMenuProps { onClose: (callback: (...args: Array) => any) => void; } -const patchedMenus = new WeakSet(); +export function _usePatchContextMenu(props: ContextMenuProps) { + props = { + ...props, + children: cloneMenuChildren(props.children), + }; -export function _patchContextMenu(props: ContextMenuProps) { props.contextMenuApiArguments ??= []; const contextMenuPatches = navPatches.get(props.navId); @@ -137,8 +143,7 @@ export function _patchContextMenu(props: ContextMenuProps) { if (contextMenuPatches) { for (const patch of contextMenuPatches) { try { - const callback = patch(props.children, ...props.contextMenuApiArguments); - if (!patchedMenus.has(props)) callback?.(); + patch(props.children, ...props.contextMenuApiArguments); } catch (err) { ContextMenuLogger.error(`Patch for ${props.navId} errored,`, err); } @@ -147,12 +152,30 @@ export function _patchContextMenu(props: ContextMenuProps) { for (const patch of globalPatches) { try { - const callback = patch(props.navId, props.children, ...props.contextMenuApiArguments); - if (!patchedMenus.has(props)) callback?.(); + patch(props.navId, props.children, ...props.contextMenuApiArguments); } catch (err) { ContextMenuLogger.error("Global patch errored,", err); } } - patchedMenus.add(props); + return props; +} + +function cloneMenuChildren(obj: ReactElement | Array | null) { + if (Array.isArray(obj)) { + return obj.map(cloneMenuChildren); + } + + if (React.isValidElement(obj)) { + obj = React.cloneElement(obj); + + if ( + obj?.props?.children && + (obj.type !== Menu.MenuControlItem || obj.type === Menu.MenuControlItem && obj.props.control != null) + ) { + obj.props.children = cloneMenuChildren(obj.props.children); + } + } + + return obj; } diff --git a/src/api/DataStore/index.ts b/src/api/DataStore/index.ts index 49c85952f..97f43edd6 100644 --- a/src/api/DataStore/index.ts +++ b/src/api/DataStore/index.ts @@ -1,4 +1,4 @@ -/* eslint-disable header/header */ +/* eslint-disable simple-header/header */ /*! * idb-keyval v6.2.0 diff --git a/src/api/MemberListDecorators.ts b/src/api/MemberListDecorators.ts index fade2a7ca..e148bb0a4 100644 --- a/src/api/MemberListDecorators.ts +++ b/src/api/MemberListDecorators.ts @@ -20,7 +20,6 @@ import { Channel, User } from "discord-types/general/index.js"; interface DecoratorProps { activities: any[]; - canUseAvatarDecorations: boolean; channel: Channel; /** * Only for DM members @@ -52,9 +51,9 @@ export function removeDecorator(identifier: string) { decorators.delete(identifier); } -export function __addDecoratorsToList(props: DecoratorProps): (JSX.Element | null)[] { +export function __getDecorators(props: DecoratorProps): (JSX.Element | null)[] { const isInGuild = !!(props.guildId); - return [...decorators.values()].map(decoratorObj => { + return Array.from(decorators.values(), decoratorObj => { const { decorator, onlyIn } = decoratorObj; // this can most likely be done cleaner if (!onlyIn || (onlyIn === "guilds" && isInGuild) || (onlyIn === "dms" && !isInGuild)) { diff --git a/src/api/MessageEvents.ts b/src/api/MessageEvents.ts index 341b4e678..d6eba748f 100644 --- a/src/api/MessageEvents.ts +++ b/src/api/MessageEvents.ts @@ -74,7 +74,7 @@ export interface MessageExtra { } export type SendListener = (channelId: string, messageObj: MessageObject, extra: MessageExtra) => Promisable; -export type EditListener = (channelId: string, messageId: string, messageObj: MessageObject) => Promisable; +export type EditListener = (channelId: string, messageId: string, messageObj: MessageObject) => Promisable; const sendListeners = new Set(); const editListeners = new Set(); @@ -84,7 +84,7 @@ export async function _handlePreSend(channelId: string, messageObj: MessageObjec for (const listener of sendListeners) { try { const result = await listener(channelId, messageObj, extra); - if (result && result.cancel === true) { + if (result?.cancel) { return true; } } catch (e) { @@ -97,11 +97,15 @@ export async function _handlePreSend(channelId: string, messageObj: MessageObjec export async function _handlePreEdit(channelId: string, messageId: string, messageObj: MessageObject) { for (const listener of editListeners) { try { - await listener(channelId, messageId, messageObj); + const result = await listener(channelId, messageId, messageObj); + if (result?.cancel) { + return true; + } } catch (e) { MessageEventsLogger.error("MessageEditHandler: Listener encountered an unknown error\n", e); } } + return false; } /** diff --git a/src/api/Notifications/notificationLog.tsx b/src/api/Notifications/notificationLog.tsx index 9535fb62c..6f79ef70a 100644 --- a/src/api/Notifications/notificationLog.tsx +++ b/src/api/Notifications/notificationLog.tsx @@ -21,7 +21,7 @@ import { Settings } from "@api/Settings"; import { classNameFactory } from "@api/Styles"; import { closeModal, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal"; import { useAwaiter } from "@utils/react"; -import { Alerts, Button, Forms, moment, React, Text, Timestamp, useEffect, useReducer, useState } from "@webpack/common"; +import { Alerts, Button, Forms, React, Text, Timestamp, useEffect, useReducer, useState } from "@webpack/common"; import { nanoid } from "nanoid"; import type { DispatchWithoutAction } from "react"; @@ -129,7 +129,7 @@ function NotificationEntry({ data }: { data: PersistentNotificationData; }) { richBody={
{data.body} - +
} /> diff --git a/src/api/ServerList.ts b/src/api/ServerList.ts index 480441391..75016e897 100644 --- a/src/api/ServerList.ts +++ b/src/api/ServerList.ts @@ -20,7 +20,7 @@ import { Logger } from "@utils/Logger"; const logger = new Logger("ServerListAPI"); -export enum ServerListRenderPosition { +export const enum ServerListRenderPosition { Above, In, } diff --git a/src/api/Settings.ts b/src/api/Settings.ts index e481e48c0..0b7975300 100644 --- a/src/api/Settings.ts +++ b/src/api/Settings.ts @@ -16,7 +16,8 @@ * along with this program. If not, see . */ -import { debounce } from "@utils/debounce"; +import { debounce } from "@shared/debounce"; +import { SettingsStore as SettingsStoreClass } from "@shared/SettingsStore"; import { localStorage } from "@utils/localStorage"; import { Logger } from "@utils/Logger"; import { mergeDefaults } from "@utils/misc"; @@ -34,10 +35,24 @@ export interface Settings { useQuickCss: boolean; enableReactDevtools: boolean; themeLinks: string[]; + enabledThemes: string[]; frameless: boolean; transparent: boolean; winCtrlQ: boolean; - macosTranslucency: boolean; + macosVibrancyStyle: + | "content" + | "fullscreen-ui" + | "header" + | "hud" + | "menu" + | "popover" + | "selection" + | "sidebar" + | "titlebar" + | "tooltip" + | "under-page" + | "window" + | undefined; disableMinSize: boolean; winNativeTitleBar: boolean; plugins: { @@ -68,11 +83,12 @@ const DefaultSettings: Settings = { autoUpdateNotification: true, useQuickCss: true, themeLinks: [], + enabledThemes: [], enableReactDevtools: false, frameless: false, transparent: false, winCtrlQ: false, - macosTranslucency: false, + macosVibrancyStyle: undefined, disableMinSize: false, winNativeTitleBar: false, plugins: {}, @@ -92,13 +108,8 @@ const DefaultSettings: Settings = { } }; -try { - var settings = JSON.parse(VencordNative.settings.get()) as Settings; - mergeDefaults(settings, DefaultSettings); -} catch (err) { - var settings = mergeDefaults({} as Settings, DefaultSettings); - logger.error("An error occurred while loading the settings. Corrupt settings file?\n", err); -} +const settings = VencordNative.settings.get(); +mergeDefaults(settings, DefaultSettings); const saveSettingsOnFrequentAction = debounce(async () => { if (Settings.cloud.settingsSync && Settings.cloud.authenticated) { @@ -107,76 +118,52 @@ const saveSettingsOnFrequentAction = debounce(async () => { } }, 60_000); -type SubscriptionCallback = ((newValue: any, path: string) => void) & { _path?: string; }; -const subscriptions = new Set(); -const proxyCache = {} as Record; +export const SettingsStore = new SettingsStoreClass(settings, { + readOnly: true, + getDefaultValue({ + target, + key, + path + }) { + const v = target[key]; + if (!plugins) return v; // plugins not initialised yet. this means this path was reached by being called on the top level -// Wraps the passed settings object in a Proxy to nicely handle change listeners and default values -function makeProxy(settings: any, root = settings, path = ""): Settings { - return proxyCache[path] ??= new Proxy(settings, { - get(target, p: string) { - const v = target[p]; + if (path === "plugins" && key in plugins) + return target[key] = { + enabled: plugins[key].required ?? plugins[key].enabledByDefault ?? false + }; - // using "in" is important in the following cases to properly handle falsy or nullish values - if (!(p in target)) { - // Return empty for plugins with no settings - if (path === "plugins" && p in plugins) - return target[p] = makeProxy({ - enabled: plugins[p].required ?? plugins[p].enabledByDefault ?? false - }, root, `plugins.${p}`); + // Since the property is not set, check if this is a plugin's setting and if so, try to resolve + // the default value. + if (path.startsWith("plugins.")) { + const plugin = path.slice("plugins.".length); + if (plugin in plugins) { + const setting = plugins[plugin].options?.[key]; + if (!setting) return v; - // Since the property is not set, check if this is a plugin's setting and if so, try to resolve - // the default value. - if (path.startsWith("plugins.")) { - const plugin = path.slice("plugins.".length); - if (plugin in plugins) { - const setting = plugins[plugin].options?.[p]; - if (!setting) return v; - if ("default" in setting) - // normal setting with a default value - return (target[p] = setting.default); - if (setting.type === OptionType.SELECT) { - const def = setting.options.find(o => o.default); - if (def) - target[p] = def.value; - return def?.value; - } - } - } - return v; - } + if ("default" in setting) + // normal setting with a default value + return (target[key] = setting.default); - // Recursively proxy Objects with the updated property path - if (typeof v === "object" && !Array.isArray(v) && v !== null) - return makeProxy(v, root, `${path}${path && "."}${p}`); - - // primitive or similar, no need to proxy further - return v; - }, - - set(target, p: string, v) { - // avoid unnecessary updates to React Components and other listeners - if (target[p] === v) return true; - - target[p] = v; - // Call any listeners that are listening to a setting of this path - const setPath = `${path}${path && "."}${p}`; - delete proxyCache[setPath]; - for (const subscription of subscriptions) { - if (!subscription._path || subscription._path === setPath) { - subscription(v, setPath); + if (setting.type === OptionType.SELECT) { + const def = setting.options.find(o => o.default); + if (def) + target[key] = def.value; + return def?.value; } } - // And don't forget to persist the settings! - PlainSettings.cloud.settingsSyncVersion = Date.now(); - localStorage.Vencord_settingsDirty = true; - saveSettingsOnFrequentAction(); - VencordNative.settings.set(JSON.stringify(root, null, 4)); - return true; } - }); -} + return v; + } +}); + +SettingsStore.addGlobalChangeListener((_, path) => { + SettingsStore.plain.cloud.settingsSyncVersion = Date.now(); + localStorage.Vencord_settingsDirty = true; + saveSettingsOnFrequentAction(); + VencordNative.settings.set(SettingsStore.plain, path); +}); /** * Same as {@link Settings} but unproxied. You should treat this as readonly, @@ -192,7 +179,7 @@ export const PlainSettings = settings; * the updated settings to disk. * This recursively proxies objects. If you need the object non proxied, use {@link PlainSettings} */ -export const Settings = makeProxy(settings); +export const Settings = SettingsStore.store; /** * Settings hook for React components. Returns a smart settings @@ -205,42 +192,21 @@ export const Settings = makeProxy(settings); export function useSettings(paths?: UseSettings[]) { const [, forceUpdate] = React.useReducer(() => ({}), {}); - const onUpdate: SubscriptionCallback = paths - ? (value, path) => paths.includes(path as UseSettings) && forceUpdate() - : forceUpdate; - React.useEffect(() => { - subscriptions.add(onUpdate); - return () => void subscriptions.delete(onUpdate); + if (paths) { + paths.forEach(p => SettingsStore.addChangeListener(p, forceUpdate)); + return () => paths.forEach(p => SettingsStore.removeChangeListener(p, forceUpdate)); + } else { + SettingsStore.addGlobalChangeListener(forceUpdate); + return () => SettingsStore.removeGlobalChangeListener(forceUpdate); + } }, []); - return Settings; -} - -// Resolves a possibly nested prop in the form of "some.nested.prop" to type of T.some.nested.prop -type ResolvePropDeep = P extends "" ? T : - P extends `${infer Pre}.${infer Suf}` ? - Pre extends keyof T ? ResolvePropDeep : never : P extends keyof T ? T[P] : never; - -/** - * Add a settings listener that will be invoked whenever the desired setting is updated - * @param path Path to the setting that you want to watch, for example "plugins.Unindent.enabled" will fire your callback - * whenever Unindent is toggled. Pass an empty string to get notified for all changes - * @param onUpdate Callback function whenever a setting matching path is updated. It gets passed the new value and the path - * to the updated setting. This path will be the same as your path argument, unless it was an empty string. - * - * @example addSettingsListener("", (newValue, path) => console.log(`${path} is now ${newValue}`)) - * addSettingsListener("plugins.Unindent.enabled", v => console.log("Unindent is now", v ? "enabled" : "disabled")) - */ -export function addSettingsListener(path: Path, onUpdate: (newValue: Settings[Path], path: Path) => void): void; -export function addSettingsListener(path: Path, onUpdate: (newValue: Path extends "" ? any : ResolvePropDeep, path: Path extends "" ? string : Path) => void): void; -export function addSettingsListener(path: string, onUpdate: (newValue: any, path: string) => void) { - (onUpdate as SubscriptionCallback)._path = path; - subscriptions.add(onUpdate); + return SettingsStore.store; } export function migratePluginSettings(name: string, ...oldNames: string[]) { - const { plugins } = settings; + const { plugins } = SettingsStore.plain; if (name in plugins) return; for (const oldName of oldNames) { @@ -248,14 +214,18 @@ export function migratePluginSettings(name: string, ...oldNames: string[]) { logger.info(`Migrating settings from old name ${oldName} to ${name}`); plugins[name] = plugins[oldName]; delete plugins[oldName]; - VencordNative.settings.set(JSON.stringify(settings, null, 4)); + SettingsStore.markAsChanged(); break; } } } -export function definePluginSettings>(def: D, checks?: C) { - const definedSettings: DefinedSettings = { +export function definePluginSettings< + Def extends SettingsDefinition, + Checks extends SettingsChecks, + PrivateSettings extends object = {} +>(def: Def, checks?: Checks) { + const definedSettings: DefinedSettings = { get store() { if (!definedSettings.pluginName) throw new Error("Cannot access settings before plugin is initialized"); return Settings.plugins[definedSettings.pluginName] as any; @@ -264,9 +234,14 @@ export function definePluginSettings `plugins.${definedSettings.pluginName}.${name}`) as UseSettings[] ).plugins[definedSettings.pluginName] as any, def, - checks: checks ?? {}, + checks: checks ?? {} as any, pluginName: "", + + withPrivateSettings() { + return this as DefinedSettings; + } }; + return definedSettings; } diff --git a/src/api/SettingsStore.ts b/src/api/SettingsStore.ts deleted file mode 100644 index d9369a956..000000000 --- a/src/api/SettingsStore.ts +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Vencord, a modification for Discord's desktop app - * Copyright (c) 2023 Vendicated and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . -*/ - -import { proxyLazy } from "@utils/lazy"; -import { Logger } from "@utils/Logger"; -import { findModuleId, wreq } from "@webpack"; - -import { Settings } from "./Settings"; - -interface Setting { - /** - * Get the setting value - */ - getSetting(): T; - /** - * Update the setting value - * @param value The new value - */ - updateSetting(value: T | ((old: T) => T)): Promise; - /** - * React hook for automatically updating components when the setting is updated - */ - useSetting(): T; - settingsStoreApiGroup: string; - settingsStoreApiName: string; -} - -const SettingsStores: Array> | undefined = proxyLazy(() => { - const modId = findModuleId('"textAndImages","renderSpoilers"'); - if (modId == null) return new Logger("SettingsStoreAPI").error("Didn't find stores module."); - - const mod = wreq(modId); - if (mod == null) return; - - return Object.values(mod).filter((s: any) => s?.settingsStoreApiGroup) as any; -}); - -/** - * Get the store for a setting - * @param group The setting group - * @param name The name of the setting - */ -export function getSettingStore(group: string, name: string): Setting | undefined { - if (!Settings.plugins.SettingsStoreAPI.enabled) throw new Error("Cannot use SettingsStoreAPI without setting as dependency."); - - return SettingsStores?.find(s => s?.settingsStoreApiGroup === group && s?.settingsStoreApiName === name); -} - -/** - * getSettingStore but lazy - */ -export function getSettingStoreLazy(group: string, name: string) { - return proxyLazy(() => getSettingStore(group, name)); -} diff --git a/src/api/Styles.ts b/src/api/Styles.ts index 6b189cab8..6b0ac2cdf 100644 --- a/src/api/Styles.ts +++ b/src/api/Styles.ts @@ -141,7 +141,7 @@ export const compileStyle = (style: Style) => { */ export const classNameToSelector = (name: string, prefix = "") => name.split(" ").map(n => `.${prefix}${n}`).join(""); -type ClassNameFactoryArg = string | string[] | Record; +type ClassNameFactoryArg = string | string[] | Record | false | null | undefined | 0 | ""; /** * @param prefix The prefix to add to each class, defaults to `""` * @returns A classname generator function @@ -154,9 +154,9 @@ type ClassNameFactoryArg = string | string[] | Record; export const classNameFactory = (prefix: string = "") => (...args: ClassNameFactoryArg[]) => { const classNames = new Set(); for (const arg of args) { - if (typeof arg === "string") classNames.add(arg); + if (arg && typeof arg === "string") classNames.add(arg); else if (Array.isArray(arg)) arg.forEach(name => classNames.add(name)); - else if (typeof arg === "object") Object.entries(arg).forEach(([name, value]) => value && classNames.add(name)); + else if (arg && typeof arg === "object") Object.entries(arg).forEach(([name, value]) => value && classNames.add(name)); } return Array.from(classNames, name => prefix + name).join(" "); }; diff --git a/src/api/index.ts b/src/api/index.ts index f2c47e559..5dca63105 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -17,6 +17,7 @@ */ import * as $Badges from "./Badges"; +import * as $ChatButtons from "./ChatButtons"; import * as $Commands from "./Commands"; import * as $ContextMenu from "./ContextMenu"; import * as $DataStore from "./DataStore"; @@ -29,7 +30,6 @@ import * as $Notices from "./Notices"; import * as $Notifications from "./Notifications"; import * as $ServerList from "./ServerList"; import * as $Settings from "./Settings"; -import * as $SettingsStore from "./SettingsStore"; import * as $Styles from "./Styles"; /** @@ -91,10 +91,6 @@ export const MemberListDecorators = $MemberListDecorators; * An API allowing you to persist data */ export const Settings = $Settings; -/** - * An API allowing you to read, manipulate and automatically update components based on Discord settings - */ -export const SettingsStore = $SettingsStore; /** * An API allowing you to dynamically load styles * a @@ -109,3 +105,8 @@ export const Notifications = $Notifications; * An api allowing you to patch and add/remove items to/from context menus */ export const ContextMenu = $ContextMenu; + +/** + * An API allowing you to add buttons to the chat input + */ +export const ChatButtons = $ChatButtons; diff --git a/src/components/CodeBlock.tsx b/src/components/CodeBlock.tsx new file mode 100644 index 000000000..41c5ef0c1 --- /dev/null +++ b/src/components/CodeBlock.tsx @@ -0,0 +1,21 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2023 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { findByPropsLazy } from "@webpack"; +import { Parser } from "@webpack/common"; + +const CodeContainerClasses = findByPropsLazy("markup", "codeContainer"); + +/** + * Renders code in a Discord codeblock + */ +export function CodeBlock(props: { content?: string, lang: string; }) { + return ( +
+ {Parser.defaultRules.codeBlock.react(props, null, {})} +
+ ); +} diff --git a/src/components/ExpandableHeader.css b/src/components/ExpandableHeader.css new file mode 100644 index 000000000..14e291b06 --- /dev/null +++ b/src/components/ExpandableHeader.css @@ -0,0 +1,12 @@ +.vc-expandableheader-center-flex { + display: flex; + justify-items: center; + align-items: center; +} + +.vc-expandableheader-btn { + all: unset; + cursor: pointer; + width: 24px; + height: 24px; +} diff --git a/src/components/ExpandableHeader.tsx b/src/components/ExpandableHeader.tsx new file mode 100644 index 000000000..1cbce4f2e --- /dev/null +++ b/src/components/ExpandableHeader.tsx @@ -0,0 +1,108 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2023 Vendicated and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +import { classNameFactory } from "@api/Styles"; +import { Text, Tooltip, useState } from "@webpack/common"; +export const cl = classNameFactory("vc-expandableheader-"); +import "./ExpandableHeader.css"; + +export interface ExpandableHeaderProps { + onMoreClick?: () => void; + moreTooltipText?: string; + onDropDownClick?: (state: boolean) => void; + defaultState?: boolean; + headerText: string; + children: React.ReactNode; + buttons?: React.ReactNode[]; +} + +export default function ExpandableHeader({ children, onMoreClick, buttons, moreTooltipText, defaultState = false, onDropDownClick, headerText }: ExpandableHeaderProps) { + const [showContent, setShowContent] = useState(defaultState); + + return ( + <> +
+ + {headerText} + + +
+ { + buttons ?? null + } + + { + onMoreClick && // only show more button if callback is provided + + {tooltipProps => ( + + )} + + } + + + + {tooltipProps => ( + + )} + +
+
+ {showContent && children} + + ); +} diff --git a/src/components/Icons.tsx b/src/components/Icons.tsx index 4227fcea2..2eb83d4ef 100644 --- a/src/components/Icons.tsx +++ b/src/components/Icons.tsx @@ -28,8 +28,8 @@ interface BaseIconProps extends IconProps { interface IconProps extends SVGProps { className?: string; - height?: number; - width?: number; + height?: string | number; + width?: string | number; } function Icon({ height = 24, width = 24, className, children, viewBox, ...svgProps }: PropsWithChildren) { @@ -97,7 +97,7 @@ export function OpenExternalIcon(props: IconProps) { > @@ -121,9 +121,13 @@ export function InfoIcon(props: IconProps) { - + ); } @@ -139,10 +143,150 @@ export function OwnerCrownIcon(props: IconProps) { > ); } + +/** + * Discord's screenshare icon, as seen in the connection panel + */ +export function ScreenshareIcon(props: IconProps) { + return ( + + + + ); +} + +export function ImageVisible(props: IconProps) { + return ( + + + + ); +} + +export function ImageInvisible(props: IconProps) { + return ( + + + + ); +} + +export function Microphone(props: IconProps) { + return ( + + + + + ); +} + +export function CogWheel(props: IconProps) { + return ( + + + + ); +} + +export function ReplyIcon(props: IconProps) { + return ( + + + + ); +} + +export function DeleteIcon(props: IconProps) { + return ( + + + + + ); +} + +export function PlusIcon(props: IconProps) { + return ( + + + + ); +} + +export function NoEntrySignIcon(props: IconProps) { + return ( + + + + + ); +} diff --git a/src/components/PluginSettings/ContributorModal.tsx b/src/components/PluginSettings/ContributorModal.tsx new file mode 100644 index 000000000..82c230259 --- /dev/null +++ b/src/components/PluginSettings/ContributorModal.tsx @@ -0,0 +1,113 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2023 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import "./contributorModal.css"; + +import { useSettings } from "@api/Settings"; +import { classNameFactory } from "@api/Styles"; +import ErrorBoundary from "@components/ErrorBoundary"; +import { DevsById } from "@utils/constants"; +import { fetchUserProfile, getTheme, Theme } from "@utils/discord"; +import { ModalContent, ModalRoot, openModal } from "@utils/modal"; +import { Forms, MaskedLink, showToast, useEffect, useMemo, UserProfileStore, useStateFromStores } from "@webpack/common"; +import { User } from "discord-types/general"; + +import Plugins from "~plugins"; + +import { PluginCard } from "."; + +const WebsiteIconDark = "/assets/e1e96d89e192de1997f73730db26e94f.svg"; +const WebsiteIconLight = "/assets/730f58bcfd5a57a5e22460c445a0c6cf.svg"; +const GithubIconLight = "/assets/3ff98ad75ac94fa883af5ed62d17c459.svg"; +const GithubIconDark = "/assets/6a853b4c87fce386cbfef4a2efbacb09.svg"; + +const cl = classNameFactory("vc-author-modal-"); + +export function openContributorModal(user: User) { + openModal(modalProps => + + + + + + + + ); +} + +function GithubIcon() { + const src = getTheme() === Theme.Light ? GithubIconLight : GithubIconDark; + return GitHub; +} + +function WebsiteIcon() { + const src = getTheme() === Theme.Light ? WebsiteIconLight : WebsiteIconDark; + return Website; +} + +function ContributorModal({ user }: { user: User; }) { + useSettings(); + + const profile = useStateFromStores([UserProfileStore], () => UserProfileStore.getUserProfile(user.id)); + + useEffect(() => { + if (!profile && !user.bot && user.id) + fetchUserProfile(user.id); + }, [user.id]); + + const githubName = profile?.connectedAccounts?.find(a => a.type === "github")?.name; + const website = profile?.connectedAccounts?.find(a => a.type === "domain")?.name; + + const plugins = useMemo(() => { + const allPlugins = Object.values(Plugins); + const pluginsByAuthor = DevsById[user.id] + ? allPlugins.filter(p => p.authors.includes(DevsById[user.id])) + : allPlugins.filter(p => p.authors.some(a => a.name === user.username)); + + return pluginsByAuthor + .filter(p => !p.name.endsWith("API")) + .sort((a, b) => Number(a.required ?? false) - Number(b.required ?? false)); + }, [user.id, user.username]); + + return ( + <> +
+ + {user.username} + +
+ {website && ( + + + + )} + {githubName && ( + + + + )} +
+
+ +
+ {plugins.map(p => + showToast("Restart to apply changes!")} + /> + )} +
+ + ); +} diff --git a/src/components/PluginSettings/PluginModal.tsx b/src/components/PluginSettings/PluginModal.tsx index 1818a8bcf..34de43c2d 100644 --- a/src/components/PluginSettings/PluginModal.tsx +++ b/src/components/PluginSettings/PluginModal.tsx @@ -22,12 +22,11 @@ import ErrorBoundary from "@components/ErrorBoundary"; import { Flex } from "@components/Flex"; import { proxyLazy } from "@utils/lazy"; import { Margins } from "@utils/margins"; -import { classes } from "@utils/misc"; +import { classes, isObjectEmpty } from "@utils/misc"; import { ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, ModalSize } from "@utils/modal"; -import { LazyComponent } from "@utils/react"; import { OptionType, Plugin } from "@utils/types"; -import { findByCode, findByPropsLazy } from "@webpack"; -import { Button, FluxDispatcher, Forms, React, Text, Tooltip, UserStore, UserUtils } from "@webpack/common"; +import { findByPropsLazy, findComponentByCodeLazy } from "@webpack"; +import { Button, Clickable, FluxDispatcher, Forms, React, Text, Tooltip, UserStore, UserUtils } from "@webpack/common"; import { User } from "discord-types/general"; import { Constructor } from "type-fest"; @@ -40,8 +39,9 @@ import { SettingSliderComponent, SettingTextComponent } from "./components"; +import { openContributorModal } from "./ContributorModal"; -const UserSummaryItem = LazyComponent(() => findByCode("defaultRenderUser", "showDefaultAvatarsForNullUsers")); +const UserSummaryItem = findComponentByCodeLazy("defaultRenderUser", "showDefaultAvatarsForNullUsers"); const AvatarStyles = findByPropsLazy("moreUsers", "emptyUser", "avatarContainer", "clickableAvatar"); const UserRecord: Constructor> = proxyLazy(() => UserStore.getCurrentUser().constructor) as any; @@ -50,11 +50,12 @@ interface PluginModalProps extends ModalProps { onRestartNeeded(): void; } -/** To stop discord making unwanted requests... */ -function makeDummyUser(user: { name: string, id: BigInt; }) { +function makeDummyUser(user: { username: string; id?: string; avatar?: string; }) { const newUser = new UserRecord({ - username: user.name, - id: generateId(), + username: user.username, + id: user.id ?? generateId(), + avatar: user.avatar, + /** To stop discord making unwanted requests... */ bot: true, }); FluxDispatcher.dispatch({ @@ -86,14 +87,16 @@ export default function PluginModal({ plugin, onRestartNeeded, onClose, transiti const canSubmit = () => Object.values(errors).every(e => !e); - const hasSettings = Boolean(pluginSettings && plugin.options); + const hasSettings = Boolean(pluginSettings && plugin.options && !isObjectEmpty(plugin.options)); React.useEffect(() => { (async () => { for (const user of plugin.authors.slice(0, 6)) { const author = user.id - ? await UserUtils.fetchUser(`${user.id}`).catch(() => makeDummyUser(user)) - : makeDummyUser(user); + ? await UserUtils.getUser(`${user.id}`) + .catch(() => makeDummyUser({ username: user.name })) + : makeDummyUser({ username: user.name }); + setAuthors(a => [...a, author]); } })(); @@ -198,6 +201,19 @@ export default function PluginModal({ plugin, onRestartNeeded, onClose, transiti showDefaultAvatarsForNullUsers showUserPopout renderMoreUsers={renderMoreUsers} + renderUser={(user: User) => ( + openContributorModal(user)} + > + {user.username} + + )} /> @@ -210,7 +226,7 @@ export default function PluginModal({ plugin, onRestartNeeded, onClose, transiti )} - + Settings {renderSettings()} @@ -221,7 +237,7 @@ export default function PluginModal({ plugin, onRestartNeeded, onClose, transiti