diff --git a/Bar/Modules/Calendar.qml b/Bar/Modules/Calendar.qml index 55f1b83..b034681 100644 --- a/Bar/Modules/Calendar.qml +++ b/Bar/Modules/Calendar.qml @@ -5,7 +5,7 @@ import Quickshell import qs.Components import qs.Settings import Quickshell.Wayland -import "../../Helpers/Holidays.js" as Holidays +import "root:/Helpers/Holidays.js" as Holidays PanelWithOverlay { id: calendarOverlay diff --git a/Helpers/Holidays.js b/Helpers/Holidays.js index 4bb3a60..a5879a6 100644 --- a/Helpers/Holidays.js +++ b/Helpers/Holidays.js @@ -1,6 +1,4 @@ var _countryCode = null; -var _regionCode = null; -var _regionName = null; var _holidaysCache = {}; function getCountryCode(callback) { @@ -9,13 +7,11 @@ function getCountryCode(callback) { return; } var xhr = new XMLHttpRequest(); - xhr.open("GET", "https://nominatim.openstreetmap.org/search?city="+ Settings.settings.weatherCity+"&country=&format=json&addressdetails=1&extratags=1", true); + xhr.open("GET", "http://ip-api.com/json/", true); xhr.onreadystatechange = function() { if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) { var response = JSON.parse(xhr.responseText); - _countryCode = response?.[0]?.address?.country_code ?? "US"; - _regionCode = response?.[0]?.address?.["ISO3166-2-lvl4"] ?? ""; - _regionName = response?.[0]?.address?.state ?? ""; + _countryCode = response.countryCode; callback(_countryCode); } } @@ -34,43 +30,17 @@ function getHolidays(year, countryCode, callback) { xhr.onreadystatechange = function() { if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) { var holidays = JSON.parse(xhr.responseText); - var augmentedHolidays = filterHolidaysByRegion(holidays); - _holidaysCache[cacheKey] = augmentedHolidays; - callback(augmentedHolidays); + _holidaysCache[cacheKey] = holidays; + callback(holidays); } } xhr.send(); } -function filterHolidaysByRegion(holidays) { - if (!_regionCode) { - return holidays; - } - const retHolidays = []; - holidays.forEach(function(holiday) { - if (holiday.counties?.length > 0) { - let found = false; - holiday.counties.forEach(function(county) { - if (county.toLowerCase() === _regionCode.toLowerCase()) { - found = true; - } - }); - if (found) { - var regionText = " (" + _regionName + ")"; - holiday.name = holiday.name + regionText; - holiday.localName = holiday.localName + regionText; - retHolidays.push(holiday); - } - } else { - retHolidays.push(holiday); - } - }); - return retHolidays; -} - function getHolidaysForMonth(year, month, callback) { getCountryCode(function(countryCode) { getHolidays(year, countryCode, function(holidays) { + // 0-based months (0=Jan, 11=Dec) var filtered = holidays.filter(function(h) { var date = new Date(h.date); return date.getFullYear() === year && date.getMonth() === month; diff --git a/Settings/Settings.qml b/Settings/Settings.qml index bebac9a..426bc39 100644 --- a/Settings/Settings.qml +++ b/Settings/Settings.qml @@ -37,9 +37,6 @@ Singleton { JsonAdapter { id: settingAdapter property string weatherCity: "Dinslaken" - property string countryCode: "" - property string regionCode: "" - property string weatherCountry: "" property string profileImage: Quickshell.env("HOME") + "/.face" property bool useFahrenheit: false property string wallpaperFolder: "/usr/share/wallpapers" diff --git a/Widgets/Sidebar/Config/SettingsModal.qml b/Widgets/Sidebar/Config/SettingsModal.qml index 282b6b4..9e17195 100644 --- a/Widgets/Sidebar/Config/SettingsModal.qml +++ b/Widgets/Sidebar/Config/SettingsModal.qml @@ -187,13 +187,9 @@ PanelWindow { // Release focus when modal becomes invisible onVisibleChanged: { - if (!visible) { - // Focus will be handled by the individual components - // Also trigger weather update if possible - if (typeof weather !== 'undefined' && weather !== null && weather.fetchCityWeather) { - weather.fetchCityWeather(); - } - } + if (!visible) + // Focus will be handled by the individual components + {} } }