Use openPath workaround on windows

Fixes #1700
This commit is contained in:
Zerebos 2024-02-21 19:05:28 -05:00
parent eb522cd645
commit c6c54bf620
7 changed files with 23 additions and 8 deletions

View File

@ -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";
export const GET_ACCENT_COLOR = "bd-get-accent-color";
export const OPEN_PATH = "bd-open-path";

View File

@ -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;

View File

@ -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);

View File

@ -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"],

View File

@ -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 = /^\\@/;

View File

@ -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);
}
};

View File

@ -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) {