Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swiftui 6 related changes #143

Merged
merged 5 commits into from
Jun 24, 2024
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
119 changes: 56 additions & 63 deletions DatWeatherDoe.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "2ecd2da1a055fe68770a610bd4a2ebb61dd5863b1916b7c029bc31d4b431fb0f",
"originHash" : "63091535703c641c976bb81ec8c72ec90356d9cf63775f9adf7d66d3261479dc",
"pins" : [
{
"identity" : "collectionconcurrencykit",
Expand All @@ -19,6 +19,15 @@
"version" : "1.8.2"
}
},
{
"identity" : "menubarextraaccess",
"kind" : "remoteSourceControl",
"location" : "https://github.com/orchetect/MenuBarExtraAccess",
"state" : {
"revision" : "f5896b47e15e114975897354c7e1082c51a2bffd",
"version" : "1.0.5"
}
},
{
"identity" : "reachability.swift",
"kind" : "remoteSourceControl",
Expand Down
2 changes: 1 addition & 1 deletion DatWeatherDoe/API/NetworkClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ protocol NetworkClientType {
func performRequest(url: URL) async throws -> Data
}

final class NetworkClient: NetworkClientType {
final actor NetworkClient: NetworkClientType {
func performRequest(url: URL) async throws -> Data {
try await URLSession.shared.data(from: url).0
}
Expand Down
6 changes: 0 additions & 6 deletions DatWeatherDoe/API/Response/SunriseSunsetData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@
import Foundation

struct SunriseSunsetData: Decodable {
let isDay: Int
let sunrise: String
let sunset: String

private enum CodingKeys: String, CodingKey {
case isDay = "is_sun_up"
case sunrise, sunset
}

var isDayBool: Bool {
isDay > 0
}
}
8 changes: 8 additions & 0 deletions DatWeatherDoe/API/Response/WeatherAPIResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Foundation
struct WeatherAPIResponse: Decodable {
let locationName: String
let temperatureData: TemperatureData
let isDay: Int
let weatherConditionCode: Int
let humidity: Int
let windData: WindData
Expand All @@ -25,6 +26,7 @@ struct WeatherAPIResponse: Decodable {
}

private enum CurrentKeys: String, CodingKey {
case isDay = "is_day"
case condition, humidity
}

Expand All @@ -48,6 +50,8 @@ struct WeatherAPIResponse: Decodable {
temperatureData = try container.decode(TemperatureData.self, forKey: .current)

let currentContainer = try container.nestedContainer(keyedBy: CurrentKeys.self, forKey: .current)
isDay = try currentContainer.decode(Int.self, forKey: .isDay)

let weatherConditionContainer = try currentContainer.nestedContainer(
keyedBy: WeatherConditionKeys.self,
forKey: .condition
Expand All @@ -69,4 +73,8 @@ struct WeatherAPIResponse: Decodable {
)
}
}

var isDayBool: Bool {
isDay > 0
}
}
105 changes: 0 additions & 105 deletions DatWeatherDoe/AppDelegate.swift

This file was deleted.

8 changes: 4 additions & 4 deletions DatWeatherDoe/Config/ConfigManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import SwiftUI
protocol ConfigManagerType: AnyObject {
var measurementUnit: String { get set }
var weatherSource: String { get set }
var weatherSourceText: String? { get set }
var weatherSourceText: String { get set }
var refreshInterval: TimeInterval { get set }
var isShowingWeatherIcon: Bool { get set }
var isShowingHumidity: Bool { get set }
Expand All @@ -32,10 +32,10 @@ final class ConfigManager: ConfigManagerType {
public var measurementUnit = MeasurementUnit.imperial.rawValue

@AppStorage("weatherSource")
public var weatherSource = WeatherSource.location.rawValue
public var weatherSource = WeatherSource.latLong.rawValue

@AppStorage("weatherSourceText")
public var weatherSourceText: String?
public var weatherSourceText = ""

@AppStorage("refreshInterval")
public var refreshInterval = RefreshInterval.fifteenMinutes.rawValue
Expand Down Expand Up @@ -66,7 +66,7 @@ final class ConfigManager: ConfigManagerType {

func updateWeatherSource(_ source: WeatherSource, sourceText: String) {
weatherSource = source.rawValue
weatherSourceText = source == .location ? nil : sourceText
weatherSourceText = source == .location ? "" : sourceText
}

func setConfigOptions(_ options: ConfigOptions) {
Expand Down
72 changes: 72 additions & 0 deletions DatWeatherDoe/DatWeatherDoeApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//
// DatWeatherDoeApp.swift
// DatWeatherDoe
//
// Created by Inder Dhir on 6/17/24.
// Copyright © 2024 Inder Dhir. All rights reserved.
//

import MenuBarExtraAccess
import OSLog
import SwiftUI

@main
struct DatWeatherDoeApp: App {
@State private var configManager: ConfigManager
@ObservedObject private var viewModel: WeatherViewModel
@State private var isMenuPresented: Bool = false
@State private var statusItem: NSStatusItem?

init() {
configManager = ConfigManager()

let logger = Logger(subsystem: Bundle.main.bundleIdentifier ?? "bundleID", category: "main")
viewModel = WeatherViewModel(
locationFetcher: SystemLocationFetcher(logger: logger),
weatherFactory: WeatherRepositoryFactory(
appId: APIKeyParser().parse(),
networkClient: NetworkClient(),
logger: logger
),
configManager: ConfigManager(),
logger: logger
)
}

var body: some Scene {
MenuBarExtra(
content: {
MenuView(
viewModel: viewModel,
onSeeWeather: {
viewModel.seeForecastForCurrentCity()
closePopover()
},
onRefresh: {
viewModel.getUpdatedWeatherAfterRefresh()
closePopover()
},
onSave: {
viewModel.getUpdatedWeatherAfterRefresh()
closePopover()
}
)
},
label: {
StatusBarView(weatherResult: viewModel.weatherResult)
.onAppear {
viewModel.getUpdatedWeatherAfterRefresh()
}
}
)
.menuBarExtraAccess(isPresented: $isMenuPresented) { statusItem in
self.statusItem = statusItem
}
.windowStyle(.hiddenTitleBar)
.menuBarExtraStyle(.window)
}

private func closePopover() {
statusItem?.togglePresented()
}
}
Loading
Loading