ref: use dbus-native for getting accent color
This commit is contained in:
parent
d379f96123
commit
066afb837b
2 changed files with 32 additions and 30 deletions
|
@ -28,7 +28,8 @@
|
||||||
"electron-updater": "^6.2.1"
|
"electron-updater": "^6.2.1"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"@vencord/venmic": "^6.1.0"
|
"@vencord/venmic": "^6.1.0",
|
||||||
|
"@homebridge/dbus-native": "0.6.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@fal-works/esbuild-plugin-global-externals": "^2.1.2",
|
"@fal-works/esbuild-plugin-global-externals": "^2.1.2",
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* Copyright (c) 2023 Vendicated and Vencord contributors
|
* Copyright (c) 2023 Vendicated and Vencord contributors
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { execFileSync } from "child_process";
|
import dbus from "@homebridge/dbus-native";
|
||||||
import {
|
import {
|
||||||
app,
|
app,
|
||||||
BrowserWindow,
|
BrowserWindow,
|
||||||
|
@ -508,35 +508,36 @@ export async function createWindows() {
|
||||||
|
|
||||||
export function getAccentColor() {
|
export function getAccentColor() {
|
||||||
if (process.platform === "linux") {
|
if (process.platform === "linux") {
|
||||||
var accentColor = execFileSync("gdbus", [
|
return new Promise((resolve, reject) => {
|
||||||
"call",
|
const sessionBus = dbus.sessionBus();
|
||||||
"--session",
|
sessionBus
|
||||||
"--dest",
|
.getService("org.freedesktop.portal.Desktop")
|
||||||
"org.freedesktop.portal.Desktop",
|
.getInterface(
|
||||||
"--object-path",
|
|
||||||
"/org/freedesktop/portal/desktop",
|
"/org/freedesktop/portal/desktop",
|
||||||
"--method",
|
"org.freedesktop.portal.Settings",
|
||||||
"org.freedesktop.portal.Settings.Read",
|
function (err, settings) {
|
||||||
"org.freedesktop.appearance",
|
if (err) {
|
||||||
"accent-color"
|
resolve("");
|
||||||
]);
|
return;
|
||||||
const rgbMatch = accentColor.toString().match(/\((\d+\.\d+),\s*(\d+\.\d+),\s*(\d+\.\d+)\)/);
|
}
|
||||||
|
settings.Read("org.freedesktop.appearance", "accent-color", function (err, result) {
|
||||||
if (rgbMatch) {
|
if (err) {
|
||||||
const r = parseFloat(rgbMatch[1]);
|
resolve("");
|
||||||
const g = parseFloat(rgbMatch[2]);
|
return;
|
||||||
const b = parseFloat(rgbMatch[3]);
|
}
|
||||||
|
const [r, g, b] = result[1][0][1][0];
|
||||||
const r255 = Math.round(r * 255);
|
const r255 = Math.round(r * 255);
|
||||||
const g255 = Math.round(g * 255);
|
const g255 = Math.round(g * 255);
|
||||||
const b255 = Math.round(b * 255);
|
const b255 = Math.round(b * 255);
|
||||||
|
|
||||||
const toHex = (value: number) => value.toString(16).padStart(2, "0");
|
const toHex = (value: number) => value.toString(16).padStart(2, "0");
|
||||||
const hexColor = `#${toHex(r255)}${toHex(g255)}${toHex(b255)}`;
|
const hexColor = `#${toHex(r255)}${toHex(g255)}${toHex(b255)}`;
|
||||||
return hexColor;
|
resolve(hexColor);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return "";
|
);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
return `#${systemPreferences.getAccentColor?.() || ""}`;
|
return Promise.resolve(`#${systemPreferences.getAccentColor?.() || ""}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue