Skip to content

Commit

Permalink
enable rpc by default + add global max brightness
Browse files Browse the repository at this point in the history
  • Loading branch information
JustJoostNL committed Mar 8, 2024
1 parent 6f75974 commit 63d68aa
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/main/lightController/controlAllLights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const fallBackEvent = EventType.GreenFlag;

export async function controlAllLights({
color,
brightness,
brightness: initialBrightness,
controlType,
event,
eventAction,
Expand All @@ -41,6 +41,12 @@ export async function controlAllLights({
}

const config = await getConfig();

const globalMaxBrightness = config.globalMaxBrightness;
const brightness = initialBrightness
? (initialBrightness / 100) * globalMaxBrightness
: globalMaxBrightness;

if (!color || !brightness || !controlType) return;

if (config.homeAssistantEnabled) {
Expand Down
55 changes: 55 additions & 0 deletions src/renderer/components/settings/GlobalMaxBrightnessSlider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Box, Slider, Input } from "@mui/material";
import React, { useCallback } from "react";
import { useConfig } from "../../hooks/useConfig";

export function GlobalMaxBrightnessSlider() {
const { config, updateConfig } = useConfig();

const handleSliderChange = useCallback(
async (_event: Event, value: number | number[]) => {
if (typeof value !== "number") return;
updateConfig({ globalMaxBrightness: value });
},
[updateConfig],
);

const handleInputChange = useCallback(
async (event: React.ChangeEvent<HTMLInputElement>) => {
const value = parseInt(event.target.value);
if (isNaN(value)) return;
updateConfig({ globalMaxBrightness: value });
},
[updateConfig],
);

return (
<Box display="flex" alignItems="center" sx={{ width: 300 }}>
<Box sx={{ m: 1, width: "100%" }}>
<Slider
value={config.globalMaxBrightness}
onChange={handleSliderChange}
min={0}
max={100}
step={1}
valueLabelDisplay="auto"
sx={{
width: "100%",
}}
/>
</Box>
<Input
value={config.globalMaxBrightness}
onChange={handleInputChange}
size="small"
type="number"
inputProps={{
min: 0,
max: 100,
step: 1,
type: "number",
}}
sx={{ width: 55, ml: 3 }}
/>
</Box>
);
}
9 changes: 9 additions & 0 deletions src/renderer/components/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { OpenRGBConnectButton } from "./OpenRGBConnectButton";
import { WLEDConfigureDevicesButton } from "./WLEDConfigureDevicesButton";
import { IkeaGatewayIpInput } from "./IkeaGatewayIpInput.tsx";
import { IkeaSelectButton } from "./IkeaSelectButton";
import { GlobalMaxBrightnessSlider } from "./GlobalMaxBrightnessSlider";

interface ISettings extends SettingsGroupProps {
type?: "normal" | "experimental" | "debug";
Expand Down Expand Up @@ -83,6 +84,14 @@ export function Settings() {
configKeys: ["startMultiViewerWhenAppStarts"],
input: <AutoMultiViewerStartToggle />,
},
{
type: "setting",
title: "Global maximum brightness",
description:
"This is the maximum brightness the app will use for the lights.",
configKeys: ["globalMaxBrightness"],
input: <GlobalMaxBrightnessSlider />,
},
{
type: "setting",
title: "Event settings",
Expand Down
1 change: 1 addition & 0 deletions src/shared/config/config_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export interface Event {
export interface IConfig {
hideLogs: boolean;
startMultiViewerWhenAppStarts: boolean;
globalMaxBrightness: number;
events: Event[];
multiviewerLiveTimingURL: string;
multiviewerCheck: boolean;
Expand Down
3 changes: 2 additions & 1 deletion src/shared/config/defaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export const defaultConfig: IConfig = {
amount: 1,
},
],
globalMaxBrightness: 100,
multiviewerLiveTimingURL: "http://localhost:10101",
multiviewerCheck: true,
philipsHueEnabled: false,
Expand Down Expand Up @@ -181,7 +182,7 @@ export const defaultConfig: IConfig = {
mqttBrokerUsername: undefined,
mqttBrokerPassword: undefined,
streamdeckEnabled: false,
discordRPCEnabled: false,
discordRPCEnabled: true,
discordRPCAvoidSpoilers: false,
webserverEnabled: false,
webserverPort: 20202,
Expand Down

0 comments on commit 63d68aa

Please sign in to comment.