Skip to content

Commit

Permalink
Fixed a severe issue that would cause a crash
Browse files Browse the repository at this point in the history
  • Loading branch information
SammCheese committed Jan 7, 2023
1 parent d371abb commit d806df1
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 47 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"discordID": "372148345894076416",
"github": "SammCheese"
},
"version": "1.1.0",
"version": "1.1.1",
"updater": {
"type": "github",
"id": "SammCheese/invisible-chat"
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "invisible-chat",
"version": "1.0.1",
"version": "1.1.1",
"description": "Encrypt your Discord Messages",
"engines": {
"node": ">=14.0.0"
Expand All @@ -23,7 +23,6 @@
"license": "ISC",
"devDependencies": {
"@electron/asar": "^3.2.1",
"@fal-works/esbuild-plugin-global-externals": "^2.1.2",
"@types/node": "^18.11.2",
"@types/react": "^18.0.26",
"@typescript-eslint/eslint-plugin": "^5.40.1",
Expand All @@ -34,7 +33,7 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-react": "^7.31.10",
"prettier": "^2.8.1",
"replugged": "4.0.0-beta0.19",
"replugged": "4.0.0-beta0.20",
"tsx": "^3.10.3",
"typescript": "^4.8.4"
}
Expand Down
14 changes: 4 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 39 additions & 23 deletions scripts/build.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,49 @@
import esbuild from "esbuild";
import { globalExternals } from "@fal-works/esbuild-plugin-global-externals";
import path, { join } from "path";
import fs, { existsSync, rmSync } from "fs";
import _manifest from "../manifest.json";
import { Plugin } from "replugged/dist/types/addon";
import { PluginManifest } from "replugged/dist/types/addon";

const manifest: Plugin = _manifest;
const manifest: PluginManifest = _manifest;

const NODE_VERSION = "14";
const CHROME_VERSION = "91";

const globalModules = {
replugged: {
varName: "replugged",
namedExports: [
"Injector",
"webpack",
"common",
"notices",
"commands",
"settings",
"quickCSS",
"themes",
"ignition",
"plugins",
"util",
"components",
],
defaultExport: true,
const globalModules: esbuild.Plugin = {
name: "globalModules",
setup: (build) => {
build.onResolve({ filter: /^replugged.+$/ }, (args) => {
if (args.kind !== "import-statement") return;

return {
errors: [
{
text: `Importing from a path (${args.path}) is not supported. Instead, please import from "replugged" and destructure the required modules.`,
},
],
};
});

build.onResolve({ filter: /^replugged$/ }, (args) => {
if (args.kind !== "import-statement") return;

return {
path: args.path,
namespace: "replugged",
};
});

build.onLoad(
{
filter: /.*/,
namespace: "replugged",
},
() => {
return {
contents: "module.exports = window.replugged",
};
},
);
},
};

Expand Down Expand Up @@ -86,7 +102,7 @@ if ("renderer" in manifest) {
target: `chrome${CHROME_VERSION}`,
outfile: "dist/renderer.js",
format: "esm" as esbuild.Format,
plugins: [globalExternals(globalModules), install],
plugins: [globalModules, install],
}),
);

Expand Down Expand Up @@ -132,7 +148,7 @@ if ("plaintextPatches" in manifest) {
target: `chrome${CHROME_VERSION}`,
outfile: "dist/plaintextPatches.js",
format: "esm" as esbuild.Format,
plugins: [globalExternals(globalModules), install],
plugins: [globalModules, install],
}),
);

Expand Down
4 changes: 2 additions & 2 deletions scripts/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import asar from "@electron/asar";
import { readFileSync } from "fs";
import { Plugin } from "replugged/dist/types/addon";
import { PluginManifest } from "replugged/dist/types/addon";

const manifest = JSON.parse(readFileSync("manifest.json", "utf-8")) as Plugin;
const manifest = JSON.parse(readFileSync("manifest.json", "utf-8")) as PluginManifest;
const outputName = `${manifest.id}.asar`;

asar.createPackage("dist", outputName);
1 change: 0 additions & 1 deletion src/components/DecryptionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { buildEmbed, decrypt } from "../index";

const { React } = common;
const { Button, Modal } = components;
// @ts-expect-error Package doesnt include it yet
const { closeModal, openModal } = common.modal;

const FormText = components.FormText.DEFAULT;
Expand Down
3 changes: 1 addition & 2 deletions src/components/EncryptionModal.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { common, components, webpack } from "replugged";

import { encrypt } from "../index";

const { React } = common;
// @ts-expect-error Package not updated yet
const { closeModal, openModal } = common.modal;
const { Button, SwitchItem, Modal, Divider } = components;

const FormText = components.FormText.DEFAULT;

const rawTextInput: any = webpack.waitForModule(
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { cleanupEmbed, getEmbed, updateMessage } from "./utils";

const getStegCloak: Promise<StegCloakImport> = import(
// @ts-expect-error SHUT UP
"https://unpkg.com/[email protected].1/index.js"
"https://unpkg.com/[email protected].0/index.js"
);

const INV_DETECTION = new RegExp(/( \u200c|\u200d |[\u2060-\u2064])[^\u200b]/);
Expand Down
6 changes: 3 additions & 3 deletions src/plaintextPatches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ const patches: types.PlaintextPatch[] = [
// Minipopover Lock
match:
/.\?(..)\(\{key:"reply",label:.{1,40},icon:.{1,40},channel:(.{1,3}),message:(.{1,3}),onClick:.{1,5}\}\):null/gm,
replace: `$&,$3.content.match(window.invisiblechat.INV_DETECTION)?$1({key:"decrypt",label:"Decrypt Message",icon:window.invisiblechat.popoverIcon,channel:$2,message:$3,onClick:()=>window.invisiblechat.receiver($3)}):null`,
replace: `$&,$3.content.match(window.invisiblechat?.INV_DETECTION)?$1({key:"decrypt",label:"Decrypt Message",icon:window.invisiblechat.popoverIcon,channel:$2,message:$3,onClick:()=>window.invisiblechat.receiver($3)}):null`,
},
{
// Chatbar Lock
match: /,.=.\.activeCommand,.=.\.activeCommandOption,.{0,255},(.)=\[\];/,
replace: "$&;try{$1.push(window.invisiblechat.chatbarLock)}catch{};",
replace: "$&;try{$1.push(window.invisiblechat?.chatbarLock)}catch{};",
},
{
// Message Indicator
match: /var .,.,.=(.)\.className,.=.\.message,.=.\.children,.=.\.content,.=.\.onUpdate/,
replace:
"try{$1?.content[0].match(window.invisiblechat.INV_DETECTION)?$1?.content.push(window.invisiblechat.Indicator):null}catch(e){};$&",
"try{$1?.content[0].match(window.invisiblechat?.INV_DETECTION)?$1?.content.push(window.invisiblechat?.Indicator):null}catch(e){};$&",
},
],
},
Expand Down
1 change: 0 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export function cleanupEmbed(embed: rawDiscordEmbed): DiscordEmbed {
}

export function updateMessage(message: unknown): void {
// @ts-expect-error no type
common.fluxDispatcher.dispatch({
type: "MESSAGE_UPDATE",
message,
Expand Down

0 comments on commit d806df1

Please sign in to comment.