From be22c14356f2e3f3ca2750ba4b11d84efe26716c Mon Sep 17 00:00:00 2001 From: Nick Sarnie Date: Sun, 23 Oct 2016 19:07:21 -0400 Subject: [PATCH] Update Linux support to 0.0.14 Signed-off-by: Nick Sarnie --- Installers/Node/index.js | 25 +++++++++++++++++++++---- lib/BetterDiscord.js | 7 ++++--- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Installers/Node/index.js b/Installers/Node/index.js index 6e335bed..e7b6d084 100644 --- a/Installers/Node/index.js +++ b/Installers/Node/index.js @@ -47,6 +47,9 @@ function install() { _functionCallSplice = 446; _functionSplice = 547; _discordPath = "/Applications/Discord.app/Contents/Resources" // Defaults to Applications directory + } else if (_os == "linux") { + _discordPath = "/opt/DiscordCanary/resources"; + _index = "/app/index.js"; } } console.log("Looking for discord resources at: " + _discordPath); @@ -80,8 +83,12 @@ function install() { asar.extractAll(_discordPath + _appArchive, _discordPath + _appFolder); console.log("Copying BetterDiscord"); - - fs.mkdirSync(_discordPath + "/node_modules/BetterDiscord"); + if(_os == "linux") { + fs.mkdirSync(_discordPath + _appFolder + "/node_modules/BetterDiscord"); + } + else { + fs.mkdirSync(_discordPath + "/node_modules/BetterDiscord"); + } wrench.copyDirSyncRecursive(__dirname + "/BetterDiscord/", _discordPath + _appFolder + "/node_modules/BetterDiscord/", {forceDelete: true}); @@ -99,8 +106,18 @@ function install() { console.log("Injecting index.js"); var data = fs.readFileSync(_discordPath + _index).toString().split("\n"); - data.splice(_importSplice, 0, 'var _betterDiscord = require(\'betterdiscord\');\n'); - data.splice(_functionCallSplice, 0, splice); + + if(_os == "linux") { + data = data.join("\n"); + data = data.replace('var _GPUSettings2 = _interopRequireDefault(_GPUSettings);','var _GPUSettings2 = _interopRequireDefault(_GPUSettings);\n\nvar _betterDiscord = require(\'BetterDiscord\');\n'); + + data = data.replace('mainWindow.setMenuBarVisibility(false);','mainWindow.setMenuBarVisibility(false);\n' + splice + '\n'); + data = data.split("\n"); + + } else { + data.splice(_importSplice, 0, 'var _betterDiscord = require(\'betterdiscord\');\n'); + data.splice(_functionCallSplice, 0, splice); + } fs.writeFile(_discordPath + _index, data.join("\n"), function(err) { if(err) return console.log(err); diff --git a/lib/BetterDiscord.js b/lib/BetterDiscord.js index bf4b1fb0..1b197cd9 100644 --- a/lib/BetterDiscord.js +++ b/lib/BetterDiscord.js @@ -10,7 +10,7 @@ var _fs = require("fs"); var _config = require("./config.json"); -var _utils = require("./utils"); +var _utils; var _utils2; var _bdIpc = require('electron').ipcMain; var _error = false; @@ -79,6 +79,7 @@ function BetterDiscord(mainWindow) { _cfg = _config.cfg; _cfg.version = _config.Core.Version; _cfg.os = process.platform; + _utils = _cfg.os == "linux" ? require("./Utils") : require("./utils"); _utils2 = new _utils.Utils(mainWindow); hook(); createAndCheckData(); @@ -87,7 +88,7 @@ function BetterDiscord(mainWindow) { function createAndCheckData() { getUtils().log("Checking data/cache"); - _cfg.dataPath = (_cfg.os == 'win32' ? process.env.APPDATA : _cfg.os == 'darwin' ? process.env.HOME + '/Library/Preferences' : '/var/local') + '/BetterDiscord/'; + _cfg.dataPath = (_cfg.os == 'win32' ? process.env.APPDATA : _cfg.os == 'darwin' ? process.env.HOME + '/Library/Preferences' : process.env.HOME + '/.config') + '/BetterDiscord/'; _cfg.userFile = _cfg.dataPath + 'user.json'; try { @@ -833,4 +834,4 @@ function exit(reason) { BetterDiscord.prototype.init = function() {}//Compatibility -exports.BetterDiscord = BetterDiscord; \ No newline at end of file +exports.BetterDiscord = BetterDiscord;