From c6c54bf62085d182f07a9bc1870ebf998dd74316 Mon Sep 17 00:00:00 2001 From: Zerebos Date: Wed, 21 Feb 2024 19:05:28 -0500 Subject: [PATCH] Use openPath workaround on windows Fixes #1700 --- common/constants/ipcevents.js | 3 ++- injector/src/modules/betterdiscord.js | 4 +++- injector/src/modules/ipc.js | 9 ++++++++- injector/webpack.config.js | 3 ++- renderer/src/modules/addonmanager.js | 3 ++- renderer/src/modules/ipc.js | 4 ++++ renderer/src/ui/settings/addonlist.jsx | 5 ++--- 7 files changed, 23 insertions(+), 8 deletions(-) diff --git a/common/constants/ipcevents.js b/common/constants/ipcevents.js index 6aa2997b..7b52f3c4 100644 --- a/common/constants/ipcevents.js +++ b/common/constants/ipcevents.js @@ -16,4 +16,5 @@ export const WINDOW_SIZE = "bd-window-size"; export const DEVTOOLS_WARNING = "bd-remove-devtools-message"; export const OPEN_DIALOG = "bd-open-dialog"; export const REGISTER_PRELOAD = "bd-register-preload"; -export const GET_ACCENT_COLOR = "bd-get-accent-color"; \ No newline at end of file +export const GET_ACCENT_COLOR = "bd-get-accent-color"; +export const OPEN_PATH = "bd-open-path"; \ No newline at end of file diff --git a/injector/src/modules/betterdiscord.js b/injector/src/modules/betterdiscord.js index cd455ee9..d9481ac3 100644 --- a/injector/src/modules/betterdiscord.js +++ b/injector/src/modules/betterdiscord.js @@ -1,6 +1,7 @@ import fs from "fs"; import path from "path"; import electron from "electron"; +import {spawn} from "child_process"; import ReactDevTools from "./reactdevtools"; import * as IPCEvents from "common/constants/ipcevents"; @@ -97,7 +98,8 @@ export default class BetterDiscord { electron.app.exit(); } if (result.response === 1) { - electron.shell.openPath(path.join(dataPath, "plugins")); + if (process.platform === "win32") spawn("explorer.exe", [path.join(dataPath, "plugins")]); + else electron.shell.openPath(path.join(dataPath, "plugins")); } }); hasCrashed = false; diff --git a/injector/src/modules/ipc.js b/injector/src/modules/ipc.js index 0de96f9a..1d2f1a46 100644 --- a/injector/src/modules/ipc.js +++ b/injector/src/modules/ipc.js @@ -1,4 +1,5 @@ -import {ipcMain as ipc, BrowserWindow, app, dialog, systemPreferences} from "electron"; +import {spawn} from "child_process"; +import {ipcMain as ipc, BrowserWindow, app, dialog, systemPreferences, shell} from "electron"; import * as IPCEvents from "common/constants/ipcevents"; @@ -32,6 +33,11 @@ const getPath = (event, pathReq) => { event.returnValue = returnPath; }; +const openPath = (event, path) => { + if (process.platform === "win32") spawn("explorer.exe", [path]); + else shell.openPath(path); +}; + const relaunch = () => { app.quit(); app.relaunch(); @@ -140,6 +146,7 @@ export default class IPCMain { static registerEvents() { try { ipc.on(IPCEvents.GET_PATH, getPath); + ipc.on(IPCEvents.OPEN_PATH, openPath); ipc.on(IPCEvents.RELAUNCH, relaunch); ipc.on(IPCEvents.OPEN_DEVTOOLS, openDevTools); ipc.on(IPCEvents.CLOSE_DEVTOOLS, closeDevTools); diff --git a/injector/webpack.config.js b/injector/webpack.config.js index 5a0f1854..38b5e4fe 100644 --- a/injector/webpack.config.js +++ b/injector/webpack.config.js @@ -19,7 +19,8 @@ module.exports = (env, argv) => ({ rimraf: `require("rimraf")`, yauzl: `require("yauzl")`, mkdirp: `require("mkdirp")`, - module: `require("module")` + module: `require("module")`, + child_process: `require("child_process")`, }, resolve: { extensions: [".js"], diff --git a/renderer/src/modules/addonmanager.js b/renderer/src/modules/addonmanager.js index 365445b2..a88a5262 100644 --- a/renderer/src/modules/addonmanager.js +++ b/renderer/src/modules/addonmanager.js @@ -11,13 +11,14 @@ import Events from "./emitter"; import DataStore from "./datastore"; import React from "./react"; import Strings from "./strings"; +import ipc from "./ipc"; import AddonEditor from "@ui/misc/addoneditor"; import FloatingWindows from "@ui/floatingwindows"; import Toasts from "@ui/toasts"; -const openItem = shell.openItem || shell.openPath; +const openItem = ipc.openPath; const splitRegex = /[^\S\r\n]*?\r?(?:\r\n|\n)[^\S\r\n]*?\*[^\S\r\n]?/; const escapedAtRegex = /^\\@/; diff --git a/renderer/src/modules/ipc.js b/renderer/src/modules/ipc.js index bb937b05..2f72d1df 100644 --- a/renderer/src/modules/ipc.js +++ b/renderer/src/modules/ipc.js @@ -60,4 +60,8 @@ export default new class IPCRenderer { getSystemAccentColor() { return ipc.invoke(IPCEvents.GET_ACCENT_COLOR); } + + openPath(path) { + return ipc.send(IPCEvents.OPEN_PATH, path); + } }; \ No newline at end of file diff --git a/renderer/src/ui/settings/addonlist.jsx b/renderer/src/ui/settings/addonlist.jsx index 3d1cfec2..3b28d427 100644 --- a/renderer/src/ui/settings/addonlist.jsx +++ b/renderer/src/ui/settings/addonlist.jsx @@ -3,6 +3,7 @@ import Strings from "@modules/strings"; import Events from "@modules/emitter"; import DataStore from "@modules/datastore"; import DiscordModules from "@modules/discordmodules"; +import ipc from "@modules/ipc"; import SettingsTitle from "./title"; import AddonCard from "./addoncard"; @@ -37,9 +38,7 @@ const buildDirectionOptions = () => [ function openFolder(folder) { - const shell = require("electron").shell; - const open = shell.openItem || shell.openPath; - open(folder); + ipc.openPath(folder); } function blankslate(type, onClick) {