Skip to content

Commit

Permalink
v3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JustJoostNL committed Aug 22, 2024
1 parent 5b44a80 commit d125a13
Show file tree
Hide file tree
Showing 29 changed files with 283 additions and 159 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "F1MV-Lights-Integration",
"version": "3.1.1",
"version": "3.2.0",
"main": "dist-electron/main/index.js",
"description": "The best way to connect your smart home lights to MultiViewer.",
"author": "JustJoostNL",
Expand Down
6 changes: 3 additions & 3 deletions src/main/ipc/appInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ function handleGetAppVersion() {
}

function registerAppInfoIPCHandlers() {
ipcMain.handle("f1mvli:appInfo:getAppVersion", handleGetAppVersion);
ipcMain.handle("f1mvli:appInfo:get-app-version", handleGetAppVersion);

return function () {
ipcMain.removeHandler("f1mvli:appInfo:getAppVersion");
return () => {
ipcMain.removeHandler("f1mvli:appInfo:get-app-version");
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/ipc/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ function registerConfigIPCHandlers() {
ipcMain.handle("f1mvli:config:set", handleConfigSet);
ipcMain.handle("f1mvli:config:reset", handleConfigReset);
ipcMain.handle("f1mvli:config:open", handleConfigOpen);
ipcMain.handle("f1mvli:config:updateOTA", fetchAuthoritativeConfig);
ipcMain.handle("f1mvli:config:ota:get", fetchAuthoritativeConfig);

return function () {
return () => {
ipcMain.removeHandler("f1mvli:config:get");
ipcMain.removeHandler("f1mvli:config:set");
ipcMain.removeHandler("f1mvli:config:reset");
Expand Down
10 changes: 5 additions & 5 deletions src/main/ipc/eventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ function registerEventManagerIPCHandlers() {
return handleSimulate(arg);
});
ipcMain.handle(
"f1mvli:eventManager:simulateBackToStatic",
"f1mvli:eventManager:simulate:static",
handleSimulateBackToStatic,
);
ipcMain.handle("f1mvli:eventManager:allOff", handleAllOff);
ipcMain.handle("f1mvli:eventManager:all-off", handleAllOff);

return function () {
return () => {
ipcMain.removeHandler("f1mvli:eventManager:simulate");
ipcMain.removeHandler("f1mvli:eventManager:simulateBackToStatic");
ipcMain.removeHandler("f1mvli:eventManager:allOff");
ipcMain.removeHandler("f1mvli:eventManager:simulate:static");
ipcMain.removeHandler("f1mvli:eventManager:all-off");
};
}

Expand Down
40 changes: 21 additions & 19 deletions src/main/ipc/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,58 +63,60 @@ async function handleGetTradfriDevices() {

function registerIntegrationsIPCHandlers() {
ipcMain.handle(
"f1mvli:integrations:homeAssistant:getDevices",
"f1mvli:integrations:homeassistant:get-devices",
handleHomeAssistantGetDevices,
);
ipcMain.handle(
"f1mvli:integrations:homeAssistant:checkDeviceSpectrum",
"f1mvli:integrations:homeassistant:check-device-spectrum",
(_, arg) => {
return handleHomeAssistantCheckDeviceSpectrum(arg);
},
);
ipcMain.handle(
"f1mvli:integrations:homebridge:getAccessories",
"f1mvli:integrations:homebridge:get-accessories",
handleHomebridgeGetAccessories,
);
ipcMain.handle(
"f1mvli:integrations:philipsHue:discoverBridge",
"f1mvli:integrations:philips-hue:discover-bridge",
handleDiscoverPhilipsHueBridge,
);
ipcMain.handle(
"f1mvli:integrations:philipsHue:generateAuthToken",
"f1mvli:integrations:philips-hue:generate-auth-token",
handleGeneratePhilipsHueBridgeAuthToken,
);
ipcMain.handle(
"f1mvli:integrations:philipsHue:getDevices",
"f1mvli:integrations:philips-hue:get-devices",
handlePhilipsHueGetDevices,
);
ipcMain.handle(
"f1mvli:integrations:philipsHue:getGroups",
"f1mvli:integrations:philips-hue:get-groups",
handlePhilipsHueGetGroups,
);
ipcMain.handle("f1mvli:integrations:openrgb:connect", handleConnectOpenRGB);
ipcMain.handle(
"f1mvli:integrations:tradfri:discoverGateway",
"f1mvli:integrations:tradfri:discover-gateway",
handleDiscoverTradfriBridge,
);
ipcMain.handle(
"f1mvli:integrations:tradfri:getDevices",
"f1mvli:integrations:tradfri:get-devices",
handleGetTradfriDevices,
);

return function () {
ipcMain.removeHandler("f1mvli:integrations:homeAssistant:getDevices");
return () => {
ipcMain.removeHandler("f1mvli:integrations:homeassistant:get-devices");
ipcMain.removeHandler(
"f1mvli:integrations:homeAssistant:checkDeviceSpectrum",
"f1mvli:integrations:homeassistant:check-device-spectrum",
);
ipcMain.removeHandler("f1mvli:integrations:homebridge:getAccessories");
ipcMain.removeHandler("f1mvli:integrations:philipsHue:discoverBridge");
ipcMain.removeHandler("f1mvli:integrations:philipsHue:generateAuthToken");
ipcMain.removeHandler("f1mvli:integrations:philipsHue:getDevices");
ipcMain.removeHandler("f1mvli:integrations:philipsHue:getGroups");
ipcMain.removeHandler("f1mvli:integrations:homebridge:get-accessories");
ipcMain.removeHandler("f1mvli:integrations:philips-hue:discover-bridge");
ipcMain.removeHandler(
"f1mvli:integrations:philips-hue:generate-auth-token",
);
ipcMain.removeHandler("f1mvli:integrations:philips-hue:get-devices");
ipcMain.removeHandler("f1mvli:integrations:philips-hue:get-groups");
ipcMain.removeHandler("f1mvli:integrations:openrgb:connect");
ipcMain.removeHandler("f1mvli:integrations:tradfri:discoverGateway");
ipcMain.removeHandler("f1mvli:integrations:tradfri:getDevices");
ipcMain.removeHandler("f1mvli:integrations:tradfri:discover-gateway");
ipcMain.removeHandler("f1mvli:integrations:tradfri:get-devices");
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/ipc/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function registerLoggerIPCHandlers() {
ipcMain.handle("f1mvli:log:open", handleOpenLogfile);
ipcMain.handle("f1mvli:log:get", handleGetLogs);

return function () {
return () => {
ipcMain.removeHandler("f1mvli:log:open");
ipcMain.removeHandler("f1mvli:log:get");
};
Expand Down
17 changes: 10 additions & 7 deletions src/main/ipc/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,23 @@ function registerUpdaterIPCHandlers() {
autoUpdater.on("update-not-available", handleUpdateNotAvailable);
autoUpdater.on("error", handleUpdateError);

ipcMain.handle("f1mvli:updater:checkForUpdates", handleCheckForUpdates);
ipcMain.handle("f1mvli:updater:getUpdateAvailable", handleGetUpdateAvailable);
ipcMain.handle("f1mvli:updater:quitAndInstall", handleQuitAndInstall);
ipcMain.handle("f1mvli:updater:check-for-updates", handleCheckForUpdates);
ipcMain.handle(
"f1mvli:updater:get-update-available",
handleGetUpdateAvailable,
);
ipcMain.handle("f1mvli:updater:quit-and-install", handleQuitAndInstall);

return function () {
return () => {
autoUpdater.off("error", handleUpdateError);
autoUpdater.off("update-downloaded", handleUpdateDownloaded);
autoUpdater.off("update-available", handleUpdateAvailable);
autoUpdater.off("update-not-available", handleUpdateNotAvailable);
autoUpdater.off("error", handleUpdateError);

ipcMain.removeHandler("f1mvli:updater:checkForUpdates");
ipcMain.removeHandler("f1mvli:updater:getUpdateAvailable");
ipcMain.removeHandler("f1mvli:updater:quitAndInstall");
ipcMain.removeHandler("f1mvli:updater:check-for-updates");
ipcMain.removeHandler("f1mvli:updater:get-update-available");
ipcMain.removeHandler("f1mvli:updater:quit-and-install");
};
}

Expand Down
49 changes: 31 additions & 18 deletions src/main/ipc/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,35 @@ import { getConfig } from "./config";

const handleGetIntegrationStates = async () => {
const config = await getConfig();
if (config.homeAssistantEnabled) await homeAssistantOnlineCheck();
if (config.homebridgeEnabled) await homebridgeOnlineCheck();
if (config.philipsHueEnabled) await philipsHueOnlineCheck();
if (config.ikeaEnabled) await tradfriOnlineCheck();

const checks: { enabled: boolean; fn: () => Promise<string> }[] = [
{
enabled: config.homeAssistantEnabled,
fn: homeAssistantOnlineCheck,
},
{
enabled: config.homebridgeEnabled,
fn: homebridgeOnlineCheck,
},
{
enabled: config.philipsHueEnabled,
fn: philipsHueOnlineCheck,
},
{
enabled: config.ikeaEnabled,
fn: tradfriOnlineCheck,
},
];

const enabledChecks = checks.filter((check) => check.enabled);
await Promise.all(enabledChecks.map((check) => check.fn()));

const states = [
{
name: "multiviewer",
state: integrationStates.multiviewer,
disabled: false,
},
{
name: "autoUpdater",
state: integrationStates.autoUpdater,
disabled: false,
},
{
name: "f1tvLiveSession",
state: integrationStates.f1tvLiveSession,
Expand Down Expand Up @@ -104,18 +117,18 @@ const handleExitApp = () => {

function registerUtilsIPCHandlers() {
ipcMain.handle(
"f1mvli:utils:getIntegrationStates",
"f1mvli:utils:get-integration-states",
handleGetIntegrationStates,
);
ipcMain.handle("f1mvli:utils:getWindowSizes", handleGetWindowSizes);
ipcMain.handle("f1mvli:utils:relaunchApp", handleRelaunchApp);
ipcMain.handle("f1mvli:utils:exitApp", handleExitApp);
ipcMain.handle("f1mvli:utils:get-window-sizes", handleGetWindowSizes);
ipcMain.handle("f1mvli:utils:relaunch-app", handleRelaunchApp);
ipcMain.handle("f1mvli:utils:exit-app", handleExitApp);

return function () {
ipcMain.removeHandler("f1mvli:utils:getIntegrationStates");
ipcMain.removeHandler("f1mvli:utils:getWindowSizes");
ipcMain.removeHandler("f1mvli:utils:relaunchApp");
ipcMain.removeHandler("f1mvli:utils:exitApp");
return () => {
ipcMain.removeHandler("f1mvli:utils:get-integration-states");
ipcMain.removeHandler("f1mvli:utils:get-window-sizes");
ipcMain.removeHandler("f1mvli:utils:relaunch-app");
ipcMain.removeHandler("f1mvli:utils:exit-app");
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/lightController/integrations/govee/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { integrationStates } from "../states";

let goveeInstance: Govee | undefined = undefined;

export interface GoveeControlArgs {
interface GoveeControlArgs {
controlType: ControlType;
color: {
r: number;
Expand Down
5 changes: 3 additions & 2 deletions src/main/lightController/integrations/homeAssistant/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
IHomeAssistantStatesResponse,
IHomeAssistantStateResponse,
} from "../../../../shared/integrations/homeAssistant_types";
import { fetchWithTimeout } from "../../../utils/fetch";

export async function homeAssistantOnlineCheck(): Promise<
"online" | "offline"
Expand All @@ -27,7 +28,7 @@ export async function homeAssistantOnlineCheck(): Promise<
url.port = globalConfig.homeAssistantPort.toString();

try {
const res = await fetch(url, options);
const res = await fetchWithTimeout(url.toString(), options);
const data: IHomeAssistantAPIPingResponse = await res.json();
integrationStates.homeAssistant = data.message === "API running.";
return integrationStates.homeAssistant ? "online" : "offline";
Expand Down Expand Up @@ -111,7 +112,7 @@ export async function homeAssistantCheckDeviceSpectrum(entityId: string) {
}
}

export interface HomeAssistantControlArgs {
interface HomeAssistantControlArgs {
controlType: ControlType;
color: {
r: number;
Expand Down
11 changes: 6 additions & 5 deletions src/main/lightController/integrations/homebridge/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
IHomebridgeAuthCheckResponse,
IHomebridgeTokenResponse,
} from "../../../../shared/integrations/homebridge_types";
import { fetchWithTimeout } from "../../../utils/fetch";

let storedToken: { token: string; expiry: number } | null = null;

Expand All @@ -28,7 +29,7 @@ export async function homebridgeOnlineCheck(): Promise<"online" | "offline"> {
};

try {
const res = await fetch(url, options);
const res = await fetchWithTimeout(url.toString(), options);
const data: IHomebridgeAuthCheckResponse = await res.json();

const isOnline = data.status === "OK";
Expand Down Expand Up @@ -59,7 +60,7 @@ export async function requestHomebridgeToken() {
};

try {
const res = await fetch(url, options);
const res = await fetchWithTimeout(url.toString(), options);
const data: IHomebridgeTokenResponse = await res.json();

storedToken = {
Expand Down Expand Up @@ -104,7 +105,7 @@ export async function homebridgeGetAccessories() {
},
};

const res = await fetch(url, options);
const res = await fetch(url.toString(), options);
const json: IHomebridgeAccessoryResponse = await res.json();

const lightList: IHomebridgeAccessory[] = [];
Expand Down Expand Up @@ -195,7 +196,7 @@ export async function homebridgeControl({
body: JSON.stringify(data),
};

const response = await fetch(url, options);
const response = await fetch(url.toString(), options);

if (!response.ok) {
log.error(
Expand Down Expand Up @@ -225,7 +226,7 @@ export async function homebridgeControl({
};

try {
await fetch(url, options);
await fetch(url.toString(), options);
} catch (err) {
log.error(
`An error occurred while turning off Homebridge device ${uniqueId}: ${err}`,
Expand Down
2 changes: 1 addition & 1 deletion src/main/lightController/integrations/openrgb/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IOpenRGBClient } from "./types";
let openrgbClient: IOpenRGBClient | undefined = undefined;
let manualDisconnect = false;

export interface OpenRGBControlArgs {
interface OpenRGBControlArgs {
controlType: ControlType;
color: {
r: number;
Expand Down
9 changes: 6 additions & 3 deletions src/main/lightController/integrations/philipsHue/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import {
import { integrationStates } from "../states";
import { ControlType } from "../../controlAllLights";
import { Action } from "../../../../shared/config/config_types";
import { fetchWithoutSSLCheck } from "./fetchWithoutSSLCheck";
import {
fetchWithoutSSLCheck,
fetchWithoutSSLCheckWithTimeout,
} from "../../../utils/fetch";
import { rgbToXY } from "./rgbToXyUsingGamut";

export async function discoverPhilipsHueBridge(): Promise<DiscoverPhilipsHueBridgeResponse> {
Expand Down Expand Up @@ -65,7 +68,7 @@ export async function philipsHueOnlineCheck(): Promise<"online" | "offline"> {
globalConfig.philipsHueBridgeAuthToken,
);

const res = await fetchWithoutSSLCheck(
const res = await fetchWithoutSSLCheckWithTimeout(
`https://${globalConfig.philipsHueBridgeIP}/clip/v2/resource/bridge`,
{
headers,
Expand Down Expand Up @@ -134,7 +137,7 @@ export async function getPhilipsHueGroups(): Promise<GetPhilipsHueGroupsResponse
};
}

export interface PhilipsHueControlArgs {
interface PhilipsHueControlArgs {
controlType: ControlType;
color: {
r: number;
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/lightController/integrations/streamdeck/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function streamdeckInitialize() {
}
}

export interface StreamDeckControlArgs {
interface StreamDeckControlArgs {
controlType: ControlType;
color: {
r: number;
Expand Down
Loading

0 comments on commit d125a13

Please sign in to comment.