Skip to content

Commit

Permalink
[feat] #154 DeviceClient ์ž‘์„ฑ
Browse files Browse the repository at this point in the history
  • Loading branch information
ShapeKim98 committed Nov 6, 2024
1 parent ee02f57 commit 84eb77c
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 23 deletions.
13 changes: 11 additions & 2 deletions Projects/App/Sources/Root/RootFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Util
public struct RootFeature {
@Dependency(UserDefaultsClient.self) var userDefaults
@Dependency(UserClient.self) var userClient
@Dependency(DeviceClient.self) var deviceClient
@Reducer(state: .equatable)
public enum Destination {

Expand Down Expand Up @@ -48,15 +49,23 @@ public struct RootFeature {
return .run { send in

guard let fcmToken = userDefaults.stringKey(.fcmToken) else {
await send(._sceneChange(UIDevice.isPhone ? .mainTab() : .mainTabSplit()))
await send(._sceneChange(
deviceClient.isPhone()
? .mainTab()
: .mainTabSplit())
)
return
}
let fcmRequest = FCMRequest(token: fcmToken)
let user = try await userClient.fcm_ํ† ํฐ_์ €์žฅ(fcmRequest)

await userDefaults.setString(user.token, .fcmToken)
await userDefaults.setString("\(user.userId)", .userId)
await send(._sceneChange(UIDevice.isPhone ? .mainTab() : .mainTabSplit()))
await send(._sceneChange(
deviceClient.isPhone()
? .mainTab()
: .mainTabSplit()
))
}

case .mainTab(.delegate(.๋กœ๊ทธ์•„์›ƒ)),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// DeviceClient+LiveKey.swift
// CoreKit
//
// Created by ๊น€๋„ํ˜• on 10/25/24.
//

import SwiftUI

import Dependencies

extension DeviceClient: DependencyKey {
public static let liveValue: Self = {
#if os(iOS)
let device = UIDevice.current.userInterfaceIdiom
#endif

return Self(
isPhone: {
#if os(macOS)
return false
#endif
return device == .phone
},
isPad: {
#if os(macOS)
return false
#endif
return device == .pad
},
isMac: {
#if os(macOS)
return true
#endif
return false
}
)
}()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// DeviceClient.swift
// CoreKit
//
// Created by ๊น€๋„ํ˜• on 10/25/24.
//

import Foundation
import DependenciesMacros

@DependencyClient
public struct DeviceClient: Sendable {
public var isPhone: @Sendable () -> Bool = { false }
public var isPad: @Sendable () -> Bool = { false }
public var isMac: @Sendable () -> Bool = { false }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Created by ๊น€๋„ํ˜• on 7/17/24.

import UIKit
import Foundation

import ComposableArchitecture
import DSKit
Expand All @@ -26,6 +26,8 @@ public struct ContentSettingFeature {
private var contentClient
@Dependency(CategoryClient.self)
private var categoryClient
@Dependency(DeviceClient.self)
private var deviceClient
/// - State
@ObservableState
public struct State: Equatable {
Expand Down Expand Up @@ -212,7 +214,7 @@ private extension ContentSettingFeature {

return .send(.delegate(.ํฌํ‚ท์ถ”๊ฐ€ํ•˜๊ธฐ))
case .๋’ค๋กœ๊ฐ€๊ธฐ_๋ฒ„ํŠผ_๋ˆŒ๋ €์„๋•Œ:
guard UIDevice.isPhone else {
guard deviceClient.isPhone() else {
return .send(.delegate(.dismiss))
}
return state.isShareExtension
Expand Down Expand Up @@ -316,7 +318,7 @@ private extension ContentSettingFeature {
}
return .none
case .์„ ํƒํ•œ_ํฌํ‚ท_์ธ๋ฉ”๋ชจ๋ฆฌ_์‚ญ์ œ:
guard UIDevice.isPhone else { return .none }
guard deviceClient.isPhone() else { return .none }
state.selectedPokit = nil
return .none
}
Expand Down
18 changes: 0 additions & 18 deletions Projects/Util/Sources/Extension/UIDevice+Extension.swift

This file was deleted.

0 comments on commit 84eb77c

Please sign in to comment.