Skip to content

Commit

Permalink
Fix: Null openItem, use bd-open-path instead
Browse files Browse the repository at this point in the history
- Fixes an issue that occured starting with BetterDiscord 1.10.0 resulting
  in an inability to "open" theme or plugin directories to upload new files.
  (Reported by @Spectre-856)
- Added a simple preselection logic for the filetype to the file chooser.
- Adjusted eslint checks for declarations in case statements.
  • Loading branch information
tsukasa committed Mar 15, 2024
1 parent c4d859c commit aced1e5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"keyword-spacing": "error",
"new-cap": ["error", {"newIsCap": true}],
"no-array-constructor": "error",
"no-case-declarations": "warn",
"no-caller": "error",
"no-console": "error",
"no-duplicate-imports": "error",
Expand Down
2 changes: 1 addition & 1 deletion assets/chrome/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "__MSG_extName__",
"version": "1.9.5.20231111",
"version": "1.10.0.20240315",
"description": "__MSG_extDesc__",
"homepage_url": "https://github.com/tsukasa/BdBrowser",
"icons": {
Expand Down
16 changes: 1 addition & 15 deletions frontend/src/app_shims/electron.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import DOM from "common/dom";
import fs from "node_shims/fs";
import ipcRenderer from "modules/ipcrenderer";

ipcRenderer.initialize();
Expand All @@ -16,19 +14,7 @@ export const remote = {
};

export const shell = {
openItem: item => {
const inputEl = DOM.createElement("input", {type: "file", multiple: "multiple"});
inputEl.addEventListener("change", () => {
for (const file of inputEl.files) {
const reader = new FileReader();
reader.onload = () => {
fs.writeFileSync(`AppData/BetterDiscord/${item.split("/").pop()}/${file.name}`, new Uint8Array(reader.result));
};
reader.readAsArrayBuffer(file);
}
});
inputEl.click();
},
openItem: () => {},
openExternal: () => {}
};

Expand Down
36 changes: 35 additions & 1 deletion frontend/src/modules/ipcrenderer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import DiscordModules from "modules/discordmodules";
import Logger from "common/logger";
import DOM from "common/dom";
import fs from "node_shims/fs";

// https://developer.mozilla.org/en/docs/Web/API/Page_Visibility_API
const [hidden, visibilityChange] = (() => {
Expand Down Expand Up @@ -78,7 +80,39 @@ export default class IPCRenderer {
case "bd-relaunch-app":
document.location.reload();
break;

case "bd-open-path":
// In case there is more than one argument, we cannot deal with this.
if (args.length !== 1) {
Logger.log("IPCRenderer", "IPCRenderer bd-open-path called:", args);
break;
}
// If this becomes a more prominent issue, a proper implementation might be required...
const pathElement = args[0].split("/").pop();

Check warning on line 90 in frontend/src/modules/ipcrenderer.js

View workflow job for this annotation

GitHub Actions / build

Unexpected lexical declaration in case block

Check warning on line 90 in frontend/src/modules/ipcrenderer.js

View workflow job for this annotation

GitHub Actions / build

Unexpected lexical declaration in case block
let acceptedFileTypes = "*.*";

Check warning on line 91 in frontend/src/modules/ipcrenderer.js

View workflow job for this annotation

GitHub Actions / build

Unexpected lexical declaration in case block

Check warning on line 91 in frontend/src/modules/ipcrenderer.js

View workflow job for this annotation

GitHub Actions / build

Unexpected lexical declaration in case block
if (pathElement !== "themes" && pathElement !== "plugins") {
Logger.log("IPCRenderer", "IPCRenderer bd-open-path called with unsupported path type:", args);
break;
}
switch (pathElement.toLowerCase()) {
case "themes":
acceptedFileTypes = ".theme.css";
break;
case "plugins":
acceptedFileTypes = ".plugin.js";
break;
}
const inputEl = DOM.createElement("input", {type: "file", multiple: "multiple", accept: acceptedFileTypes});

Check warning on line 104 in frontend/src/modules/ipcrenderer.js

View workflow job for this annotation

GitHub Actions / build

Unexpected lexical declaration in case block

Check warning on line 104 in frontend/src/modules/ipcrenderer.js

View workflow job for this annotation

GitHub Actions / build

Unexpected lexical declaration in case block
inputEl.addEventListener("change", () => {
for (const file of inputEl.files) {
const reader = new FileReader();
reader.onload = () => {
fs.writeFileSync(`AppData/BetterDiscord/${pathElement}/${file.name}`, new Uint8Array(reader.result));
};
reader.readAsArrayBuffer(file);
}
});
inputEl.click();
break;
default:
Logger.log("IPCRenderer", "IPCRenderer SEND:", event, args);
}
Expand Down

0 comments on commit aced1e5

Please sign in to comment.