From 9bdaf5478b1846f83570f8edf87619e1362ef41b Mon Sep 17 00:00:00 2001 From: bobrosoft Date: Tue, 28 Feb 2023 19:57:52 +0400 Subject: [PATCH] YandexWeatherBarItem: fixes in parsing --- MTMR/HapticFeedback.swift | 4 ++- MTMR/Widgets/YandexWeatherBarItem.swift | 46 +++++++++---------------- 2 files changed, 19 insertions(+), 31 deletions(-) diff --git a/MTMR/HapticFeedback.swift b/MTMR/HapticFeedback.swift index 9e5c17f..70c3164 100644 --- a/MTMR/HapticFeedback.swift +++ b/MTMR/HapticFeedback.swift @@ -13,13 +13,15 @@ class HapticFeedback { // Here we have list of possible IDs for Haptic Generator Device. They are not constant // To find deviceID, you will need IORegistryExplorer app from Additional Tools for Xcode dmg // which you can download from https://developer.apple.com/download/more/?=Additional%20Tools - // Open IORegistryExplorer app, search for AppleMultitouchDevice and get "Multitouch ID" + // Open IORegistryExplorer app, search for "AppleMultitouchDevice" and get "Multitouch ID" + // or "AppleMultitouchTrackpadHIDEventDriver" and get "mt-device-id" // There should be programmatic way to get it but I can't find, no docs for macOS :( private let possibleDeviceIDs: [UInt64] = [ 0x200_0000_0100_0000, // MacBook Pro 2016/2017 0x300_0000_8050_0000, // MacBook Pro 2019/2018 0x200_0000_0000_0024, // MacBook Pro (13-inch, M1, 2020) 0x200_0000_0000_0023 // MacBook Pro M1 13-Inch 2020 with 1tb +// 0x300000080500000, ] // you can get a plist `otool -s __TEXT __tpad_act_plist /System/Library/PrivateFrameworks/MultitouchSupport.framework/Versions/Current/MultitouchSupport|tail -n +3|awk -F'\t' '{print $2}'|xxd -r -p` diff --git a/MTMR/Widgets/YandexWeatherBarItem.swift b/MTMR/Widgets/YandexWeatherBarItem.swift index 9f40676..596aa90 100644 --- a/MTMR/Widgets/YandexWeatherBarItem.swift +++ b/MTMR/Widgets/YandexWeatherBarItem.swift @@ -13,35 +13,21 @@ class YandexWeatherBarItem: CustomButtonTouchBarItem, CLLocationManagerDelegate private let activity: NSBackgroundActivityScheduler private let unitsStr = "°C" private let iconsSource = [ - "Ясно": "☀️", - "Малооблачно": "🌤", - "Облачно с прояснениями": "⛅️", - "Пасмурно": "☁️", - "Небольшой дождь": "🌦", - "Морось": "💦", - "Дождь": "🌧", - "Ливень": "⛈", - "Гроза": "🌩", - "Дождь с грозой": "⛈", - "Дождь со снегом": "☔️", - "Небольшой снег": "❄️", - "Снег": "🌨", - "Туман": "🌫", - - "Clear": "☀️", - "Mostly clear": "🌤", - "Partly cloudy": "⛅️", - "Overcast": "☁️", - "Light rain": "🌦", - "Drizzle": "💦", - "Rain": "🌧", - "Heavy rain": "⛈", - "Storm": "🌩", - "Thunderstorm with rain": "⛈", - "Sleet": "☔️", - "Light snow": "❄️", - "Snow": "🌨", - "Fog": "🌫" + "clear": "☀️", + "mostly-clear": "🌤", + "partly-cloudy": "⛅️", + "overcast": "☁️", + "cloudy": "☁️", + "light-rain": "🌦", + "drizzle": "💦", + "rain": "🌧", + "heavy-rain": "⛈", + "storm": "🌩", + "thunderstorm-with-rain": "⛈", + "sleet": "☔️", + "light-snow": "❄️", + "snow": "🌨", + "fog": "🌫" ] private var location: CLLocation! private var prevLocation: CLLocation! @@ -107,7 +93,7 @@ class YandexWeatherBarItem: CustomButtonTouchBarItem, CLLocationManagerDelegate temperature = matches.first?.item(at: 1) var icon: String? - matches = response.matchingStrings(regex: "link__condition.*?>(.*?)<") + matches = response.matchingStrings(regex: "\"condition\":\"(.*?)\"") icon = matches.first?.item(at: 1) if let _ = icon, let test = self.iconsSource[icon!] { icon = test