mirror of
https://github.com/smartfrigde/armcord.git
synced 2024-08-14 23:56:58 +00:00
Add language detection from Discord
This commit is contained in:
parent
e518c0f04e
commit
fa24b7996f
4 changed files with 33 additions and 8 deletions
|
@ -1,7 +1,7 @@
|
||||||
//ipc stuff
|
//ipc stuff
|
||||||
import {app, ipcMain, shell, desktopCapturer} from "electron";
|
import {app, ipcMain, shell, desktopCapturer} from "electron";
|
||||||
import {createTabsGuest, mainWindow} from "./window";
|
import {createTabsGuest, mainWindow} from "./window";
|
||||||
import {setConfigBulk, getVersion, getConfig} from "./utils";
|
import {setConfigBulk, getVersion, getConfig, setLang} from "./utils";
|
||||||
import {customTitlebar, tabs} from "./main";
|
import {customTitlebar, tabs} from "./main";
|
||||||
import {createSettingsWindow} from "./settings/main";
|
import {createSettingsWindow} from "./settings/main";
|
||||||
export function registerIpc() {
|
export function registerIpc() {
|
||||||
|
@ -11,6 +11,9 @@ export function registerIpc() {
|
||||||
ipcMain.on("openTab", (event, number: number) => {
|
ipcMain.on("openTab", (event, number: number) => {
|
||||||
createTabsGuest(number);
|
createTabsGuest(number);
|
||||||
});
|
});
|
||||||
|
ipcMain.on("setLang", (event, lang: string) => {
|
||||||
|
setLang(lang);
|
||||||
|
});
|
||||||
ipcMain.on("open-external-link", (event, href: string) => {
|
ipcMain.on("open-external-link", (event, href: string) => {
|
||||||
shell.openExternal(href);
|
shell.openExternal(href);
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,6 +16,7 @@ contextBridge.exposeInMainWorld("armcord", {
|
||||||
electron: process.versions.electron,
|
electron: process.versions.electron,
|
||||||
channel: ipcRenderer.sendSync("channel"),
|
channel: ipcRenderer.sendSync("channel"),
|
||||||
openTab: (number: number) => ipcRenderer.sendSync("openTab", number),
|
openTab: (number: number) => ipcRenderer.sendSync("openTab", number),
|
||||||
|
setLang: (lang: string) => ipcRenderer.send("setLang", lang),
|
||||||
version: ipcRenderer.sendSync("get-app-version", "app-version"),
|
version: ipcRenderer.sendSync("get-app-version", "app-version"),
|
||||||
getDisplayMediaSelector: getDisplayMediaSelector,
|
getDisplayMediaSelector: getDisplayMediaSelector,
|
||||||
openSettingsWindow: () => ipcRenderer.send("openSettingsWindow")
|
openSettingsWindow: () => ipcRenderer.send("openSettingsWindow")
|
||||||
|
|
|
@ -4,11 +4,15 @@ import "./patch";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import {injectTitlebar} from "./titlebar";
|
import {injectTitlebar} from "./titlebar";
|
||||||
import {sleep, addStyle, injectJS} from "../utils";
|
import {sleep, addStyle, injectJS, addScript} from "../utils";
|
||||||
import {ipcRenderer} from "electron";
|
import {ipcRenderer} from "electron";
|
||||||
import {injectTabs} from "./tabs";
|
import {injectTabs} from "./tabs";
|
||||||
var version = ipcRenderer.sendSync("get-app-version", "app-version");
|
var version = ipcRenderer.sendSync("get-app-version", "app-version");
|
||||||
|
async function updateLang() {
|
||||||
|
addScript(`function getDiscordLang() {
|
||||||
|
{const _w=webpackChunkdiscord_app;let lang;_w.push([[Symbol()],{},e=>{for(const k in e.c){const m=e.c[k].exports;const mDef=m?.default&&m.__esModule?m.default:m;if(mDef?._chosenLocale&&!lang)lang=mDef}}]);_w.pop();window.armcord.setLang(lang._chosenLocale);return lang._chosenLocale;void 0}}
|
||||||
|
getDiscordLang();`);
|
||||||
|
}
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
armcord: any;
|
armcord: any;
|
||||||
|
@ -30,7 +34,7 @@ if (window.location.href.indexOf("splash.html") > -1) {
|
||||||
if (ipcRenderer.sendSync("tabs")) {
|
if (ipcRenderer.sendSync("tabs")) {
|
||||||
injectTabs();
|
injectTabs();
|
||||||
}
|
}
|
||||||
sleep(5000).then(() => {
|
sleep(5000).then(async () => {
|
||||||
const cssPath = path.join(__dirname, "../", "/content/css/discord.css");
|
const cssPath = path.join(__dirname, "../", "/content/css/discord.css");
|
||||||
addStyle(fs.readFileSync(cssPath, "utf8"));
|
addStyle(fs.readFileSync(cssPath, "utf8"));
|
||||||
|
|
||||||
|
@ -38,14 +42,17 @@ if (window.location.href.indexOf("splash.html") > -1) {
|
||||||
case "goosemod":
|
case "goosemod":
|
||||||
injectJS(clientMods.goosemod);
|
injectJS(clientMods.goosemod);
|
||||||
console.log("Loading GooseMod...");
|
console.log("Loading GooseMod...");
|
||||||
|
await updateLang();
|
||||||
break;
|
break;
|
||||||
case "cumcord":
|
case "cumcord":
|
||||||
injectJS(clientMods.cumcord);
|
injectJS(clientMods.cumcord);
|
||||||
console.log("Loading Cumcord...");
|
console.log("Loading Cumcord...");
|
||||||
|
await updateLang();
|
||||||
break;
|
break;
|
||||||
case "flicker":
|
case "flicker":
|
||||||
injectJS(clientMods.flicker);
|
injectJS(clientMods.flicker);
|
||||||
console.log("Loading FlickerMod...");
|
console.log("Loading FlickerMod...");
|
||||||
|
await updateLang();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
20
src/utils.ts
20
src/utils.ts
|
@ -88,8 +88,8 @@ export async function injectElectronFlags() {
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
const presets = {
|
const presets = {
|
||||||
'performance': `--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
|
performance: `--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?
|
battery: "--enable-features=TurnOffStreamingMediaCachingOnBattery --force_low_power_gpu" // Known to have better battery life for Chromium?
|
||||||
};
|
};
|
||||||
switch (await getConfig("performanceMode")) {
|
switch (await getConfig("performanceMode")) {
|
||||||
case "performance":
|
case "performance":
|
||||||
|
@ -104,6 +104,20 @@ export async function injectElectronFlags() {
|
||||||
console.log("No performance modes set");
|
console.log("No performance modes set");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
export async function setLang(language: string) {
|
||||||
|
const userDataPath = app.getPath("userData");
|
||||||
|
const storagePath = path.join(userDataPath, "/storage/");
|
||||||
|
const langConfigFile = storagePath + "lang.json";
|
||||||
|
if (!fs.existsSync(langConfigFile)) {
|
||||||
|
fs.writeFileSync(langConfigFile, "{}", "utf-8");
|
||||||
|
}
|
||||||
|
let rawdata = fs.readFileSync(langConfigFile, "utf-8");
|
||||||
|
let parsed = JSON.parse(rawdata);
|
||||||
|
parsed["lang"] = language;
|
||||||
|
let toSave = JSON.stringify(parsed);
|
||||||
|
fs.writeFileSync(langConfigFile, toSave, "utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
//ArmCord Settings/Storage manager
|
//ArmCord Settings/Storage manager
|
||||||
|
|
||||||
export interface Settings {
|
export interface Settings {
|
||||||
|
@ -113,7 +127,7 @@ export interface Settings {
|
||||||
minimizeToTray: boolean;
|
minimizeToTray: boolean;
|
||||||
automaticPatches: boolean;
|
automaticPatches: boolean;
|
||||||
mods: string;
|
mods: string;
|
||||||
performanceMode: string,
|
performanceMode: string;
|
||||||
blurType: string;
|
blurType: string;
|
||||||
inviteWebsocket: boolean;
|
inviteWebsocket: boolean;
|
||||||
doneSetup: boolean;
|
doneSetup: boolean;
|
||||||
|
|
Loading…
Reference in a new issue