Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions clientonly/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ const https = require("node:https");
* @param {string} defaultValue value if no key is given at the command line
* @returns {string} the value of the parameter
*/
function getCommandLineParameter (key, defaultValue = undefined) {
const getCommandLineParameter = (key, defaultValue = undefined) => {
const index = process.argv.indexOf(`--${key}`);
const value = index > -1 ? process.argv[index + 1] : undefined;
return value !== undefined ? String(value) : defaultValue;
}
};

/**
* Helper function to get server address/hostname from either the commandline or env
* @returns {object} config object containing address, port, and tls properties
*/
function getServerParameters () {
const getServerParameters = () => {
const config = {};

// Prefer command line arguments over environment variables
Expand All @@ -34,14 +34,14 @@ function getServerParameters () {
config.tls = process.argv.includes("--use-tls");

return config;
}
};

/**
* Gets the config from the specified server url
* @param {string} url location where the server is running.
* @returns {Promise} the config
*/
function getServerConfig (url) {
const getServerConfig = (url) => {
// Return new pending promise
return new Promise((resolve, reject) => {
// Select http or https module, depending on requested url
Expand All @@ -67,29 +67,29 @@ function getServerConfig (url) {
reject(new Error(`Unable to read config from server (${url}) (${error.message})`));
});
});
}
};

/**
* Print a message to the console in case of errors
* @param {string} message error message to print
* @param {number} code error code for the exit call
*/
function fail (message, code = 1) {
const fail = (message, code = 1) => {
if (message !== undefined && typeof message === "string") {
console.error(message);
} else {
console.error("Usage: 'node clientonly --address 192.168.1.10 --port 8080 [--use-tls]'");
}
process.exit(code);
}
};

/**
* Starts the client by connecting to the server and launching the Electron application
* @param {object} config server configuration
* @param {string} prefix http or https prefix
* @async
*/
async function startClient (config, prefix) {
const startClient = async (config, prefix) => {
try {
const serverUrl = `${prefix}${config.address}:${config.port}/config/`;
console.log(`Client: Connecting to server at ${serverUrl}`);
Expand Down Expand Up @@ -143,7 +143,7 @@ async function startClient (config, prefix) {
} catch (reason) {
fail(`Unable to connect to server: (${reason})`);
}
}
};

// Main execution
const config = getServerParameters();
Expand Down
2 changes: 1 addition & 1 deletion defaultmodules/compliments/compliments.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Module.register("compliments", {
return 0;
}

const generate = function () {
const generate = () => {
return Math.floor(Math.random() * compliments.length);
};

Expand Down
2 changes: 1 addition & 1 deletion defaultmodules/newsfeed/newsfeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ Module.register("newsfeed", {
}

if (this.config.prohibitedWords.length > 0) {
newsItems = newsItems.filter(function (item) {
newsItems = newsItems.filter((item) => {
for (const word of this.config.prohibitedWords) {
if (item.title.toLowerCase().indexOf(word.toLowerCase()) > -1) {
return false;
Expand Down
40 changes: 20 additions & 20 deletions defaultmodules/weather/provider-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const SunCalc = require("suncalc");
* @param {string} weatherType - OpenWeatherMap icon code (e.g., "01d", "02n")
* @returns {string|null} Internal weather type
*/
function convertWeatherType (weatherType) {
const convertWeatherType = (weatherType) => {
const weatherTypes = {
"01d": "day-sunny",
"02d": "day-cloudy",
Expand All @@ -32,26 +32,26 @@ function convertWeatherType (weatherType) {
};

return weatherTypes.hasOwnProperty(weatherType) ? weatherTypes[weatherType] : null;
}
};

/**
* Apply timezone offset to a date
* @param {Date} date - The date to apply offset to
* @param {number} offsetMinutes - Timezone offset in minutes
* @returns {Date} Date with applied offset
*/
function applyTimezoneOffset (date, offsetMinutes) {
const applyTimezoneOffset = (date, offsetMinutes) => {
const utcTime = date.getTime() + (date.getTimezoneOffset() * 60000);
return new Date(utcTime + (offsetMinutes * 60000));
}
};

/**
* Limit decimal places for coordinates (truncate, not round)
* @param {number} value - The coordinate value
* @param {number} decimals - Maximum number of decimal places
* @returns {number} Value with limited decimal places
*/
function limitDecimals (value, decimals) {
const limitDecimals = (value, decimals) => {
const str = value.toString();
if (str.includes(".")) {
const parts = str.split(".");
Expand All @@ -60,7 +60,7 @@ function limitDecimals (value, decimals) {
}
}
return value;
}
};

/**
* Get sunrise and sunset times for a given date and location
Expand All @@ -69,13 +69,13 @@ function limitDecimals (value, decimals) {
* @param {number} lon - Longitude
* @returns {object} Object with sunrise and sunset Date objects
*/
function getSunTimes (date, lat, lon) {
const getSunTimes = (date, lat, lon) => {
const sunTimes = SunCalc.getTimes(date, lat, lon);
return {
sunrise: sunTimes.sunrise,
sunset: sunTimes.sunset
};
}
};

/**
* Check if a given time is during daylight hours
Expand All @@ -84,52 +84,52 @@ function getSunTimes (date, lat, lon) {
* @param {Date} sunset - Sunset time
* @returns {boolean} True if during daylight hours
*/
function isDayTime (date, sunrise, sunset) {
const isDayTime = (date, sunrise, sunset) => {
if (!sunrise || !sunset) {
return true; // Default to day if times unavailable
}
return date >= sunrise && date < sunset;
}
};

/**
* Format timezone offset as string (e.g., "+01:00", "-05:30")
* @param {number} offsetMinutes - Timezone offset in minutes (use -new Date().getTimezoneOffset() for local)
* @returns {string} Formatted offset string
*/
function formatTimezoneOffset (offsetMinutes) {
const formatTimezoneOffset = (offsetMinutes) => {
const hours = Math.floor(Math.abs(offsetMinutes) / 60);
const minutes = Math.abs(offsetMinutes) % 60;
const sign = offsetMinutes >= 0 ? "+" : "-";
return `${sign}${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}`;
}
};

/**
* Get date string in YYYY-MM-DD format (local time)
* @param {Date} date - The date to format
* @returns {string} Date string in YYYY-MM-DD format
*/
function getDateString (date) {
const getDateString = (date) => {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, "0");
const day = String(date.getDate()).padStart(2, "0");
return `${year}-${month}-${day}`;
}
};

/**
* Convert wind speed from km/h to m/s
* @param {number} kmh - Wind speed in km/h
* @returns {number} Wind speed in m/s
*/
function convertKmhToMs (kmh) {
const convertKmhToMs = (kmh) => {
return kmh / 3.6;
}
};

/**
* Convert cardinal wind direction string to degrees
* @param {string} direction - Cardinal direction (e.g., "N", "NNE", "SW")
* @returns {number|null} Direction in degrees (0-360) or null if unknown
*/
function cardinalToDegrees (direction) {
const cardinalToDegrees = (direction) => {
const directions = {
N: 0,
NNE: 22.5,
Expand All @@ -149,23 +149,23 @@ function cardinalToDegrees (direction) {
NNW: 337.5
};
return directions[direction] ?? null;
}
};

/**
* Validate and limit coordinate precision
* @param {object} config - Configuration object with lat/lon properties
* @param {number} maxDecimals - Maximum decimal places to preserve
* @throws {Error} If coordinates are missing or invalid
*/
function validateCoordinates (config, maxDecimals = 4) {
const validateCoordinates = (config, maxDecimals = 4) => {
if (config.lat == null || config.lon == null
|| !Number.isFinite(config.lat) || !Number.isFinite(config.lon)) {
throw new Error("Latitude and longitude are required");
}

config.lat = limitDecimals(config.lat, maxDecimals);
config.lon = limitDecimals(config.lon, maxDecimals);
}
};

module.exports = {
convertWeatherType,
Expand Down
2 changes: 1 addition & 1 deletion js/alias-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const resolved = Object.fromEntries(
// Prevent multiple patching if this file is required more than once.
if (!Module._mmAliasPatched) {
const origResolveFilename = Module._resolveFilename;
Module._resolveFilename = function (request, parent, isMain, options) {
Module._resolveFilename = (request, parent, isMain, options) => {
if (Object.prototype.hasOwnProperty.call(resolved, request)) {
return resolved[request];
}
Expand Down
8 changes: 4 additions & 4 deletions js/animateCSS.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const AnimateCSSOut = [
* @param {string} [animation] animation name.
* @param {number} [animationTime] animation duration.
*/
function addAnimateCSS (element, animation, animationTime) {
const addAnimateCSS = (element, animation, animationTime) => {
const animationName = `animate__${animation}`;
const node = document.getElementById(element);
if (!node) {
Expand All @@ -138,14 +138,14 @@ function addAnimateCSS (element, animation, animationTime) {
}
node.style.setProperty("--animate-duration", `${animationTime}s`);
node.classList.add("animate__animated", animationName);
}
};

/**
* Remove an animation with Animate CSS
* @param {string} [element] div element to animate.
* @param {string} [animation] animation name.
*/
function removeAnimateCSS (element, animation) {
const removeAnimateCSS = (element, animation) => {
const animationName = `animate__${animation}`;
const node = document.getElementById(element);
if (!node) {
Expand All @@ -155,5 +155,5 @@ function removeAnimateCSS (element, animation) {
}
node.classList.remove("animate__animated", animationName);
node.style.removeProperty("--animate-duration");
}
};
if (typeof window === "undefined") module.exports = { AnimateCSSIn, AnimateCSSOut, addAnimateCSS, removeAnimateCSS };
16 changes: 8 additions & 8 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function App () {
* Loads a specific module.
* @param {string} module The name of the module (including subpath).
*/
function loadModule (module) {
const loadModule = (module) => {
const elements = module.split("/");
const moduleName = elements[elements.length - 1];
let moduleFolder = path.resolve(`${global.root_path}/${env.modulesDir}`, module);
Expand Down Expand Up @@ -130,22 +130,22 @@ function App () {

m.loaded();
}
}
};

/**
* Loads all modules.
* @param {Module[]} modules All modules to be loaded
* @returns {Promise} A promise that is resolved when all modules been loaded
*/
async function loadModules (modules) {
const loadModules = async (modules) => {
Log.log("Loading module helpers ...");

for (const module of modules) {
await loadModule(module);
}

Log.log("All module helpers loaded.");
}
};

/**
* Compare two semantic version numbers and return the difference.
Expand All @@ -154,7 +154,7 @@ function App () {
* @returns {number} A positive number if a is larger than b, a negative
* number if a is smaller and 0 if they are the same
*/
function cmpVersions (a, b) {
const cmpVersions = (a, b) => {
let i, diff;
const regExStrip0 = /(\.0+)+$/;
const segmentsA = a.replace(regExStrip0, "").split(".");
Expand All @@ -168,7 +168,7 @@ function App () {
}
}
return segmentsA.length - segmentsB.length;
}
};

/**
* Start the core app.
Expand All @@ -177,7 +177,7 @@ function App () {
* @async
* @returns {Promise<object>} the config used
*/
this.start = async function () {
this.start = async () => {
try {
const configObj = Utils.loadConfig();
global.config = configObj.fullConf;
Expand Down Expand Up @@ -277,7 +277,7 @@ function App () {
* @returns {Promise} A promise that is resolved when all node_helpers and
* the http server has been closed
*/
this.stop = async function () {
this.stop = async () => {
const nodePromises = [];
for (const nodeHelper of nodeHelpers) {
try {
Expand Down
Loading