Implemented strict linting standards and prettier formatting config. (#248)
* Implemented strict linting standards and prettier formatting config. * More linter fixes and type updates. * More linter updates and type fixes * Remove noisy comments * Linter and type updates * Linter, formatting and type updates. * Linter updates * Type updates * Type updates * fixed all linter errors * Fixed all linting, formatting and type issues. * Resolve merge conflicts.
This commit is contained in:
@@ -1,70 +1,74 @@
|
||||
// <3 Aylur for this brightness service
|
||||
import { bash, dependencies, sh } from "lib/utils"
|
||||
import { bash, dependencies, sh } from 'lib/utils';
|
||||
|
||||
if (!dependencies("brightnessctl"))
|
||||
App.quit()
|
||||
if (!dependencies('brightnessctl')) App.quit();
|
||||
|
||||
const get = (args: string) => Number(Utils.exec(`brightnessctl ${args}`))
|
||||
const screen = await bash`ls -w1 /sys/class/backlight | head -1`
|
||||
const kbd = await bash`ls -w1 /sys/class/leds | head -1`
|
||||
const get = (args: string): number => Number(Utils.exec(`brightnessctl ${args}`));
|
||||
const screen = await bash`ls -w1 /sys/class/backlight | head -1`;
|
||||
const kbd = await bash`ls -w1 /sys/class/leds | head -1`;
|
||||
|
||||
class Brightness extends Service {
|
||||
static {
|
||||
Service.register(this, {}, {
|
||||
"screen": ["float", "rw"],
|
||||
"kbd": ["int", "rw"],
|
||||
})
|
||||
Service.register(
|
||||
this,
|
||||
{},
|
||||
{
|
||||
screen: ['float', 'rw'],
|
||||
kbd: ['int', 'rw'],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#kbdMax = get(`--device ${kbd} max`)
|
||||
#kbd = get(`--device ${kbd} get`)
|
||||
#screenMax = get(`--device ${screen} max`)
|
||||
#screen = get(`--device ${screen} get`) / (get(`--device ${screen} max`) || 1)
|
||||
#kbdMax = get(`--device ${kbd} max`);
|
||||
#kbd = get(`--device ${kbd} get`);
|
||||
#screenMax = get(`--device ${screen} max`);
|
||||
#screen = get(`--device ${screen} get`) / (get(`--device ${screen} max`) || 1);
|
||||
|
||||
get kbd() { return this.#kbd }
|
||||
get screen() { return this.#screen }
|
||||
get kbd(): number {
|
||||
return this.#kbd;
|
||||
}
|
||||
get screen(): number {
|
||||
return this.#screen;
|
||||
}
|
||||
|
||||
set kbd(value) {
|
||||
if (value < 0 || value > this.#kbdMax)
|
||||
return
|
||||
if (value < 0 || value > this.#kbdMax) return;
|
||||
|
||||
sh(`brightnessctl -d ${kbd} s ${value} -q`).then(() => {
|
||||
this.#kbd = value
|
||||
this.changed("kbd")
|
||||
})
|
||||
this.#kbd = value;
|
||||
this.changed('kbd');
|
||||
});
|
||||
}
|
||||
|
||||
set screen(percent) {
|
||||
if (percent < 0)
|
||||
percent = 0
|
||||
if (percent < 0) percent = 0;
|
||||
|
||||
if (percent > 1)
|
||||
percent = 1
|
||||
if (percent > 1) percent = 1;
|
||||
|
||||
sh(`brightnessctl set ${Math.round(percent * 100)}% -d ${screen} -q`).then(() => {
|
||||
this.#screen = percent
|
||||
this.changed("screen")
|
||||
})
|
||||
this.#screen = percent;
|
||||
this.changed('screen');
|
||||
});
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
super();
|
||||
|
||||
const screenPath = `/sys/class/backlight/${screen}/brightness`
|
||||
const kbdPath = `/sys/class/leds/${kbd}/brightness`
|
||||
const screenPath = `/sys/class/backlight/${screen}/brightness`;
|
||||
const kbdPath = `/sys/class/leds/${kbd}/brightness`;
|
||||
|
||||
Utils.monitorFile(screenPath, async f => {
|
||||
const v = await Utils.readFileAsync(f)
|
||||
this.#screen = Number(v) / this.#screenMax
|
||||
this.changed("screen")
|
||||
})
|
||||
Utils.monitorFile(screenPath, async (f) => {
|
||||
const v = await Utils.readFileAsync(f);
|
||||
this.#screen = Number(v) / this.#screenMax;
|
||||
this.changed('screen');
|
||||
});
|
||||
|
||||
Utils.monitorFile(kbdPath, async f => {
|
||||
const v = await Utils.readFileAsync(f)
|
||||
this.#kbd = Number(v) / this.#kbdMax
|
||||
this.changed("kbd")
|
||||
})
|
||||
Utils.monitorFile(kbdPath, async (f) => {
|
||||
const v = await Utils.readFileAsync(f);
|
||||
this.#kbd = Number(v) / this.#kbdMax;
|
||||
this.changed('kbd');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default new Brightness
|
||||
export default new Brightness();
|
||||
|
||||
@@ -1,87 +1,97 @@
|
||||
import { dependencies, sh } from "lib/utils"
|
||||
import options from "options";
|
||||
const hyprland = await Service.import("hyprland");
|
||||
import { dependencies, sh } from 'lib/utils';
|
||||
import options from 'options';
|
||||
const hyprland = await Service.import('hyprland');
|
||||
|
||||
const WP = `${Utils.HOME}/.config/background`
|
||||
const WP = `${Utils.HOME}/.config/background`;
|
||||
|
||||
class Wallpaper extends Service {
|
||||
static {
|
||||
Service.register(this, {}, {
|
||||
"wallpaper": ["string"],
|
||||
})
|
||||
Service.register(
|
||||
this,
|
||||
{},
|
||||
{
|
||||
wallpaper: ['string'],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#blockMonitor = false
|
||||
#isRunning = false
|
||||
#blockMonitor = false;
|
||||
#isRunning = false;
|
||||
|
||||
#wallpaper() {
|
||||
if (!dependencies("swww"))
|
||||
return
|
||||
#wallpaper(): void {
|
||||
if (!dependencies('swww')) return;
|
||||
|
||||
hyprland.monitors.map(m => m.name);
|
||||
sh("hyprctl cursorpos").then(pos => {
|
||||
hyprland.monitors.map((m) => m.name);
|
||||
sh('hyprctl cursorpos').then((pos) => {
|
||||
sh([
|
||||
"swww", "img",
|
||||
"--invert-y",
|
||||
"--transition-type", "grow",
|
||||
"--transition-duration", "1.5",
|
||||
"--transition-fps", "30",
|
||||
"--transition-pos", pos.replace(" ", ""),
|
||||
'swww',
|
||||
'img',
|
||||
'--invert-y',
|
||||
'--transition-type',
|
||||
'grow',
|
||||
'--transition-duration',
|
||||
'1.5',
|
||||
'--transition-fps',
|
||||
'30',
|
||||
'--transition-pos',
|
||||
pos.replace(' ', ''),
|
||||
WP,
|
||||
]).then(() => {
|
||||
this.changed("wallpaper")
|
||||
})
|
||||
})
|
||||
this.changed('wallpaper');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async #setWallpaper(path: string) {
|
||||
this.#blockMonitor = true
|
||||
async #setWallpaper(path: string): Promise<void> {
|
||||
this.#blockMonitor = true;
|
||||
|
||||
await sh(`cp ${path} ${WP}`)
|
||||
this.#wallpaper()
|
||||
await sh(`cp ${path} ${WP}`);
|
||||
this.#wallpaper();
|
||||
|
||||
this.#blockMonitor = false
|
||||
this.#blockMonitor = false;
|
||||
}
|
||||
|
||||
readonly set = (path: string) => { this.#setWallpaper(path) }
|
||||
readonly isRunning = () => { return this.#isRunning }
|
||||
readonly set = (path: string): void => {
|
||||
this.#setWallpaper(path);
|
||||
};
|
||||
readonly isRunning = (): boolean => {
|
||||
return this.#isRunning;
|
||||
};
|
||||
|
||||
get wallpaper() { return WP }
|
||||
get wallpaper(): string {
|
||||
return WP;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
super();
|
||||
|
||||
options.wallpaper.enable.connect("changed", () => {
|
||||
options.wallpaper.enable.connect('changed', () => {
|
||||
if (options.wallpaper.enable.value) {
|
||||
this.#isRunning = true
|
||||
Utils.execAsync("swww-daemon")
|
||||
this.#isRunning = true;
|
||||
Utils.execAsync('swww-daemon')
|
||||
.then(() => {
|
||||
this.#wallpaper
|
||||
this.#wallpaper();
|
||||
})
|
||||
.catch(() => null)
|
||||
.catch(() => null);
|
||||
} else {
|
||||
this.#isRunning = false
|
||||
Utils.execAsync("pkill swww-daemon")
|
||||
.catch(() => null)
|
||||
this.#isRunning = false;
|
||||
Utils.execAsync('pkill swww-daemon').catch(() => null);
|
||||
}
|
||||
});
|
||||
|
||||
})
|
||||
if (!dependencies('swww') || !options.wallpaper.enable.value) return this;
|
||||
|
||||
if (!dependencies("swww") || !options.wallpaper.enable.value)
|
||||
return this
|
||||
|
||||
this.#isRunning = true
|
||||
this.#isRunning = true;
|
||||
Utils.monitorFile(WP, () => {
|
||||
if (!this.#blockMonitor)
|
||||
this.#wallpaper()
|
||||
})
|
||||
if (!this.#blockMonitor) this.#wallpaper();
|
||||
});
|
||||
|
||||
Utils.execAsync("swww-daemon")
|
||||
Utils.execAsync('swww-daemon')
|
||||
.then(() => {
|
||||
this.#wallpaper
|
||||
this.#wallpaper();
|
||||
})
|
||||
.catch(() => null)
|
||||
.catch(() => null);
|
||||
}
|
||||
}
|
||||
|
||||
export default new Wallpaper
|
||||
export default new Wallpaper();
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { defaultColorMap } from "lib/types/defaults/options";
|
||||
import { HexColor, MatugenColors } from "lib/types/options";
|
||||
import { getMatugenVariations } from "./variations";
|
||||
import { bash, dependencies, Notify, isAnImage } from "lib/utils";
|
||||
import options from "options";
|
||||
import icons from "lib/icons";
|
||||
import { Variable } from "types/variable";
|
||||
import { defaultColorMap } from 'lib/types/defaults/options';
|
||||
import { ColorMapValue, ColorMapKey, HexColor, MatugenColors } from 'lib/types/options';
|
||||
import { getMatugenVariations } from './variations';
|
||||
import { bash, dependencies, Notify, isAnImage } from 'lib/utils';
|
||||
import options from 'options';
|
||||
import icons from 'lib/icons';
|
||||
import { Variable } from 'types/variable';
|
||||
const { scheme_type, contrast } = options.theme.matugen_settings;
|
||||
const { matugen } = options.theme;
|
||||
|
||||
const updateOptColor = (color: HexColor, opt: Variable<HexColor>) => {
|
||||
const updateOptColor = (color: HexColor, opt: Variable<HexColor>): void => {
|
||||
opt.value = color;
|
||||
}
|
||||
};
|
||||
|
||||
export async function generateMatugenColors(): Promise<MatugenColors | undefined> {
|
||||
if (!matugen.value || !dependencies('matugen')) {
|
||||
@@ -21,18 +21,18 @@ export async function generateMatugenColors(): Promise<MatugenColors | undefined
|
||||
try {
|
||||
if (!wallpaperPath.length || !isAnImage(wallpaperPath)) {
|
||||
Notify({
|
||||
summary: "Matugen Failed",
|
||||
summary: 'Matugen Failed',
|
||||
body: "Please select a wallpaper in 'Theming > General' first.",
|
||||
iconName: icons.ui.warning,
|
||||
timeout: 7000
|
||||
})
|
||||
timeout: 7000,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const normalizedContrast = contrast.value > 1 ? 1
|
||||
: contrast.value < -1 ? -1
|
||||
: contrast.value
|
||||
const contents = await bash(`matugen image ${wallpaperPath} -t scheme-${scheme_type.value} --contrast ${normalizedContrast} --json hex`);
|
||||
const normalizedContrast = contrast.value > 1 ? 1 : contrast.value < -1 ? -1 : contrast.value;
|
||||
const contents = await bash(
|
||||
`matugen image ${wallpaperPath} -t scheme-${scheme_type.value} --contrast ${normalizedContrast} --json hex`,
|
||||
);
|
||||
|
||||
return JSON.parse(contents).colors[options.theme.matugen_settings.mode.value];
|
||||
} catch (error) {
|
||||
@@ -42,6 +42,10 @@ export async function generateMatugenColors(): Promise<MatugenColors | undefined
|
||||
}
|
||||
}
|
||||
|
||||
const isColorValid = (color: string): color is ColorMapKey => {
|
||||
return defaultColorMap.hasOwnProperty(color);
|
||||
};
|
||||
|
||||
export const replaceHexValues = (incomingHex: HexColor, matugenColors: MatugenColors): HexColor => {
|
||||
if (!options.theme.matugen.value) {
|
||||
return incomingHex;
|
||||
@@ -49,11 +53,18 @@ export const replaceHexValues = (incomingHex: HexColor, matugenColors: MatugenCo
|
||||
|
||||
const matugenVariation = getMatugenVariations(matugenColors, options.theme.matugen_settings.variation.value);
|
||||
updateOptColor(matugenVariation.base, options.theme.bar.menus.menu.media.card.color as Variable<HexColor>);
|
||||
for (let curColor of Object.keys(defaultColorMap)) {
|
||||
if (defaultColorMap[curColor] === incomingHex) {
|
||||
return matugenVariation[curColor];
|
||||
|
||||
for (const curColor of Object.keys(defaultColorMap)) {
|
||||
const currentColor: string = curColor;
|
||||
if (!isColorValid(currentColor)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const curColorValue: ColorMapValue = defaultColorMap[currentColor];
|
||||
if (curColorValue === incomingHex) {
|
||||
return matugenVariation[currentColor];
|
||||
}
|
||||
}
|
||||
|
||||
return incomingHex;
|
||||
}
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user