mirror of https://github.com/vizality/vizality
move injector stuff over to top-level injector dir
parent
df56ba62f9
commit
c518b5411c
@ -1 +0,0 @@
|
||||
exports.getAppDir = async () => '/Applications/Discord.app/Contents/Resources/app';
|
@ -1,51 +0,0 @@
|
||||
const { existsSync, promises } = require('fs');
|
||||
const { execSync } = require('child_process');
|
||||
const { join, posix, sep } = require('path');
|
||||
|
||||
const rootPath = join(__dirname, '..', '..');
|
||||
const nodeModulesPath = join(rootPath, 'node_modules');
|
||||
|
||||
function installDeps () {
|
||||
console.log('\x1b[1m\x1b[34mACTION: \x1b[0mInstalling dependencies...');
|
||||
execSync('npm install --only=prod --legacy-peer-deps', {
|
||||
cwd: rootPath,
|
||||
stdio: [ null, null, null ]
|
||||
});
|
||||
console.log('\x1b[1m\x1b[34mACTION: \x1b[0mDependencies successfully installed!');
|
||||
}
|
||||
|
||||
module.exports = () => {
|
||||
// Don't clone in System32
|
||||
if (__dirname.toLowerCase().split(sep).join(posix.sep).includes('/windows/system32')) {
|
||||
console.error('\x1b[1m\x1b[31mERROR: \x1b[0mVizality shouldn\'t be cloned in System32, as this will generate conflicts and bloat your Windows installation. Please remove it and clone it in another place.\n' +
|
||||
'\x1b[1m\x1b[36mNOTE: \x1b[0mNot opening cmd as administrator will be enough.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Verify if we're on node 10.x
|
||||
if (!promises) {
|
||||
console.error('\x1b[1m\x1b[31mERROR: \x1b[0mYou\'re on an outdated Node.js version. Vizality requires you to run at least Node 10. You can download it here: https://nodejs.org');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Verify if deps have been installed. If not, install them automatically
|
||||
if (!existsSync(nodeModulesPath)) {
|
||||
installDeps();
|
||||
} else {
|
||||
const { dependencies } = require('../../package.json');
|
||||
for (const dependency in dependencies) {
|
||||
const depPath = join(nodeModulesPath, dependency);
|
||||
if (!existsSync(depPath)) {
|
||||
installDeps();
|
||||
break;
|
||||
}
|
||||
const depPackage = require(join(depPath, 'package.json'));
|
||||
const expectedVerInt = parseInt(dependencies[dependency].replace(/[^\d]/g, ''));
|
||||
const installedVerInt = parseInt(depPackage.version.replace(/[^\d]/g, ''));
|
||||
if (installedVerInt < expectedVerInt) {
|
||||
installDeps();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
@ -1,37 +0,0 @@
|
||||
// Perform checks
|
||||
require('./env_check')();
|
||||
|
||||
const { promises: { writeFile } } = require('fs');
|
||||
const { resolve } = require('path');
|
||||
const main = require('./main.js');
|
||||
|
||||
let platformModule;
|
||||
try {
|
||||
platformModule = require(`./${process.platform}.js`);
|
||||
} catch (err) {
|
||||
if (err.code === 'MODULE_NOT_FOUND') {
|
||||
console.log(`\x1b[1m\x1b[31mERROR: \x1b[0mUnsupported platform '${process.platform}'`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
(async () => {
|
||||
if (process.argv[2] === 'inject') {
|
||||
if (await main.inject(platformModule)) {
|
||||
// To have it show the dashboard on startup for new users
|
||||
await writeFile(
|
||||
resolve(__dirname, '..', '__injected.txt'),
|
||||
'Vizality successfully injected.'
|
||||
);
|
||||
|
||||
console.log('\x1b[32mSUCCESS: \x1b[0mVizality has been injected!');
|
||||
}
|
||||
} else if (process.argv[2] === 'uninject') {
|
||||
if (await main.uninject(platformModule)) {
|
||||
console.log('\x1b[32mSUCCESS: \x1b[0mVizality has been uninjected.');
|
||||
}
|
||||
} else {
|
||||
console.log(`\x1b[1m\x1b[31mERROR: \x1b[0mUnsupported argument '${process.argv[2]}'`);
|
||||
process.exit(1);
|
||||
}
|
||||
})().catch(e => console.error('\x1b[1m\x1b[31mERROR: \x1b[0mHmm, something seems to have gone wrong...', e));
|
@ -1,28 +0,0 @@
|
||||
const { join } = require('path');
|
||||
const { existsSync } = require('fs');
|
||||
const { execSync } = require('child_process');
|
||||
|
||||
exports.getAppDir = async () => {
|
||||
const discordProcess = execSync('ps x')
|
||||
.toString()
|
||||
.split('\n')
|
||||
.map(s => s.split(' ').filter(Boolean))
|
||||
.find(p => p[4] && (/discord$/i).test(p[4]) && p.includes('--type=renderer'));
|
||||
|
||||
if (!discordProcess) {
|
||||
console.log('\x1b[1m\x1b[33mWARNING: \x1b[0mCannot find Discord process, falling back to legacy path detection.');
|
||||
const paths = [
|
||||
'/usr/share/discord',
|
||||
'/usr/lib64/discord',
|
||||
'/opt/discord',
|
||||
'/opt/Discord',
|
||||
'~/.local/bin/Discord/'
|
||||
];
|
||||
const discordPath = paths.find(path => existsSync(path));
|
||||
return join(discordPath, 'resources', 'app');
|
||||
}
|
||||
|
||||
const discordPath = discordProcess[4].split('/');
|
||||
discordPath.splice(discordPath.length - 1, 1);
|
||||
return join('/', ...discordPath, 'resources', 'app');
|
||||
};
|
@ -1,50 +0,0 @@
|
||||
const { promises: { mkdir, writeFile, unlink, rmdir, access } } = require('fs');
|
||||
const { join, sep } = require('path');
|
||||
|
||||
const exists = path =>
|
||||
access(path)
|
||||
.then(() => true)
|
||||
.catch(() => false);
|
||||
|
||||
exports.inject = async ({ getAppDir }) => {
|
||||
const appDir = await getAppDir();
|
||||
if (await exists(appDir)) {
|
||||
console.log('\x1b[1m\x1b[31mERROR: \x1b[0mLooks like you already have an injector in place. Try uninjecting (`npm run uninject`) and try again.');
|
||||
return false;
|
||||
}
|
||||
|
||||
await mkdir(appDir);
|
||||
|
||||
await Promise.all([
|
||||
writeFile(
|
||||
join(appDir, 'index.js'),
|
||||
`require(\`${__dirname.replace(RegExp(sep.repeat(2), 'g'), '/')}/../patch\`)`
|
||||
),
|
||||
writeFile(
|
||||
join(appDir, 'package.json'),
|
||||
JSON.stringify({
|
||||
main: 'index.js',
|
||||
name: 'discord'
|
||||
})
|
||||
)
|
||||
]);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
exports.uninject = async ({ getAppDir }) => {
|
||||
const appDir = await getAppDir();
|
||||
|
||||
if (!(await exists(appDir))) {
|
||||
console.log('\x1b[1m\x1b[33mWARNING: \x1b[0mThere is nothing to uninject.');
|
||||
return false;
|
||||
}
|
||||
|
||||
await Promise.all([
|
||||
unlink(join(appDir, 'package.json')),
|
||||
unlink(join(appDir, 'index.js'))
|
||||
]);
|
||||
|
||||
await rmdir(appDir);
|
||||
return true;
|
||||
};
|
@ -1,15 +0,0 @@
|
||||
const { promises: { readdir } } = require('fs');
|
||||
const { join } = require('path');
|
||||
|
||||
exports.getAppDir = async () => {
|
||||
const discordPath = join(process.env.LOCALAPPDATA, 'Discord');
|
||||
const discordDirectory = await readdir(discordPath);
|
||||
|
||||
console.log('discordPath', discordPath);
|
||||
const currentBuild = discordDirectory
|
||||
.filter(path => path.startsWith('app-'))
|
||||
.reverse()[0];
|
||||
|
||||
console.log('final', join(discordPath, currentBuild, 'resources', 'app'));
|
||||
return join(discordPath, currentBuild, 'resources', 'app');
|
||||
};
|
@ -1,50 +0,0 @@
|
||||
const { ipcRenderer } = require('electron');
|
||||
const { join } = require('path');
|
||||
// Discord's preload
|
||||
const preload = ipcRenderer.sendSync('VIZALITY_GET_PRELOAD');
|
||||
if (preload) {
|
||||
require(preload);
|
||||
}
|
||||
|
||||
window.__SPLASH__ = true;
|
||||
|
||||
require('module-alias/register');
|
||||
require('@vizality/compilers');
|
||||
require('../ipc/renderer');
|
||||
|
||||
(() => {
|
||||
const { Module } = require('module');
|
||||
const extensions = [ '.jsx', '.js', '.ts', '.tsx' ];
|
||||
for (const ext of extensions) {
|
||||
const oldRequireExt = Module._extensions[ext];
|
||||
Module._extensions[ext] = (module, filename) => {
|
||||
const coreDir = join(__dirname, '..', 'core');
|
||||
const addonsDir = join(__dirname, '..', '..', 'addons');
|
||||
if ((filename.indexOf(coreDir) &&
|
||||
filename.indexOf(addonsDir)) ||
|
||||
filename.indexOf('node_modules') !== -1
|
||||
) {
|
||||
return oldRequireExt(module, filename);
|
||||
}
|
||||
|
||||
const compiler = new (require(`@vizality/compilers/${ext.substring(1).toUpperCase()}`))(filename);
|
||||
const compiled = compiler.compile();
|
||||
module._compile(compiled, filename);
|
||||
};
|
||||
}
|
||||
})();
|
||||
|
||||
/*
|
||||
* Theme injection
|
||||
*/
|
||||
const initialize = () => {
|
||||
document.documentElement.setAttribute('vizality', '');
|
||||
const ThemeManager = require('../core/managers/Theme').default;
|
||||
new ThemeManager();
|
||||
};
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', initialize);
|
||||
} else {
|
||||
initialize();
|
||||
}
|
Loading…
Reference in new issue