add support for linux
This commit is contained in:
parent
d67bf182c5
commit
2b08532e7a
|
@ -0,0 +1,47 @@
|
||||||
|
const fs = require("fs")
|
||||||
|
const fsAsync = fs.promises
|
||||||
|
const yazl = require("yazl")
|
||||||
|
const __path = require("path")
|
||||||
|
|
||||||
|
fs.unlinkSync(__path.join(__dirname, "builds", "lightcord-win32-ia32.zip"))
|
||||||
|
fs.unlinkSync(__path.join(__dirname, "builds", "lightcord-linux-x64.zip"))
|
||||||
|
|
||||||
|
const winZip = new yazl.ZipFile()
|
||||||
|
winZip.outputStream.pipe(fs.createWriteStream(__path.join(__dirname, "builds", "lightcord-win32-ia32.zip")))
|
||||||
|
|
||||||
|
const linuxZip = new yazl.ZipFile()
|
||||||
|
linuxZip.outputStream.pipe(fs.createWriteStream(__path.join(__dirname, "builds", "lightcord-linux-x64.zip")))
|
||||||
|
|
||||||
|
async function processNextDir(dir, zip, bpath, platform){
|
||||||
|
if(!bpath)bpath = dir
|
||||||
|
if(dir.replace(bpath, ""))zip.addEmptyDirectory(dir.replace(bpath, "").slice(1))
|
||||||
|
await Promise.all(fs.readdirSync(dir, {withFileTypes: true})
|
||||||
|
.map(async file => {
|
||||||
|
let path = __path.join(dir, file.name)
|
||||||
|
if(file.isDirectory()){
|
||||||
|
return await processNextDir(path, zip, bpath)
|
||||||
|
}else if(file.isFile()){
|
||||||
|
console.log(file.name)
|
||||||
|
if((file.name.endsWith("_linux.node") && platform === "win") || (file.name.endsWith(".node") && !file.name.endsWith("_linux.node") && platform === "lin")){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let stat = fs.statSync(path)
|
||||||
|
zip.addBuffer(await fsAsync.readFile(path), __path.relative(bpath, path), {
|
||||||
|
mode: stat.mode,
|
||||||
|
mtime: stat.mtime
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
processNextDir(__path.join(__dirname, "builds", "lightcord-win32-ia32"), winZip, undefined, "win")
|
||||||
|
.then(() => {
|
||||||
|
console.log(`Zipped win32.`)
|
||||||
|
winZip.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
processNextDir(__path.join(__dirname, "builds", "lightcord-linux-x64"), linuxZip, undefined, "lin")
|
||||||
|
.then(() => {
|
||||||
|
console.log(`Zipped linux.`)
|
||||||
|
linuxZip.end()
|
||||||
|
})
|
288
build.js
288
build.js
|
@ -1,145 +1,145 @@
|
||||||
const child_process = require("child_process")
|
const child_process = require("child_process")
|
||||||
const path = require("path")
|
const path = require("path")
|
||||||
const terser = require("terser")
|
const terser = require("terser")
|
||||||
const util = require("util")
|
const util = require("util")
|
||||||
|
|
||||||
/** Super noisy if production is on. */
|
/** Super noisy if production is on. */
|
||||||
const production = true
|
const production = true
|
||||||
|
|
||||||
let fs = require("fs")
|
let fs = require("fs")
|
||||||
|
|
||||||
console.log = (...args) => {
|
console.log = (...args) => {
|
||||||
process.stdout.write(Buffer.from(util.formatWithOptions({colors: true}, ...args)+"\n", "binary").toString("utf8"))
|
process.stdout.write(Buffer.from(util.formatWithOptions({colors: true}, ...args)+"\n", "binary").toString("utf8"))
|
||||||
}
|
}
|
||||||
console.info = (...args) => {
|
console.info = (...args) => {
|
||||||
console.log(`\x1b[34m[INFO]\x1b[0m`, ...args)
|
console.log(`\x1b[34m[INFO]\x1b[0m`, ...args)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main(){
|
async function main(){
|
||||||
console.log(__dirname, process.cwd())
|
console.log(__dirname, process.cwd())
|
||||||
|
|
||||||
console.info("Reseting existent directory...")
|
console.info("Reseting existent directory...")
|
||||||
await fs.promises.rmdir("./distApp", {"recursive": true})
|
await fs.promises.rmdir("./distApp", {"recursive": true})
|
||||||
await fs.promises.mkdir(__dirname+"/distApp/dist", {"recursive": true})
|
await fs.promises.mkdir(__dirname+"/distApp/dist", {"recursive": true})
|
||||||
|
|
||||||
console.info("Executing command `npm run compile`")
|
console.info("Executing command `npm run compile`")
|
||||||
//console.log(child_process.execSync("npm run compile", {encoding: "binary"}))
|
//console.log(child_process.execSync("npm run compile", {encoding: "binary"}))
|
||||||
|
|
||||||
let startDir = path.join(__dirname, "./dist")
|
let startDir = path.join(__dirname, "./dist")
|
||||||
let newDir = path.join(__dirname, "./distApp/dist")
|
let newDir = path.join(__dirname, "./distApp/dist")
|
||||||
console.info("No error detected. Copying files from "+startDir+".")
|
console.info("No error detected. Copying files from "+startDir+".")
|
||||||
await fs.promises.mkdir(startDir, {recursive: true})
|
await fs.promises.mkdir(startDir, {recursive: true})
|
||||||
|
|
||||||
async function processNextDir(folder, folders, predicate, compile){
|
async function processNextDir(folder, folders, predicate, compile){
|
||||||
for(let file of fs.readdirSync(folder, {withFileTypes: true})){
|
for(let file of fs.readdirSync(folder, {withFileTypes: true})){
|
||||||
if(file.isFile()){
|
if(file.isFile()){
|
||||||
let filepath = path.join(folder, file.name)
|
let filepath = path.join(folder, file.name)
|
||||||
if(predicate(filepath) && filepath.split(/[\\/]+/).reverse()[1] !== "js"){
|
if(predicate(filepath) && filepath.split(/[\\/]+/).reverse()[1] !== "js"){
|
||||||
await compile(filepath, path.join(filepath.replace(folders.startDir, folders.newDir)), "..")
|
await compile(filepath, path.join(filepath.replace(folders.startDir, folders.newDir)), "..")
|
||||||
}else{
|
}else{
|
||||||
await fs.promises.copyFile(filepath, filepath.replace(folders.startDir, folders.newDir))
|
await fs.promises.copyFile(filepath, filepath.replace(folders.startDir, folders.newDir))
|
||||||
}
|
}
|
||||||
}else if(file.isDirectory()){
|
}else if(file.isDirectory()){
|
||||||
await fs.promises.mkdir(path.join(folder, file.name).replace(folders.startDir, folders.newDir), {recursive: true})
|
await fs.promises.mkdir(path.join(folder, file.name).replace(folders.startDir, folders.newDir), {recursive: true})
|
||||||
await processNextDir(path.join(folder, file.name), ...Array.from(arguments).slice(1))
|
await processNextDir(path.join(folder, file.name), ...Array.from(arguments).slice(1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await processNextDir(startDir, {
|
await processNextDir(startDir, {
|
||||||
startDir,
|
startDir,
|
||||||
newDir
|
newDir
|
||||||
}, ((filepath) => filepath.endsWith(".js") && (!production ? !filepath.includes("node_modules") : true)), async (filepath, newpath) => {
|
}, ((filepath) => filepath.endsWith(".js") && (!production ? !filepath.includes("node_modules") : true)), async (filepath, newpath) => {
|
||||||
console.info(`Minifying ${filepath} to ${newpath}`)
|
console.info(`Minifying ${filepath} to ${newpath}`)
|
||||||
|
|
||||||
if(filepath.endsWith("git.js")){
|
if(filepath.endsWith("git.js")){
|
||||||
let commit = child_process.execSync("git rev-parse HEAD").toString().split("\n")[0].trim()
|
let commit = child_process.execSync("git rev-parse HEAD").toString().split("\n")[0].trim()
|
||||||
console.info(`Obtained commit ${commit} for the build`)
|
console.info(`Obtained commit ${commit} for the build`)
|
||||||
await fs.promises.writeFile(newpath, terser.minify(fs.readFileSync(filepath, "utf8").replace(/"{commit}"/g, `"${commit}"`)).code, "utf8")
|
await fs.promises.writeFile(newpath, terser.minify(fs.readFileSync(filepath, "utf8").replace(/"{commit}"/g, `"${commit}"`)).code, "utf8")
|
||||||
}else{
|
}else{
|
||||||
await fs.promises.writeFile(newpath, terser.minify(await fs.promises.readFile(filepath, "utf8")).code, "utf8")
|
await fs.promises.writeFile(newpath, terser.minify(await fs.promises.readFile(filepath, "utf8")).code, "utf8")
|
||||||
}
|
}
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
console.info(`Copied files and minified them from ${startDir}.`)
|
console.info(`Copied files and minified them from ${startDir}.`)
|
||||||
}).catch(console.error)
|
}).catch(console.error)
|
||||||
|
|
||||||
await processNextDir(path.join(__dirname, "modules"), {
|
await processNextDir(path.join(__dirname, "modules"), {
|
||||||
startDir: path.join(__dirname, "modules"),
|
startDir: path.join(__dirname, "modules"),
|
||||||
newDir: path.join(__dirname, "distApp", "modules")
|
newDir: path.join(__dirname, "distApp", "modules")
|
||||||
}, ((filepath) => filepath.endsWith(".js") && (!production ? !filepath.includes("node_modules") : true)), async (filepath, newpath) => {
|
}, ((filepath) => filepath.endsWith(".js") && (!production ? !filepath.includes("node_modules") : true)), async (filepath, newpath) => {
|
||||||
console.info(`Minifying ${filepath} to ${newpath}`)
|
console.info(`Minifying ${filepath} to ${newpath}`)
|
||||||
await fs.promises.writeFile(newpath, terser.minify(await fs.promises.readFile(filepath, "utf8")).code, "utf8")
|
await fs.promises.writeFile(newpath, terser.minify(await fs.promises.readFile(filepath, "utf8")).code, "utf8")
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
console.info(`Copied files and minified them from ${path.join(__dirname, "modules")}.`)
|
console.info(`Copied files and minified them from ${path.join(__dirname, "modules")}.`)
|
||||||
})
|
})
|
||||||
|
|
||||||
await processNextDir(path.join(__dirname, "LightcordApi"), {
|
await processNextDir(path.join(__dirname, "LightcordApi"), {
|
||||||
startDir: path.join(__dirname, "LightcordApi"),
|
startDir: path.join(__dirname, "LightcordApi"),
|
||||||
newDir: path.join(__dirname, "distApp", "LightcordApi")
|
newDir: path.join(__dirname, "distApp", "LightcordApi")
|
||||||
}, ((filepath) => filepath.endsWith(".js") && (!production ? !filepath.includes("node_modules") : true)), async (filepath, newpath) => {
|
}, ((filepath) => filepath.endsWith(".js") && (!production ? !filepath.includes("node_modules") : true)), async (filepath, newpath) => {
|
||||||
console.info(`Minifying ${filepath} to ${newpath}`)
|
console.info(`Minifying ${filepath} to ${newpath}`)
|
||||||
await fs.promises.writeFile(newpath, terser.minify(await fs.promises.readFile(filepath, "utf8")).code, "utf8")
|
await fs.promises.writeFile(newpath, terser.minify(await fs.promises.readFile(filepath, "utf8")).code, "utf8")
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
console.info(`Copied files and minified them from ${path.join(__dirname, "LightcordApi")}.`)
|
console.info(`Copied files and minified them from ${path.join(__dirname, "LightcordApi")}.`)
|
||||||
})
|
})
|
||||||
|
|
||||||
await fs.promises.rmdir(path.join(__dirname, "distApp", "LightcordApi", "src"), {"recursive": true})
|
await fs.promises.rmdir(path.join(__dirname, "distApp", "LightcordApi", "src"), {"recursive": true})
|
||||||
await fs.promises.unlink(path.join(__dirname, "distApp", "LightcordApi", "webpack.config.js"))
|
await fs.promises.unlink(path.join(__dirname, "distApp", "LightcordApi", "webpack.config.js"))
|
||||||
await fs.promises.unlink(path.join(__dirname, "distApp", "LightcordApi", "tsconfig.json"))
|
await fs.promises.unlink(path.join(__dirname, "distApp", "LightcordApi", "tsconfig.json"))
|
||||||
|
|
||||||
await processNextDir(path.join(__dirname, "DiscordJS"), {
|
await processNextDir(path.join(__dirname, "DiscordJS"), {
|
||||||
startDir: path.join(__dirname, "DiscordJS"),
|
startDir: path.join(__dirname, "DiscordJS"),
|
||||||
newDir: path.join(__dirname, "distApp", "DiscordJS")
|
newDir: path.join(__dirname, "distApp", "DiscordJS")
|
||||||
}, ((filepath) => filepath.endsWith(".js") && (!production ? !filepath.includes("node_modules") : true)), async (filepath, newpath) => {
|
}, ((filepath) => filepath.endsWith(".js") && (!production ? !filepath.includes("node_modules") : true)), async (filepath, newpath) => {
|
||||||
console.info(`Minifying ${filepath} to ${newpath}`)
|
console.info(`Minifying ${filepath} to ${newpath}`)
|
||||||
await fs.promises.writeFile(newpath, terser.minify(await fs.promises.readFile(filepath, "utf8")).code, "utf8")
|
await fs.promises.writeFile(newpath, terser.minify(await fs.promises.readFile(filepath, "utf8")).code, "utf8")
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
console.info(`Copied files and minified them from ${path.join(__dirname, "DiscordJS")}.`)
|
console.info(`Copied files and minified them from ${path.join(__dirname, "DiscordJS")}.`)
|
||||||
})
|
})
|
||||||
|
|
||||||
await fs.promises.rmdir(path.join(__dirname, "distApp", "DiscordJS", "src"), {"recursive": true})
|
await fs.promises.rmdir(path.join(__dirname, "distApp", "DiscordJS", "src"), {"recursive": true})
|
||||||
await fs.promises.unlink(path.join(__dirname, "distApp", "DiscordJS", "webpack.config.js"))
|
await fs.promises.unlink(path.join(__dirname, "distApp", "DiscordJS", "webpack.config.js"))
|
||||||
await fs.promises.unlink(path.join(__dirname, "distApp", "DiscordJS", "tsconfig.json"))
|
await fs.promises.unlink(path.join(__dirname, "distApp", "DiscordJS", "tsconfig.json"))
|
||||||
|
|
||||||
fs.mkdirSync(path.join(__dirname, "distApp", "BetterDiscordApp", "js"), {recursive: true})
|
fs.mkdirSync(path.join(__dirname, "distApp", "BetterDiscordApp", "js"), {recursive: true})
|
||||||
fs.mkdirSync(path.join(__dirname, "distApp", "BetterDiscordApp", "css"), {recursive: true})
|
fs.mkdirSync(path.join(__dirname, "distApp", "BetterDiscordApp", "css"), {recursive: true})
|
||||||
const BDPackageJSON = require("./BetterDiscordApp/package.json")
|
const BDPackageJSON = require("./BetterDiscordApp/package.json")
|
||||||
fs.writeFileSync(path.join(__dirname, "distApp", "BetterDiscordApp", "package.json"), JSON.stringify(BDPackageJSON), "utf8")
|
fs.writeFileSync(path.join(__dirname, "distApp", "BetterDiscordApp", "package.json"), JSON.stringify(BDPackageJSON), "utf8")
|
||||||
fs.writeFileSync(path.join(__dirname, "distApp", "BetterDiscordApp", "css", "main.css"), fs.readFileSync(path.join(__dirname, "BetterDiscordApp", "css", "main.css")))
|
fs.writeFileSync(path.join(__dirname, "distApp", "BetterDiscordApp", "css", "main.css"), fs.readFileSync(path.join(__dirname, "BetterDiscordApp", "css", "main.css")))
|
||||||
fs.writeFileSync(path.join(__dirname, "distApp", "BetterDiscordApp", "css", "main.min.css"), fs.readFileSync(path.join(__dirname, "BetterDiscordApp", "css", "main.min.css")))
|
fs.writeFileSync(path.join(__dirname, "distApp", "BetterDiscordApp", "css", "main.min.css"), fs.readFileSync(path.join(__dirname, "BetterDiscordApp", "css", "main.min.css")))
|
||||||
fs.writeFileSync(path.join(__dirname, "distApp", "BetterDiscordApp", "js", "main.js"), fs.readFileSync(path.join(__dirname, "BetterDiscordApp", "js", "main.js")))
|
fs.writeFileSync(path.join(__dirname, "distApp", "BetterDiscordApp", "js", "main.js"), fs.readFileSync(path.join(__dirname, "BetterDiscordApp", "js", "main.js")))
|
||||||
fs.writeFileSync(path.join(__dirname, "distApp", "BetterDiscordApp", "js", "main.min.js"), fs.readFileSync(path.join(__dirname, "BetterDiscordApp", "js", "main.min.js")))
|
fs.writeFileSync(path.join(__dirname, "distApp", "BetterDiscordApp", "js", "main.min.js"), fs.readFileSync(path.join(__dirname, "BetterDiscordApp", "js", "main.min.js")))
|
||||||
|
|
||||||
await fs.promises.mkdir(path.join(__dirname, "distApp", "splash", "videos"), {recursive: true})
|
await fs.promises.mkdir(path.join(__dirname, "distApp", "splash", "videos"), {recursive: true})
|
||||||
await processNextDir(path.join(__dirname, "splash"), {
|
await processNextDir(path.join(__dirname, "splash"), {
|
||||||
startDir: path.join(__dirname, "splash"),
|
startDir: path.join(__dirname, "splash"),
|
||||||
newDir: path.join(__dirname, "distApp", "splash")
|
newDir: path.join(__dirname, "distApp", "splash")
|
||||||
}, (filepath) => {
|
}, (filepath) => {
|
||||||
if(filepath.endsWith(".js"))return true
|
if(filepath.endsWith(".js"))return true
|
||||||
return false
|
return false
|
||||||
}, async (filepath, newpath) => {
|
}, async (filepath, newpath) => {
|
||||||
console.info(`Minifying ${filepath} to ${newpath}`)
|
console.info(`Minifying ${filepath} to ${newpath}`)
|
||||||
await fs.promises.writeFile(newpath, terser.minify(await fs.promises.readFile(filepath, "utf8")).code, "utf8")
|
await fs.promises.writeFile(newpath, terser.minify(await fs.promises.readFile(filepath, "utf8")).code, "utf8")
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
console.info(`Copied files and minified them from ${path.join(__dirname, "splash")}.`)
|
console.info(`Copied files and minified them from ${path.join(__dirname, "splash")}.`)
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
await processNextDir(startDir, {
|
await processNextDir(startDir, {
|
||||||
startDir,
|
startDir,
|
||||||
newDir
|
newDir
|
||||||
}, ((filepath) => false), ()=>{}).then(() => {
|
}, ((filepath) => false), ()=>{}).then(() => {
|
||||||
console.info(`Copied files and minified them from ${startDir}.`)
|
console.info(`Copied files and minified them from ${startDir}.`)
|
||||||
}).catch(console.error)*/
|
}).catch(console.error)*/
|
||||||
|
|
||||||
let packageJSON = require("./package.json")
|
let packageJSON = require("./package.json")
|
||||||
packageJSON.scripts.build = packageJSON.scripts.build.replace("./distApp", ".")
|
packageJSON.scripts.build = packageJSON.scripts.build.replace("./distApp", ".")
|
||||||
|
|
||||||
fs.writeFileSync(path.join(__dirname, "distApp", "package.json"), JSON.stringify(packageJSON), "utf8")
|
fs.writeFileSync(path.join(__dirname, "distApp", "package.json"), JSON.stringify(packageJSON), "utf8")
|
||||||
|
|
||||||
console.info(`Installing ${Object.keys(packageJSON.dependencies).length + Object.keys(packageJSON.devDependencies).length} packages...`)
|
console.info(`Installing ${Object.keys(packageJSON.dependencies).length + Object.keys(packageJSON.devDependencies).length} packages...`)
|
||||||
console.log(child_process.execSync("npm i", {
|
console.log(child_process.execSync("npm i", {
|
||||||
encoding: "binary",
|
encoding: "binary",
|
||||||
cwd: path.join(__dirname, "distApp")
|
cwd: path.join(__dirname, "distApp")
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
main()
|
main()
|
Binary file not shown.
|
@ -1,28 +1,32 @@
|
||||||
const EventEmitter = require('events');
|
const EventEmitter = require('events');
|
||||||
const {CloudSync: CloudSyncNative} = require('./discord_cloudsync.node');
|
let addon = './discord_cloudsync.node'
|
||||||
|
if(process.platform === "linux"){
|
||||||
function makeCallback(resolve, reject) {
|
addon = './discord_cloudsync_linux.node'
|
||||||
return (err, result) => {
|
}
|
||||||
if (err != null && err !== '') {
|
const {CloudSync: CloudSyncNative} = require(addon);
|
||||||
reject(new Error(JSON.parse(err)));
|
|
||||||
} else {
|
function makeCallback(resolve, reject) {
|
||||||
resolve(result != null && result !== '' ? JSON.parse(result) : null);
|
return (err, result) => {
|
||||||
}
|
if (err != null && err !== '') {
|
||||||
};
|
reject(new Error(JSON.parse(err)));
|
||||||
}
|
} else {
|
||||||
|
resolve(result != null && result !== '' ? JSON.parse(result) : null);
|
||||||
class CloudSync extends EventEmitter {
|
}
|
||||||
constructor() {
|
};
|
||||||
super();
|
}
|
||||||
|
|
||||||
this._cloudSync = new CloudSyncNative(state => this.emit('state', JSON.parse(state)));
|
class CloudSync extends EventEmitter {
|
||||||
}
|
constructor() {
|
||||||
|
super();
|
||||||
sync(id, config) {
|
|
||||||
return new Promise((resolve, reject) =>
|
this._cloudSync = new CloudSyncNative(state => this.emit('state', JSON.parse(state)));
|
||||||
this._cloudSync.command(JSON.stringify({type: 'SYNC', id, config}), makeCallback(resolve, reject))
|
}
|
||||||
);
|
|
||||||
}
|
sync(id, config) {
|
||||||
}
|
return new Promise((resolve, reject) =>
|
||||||
|
this._cloudSync.command(JSON.stringify({type: 'SYNC', id, config}), makeCallback(resolve, reject))
|
||||||
module.exports = CloudSync;
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = CloudSync;
|
||||||
|
|
|
@ -87,6 +87,10 @@ if(process.platform === "win32"){
|
||||||
useShim = !!use
|
useShim = !!use
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
module.exports = {
|
||||||
|
useShim(){}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let settingStore
|
let settingStore
|
||||||
|
|
Binary file not shown.
|
@ -1 +1 @@
|
||||||
module.exports = require('./discord_dispatch.node');
|
module.exports = require(process.platform === "linux" ? './discord_dispatch_linux.node' : './discord_dispatch.node');
|
||||||
|
|
Binary file not shown.
|
@ -1 +1 @@
|
||||||
module.exports = require('./discord_erlpack.node');
|
module.exports = require(process.platform === "linux" ? './discord_erlpack_linux.node' : './discord_erlpack.node');
|
||||||
|
|
Binary file not shown.
|
@ -1 +1 @@
|
||||||
module.exports = require('./discord_game_utils.node');
|
module.exports = require(process.platform === "linux" ? './discord_game_utils_linux.node' : './discord_game_utils.node');
|
||||||
|
|
Binary file not shown.
|
@ -1 +1 @@
|
||||||
module.exports = require('./discord_modules.node');
|
module.exports = require(process.platform === "linux" ? './discord_modules_linux.node' : './discord_modules.node');
|
||||||
|
|
Binary file not shown.
|
@ -1,50 +1,55 @@
|
||||||
const execa = require('execa');
|
const execa = require('execa');
|
||||||
const superagent = require('superagent');
|
const superagent = require('superagent');
|
||||||
|
|
||||||
module.exports = require('./discord_utils.node');
|
let addon = './discord_utils.node'
|
||||||
module.exports.clearCandidateGamesCallback = module.exports.setCandidateGamesCallback;
|
if(process.platform === "linux"){
|
||||||
|
addon = './discord_utils_linux.node'
|
||||||
function parseNvidiaSmiOutput(result) {
|
}
|
||||||
if (!result || !result.stdout) {
|
|
||||||
return {error: 'nvidia-smi produced no output'};
|
module.exports = require(addon);
|
||||||
}
|
module.exports.clearCandidateGamesCallback = module.exports.setCandidateGamesCallback;
|
||||||
|
|
||||||
const match = result.stdout.match(/Driver Version: (\d+)\.(\d+)/);
|
function parseNvidiaSmiOutput(result) {
|
||||||
|
if (!result || !result.stdout) {
|
||||||
if (match.length === 3) {
|
return {error: 'nvidia-smi produced no output'};
|
||||||
return {major: parseInt(match[1], 10), minor: parseInt(match[2], 10)};
|
}
|
||||||
} else {
|
|
||||||
return {error: 'failed to parse nvidia-smi output'};
|
const match = result.stdout.match(/Driver Version: (\d+)\.(\d+)/);
|
||||||
}
|
|
||||||
}
|
if (match.length === 3) {
|
||||||
|
return {major: parseInt(match[1], 10), minor: parseInt(match[2], 10)};
|
||||||
module.exports.getGPUDriverVersions = async () => {
|
} else {
|
||||||
if (process.platform !== 'win32') {
|
return {error: 'failed to parse nvidia-smi output'};
|
||||||
return {};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = {};
|
module.exports.getGPUDriverVersions = async () => {
|
||||||
const nvidiaSmiPath = `${process.env['ProgramW6432']}/NVIDIA Corporation/NVSMI/nvidia-smi.exe`;
|
if (process.platform !== 'win32') {
|
||||||
|
return {};
|
||||||
try {
|
}
|
||||||
result.nvidia = parseNvidiaSmiOutput(await execa(nvidiaSmiPath, []));
|
|
||||||
} catch (e) {
|
const result = {};
|
||||||
result.nvidia = {error: e.toString()};
|
const nvidiaSmiPath = `${process.env['ProgramW6432']}/NVIDIA Corporation/NVSMI/nvidia-smi.exe`;
|
||||||
}
|
|
||||||
|
try {
|
||||||
return result;
|
result.nvidia = parseNvidiaSmiOutput(await execa(nvidiaSmiPath, []));
|
||||||
};
|
} catch (e) {
|
||||||
|
result.nvidia = {error: e.toString()};
|
||||||
module.exports.submitLiveCrashReport = async (channel, sentryMetadata) => {
|
}
|
||||||
const path = module.exports._generateLiveMinidump();
|
|
||||||
|
return result;
|
||||||
if (!path) {
|
};
|
||||||
return null;
|
|
||||||
}
|
module.exports.submitLiveCrashReport = async (channel, sentryMetadata) => {
|
||||||
|
const path = module.exports._generateLiveMinidump();
|
||||||
await superagent
|
|
||||||
.post('https://sentry.io/api/146342/minidump/?sentry_key=f11e8c3e62cb46b5a006c339b2086ba3')
|
if (!path) {
|
||||||
.attach('upload_file_minidump', path)
|
return null;
|
||||||
.field('channel', channel)
|
}
|
||||||
.field('sentry', JSON.stringify(sentryMetadata));
|
|
||||||
};
|
await superagent
|
||||||
|
.post('https://sentry.io/api/146342/minidump/?sentry_key=f11e8c3e62cb46b5a006c339b2086ba3')
|
||||||
|
.attach('upload_file_minidump', path)
|
||||||
|
.field('channel', channel)
|
||||||
|
.field('sentry', JSON.stringify(sentryMetadata));
|
||||||
|
};
|
||||||
|
|
Binary file not shown.
|
@ -1,155 +1,155 @@
|
||||||
const VoiceEngine = require('./discord_voice.node');
|
const VoiceEngine = require(process.platform === "linux" ? './discord_voice_linux.node' : './discord_voice.node');
|
||||||
const ChildProcess = require('child_process');
|
const ChildProcess = require('child_process');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const yargs = require('yargs');
|
const yargs = require('yargs');
|
||||||
|
|
||||||
const isElectronRenderer =
|
const isElectronRenderer =
|
||||||
typeof window !== 'undefined' && window != null && window.DiscordNative && window.DiscordNative.isRenderer;
|
typeof window !== 'undefined' && window != null && window.DiscordNative && window.DiscordNative.isRenderer;
|
||||||
|
|
||||||
const appSettings = isElectronRenderer ? window.DiscordNative.settings : global.appSettings;
|
const appSettings = isElectronRenderer ? window.DiscordNative.settings : global.appSettings;
|
||||||
const features = isElectronRenderer ? window.DiscordNative.features : global.features;
|
const features = isElectronRenderer ? window.DiscordNative.features : global.features;
|
||||||
const mainArgv = isElectronRenderer ? window.DiscordNative.processUtils.getMainArgvSync() : [];
|
const mainArgv = isElectronRenderer ? window.DiscordNative.processUtils.getMainArgvSync() : [];
|
||||||
const releaseChannel = isElectronRenderer ? window.DiscordNative.app.getReleaseChannel() : '';
|
const releaseChannel = isElectronRenderer ? window.DiscordNative.app.getReleaseChannel() : '';
|
||||||
const useLegacyAudioDevice = appSettings ? appSettings.getSync('useLegacyAudioDevice') : false;
|
const useLegacyAudioDevice = appSettings ? appSettings.getSync('useLegacyAudioDevice') : false;
|
||||||
const audioSubsystemSelected = appSettings
|
const audioSubsystemSelected = appSettings
|
||||||
? appSettings.getSync('audioSubsystem') === 'legacy'
|
? appSettings.getSync('audioSubsystem') === 'legacy'
|
||||||
? 'legacy'
|
? 'legacy'
|
||||||
: 'standard'
|
: 'standard'
|
||||||
: 'standard';
|
: 'standard';
|
||||||
const audioSubsystem = useLegacyAudioDevice || audioSubsystemSelected;
|
const audioSubsystem = useLegacyAudioDevice || audioSubsystemSelected;
|
||||||
const debugLogging = appSettings ? appSettings.getSync('debugLogging') : false;
|
const debugLogging = appSettings ? appSettings.getSync('debugLogging') : false;
|
||||||
|
|
||||||
const argv = yargs(mainArgv.slice(1))
|
const argv = yargs(mainArgv.slice(1))
|
||||||
.describe('log-level', 'Logging level.')
|
.describe('log-level', 'Logging level.')
|
||||||
.default('log-level', -1)
|
.default('log-level', -1)
|
||||||
.help('h')
|
.help('h')
|
||||||
.alias('h', 'help')
|
.alias('h', 'help')
|
||||||
.exitProcess(false).argv;
|
.exitProcess(false).argv;
|
||||||
const logLevel = argv['log-level'] == -1 ? (debugLogging ? 2 : -1) : argv['log-level'];
|
const logLevel = argv['log-level'] == -1 ? (debugLogging ? 2 : -1) : argv['log-level'];
|
||||||
|
|
||||||
if (debugLogging && console.discordVoiceHooked == null) {
|
if (debugLogging && console.discordVoiceHooked == null) {
|
||||||
console.discordVoiceHooked = true;
|
console.discordVoiceHooked = true;
|
||||||
|
|
||||||
for (const logFn of ['trace', 'debug', 'info', 'warn', 'error', 'log']) {
|
for (const logFn of ['trace', 'debug', 'info', 'warn', 'error', 'log']) {
|
||||||
const originalLogFn = console[logFn];
|
const originalLogFn = console[logFn];
|
||||||
|
|
||||||
if (originalLogFn != null) {
|
if (originalLogFn != null) {
|
||||||
console[logFn] = function () {
|
console[logFn] = function () {
|
||||||
originalLogFn.apply(this, arguments);
|
originalLogFn.apply(this, arguments);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
VoiceEngine.consoleLog(
|
VoiceEngine.consoleLog(
|
||||||
logFn,
|
logFn,
|
||||||
JSON.stringify(Array.from(arguments).map((v) => (v != null ? v.toString() : v)))
|
JSON.stringify(Array.from(arguments).map((v) => (v != null ? v.toString() : v)))
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Drop errors from toString()/stringify.
|
// Drop errors from toString()/stringify.
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
features.declareSupported('voice_panning');
|
features.declareSupported('voice_panning');
|
||||||
features.declareSupported('voice_multiple_connections');
|
features.declareSupported('voice_multiple_connections');
|
||||||
features.declareSupported('media_devices');
|
features.declareSupported('media_devices');
|
||||||
features.declareSupported('media_video');
|
features.declareSupported('media_video');
|
||||||
features.declareSupported('debug_logging');
|
features.declareSupported('debug_logging');
|
||||||
features.declareSupported('set_audio_device_by_id');
|
features.declareSupported('set_audio_device_by_id');
|
||||||
features.declareSupported('set_video_device_by_id');
|
features.declareSupported('set_video_device_by_id');
|
||||||
features.declareSupported('loopback');
|
features.declareSupported('loopback');
|
||||||
features.declareSupported('experiment_config');
|
features.declareSupported('experiment_config');
|
||||||
features.declareSupported('remote_locus_network_control');
|
features.declareSupported('remote_locus_network_control');
|
||||||
features.declareSupported('connection_replay');
|
features.declareSupported('connection_replay');
|
||||||
features.declareSupported('simulcast');
|
features.declareSupported('simulcast');
|
||||||
|
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
features.declareSupported('voice_legacy_subsystem');
|
features.declareSupported('voice_legacy_subsystem');
|
||||||
features.declareSupported('soundshare');
|
features.declareSupported('soundshare');
|
||||||
features.declareSupported('wumpus_video');
|
features.declareSupported('wumpus_video');
|
||||||
features.declareSupported('hybrid_video');
|
features.declareSupported('hybrid_video');
|
||||||
features.declareSupported('elevated_hook');
|
features.declareSupported('elevated_hook');
|
||||||
features.declareSupported('soundshare_loopback');
|
features.declareSupported('soundshare_loopback');
|
||||||
features.declareSupported('screen_previews');
|
features.declareSupported('screen_previews');
|
||||||
features.declareSupported('window_previews');
|
features.declareSupported('window_previews');
|
||||||
features.declareSupported('audio_debug_state');
|
features.declareSupported('audio_debug_state');
|
||||||
// NOTE(jvass): currently there's no experimental encoders! Add this back if you
|
// NOTE(jvass): currently there's no experimental encoders! Add this back if you
|
||||||
// add one and want to re-enable the UI for them.
|
// add one and want to re-enable the UI for them.
|
||||||
// features.declareSupported('experimental_encoders');
|
// features.declareSupported('experimental_encoders');
|
||||||
}
|
}
|
||||||
|
|
||||||
const VoiceReplayConnection = VoiceEngine.VoiceReplayConnection;
|
const VoiceReplayConnection = VoiceEngine.VoiceReplayConnection;
|
||||||
|
|
||||||
delete VoiceEngine.VoiceReplayConnection;
|
delete VoiceEngine.VoiceReplayConnection;
|
||||||
|
|
||||||
VoiceEngine.createTransport = VoiceEngine._createTransport;
|
VoiceEngine.createTransport = VoiceEngine._createTransport;
|
||||||
|
|
||||||
if (isElectronRenderer) {
|
if (isElectronRenderer) {
|
||||||
VoiceEngine.setImageDataAllocator((width, height) => new window.ImageData(width, height));
|
VoiceEngine.setImageDataAllocator((width, height) => new window.ImageData(width, height));
|
||||||
}
|
}
|
||||||
|
|
||||||
VoiceEngine.createReplayConnection = function (audioEngineId, callback, replayLog) {
|
VoiceEngine.createReplayConnection = function (audioEngineId, callback, replayLog) {
|
||||||
if (replayLog == null) {
|
if (replayLog == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new VoiceReplayConnection(replayLog, audioEngineId, callback);
|
return new VoiceReplayConnection(replayLog, audioEngineId, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
VoiceEngine.setAudioSubsystem = function (subsystem) {
|
VoiceEngine.setAudioSubsystem = function (subsystem) {
|
||||||
if (appSettings == null) {
|
if (appSettings == null) {
|
||||||
console.warn('Unable to access app settings.');
|
console.warn('Unable to access app settings.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: With experiment controlling ADM selection, this may be incorrect since
|
// TODO: With experiment controlling ADM selection, this may be incorrect since
|
||||||
// audioSubsystem is read from settings (or default if does not exists)
|
// audioSubsystem is read from settings (or default if does not exists)
|
||||||
// and not the actual ADM used.
|
// and not the actual ADM used.
|
||||||
if (subsystem === audioSubsystem) {
|
if (subsystem === audioSubsystem) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
appSettings.set('audioSubsystem', subsystem);
|
appSettings.set('audioSubsystem', subsystem);
|
||||||
appSettings.set('useLegacyAudioDevice', false);
|
appSettings.set('useLegacyAudioDevice', false);
|
||||||
|
|
||||||
if (isElectronRenderer) {
|
if (isElectronRenderer) {
|
||||||
window.DiscordNative.app.relaunch();
|
window.DiscordNative.app.relaunch();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
VoiceEngine.setDebugLogging = function (enable) {
|
VoiceEngine.setDebugLogging = function (enable) {
|
||||||
if (appSettings == null) {
|
if (appSettings == null) {
|
||||||
console.warn('Unable to access app settings.');
|
console.warn('Unable to access app settings.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debugLogging === enable) {
|
if (debugLogging === enable) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
appSettings.set('debugLogging', enable);
|
appSettings.set('debugLogging', enable);
|
||||||
|
|
||||||
if (isElectronRenderer) {
|
if (isElectronRenderer) {
|
||||||
window.DiscordNative.app.relaunch();
|
window.DiscordNative.app.relaunch();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
VoiceEngine.getDebugLogging = function () {
|
VoiceEngine.getDebugLogging = function () {
|
||||||
return debugLogging;
|
return debugLogging;
|
||||||
};
|
};
|
||||||
|
|
||||||
reloadElectronApp = function () {
|
reloadElectronApp = function () {
|
||||||
if (isElectronRenderer) {
|
if (isElectronRenderer) {
|
||||||
const app = require('electron').remote.app;
|
const app = require('electron').remote.app;
|
||||||
app.relaunch();
|
app.relaunch();
|
||||||
app.exit(0);
|
app.exit(0);
|
||||||
} else {
|
} else {
|
||||||
ChildProcess.spawn(process.argv[0], process.argv.splice(1), {detached: true});
|
ChildProcess.spawn(process.argv[0], process.argv.splice(1), {detached: true});
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(`Initializing voice engine with audio subsystem: ${audioSubsystem}`);
|
console.log(`Initializing voice engine with audio subsystem: ${audioSubsystem}`);
|
||||||
VoiceEngine.initialize({audioSubsystem, logLevel});
|
VoiceEngine.initialize({audioSubsystem, logLevel});
|
||||||
|
|
||||||
module.exports = VoiceEngine;
|
module.exports = VoiceEngine;
|
||||||
|
|
Binary file not shown.
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "lightcord",
|
"name": "lightcord",
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -403,9 +403,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"electron": {
|
"electron": {
|
||||||
"version": "8.3.0",
|
"version": "8.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/electron/-/electron-8.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/electron/-/electron-8.4.0.tgz",
|
||||||
"integrity": "sha512-XRjiIJICZCgUr2vKSUI2PTkfP0gPFqCtqJUaTJSfCTuE3nTrxBKOUNeRMuCzEqspKkpFQU3SB3MdbMSHmZARlQ==",
|
"integrity": "sha512-SpgyccM5rjDJSGcpQjiviUBT44fZlSyhcjy8RpKSnAad+co4xY1vYj6T25U1CfSk0PH/dhvcp63P2sdXHCwq/Q==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"@electron/get": "^1.0.1",
|
"@electron/get": "^1.0.1",
|
||||||
|
@ -1399,6 +1399,15 @@
|
||||||
"buffer-crc32": "~0.2.3",
|
"buffer-crc32": "~0.2.3",
|
||||||
"fd-slicer": "~1.1.0"
|
"fd-slicer": "~1.1.0"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"yazl": {
|
||||||
|
"version": "2.5.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/yazl/-/yazl-2.5.1.tgz",
|
||||||
|
"integrity": "sha512-phENi2PLiHnHb6QBVot+dJnaAZ0xosj7p3fWl+znIjBDlnMI2PsZCJZ306BPTFOaHf5qdDEI8x5qFrSOBN5vrw==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"buffer-crc32": "~0.2.3"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
15
package.json
15
package.json
|
@ -7,10 +7,14 @@
|
||||||
"compile": "node compile.js",
|
"compile": "node compile.js",
|
||||||
"test": "npm run compile && electron .",
|
"test": "npm run compile && electron .",
|
||||||
"run": "electron .",
|
"run": "electron .",
|
||||||
"build": "npm run build:minify && npm run build:electron",
|
"build": "npm run build:minify && npm run build:electron && npm run build:after",
|
||||||
"build:electron": "electron-packager ./distApp --ignore=\"(distApp|builds|\\.ts)\" --arch=ia32 --win32metadata.ProductName=\"Lightcord\" --win32metadata.CompanyName=\"Lightcord\" --protocol=discord --platform=\"win32,linux\" --out=builds --icon=app.ico --executable-name=\"Lightcord\" --asar.unpack=*.{node,dll} --overwrite",
|
"build:electron": "npm run build:electron_win && npm run build:electron_linux",
|
||||||
|
"build:electron_win": "electron-packager ./distApp --ignore=\"(distApp|builds|\\.ts)\" --arch=ia32 --win32metadata.ProductName=\"Lightcord\" --win32metadata.CompanyName=\"Lightcord\" --protocol=discord --platform=\"win32\" --out=builds --icon=app.ico --executable-name=\"Lightcord\" --asar.unpack=*.{node,dll} --overwrite",
|
||||||
|
"build:electron_linux": "electron-packager ./distApp --ignore=\"(distApp|builds|\\.ts)\" --arch=x64 --protocol=discord --platform=\"linux\" --out=builds --icon=app.ico --executable-name=\"Lightcord\" --asar.unpack=*.{node,dll,so.4} --overwrite",
|
||||||
"build:minify": "node build.js",
|
"build:minify": "node build.js",
|
||||||
"devInstall": "npm i -g --arch=ia32 electron@8.3.0 && npm i -g typescript && npm i --save-dev @types/node@12.12.39 && npm i --save-dev --arch=ia32 electron@8.3.0 && node installSubModules.js && echo \"Everything is installed. You should be able to do `npm run test` to compile everything and launch.\""
|
"build:after": "node afterbuild.js",
|
||||||
|
"devInstall": "npm i -g --arch=ia32 electron@8.4.0 && npm i -g typescript && npm i --save-dev @types/node@12.12.39 && npm i --save-dev --arch=ia32 electron@8.4.0 && node installSubModules.js && echo \"Everything is installed. You should be able to do `npm run test` to compile everything and launch.\"",
|
||||||
|
"devInstall:64": "npm i -g --arch=x64 electron@8.4.0 && npm i -g typescript && npm i --save-dev @types/node@12.12.39 && npm i --save-dev --arch=x64 electron@8.4.0 && node installSubModules.js && echo \"Everything is installed. You should be able to do `npm run test` to compile everything and launch.\""
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
|
@ -35,9 +39,10 @@
|
||||||
"@types/uuid": "^8.0.0",
|
"@types/uuid": "^8.0.0",
|
||||||
"@types/yauzl": "^2.9.1",
|
"@types/yauzl": "^2.9.1",
|
||||||
"cross-spawn": "^7.0.3",
|
"cross-spawn": "^7.0.3",
|
||||||
"electron": "^8.3.0",
|
"electron": "^8.4.0",
|
||||||
"react": "^16.13.1",
|
"react": "^16.13.1",
|
||||||
"react-dom": "^16.13.1",
|
"react-dom": "^16.13.1",
|
||||||
"terser": "^4.7.0"
|
"terser": "^4.7.0",
|
||||||
|
"yazl": "^2.5.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue