Skip to content

Commit

Permalink
v2.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
JustJoostNL committed May 26, 2023
1 parent 0bd8900 commit 4ba5576
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 55 deletions.
5 changes: 5 additions & 0 deletions electron-builder.json5
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@


"linux": {
mimeTypes: ["x-scheme-handler/f1mvli"],
desktop: {
exec: "f1mvli %u",
},
category: "Utility",
"target": [
"AppImage"
],
Expand Down
2 changes: 2 additions & 0 deletions electron/main/app/deeplinking/handleDeepLinking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ export default async function deepLinkPathToRoute(deepLinkPath: string) {
return "/settings";
case "f1mvli://open/page/about":
return "/about";
default:
return "no_path_found";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export default async function homeAssistantCheckDeviceSpectrum(entityId: string)
};
const response = await fetch(reqURL, options);
const data = await response.json();
// if device doesn't have supported_color_modes, return false
if(!data.attributes.supported_color_modes) return false;
// check if color modes array has one of these: rgb, hs, xy
return !!data.attributes.supported_color_modes.find((mode: string) => mode === "rgb" || mode === "hs" || mode === "xy");
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export async function handleMiscAPIChecks(){
}

export async function handleIntegrationStates(){
if (!configVars.goveeDisable && goveeVars.goveeInitialized && goveeVars.govee.devicesArray.length > 0) {
integrationStates.goveeOnline = true;
if (!configVars.goveeDisable && goveeVars.goveeInitialized) {
integrationStates.goveeOnline = goveeVars.govee.devicesArray.length > 0;
}
if (!configVars.homeAssistantDisable){
await homeAssistantOnlineCheck();
Expand Down
90 changes: 42 additions & 48 deletions electron/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {app, BrowserWindow, dialog, ipcMain, shell} from "electron";
import { app, BrowserWindow, dialog, ipcMain, shell } from "electron";
import { release } from "node:os";
import path, { join } from "node:path";
import {
Expand Down Expand Up @@ -42,6 +42,47 @@ Sentry.init({
tracesSampleRate: 0.2,
});

// handle deep-link protocol
if (process.defaultApp) {
if (process.argv.length >= 2) {
app.setAsDefaultProtocolClient("f1mvli", process.execPath, [path.resolve(process.argv[1])]);
}
} else {
app.setAsDefaultProtocolClient("f1mvli");
}

// handle deep-linking for mac/linux
app.on("open-url", async (event, url) => {
event.preventDefault();
if (win) {
win.show();
win.focus();
const deepLinkPath = await deepLinkPathToRoute(url);
if (deepLinkPath === "no_path_found") return;
if (process.env.VITE_DEV_SERVER_URL) {
await win.loadURL(`${url}#${deepLinkPath}`);
} else {
await win.loadURL(`http://localhost:${availablePort}/index.html#${deepLinkPath}`);
}
}
});

// handle deep-linking for windows
app.on("second-instance", async (event, commandLine) => {
if (win) {
if (win.isMinimized()) win.restore();
win.show();
win.focus();
const deepLinkPath = await deepLinkPathToRoute(commandLine[commandLine.length - 1]);
if (deepLinkPath === "no_path_found") return;
if (process.env.VITE_DEV_SERVER_URL) {
await win.loadURL(`${url}#${deepLinkPath}`);
} else {
await win.loadURL(`http://localhost:${availablePort}/index.html#${deepLinkPath}`);
}
}
});

process.env.DIST_ELECTRON = join(__dirname, "../");
process.env.DIST = join(process.env.DIST_ELECTRON, "../dist");
process.env.PUBLIC = process.env.VITE_DEV_SERVER_URL
Expand Down Expand Up @@ -105,35 +146,6 @@ async function createWindow() {
});
}

// handle deep-linking
app.on("open-url", (event, url) => {
event.preventDefault();
if (win) {
win.show();
win.focus();
const deepLinkPath = deepLinkPathToRoute(url);
if (process.env.VITE_DEV_SERVER_URL) {
win.loadURL(`${url}#${deepLinkPath}`);
} else {
win.loadURL(`http://localhost:${availablePort}/index.html#${deepLinkPath}`);
}
}
});

// handle deep-linking for windows
app.on("second-instance", async (event, commandLine) => {
if (win) {
win.show();
win.focus();
const deepLinkPath = await deepLinkPathToRoute(commandLine[commandLine.length - 1]);
if (process.env.VITE_DEV_SERVER_URL) {
await win.loadURL(`${url}#${deepLinkPath}`);
} else {
await win.loadURL(`http://localhost:${availablePort}/index.html#${deepLinkPath}`);
}
}
});

// Make all links open with the browser, not with the application
win.webContents.setWindowOpenHandler(({ url }) => {
if (url.startsWith("https:" || "http:")) shell.openExternal(url);
Expand All @@ -144,15 +156,6 @@ async function createWindow() {
app.whenReady().then(onReady);

function onReady() {
// handle deep-link protocol
if (process.defaultApp) {
if (process.argv.length >= 2) {
app.setAsDefaultProtocolClient("f1mvli", process.execPath, [path.resolve(process.argv[1])]);
}
} else {
app.setAsDefaultProtocolClient("f1mvli");
}

createWindow();

win.webContents.on("did-finish-load", () => {
Expand Down Expand Up @@ -207,14 +210,6 @@ app.on("window-all-closed", () => {
if (process.platform !== "darwin") app.quit();
});

app.on("second-instance", () => {
if (win) {
// Focus on the main window if the user tried to open another
if (win.isMinimized()) win.restore();
win.focus();
}
});

app.on("activate", () => {
const allWindows = BrowserWindow.getAllWindows();
if (allWindows.length) {
Expand All @@ -224,7 +219,6 @@ app.on("activate", () => {
}
});

// New window example arg: new windows url
ipcMain.handle("utils:open-win", (_, arg) => {
const childWindow = new BrowserWindow({
title: arg.browserWindowOptions.title,
Expand Down
7 changes: 6 additions & 1 deletion electron/main/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ let noUpdateFound = false;

export default function initUpdater(){
autoUpdater.forceDevUpdateConfig = true;
autoUpdater.autoDownload = true;
autoUpdater.autoDownload = false;
autoUpdater.disableWebInstaller = true;
autoUpdater.allowDowngrade = false;
autoUpdater.autoInstallOnAppQuit = true;
autoUpdater.channel = <string>configVars.updateChannel;
//autoUpdater.logger = log;

autoUpdater.on("update-downloaded", (event: UpdateDownloadedEvent) => {
//if (process.platform === "darwin") return;
const dialogOpts = {
type: "info",
buttons: ["Restart", "Later"],
Expand All @@ -30,8 +31,12 @@ export default function initUpdater(){
});

autoUpdater.on("update-available", () => {
//if (process.platform === "darwin") return;
updateFound = true;
log.info("There is an update available. Downloading now... You will be notified when the update is ready to install.");
autoUpdater.downloadUpdate().catch((err) => {
log.error("An error occurred while downloading the update: " + err);
});
});
autoUpdater.on("update-not-available", () => {
if(!noUpdateFound){
Expand Down
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": "2.1.0",
"version": "2.1.1",
"main": "dist-electron/main/index.js",
"description": "The best way to connect your smart home lights to MultiViewer.",
"author": "JustJoostNL",
Expand Down
2 changes: 1 addition & 1 deletion src/pages/device-selectors/HassDeviceSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HomeAssistantDeviceSelector } from "@/components/device-selectors/home-assistant";
import ReactGA from "react-ga4";
import {useEffect, useState} from "react";
import { useEffect, useState } from "react";

export default function HassDeviceSelector(){
const [hassOnline, setHassOnline] = useState<boolean | null>(null);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/device-selectors/HueLightSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import HueLightSelector from "@/components/device-selectors/hue/lights";
import ReactGA from "react-ga4";
import {useEffect, useState} from "react";
import { useEffect, useState } from "react";

export default function PhilipsHueLightSelector(){
const [hueOnline, setHueOnline] = useState<boolean | null>(null);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/device-selectors/IKEADeviceSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import IKEADeviceSelector from "@/components/device-selectors/ikea";
import ReactGA from "react-ga4";
import {useEffect, useState} from "react";
import { useEffect, useState } from "react";

export default function IkeaDeviceSelector(){
const [ikeaOnline, setIkeaOnline] = useState<boolean | null>(null);
Expand Down

0 comments on commit 4ba5576

Please sign in to comment.