[Config] Initial Add
This commit is contained in:
parent
c510e44aaa
commit
898a1445f6
4 changed files with 96 additions and 26 deletions
18
src/bootstrap.js
vendored
18
src/bootstrap.js
vendored
|
@ -59,6 +59,7 @@ const startCore = () => {
|
|||
bw.webContents.on('dom-ready', () => {
|
||||
if (!donePageReady) { // Only run once
|
||||
splashScreen.pageReady(); // Override Core's pageReady with our own on dom-ready to show main window earlier
|
||||
|
||||
donePageReady = true;
|
||||
}
|
||||
|
||||
|
@ -87,16 +88,17 @@ const startUpdate = async () => {
|
|||
desktopCore.setMainWindowVisible(!startMinimized);
|
||||
|
||||
setTimeout(() => { // Try to update our asar
|
||||
if (oaConfig.autoupdate === false) return; // If autoupdate disabled, don't update
|
||||
const config = require('./config');
|
||||
if (oaConfig.setup !== true || process.argv.includes('--config')) config.open();
|
||||
|
||||
const asarUpdate = require('./asarUpdate');
|
||||
|
||||
try {
|
||||
asarUpdate();
|
||||
} catch (e) {
|
||||
log('AsarUpdate', 'Failed', e);
|
||||
if (oaConfig.autoupdate !== false) { // If autoupdate disabled, don't update
|
||||
try {
|
||||
require('./asarUpdate')();
|
||||
} catch (e) {
|
||||
log('AsarUpdate', 'Failed', e);
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
}, 3000);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
45
src/config/index.js
Normal file
45
src/config/index.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
const { BrowserWindow, ipcMain, app } = require('electron');
|
||||
const { join } = require('path');
|
||||
|
||||
const settings = require('../appSettings').getSettings();
|
||||
|
||||
ipcMain.on('DISCORD_UPDATED_QUOTES', (e, c) => {
|
||||
if (c === 'o') open();
|
||||
});
|
||||
|
||||
const open = exports.open = () => {
|
||||
const win = new BrowserWindow({
|
||||
width: 500,
|
||||
height: 650,
|
||||
center: true,
|
||||
frame: false,
|
||||
resizable: false,
|
||||
center: true,
|
||||
backgroundColor: '#101418',
|
||||
webPreferences: {
|
||||
preload: join(__dirname, 'preload.js')
|
||||
}
|
||||
});
|
||||
|
||||
let config = settings.get('openasar', {});
|
||||
config.setup = true;
|
||||
settings.save();
|
||||
|
||||
ipcMain.on('config_set', (e, c) => {
|
||||
config = c;
|
||||
settings.set('openasar', config);
|
||||
settings.save(); // Ensure saving
|
||||
});
|
||||
|
||||
ipcMain.on('config_get', (e) => {
|
||||
e.returnValue = config;
|
||||
});
|
||||
|
||||
ipcMain.on('config_restart', () => {
|
||||
settings.save();
|
||||
app.relaunch({ args: process.argv.filter((x) => x !== '--config') });
|
||||
app.exit();
|
||||
});
|
||||
|
||||
win.loadURL('https://cdn.openasar.dev/config.html');
|
||||
};
|
8
src/config/preload.js
Normal file
8
src/config/preload.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
const { contextBridge, ipcRenderer } = require('electron');
|
||||
|
||||
|
||||
contextBridge.exposeInMainWorld('Native', {
|
||||
restart: () => ipcRenderer.send('config_restart'),
|
||||
set: c => ipcRenderer.send('config_set', c),
|
||||
get: () => ipcRenderer.sendSync('config_get')
|
||||
});
|
|
@ -1,16 +1,23 @@
|
|||
let lastBgPrimary = '';
|
||||
const themesync = async () => {
|
||||
const getVar = (name, el = document.body) => el && (getComputedStyle(el).getPropertyValue(name) || getVar(name, el.parentElement))?.trim();
|
||||
const getFontSource = (font) => {
|
||||
const san = (x) => x.replaceAll('\"', '').replaceAll("\'", '');
|
||||
const sanFont = san(font);
|
||||
|
||||
return [...document.styleSheets].map((x) => !(x.href && x.href.includes('discord.com/assets')) && [...x.rules].find((y) => (y.cssText.startsWith('@font-face') && san(y.style.fontFamily) === sanFont) || (y.href?.includes?.(sanFont.replaceAll(' ', '+'))))).find((x) => x).cssText.replaceAll('\\"', '"');
|
||||
};
|
||||
|
||||
const bgPrimary = getVar('--background-primary');
|
||||
if (!bgPrimary || bgPrimary === '#36393f' || bgPrimary === lastBgPrimary) return; // Default primary bg or same as last
|
||||
lastBgPrimary = bgPrimary;
|
||||
|
||||
const vars = [ '--background-primary', '--background-secondary', '--brand-experiment', '--header-primary', '--text-muted' ];
|
||||
const font = getVar('font-family');
|
||||
|
||||
let cached = await DiscordNative.userDataCache.getCached() || {};
|
||||
|
||||
const value = `body { ${vars.reduce((acc, x) => acc += `${x}: ${getVar(x)}; `, '')} }`;
|
||||
const value = (!font.startsWith('Whitney,') ? getFontSource(font) : '') + ` body { ${vars.reduce((acc, x) => acc += `${x}: ${getVar(x)};`, '')} --font-primary: ${font}; }`;
|
||||
const pastValue = cached['openasarSplashCSS'];
|
||||
cached['openasarSplashCSS'] = value;
|
||||
|
||||
|
@ -21,29 +28,37 @@ setInterval(() => {
|
|||
try {
|
||||
themesync();
|
||||
} catch (e) { }
|
||||
}, 5000);
|
||||
}, 10000);
|
||||
themesync();
|
||||
|
||||
setInterval(() => {
|
||||
const host = [...document.querySelectorAll('[class^="socialLinks-"] + [class^="info-"] [class^="colorMuted-"]')].find(x => x.textContent.startsWith('Host '));
|
||||
if (!host || document.querySelector('#openasar-ver')) return;
|
||||
|
||||
const el = document.createElement('span');
|
||||
el.id = 'openasar-ver';
|
||||
|
||||
el.textContent = 'OpenAsar <hash>';
|
||||
el.onclick = () => DiscordNative.ipc.send('DISCORD_UPDATED_QUOTES', 'o');
|
||||
|
||||
host.append(document.createTextNode(' | '), el);
|
||||
}, 2000);
|
||||
|
||||
|
||||
const css = `
|
||||
[class^="socialLinks-"] + [class^="info-"] [class^="colorMuted-"]:nth-last-child(2)::after {
|
||||
content: " | OpenAsar <hash>";
|
||||
display: inline;
|
||||
text-transform: none;
|
||||
}
|
||||
|
||||
[class^="socialLinks-"] + [class^="info-"] {
|
||||
const el = document.createElement('style');
|
||||
el.appendChild(document.createTextNode(`[class^="socialLinks-"] + [class^="info-"] {
|
||||
padding-right: 0;
|
||||
}
|
||||
|
||||
[class^="vertical-"] > div[style="display: flex; justify-content: space-between;"] > div > [class^="description-"] {
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
#openasar-ver {
|
||||
text-transform: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
`;
|
||||
|
||||
const el = document.createElement('style');
|
||||
el.appendChild(document.createTextNode(css));
|
||||
#openasar-ver:hover {
|
||||
text-decoration: underline;
|
||||
color: var(--text-normal);
|
||||
}`));
|
||||
document.body.appendChild(el);
|
||||
|
||||
|
||||
window.openasar = {};
|
||||
openasar = {};
|
Loading…
Add table
Add a link
Reference in a new issue