-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9f1c06
commit a4c5662
Showing
6 changed files
with
259 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,9 @@ | ||
# Xcode | ||
# | ||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore | ||
|
||
## User settings | ||
xcuserdata/ | ||
|
||
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) | ||
*.xcscmblueprint | ||
*.xccheckout | ||
|
||
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) | ||
DerivedData/ | ||
*.moved-aside | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
|
||
## Obj-C/Swift specific | ||
*.hmap | ||
|
||
## App packaging | ||
*.ipa | ||
*.dSYM.zip | ||
*.dSYM | ||
|
||
## Playgrounds | ||
timeline.xctimeline | ||
playground.xcworkspace | ||
|
||
# Swift Package Manager | ||
# | ||
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. | ||
# Packages/ | ||
# Package.pins | ||
# Package.resolved | ||
# *.xcodeproj | ||
# | ||
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata | ||
# hence it is not needed unless you have added a package configuration file to your project | ||
# .swiftpm | ||
|
||
.build/ | ||
|
||
# CocoaPods | ||
# | ||
# We recommend against adding the Pods directory to your .gitignore. However | ||
# you should judge for yourself, the pros and cons are mentioned at: | ||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control | ||
# | ||
# Pods/ | ||
# | ||
# Add this line if you want to avoid checking in source code from the Xcode workspace | ||
# *.xcworkspace | ||
|
||
# Carthage | ||
# | ||
# Add this line if you want to avoid checking in source code from Carthage dependencies. | ||
# Carthage/Checkouts | ||
|
||
Carthage/Build/ | ||
|
||
# Accio dependency management | ||
Dependencies/ | ||
.accio/ | ||
|
||
# fastlane | ||
# | ||
# It is recommended to not store the screenshots in the git repo. | ||
# Instead, use fastlane to re-generate the screenshots whenever they are needed. | ||
# For more information about the recommended setup visit: | ||
# https://docs.fastlane.tools/best-practices/source-control/#source-control | ||
|
||
fastlane/report.xml | ||
fastlane/Preview.html | ||
fastlane/screenshots/**/*.png | ||
fastlane/test_output | ||
|
||
# Code Injection | ||
# | ||
# After new code Injection tools there's a generated folder /iOSInjectionProject | ||
# https://github.com/johnno1962/injectionforxcode | ||
|
||
iOSInjectionProject/ | ||
Pods | ||
Podfile.lock | ||
Modules/Models/.swiftpm/xcode/package.xcworkspace/xcshareddata | ||
Modules/Models/Tests/ModelsTests/TestResources/TestJSONs | ||
Modules/BitriseAPIs/.swiftpm/xcode/package.xcworkspace/xcshareddata | ||
Buildio.swiftpm/.swiftpm/xcode/package.xcworkspace/xcshareddata | ||
Modules/BuildioUI/.swiftpm/xcode/package.xcworkspace/xcshareddata | ||
Package.resolved | ||
.swiftpm/ | ||
Modules/Derived | ||
Modules/Modules.xcodeproj | ||
Buildio.xcodeproj | ||
Buildio.xcworkspace | ||
build/ | ||
graph.png | ||
.swiftpm | ||
Modules/Modules.xcodeproj | ||
Tuist/.build | ||
build/XCBuildData | ||
Modules/Derived |
126 changes: 126 additions & 0 deletions
126
Modules/Core/Coordinator/Dependencies/TokenManager.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// | ||
// TokenManager.swift | ||
// Buildio | ||
// | ||
// Created by Sergey Khliustin on 24.10.2021. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
import KeychainAccess | ||
import Logger | ||
import Environment | ||
import Dependencies | ||
|
||
package final class PreviewTokenManager: TokenManager { | ||
public override init(_ account: String? = nil) { | ||
super.init(account) | ||
self.tokens = [Token.demo()] | ||
self.token = self.tokens.first | ||
} | ||
|
||
override func saveTokens() { | ||
|
||
} | ||
} | ||
|
||
package class TokenManager: ObservableObject, TokenManagerType { | ||
private let keychain: Keychain | ||
|
||
@Published package fileprivate(set) var tokens: [Token] { | ||
didSet { | ||
saveTokens() | ||
} | ||
} | ||
|
||
@Published package var token: Token? { | ||
didSet { | ||
guard let newValue = token else { | ||
UserDefaults.standard.lastAccount = nil | ||
return | ||
} | ||
|
||
var tokens = tokens | ||
if !tokens.contains(newValue) { | ||
tokens.append(newValue) | ||
} | ||
self.tokens = tokens | ||
UserDefaults.standard.lastAccount = newValue.email | ||
} | ||
} | ||
|
||
package init(_ account: String? = nil) { | ||
let keychain = Keychain() | ||
if ProcessInfo.processInfo.isTestEnv { | ||
self.tokens = [] | ||
} else { | ||
self.tokens = keychain.allKeys().reduce([Token]()) { partialResult, key in | ||
var result = partialResult | ||
if let token = keychain[key] { | ||
result.append(Token(token: token, email: key)) | ||
} | ||
return result | ||
} | ||
} | ||
self.keychain = keychain | ||
if let account = account { | ||
self.token = self.tokens.first(where: { $0.email == account }) | ||
} | ||
if self.token == nil, let lastUsed = UserDefaults.standard.lastAccount { | ||
self.token = self.tokens.first(where: { $0.email == lastUsed }) | ||
} | ||
if self.token == nil { | ||
self.token = self.tokens.first | ||
} | ||
} | ||
|
||
package func set(_ token: Token) { | ||
if let token = tokens.first(where: { $0.token == token.token }) { | ||
logger.debug("") | ||
self.token = token | ||
} else { | ||
self.token = token | ||
} | ||
} | ||
|
||
package func remove(_ token: Token) { | ||
guard let index = tokens.firstIndex(of: token) else { return } | ||
tokens.remove(at: index) | ||
if token == self.token { | ||
self.token = tokens.first | ||
} | ||
} | ||
|
||
fileprivate func saveTokens() { | ||
guard !ProcessInfo.processInfo.isTestEnv else { return } | ||
|
||
do { | ||
try keychain.removeAll() | ||
} catch { | ||
logger.error(error) | ||
} | ||
tokens | ||
.filter({ !$0.isDemo }) | ||
.forEach { token in | ||
do { | ||
try keychain.set(token.token, key: token.email) | ||
} catch { | ||
logger.error(error) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private extension UserDefaults { | ||
private static let lastAccountKey = "lastAccount" | ||
|
||
var lastAccount: String? { | ||
get { | ||
string(forKey: Self.lastAccountKey) | ||
} | ||
set { | ||
set(newValue, forKey: Self.lastAccountKey) | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Foundation | ||
|
||
@MainActor | ||
package protocol DependenciesType: AnyObject { | ||
var apiFactory: ApiFactory { get } | ||
var navigator: NavigatorType { get } | ||
var activityProvider: ActivityProviderType { get } | ||
var tokenManager: TokenManagerType { get } | ||
var buildStatusProvider: BuildStatusProviderType { get } | ||
} |
15 changes: 15 additions & 0 deletions
15
Modules/Core/Dependencies/Mocks/BuildStatusProviderMock.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// ActivityProviderMock.swift | ||
// Modules | ||
// | ||
// Created by Sergii Khliustin on 05.11.2024. | ||
// | ||
import Foundation | ||
import Models | ||
|
||
package final class BuildStatusProviderMock: BuildStatusProviderType { | ||
package init() {} | ||
package func subscribe(id: ObjectIdentifier, build: Models.BuildResponseItemModel) async -> AsyncStream<Models.BuildResponseItemModel> { | ||
return AsyncStream { _ in } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Foundation | ||
|
||
@MainActor | ||
package protocol NavigatorType { | ||
func show(_ path: RouteType) | ||
func dismiss() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
{ | ||
"originHash" : "a54d479dee87917a0d9f6d503cae63d68c2cd766545dcff48cba42fe706a56f8", | ||
"pins" : [ | ||
{ | ||
"identity" : "flowstacks", | ||
"kind" : "remoteSourceControl", | ||
"location" : "[email protected]:johnpatrickmorgan/FlowStacks.git", | ||
"state" : { | ||
"revision" : "0c2d1dcabcaf1a6b725f4a9d01796308d9b03db1", | ||
"version" : "0.8.3" | ||
} | ||
}, | ||
{ | ||
"identity" : "inject", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/krzysztofzablocki/Inject.git", | ||
"state" : { | ||
"revision" : "728c56639ecb3df441d51d5bc6747329afabcfc9", | ||
"version" : "1.5.2" | ||
} | ||
}, | ||
{ | ||
"identity" : "keychainaccess", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/kishikawakatsumi/KeychainAccess.git", | ||
"state" : { | ||
"revision" : "84e546727d66f1adc5439debad16270d0fdd04e7", | ||
"version" : "4.2.2" | ||
} | ||
}, | ||
{ | ||
"identity" : "kingfisher", | ||
"kind" : "remoteSourceControl", | ||
"location" : "[email protected]:onevcat/Kingfisher.git", | ||
"state" : { | ||
"revision" : "c0940e241945e6378c01fbd45fd3815579d47ef5", | ||
"version" : "8.1.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "networkimage", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/gonzalezreal/NetworkImage", | ||
"state" : { | ||
"revision" : "2849f5323265386e200484b0d0f896e73c3411b9", | ||
"version" : "6.0.1" | ||
} | ||
}, | ||
{ | ||
"identity" : "rainbow", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/onevcat/Rainbow", | ||
"state" : { | ||
"revision" : "e0dada9cd44e3fa7ec3b867e49a8ddbf543e3df3", | ||
"version" : "4.0.1" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-async-algorithms", | ||
"kind" : "remoteSourceControl", | ||
"location" : "[email protected]:apple/swift-async-algorithms.git", | ||
"state" : { | ||
"revision" : "5c8bd186f48c16af0775972700626f0b74588278", | ||
"version" : "1.0.2" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-collections", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-collections.git", | ||
"state" : { | ||
"revision" : "671108c96644956dddcd89dd59c203dcdb36cec7", | ||
"version" : "1.1.4" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-markdown-ui", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/gonzalezreal/swift-markdown-ui", | ||
"state" : { | ||
"revision" : "55441810c0f678c78ed7e2ebd46dde89228e02fc", | ||
"version" : "2.4.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "swiftui-introspect", | ||
"kind" : "remoteSourceControl", | ||
"location" : "[email protected]:siteline/swiftui-introspect.git", | ||
"state" : { | ||
"revision" : "807f73ce09a9b9723f12385e592b4e0aaebd3336", | ||
"version" : "1.3.0" | ||
} | ||
} | ||
], | ||
"version" : 3 | ||
} |