Fix Formating
This commit is contained in:
parent
8f5cc2099a
commit
94cedd3e1a
|
@ -11,6 +11,7 @@ const buildInfoFile = path.resolve(appPath, "..", "build_info.json");
|
||||||
|
|
||||||
// Locate data path to find transparency settings
|
// Locate data path to find transparency settings
|
||||||
let dataPath = "";
|
let dataPath = "";
|
||||||
|
if (process.platform === "win32" || process.platform === "darwin") dataPath = path.join(electron.app.getPath("userData"), "..");
|
||||||
if (process.argv.filter((arg) => arg.startsWith("--bd-data-dir")).length > 0)
|
if (process.argv.filter((arg) => arg.startsWith("--bd-data-dir")).length > 0)
|
||||||
dataPath = process.argv.filter((arg) => arg.startsWith("--bd-data-dir"))[0].split("=")[1];
|
dataPath = process.argv.filter((arg) => arg.startsWith("--bd-data-dir"))[0].split("=")[1];
|
||||||
else if (process.platform === "win32" || process.platform === "darwin")
|
else if (process.platform === "win32" || process.platform === "darwin")
|
||||||
|
@ -20,40 +21,40 @@ dataPath = path.join(dataPath, "BetterDiscord") + "/";
|
||||||
|
|
||||||
let hasCrashed = false;
|
let hasCrashed = false;
|
||||||
export default class BetterDiscord {
|
export default class BetterDiscord {
|
||||||
static getWindowPrefs() {
|
static getWindowPrefs() {
|
||||||
if (!fs.existsSync(buildInfoFile)) return {};
|
if (!fs.existsSync(buildInfoFile)) return {};
|
||||||
const buildInfo = __non_webpack_require__(buildInfoFile);
|
const buildInfo = __non_webpack_require__(buildInfoFile);
|
||||||
const prefsFile = path.resolve(dataPath, "data", buildInfo.releaseChannel, "windowprefs.json");
|
const prefsFile = path.resolve(dataPath, "data", buildInfo.releaseChannel, "windowprefs.json");
|
||||||
if (!fs.existsSync(prefsFile)) return {};
|
if (!fs.existsSync(prefsFile)) return {};
|
||||||
return __non_webpack_require__(prefsFile);
|
return __non_webpack_require__(prefsFile);
|
||||||
}
|
|
||||||
|
|
||||||
static getSetting(category, key) {
|
|
||||||
if (this._settings) return this._settings[category]?.[key];
|
|
||||||
|
|
||||||
try {
|
|
||||||
const buildInfo = __non_webpack_require__(buildInfoFile);
|
|
||||||
const settingsFile = path.resolve(dataPath, "data", buildInfo.releaseChannel, "settings.json");
|
|
||||||
this._settings = __non_webpack_require__(settingsFile) ?? {};
|
|
||||||
return this._settings[category]?.[key];
|
|
||||||
}
|
|
||||||
catch (_) {
|
|
||||||
this._settings = {};
|
|
||||||
return this._settings[category]?.[key];
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static ensureDirectories() {
|
static getSetting(category, key) {
|
||||||
if (!fs.existsSync(dataPath)) fs.mkdirSync(dataPath);
|
if (this._settings) return this._settings[category]?.[key];
|
||||||
if (!fs.existsSync(path.join(dataPath, "plugins"))) fs.mkdirSync(path.join(dataPath, "plugins"));
|
|
||||||
if (!fs.existsSync(path.join(dataPath, "themes"))) fs.mkdirSync(path.join(dataPath, "themes"));
|
|
||||||
}
|
|
||||||
|
|
||||||
static async injectRenderer(browserWindow) {
|
try {
|
||||||
const location = path.join(__dirname, "renderer.js");
|
const buildInfo = __non_webpack_require__(buildInfoFile);
|
||||||
if (!fs.existsSync(location)) return; // TODO: cut a fatal log
|
const settingsFile = path.resolve(dataPath, "data", buildInfo.releaseChannel, "settings.json");
|
||||||
const content = fs.readFileSync(location).toString();
|
this._settings = __non_webpack_require__(settingsFile) ?? {};
|
||||||
const success = await browserWindow.webContents.executeJavaScript(`
|
return this._settings[category]?.[key];
|
||||||
|
}
|
||||||
|
catch (_) {
|
||||||
|
this._settings = {};
|
||||||
|
return this._settings[category]?.[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static ensureDirectories() {
|
||||||
|
if (!fs.existsSync(dataPath)) fs.mkdirSync(dataPath);
|
||||||
|
if (!fs.existsSync(path.join(dataPath, "plugins"))) fs.mkdirSync(path.join(dataPath, "plugins"));
|
||||||
|
if (!fs.existsSync(path.join(dataPath, "themes"))) fs.mkdirSync(path.join(dataPath, "themes"));
|
||||||
|
}
|
||||||
|
|
||||||
|
static async injectRenderer(browserWindow) {
|
||||||
|
const location = path.join(__dirname, "renderer.js");
|
||||||
|
if (!fs.existsSync(location)) return; // TODO: cut a fatal log
|
||||||
|
const content = fs.readFileSync(location).toString();
|
||||||
|
const success = await browserWindow.webContents.executeJavaScript(`
|
||||||
(() => {
|
(() => {
|
||||||
try {
|
try {
|
||||||
${content}
|
${content}
|
||||||
|
@ -66,65 +67,65 @@ export default class BetterDiscord {
|
||||||
//# sourceURL=betterdiscord/renderer.js
|
//# sourceURL=betterdiscord/renderer.js
|
||||||
`);
|
`);
|
||||||
|
|
||||||
if (!success) return; // TODO: cut a fatal log
|
if (!success) return; // TODO: cut a fatal log
|
||||||
}
|
|
||||||
|
|
||||||
static setup(browserWindow) {
|
|
||||||
|
|
||||||
// Setup some useful vars to avoid blocking IPC calls
|
|
||||||
try {
|
|
||||||
process.env.DISCORD_RELEASE_CHANNEL = __non_webpack_require__(buildInfoFile).releaseChannel;
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
process.env.DISCORD_RELEASE_CHANNEL = "stable";
|
|
||||||
}
|
}
|
||||||
process.env.DISCORD_PRELOAD = browserWindow.__originalPreload;
|
|
||||||
process.env.DISCORD_APP_PATH = appPath;
|
|
||||||
process.env.DISCORD_USER_DATA = electron.app.getPath("userData");
|
|
||||||
process.env.BETTERDISCORD_DATA_PATH = dataPath;
|
|
||||||
|
|
||||||
// When DOM is available, pass the renderer over the wall
|
static setup(browserWindow) {
|
||||||
browserWindow.webContents.on("dom-ready", () => {
|
|
||||||
if (!hasCrashed) return this.injectRenderer(browserWindow);
|
|
||||||
|
|
||||||
// If a previous crash was detected, show a message explaining why BD isn't there
|
// Setup some useful vars to avoid blocking IPC calls
|
||||||
electron.dialog.showMessageBox({
|
try {
|
||||||
title: "Discord Crashed",
|
process.env.DISCORD_RELEASE_CHANNEL = __non_webpack_require__(buildInfoFile).releaseChannel;
|
||||||
type: "warning",
|
}
|
||||||
message: "Something crashed your Discord Client",
|
catch (e) {
|
||||||
detail: "BetterDiscord has automatically disabled itself just in case. To enable it again, restart Discord or click the button below.\n\nThis may have been caused by a plugin. Try moving all of your plugins outside the plugin folder and see if Discord still crashed.",
|
process.env.DISCORD_RELEASE_CHANNEL = "stable";
|
||||||
buttons: ["Try Again", "Open Plugins Folder", "Cancel"],
|
}
|
||||||
}).then((result)=>{
|
process.env.DISCORD_PRELOAD = browserWindow.__originalPreload;
|
||||||
if (result.response === 0) {
|
process.env.DISCORD_APP_PATH = appPath;
|
||||||
electron.app.relaunch();
|
process.env.DISCORD_USER_DATA = electron.app.getPath("userData");
|
||||||
electron.app.exit();
|
process.env.BETTERDISCORD_DATA_PATH = dataPath;
|
||||||
}
|
|
||||||
if (result.response === 1) {
|
// When DOM is available, pass the renderer over the wall
|
||||||
electron.shell.openPath(path.join(dataPath, "plugins"));
|
browserWindow.webContents.on("dom-ready", () => {
|
||||||
}
|
if (!hasCrashed) return this.injectRenderer(browserWindow);
|
||||||
|
|
||||||
|
// If a previous crash was detected, show a message explaining why BD isn't there
|
||||||
|
electron.dialog.showMessageBox({
|
||||||
|
title: "Discord Crashed",
|
||||||
|
type: "warning",
|
||||||
|
message: "Something crashed your Discord Client",
|
||||||
|
detail: "BetterDiscord has automatically disabled itself just in case. To enable it again, restart Discord or click the button below.\n\nThis may have been caused by a plugin. Try moving all of your plugins outside the plugin folder and see if Discord still crashed.",
|
||||||
|
buttons: ["Try Again", "Open Plugins Folder", "Cancel"],
|
||||||
|
}).then((result)=>{
|
||||||
|
if (result.response === 0) {
|
||||||
|
electron.app.relaunch();
|
||||||
|
electron.app.exit();
|
||||||
|
}
|
||||||
|
if (result.response === 1) {
|
||||||
|
electron.shell.openPath(path.join(dataPath, "plugins"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
hasCrashed = false;
|
||||||
});
|
});
|
||||||
hasCrashed = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
// This is used to alert renderer code to onSwitch events
|
// This is used to alert renderer code to onSwitch events
|
||||||
browserWindow.webContents.on("did-navigate-in-page", () => {
|
browserWindow.webContents.on("did-navigate-in-page", () => {
|
||||||
browserWindow.webContents.send(IPCEvents.NAVIGATE);
|
browserWindow.webContents.send(IPCEvents.NAVIGATE);
|
||||||
});
|
});
|
||||||
|
|
||||||
browserWindow.webContents.on("render-process-gone", () => {
|
browserWindow.webContents.on("render-process-gone", () => {
|
||||||
hasCrashed = true;
|
hasCrashed = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static disableMediaKeys() {
|
static disableMediaKeys() {
|
||||||
if (!BetterDiscord.getSetting("general", "mediaKeys")) return;
|
if (!BetterDiscord.getSetting("general", "mediaKeys")) return;
|
||||||
const originalDisable = electron.app.commandLine.getSwitchValue("disable-features") || "";
|
const originalDisable = electron.app.commandLine.getSwitchValue("disable-features") || "";
|
||||||
electron.app.commandLine.appendSwitch("disable-features", `${originalDisable ? "," : ""}HardwareMediaKeyHandling,MediaSessionService`);
|
electron.app.commandLine.appendSwitch("disable-features", `${originalDisable ? "," : ""}HardwareMediaKeyHandling,MediaSessionService`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BetterDiscord.getSetting("developer", "reactDevTools")) {
|
if (BetterDiscord.getSetting("developer", "reactDevTools")) {
|
||||||
electron.app.whenReady().then(async ()=>{
|
electron.app.whenReady().then(async ()=>{
|
||||||
await ReactDevTools.install(dataPath);
|
await ReactDevTools.install(dataPath);
|
||||||
});
|
});
|
||||||
}
|
}
|
Loading…
Reference in New Issue