Conversation
I have done some major changes to the weather api to enhance it. These are the following changes: - Using weather.com api to avoid Unknown Information error - Uses bing maps api to get users location for more accurate weather and location - Adds a new option to adjust update frequency - Can now display neighbourhood, city or address thanks to bing maps api - You can now see 10 day forecast by swiping on the widget - You can open the weather app on mac os 13 and over by tapping the weather widget - There's now an icon only mode
|
Thank you for you hard work! Just a quick tip for the future, you should avoid putting all changes into a single commit. Next time you could try split changes across multiple commits, with meaningful commit message (see other commits for message structure). This would make the review process much easier! :) |
|
Ok thanks for the feedback, i've just started using GitHub, in fact this is my 2nd pull request. I'll try to keep your tips in mind for future commits. |
| NotificationCenter.default.addObserver(self, selector: #selector(updateCurrentCondition), name: .didChangeWidgetPreferences, object: nil) | ||
| timer = Timer.scheduledTimer(withTimeInterval: 3600, repeats: true, block: { [weak self] _ in | ||
| if Preferences[.UpdateFrequency] == "Fifteen"{timers = 900} else if Preferences[.UpdateFrequency] == "Thirty"{timers = 1800} else{timers = 3600} |
There was a problem hiding this comment.
Modify update frequency based on user settings.
| super.didLoad() | ||
| DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { | ||
| NotificationCenter.default.post(name: .didChangeWidgetPreferences, object: nil) |
| super.didLoad() | ||
| DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { | ||
| NotificationCenter.default.post(name: .didChangeWidgetPreferences, object: nil) | ||
| } | ||
| } | ||
| override func didTapHandler() { |
There was a problem hiding this comment.
Double tap, triple tap and single tap detection. Opens weather app when taped once. In the future double and triple tap will show info like UV Index, Feels Like and more.
| return | ||
|
|
||
| } | ||
| override func didSwipeRightHandler() { |
There was a problem hiding this comment.
Goes back a day when viewing 10 day forecast.
| } | ||
| } | ||
| } | ||
| override func didSwipeLeftHandler() { |
There was a problem hiding this comment.
Shows 10 day forecast when swiped left.
Weather/WeatherWidget.swift
Outdated
| } else if let systemIcon = NSImage(named: data.weather.icon) { | ||
| view.set(image: systemIcon) | ||
| let locality = data.weather.name | ||
| if Preferences[.ShowIconOnly] == false || !(Day == 0){ |
There was a problem hiding this comment.
Shows icon only based on user settings. Intentionally shows information if not viewing current forecast.
Weather/WeatherService.swift
Outdated
| let url_for_maps = URL(string: "https://dev.virtualearth.net/REST/v1/Locations/\(latitude),\(longitude)?includeNeighborhood=1&include=ciso2&o=json&key=Amn3nivKYow4ej0mliZVLFonh7W6ZBOlQz8FVrH0AJbK6_wViio1P8mrDODAgs6U")! | ||
| let url_for_weaather = URL(string: "https://api.weather.com/v1/geocode/\(latitude)/\(longitude)/aggregate.json?apiKey=e45ff1b7c7bda231216c7ab7c33509b8&products=conditionsshort,fcstdaily10short,fcsthourly24short,nowlinks")! | ||
| let MapRequest = URLRequest(url: url_for_maps, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: 20) | ||
| let GetMaps = URLSession.shared.dataTask(with: MapRequest) { Mapdata, response, error in |
There was a problem hiding this comment.
Get's city, neighbourhood, address and other info based on coordinates using bing maps api.
| return | ||
| } | ||
| // f | ||
| let decoder = JSONDecoder() |
There was a problem hiding this comment.
Decode response received from bing maps and extract the info.
| var neighborhood = address.neighborhood | ||
| var postalCode = address.postalCode | ||
| var countryRegionIso2 = address.countryRegionIso2 | ||
| if Day == 0{ |
There was a problem hiding this comment.
Checks user settings and provides the right info to display.
| } | ||
|
|
||
| let request2 = URLRequest(url: url_for_weaather, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: 20) | ||
| let GetWeather = URLSession.shared.dataTask( with: request2) { Wdata, response, error in |
There was a problem hiding this comment.
Get's the weather using weather.com api.
| let weather = try? decoder.decode(WeatherResponse.self, from: Wdata) | ||
| let observation = weather?.conditionsshort?.observation | ||
| let FutureForcast = weather?.fcstdaily10short?.forecasts?[Day] | ||
| if !(Day == 0){ |
There was a problem hiding this comment.
Checks what day needs to be displayed.
Weather/WeatherService.swift
Outdated
| if Preferences[.show_description]{ | ||
| switch units { | ||
| case "celsius": | ||
| if description.count > 19{ |
There was a problem hiding this comment.
Adjust title and description formatting based on the length of the info.
| // } catch { | ||
| // print("Error: \(error.localizedDescription)") | ||
| // } | ||
| let decoder = JSONDecoder() |
There was a problem hiding this comment.
Decodes response received from weather.com api.
Weather/WeatherService.swift
Outdated
| }else if Preferences[.IconStyle] == "Filled"{ | ||
| Icon = "2-" + String(DisplayIcon!) | ||
| }else if Preferences[.IconStyle] == "Default"{ | ||
| if DisplayIcon == 011 || DisplayIcon == 012 || DisplayIcon == 013 || DisplayIcon == 014 || DisplayIcon == 016 || DisplayIcon == 019 || DisplayIcon == 020 || DisplayIcon == 021 || DisplayIcon == 022 || DisplayIcon == 026 || DisplayIcon == 027 || DisplayIcon == 028 || DisplayIcon == 029 || DisplayIcon == 030 || DisplayIcon == 031 || DisplayIcon == 032 || DisplayIcon == 036 || DisplayIcon == 037 || DisplayIcon == 038 || DisplayIcon == 039 || DisplayIcon == 040 || DisplayIcon == 047{ |
There was a problem hiding this comment.
Checks if icon is available in default icon pack, if not it displays outlined icon pack.
Weather/WeatherService.swift
Outdated
| } | ||
| print(String(DisplayIcon!)) | ||
| if Preferences[.IconStyle] == "Outlined"{ |
There was a problem hiding this comment.
Checks user preferences and sets the icon accordingly.
There was a problem hiding this comment.
Since the location is taken using the device's coordinates and bing maps api this is no longer needed.
Fixes a glitch where the view isn't automatically reset to the current weather/conditions after 10 seconds when swiped more than once.
- New icon and temp mode - New only temp mode - See more info about the selected day's weather by double tapping the widget - Bug Fixes
I have done some major changes to the weather widget to enhance it. These are the following changes:
Using weather.com api to avoid Unknown Information error
Uses bing maps api to get users location for more accurate weather and location
Adds a new option to adjust update frequency
Can now display neighbourhood, city or address thanks to bing maps api
You can now see 10 day forecast by swiping on the widget
You can open the weather app on mac os 13 and over by tapping the weather widget
New icons and options to switch between Illustrated, default, outlined and filled icons
There's now an icon only mode
When looking at the files changed section you can filter .png and .json files as they're all the new icons/assets and don't require any checking.