From 059c8937ca1eef8f977c5a6de4cd8c4b4c64de9c Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sat, 15 Jun 2024 21:03:50 +0700 Subject: [PATCH] weather: config option for deg c or f (#602) --- .config/ags/modules/.configuration/user_options.js | 1 + .config/ags/modules/bar/normal/system.js | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.config/ags/modules/.configuration/user_options.js b/.config/ags/modules/.configuration/user_options.js index ab3d2a3e1..1e7603379 100644 --- a/.config/ags/modules/.configuration/user_options.js +++ b/.config/ags/modules/.configuration/user_options.js @@ -116,6 +116,7 @@ let configOptions = { }, 'weather': { 'city': "", + 'preferredUnit': "C", // Either C or F }, 'workspaces': { 'shown': 10, diff --git a/.config/ags/modules/bar/normal/system.js b/.config/ags/modules/bar/normal/system.js index 468346427..7e952124d 100644 --- a/.config/ags/modules/bar/normal/system.js +++ b/.config/ags/modules/bar/normal/system.js @@ -1,4 +1,4 @@ -// This is for the right pills of the bar. +// This is for the right pills of the bar. import Widget from 'resource:///com/github/Aylur/ags/widget.js'; import * as Utils from 'resource:///com/github/Aylur/ags/utils.js'; const { Box, Label, Button, Overlay, Revealer, Scrollable, Stack, EventBox } = Widget; @@ -161,11 +161,11 @@ const BatteryModule = () => Stack({ .catch(print); const weatherCode = weather.current_condition[0].weatherCode; const weatherDesc = weather.current_condition[0].weatherDesc[0].value; - const temperature = weather.current_condition[0].temp_C; - const feelsLike = weather.current_condition[0].FeelsLikeC; + const temperature = weather.current_condition[0][`temp_${userOptions.weather.preferredUnit}`]; + const feelsLike = weather.current_condition[0][`FeelsLike${userOptions.weather.preferredUnit}`]; const weatherSymbol = WEATHER_SYMBOL[WWO_CODE[weatherCode]]; self.children[0].label = weatherSymbol; - self.children[1].label = `${temperature}℃ • Feels like ${feelsLike}℃`; + self.children[1].label = `${temperature}°${userOptions.weather.preferredUnit} • Feels like ${feelsLike}°${userOptions.weather.preferredUnit}`; self.tooltipText = weatherDesc; }).catch((err) => { try { // Read from cache @@ -174,11 +174,11 @@ const BatteryModule = () => Stack({ ); const weatherCode = weather.current_condition[0].weatherCode; const weatherDesc = weather.current_condition[0].weatherDesc[0].value; - const temperature = weather.current_condition[0].temp_C; - const feelsLike = weather.current_condition[0].FeelsLikeC; + const temperature = weather.current_condition[0][`temp_${userOptions.weather.preferredUnit}`]; + const feelsLike = weather.current_condition[0][`FeelsLike${userOptions.weather.preferredUnit}`]; const weatherSymbol = WEATHER_SYMBOL[WWO_CODE[weatherCode]]; self.children[0].label = weatherSymbol; - self.children[1].label = `${temperature}℃ • Feels like ${feelsLike}℃`; + self.children[1].label = `${temperature}°${userOptions.weather.preferredUnit} • Feels like ${feelsLike}°${userOptions.weather.preferredUnit}`; self.tooltipText = weatherDesc; } catch (err) { print(err);