initial commit

This commit is contained in:
CanadaHonk 2022-12-07 16:07:40 +00:00
parent dffa37b3ad
commit 2d16c43325
8 changed files with 131 additions and 6 deletions

2
.gitattributes vendored
View File

@ -1,2 +0,0 @@
# Auto detect text files and perform LF normalization
* text=auto

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
chrome_data
node_modules

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2022 CanadaHonk
Copyright (c) 2022 OpenAsar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,2 +1,11 @@
# gluon
Not an Electron alternative
# Gluon
*Not* an Electron alternative. Uses system installed Chromium and Node.JS. ***VERY*** early and probably never finished/production ready.
<br>
## "Comparison"
| Part | Electron | Gluon |
| ----- | -------- | ----- |
| Frontend | Self-contained Chromium | System Installed Chromium |
| Backend | Self-contained Node.JS | System Installed Node.JS |
| IPC | Electron's Internal API | Gluon's API via CDP |

11
glucord/README.md Normal file
View File

@ -0,0 +1,11 @@
# Glucord
Example/demo of Gluon, a minimal Discord client using system-installed Chrome/Node.
> **Info** |
> Gluon is currently **Windows only**.
## Usage
1. Have Chrome Stable/Canary installed
1. Clone the Gluon repo
2. `npm install`
3. `node glucord` (with `--canary` if using Chrome Canary)

29
glucord/index.js Normal file

File diff suppressed because one or more lines are too long

6
package.json Normal file
View File

@ -0,0 +1,6 @@
{
"type": "module",
"dependencies": {
"chrome-remote-interface": "^0.31.3"
}
}

70
src/index.js Normal file
View File

@ -0,0 +1,70 @@
const rgb = (r, g, b, msg) => `\x1b[38;2;${r};${g};${b}m${msg}\x1b[0m`;
const log = (...args) => console.log(`[${rgb(88, 101, 242, 'Gluon')}]`, ...args);
const presets = { // Presets from OpenAsar
'base': '--autoplay-policy=no-user-gesture-required --disable-features=WinRetrieveSuggestionsOnlyOnDemand,HardwareMediaKeyHandling,MediaSessionService', // Base Discord
'perf': `--enable-gpu-rasterization --enable-zero-copy --ignore-gpu-blocklist --enable-hardware-overlays=single-fullscreen,single-on-top,underlay --enable-features=EnableDrDc,CanvasOopRasterization,BackForwardCache:TimeToLiveInBackForwardCacheInSeconds/300/should_ignore_blocklists/true/enable_same_site/true,ThrottleDisplayNoneAndVisibilityHiddenCrossOriginIframes,UseSkiaRenderer,WebAssemblyLazyCompilation --disable-features=Vulkan --force_high_performance_gpu`, // Performance
'battery': '--enable-features=TurnOffStreamingMediaCachingOnBattery --force_low_power_gpu', // Known to have better battery life for Chromium?
'memory': '--in-process-gpu --js-flags="--lite-mode --optimize_for_size --wasm_opt --wasm_lazy_compilation --wasm_lazy_validation --always_compact" --renderer-process-limit=2 --enable-features=QuickIntensiveWakeUpThrottlingAfterLoading' // Less (?) memory usage
};
import { exec } from 'child_process';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
import CDP from 'chrome-remote-interface';
const findChromePath = () => {
const whichChrome = process.argv.includes('--canary') ? 'canary' : 'stable';
switch (whichChrome) {
case 'stable': return join(process.env.PROGRAMFILES, 'Google', 'Chrome', 'Application', 'chrome.exe');
case 'canary': return join(process.env.LOCALAPPDATA, 'Google', 'Chrome SxS', 'Application', 'chrome.exe');
}
};
const getDataPath = () => join(__dirname, '..', 'chrome_data');
const startChrome = url => new Promise(res => {
const dataPath = getDataPath();
const chromePath = findChromePath();
log('chrome path:', chromePath);
log('data path:', dataPath);
const debugPort = 9222;
exec(`"${chromePath}" --app=${url} --remote-debugging-port=${debugPort} --user-data-dir="${dataPath}" --new-window --disable-extensions --disable-default-apps --disable-breakpad --disable-crashpad --disable-background-networking --disable-domain-reliability --disable-component-update --disable-sync --disable-features=AutofillServerCommunication ${presets.perf}`, (err, stdout, stderr) => {
log(err, stdout, stderr);
});
setTimeout(() => res(debugPort), 500);
});
export const open = async (url, onLoad = () => {}) => {
log('starting chrome...');
const debugPort = await startChrome(url);
log('connecting to CDP...');
const { Runtime, Page } = await CDP({ port: debugPort });
// const run = async js => (await Runtime.evaluate({ expression: js })).result.value;
const run = async js => log(await Runtime.evaluate({ expression: js }));
const toRun = `(() => {
if (window.self !== window.top) return; // inside frame
(${onLoad})();
})()`;
run(toRun);
await Page.enable();
await Page.addScriptToEvaluateOnNewDocument({ source: toRun });
};