Skip to content

Integrate core lib #67

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

Merged
merged 8 commits into from
Jun 24, 2022
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
42 changes: 1 addition & 41 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,4 @@ swiftgen:
@(cd BuildTools; SDKROOT=macosx; swift run -c release swiftgen config run --config ./swiftgen.yml)

format:
@(cd BuildTools; SDKROOT=macosx; swift run -c release swiftformat ..)

# ################ FFIs ################

RUST_LIB_PATH = ../uniffi_test
RUST_LIB_NAME = uniffi_test
SWIFT_LIB_NAME = ProseCore
BUILD_FOLDER = Build

ffi: interface framework

interface:
uniffi-bindgen generate $(RUST_LIB_PATH)/src/$(RUST_LIB_NAME).udl -o ./$(BUILD_FOLDER)/interface --language swift
sed -i '' 's/import uniffi_testFFI/@_implementationOnly import uniffi_testFFI/g' ./$(BUILD_FOLDER)/interface/$(RUST_LIB_NAME).swift

framework:
rm -f $(BUILD_FOLDER)/lib$(SWIFT_LIB_NAME).a
rm -f $(BUILD_FOLDER)/$(SWIFT_LIB_NAME).a
rm -f $(BUILD_FOLDER)/$(SWIFT_LIB_NAME).swiftmodule

(cd $(BUILD_FOLDER); swiftc \
-module-name $(SWIFT_LIB_NAME) \
-emit-library -o lib$(SWIFT_LIB_NAME).a \
-emit-module -emit-module-path . \
-parse-as-library \
-L $(RUST_LIB_PATH)/target/aarch64-apple-darwin/release \
-l$(RUST_LIB_NAME) \
-Xcc -fmodule-map-file=./interface/$(RUST_LIB_NAME)FFI.modulemap \
-static \
-enable-library-evolution \
./interface/$(RUST_LIB_NAME).swift)

libtool -static -o $(BUILD_FOLDER)/$(SWIFT_LIB_NAME).a $(BUILD_FOLDER)/lib$(SWIFT_LIB_NAME).a $(RUST_LIB_PATH)/target/aarch64-apple-darwin/release/lib$(RUST_LIB_NAME).a

rm -rf ProseCore/ProseCore/$(SWIFT_LIB_NAME).xcframework

xcodebuild -create-xcframework \
-library ./Build/$(SWIFT_LIB_NAME).a \
-output ProseCore/ProseCore/$(SWIFT_LIB_NAME).xcframework

cp Build/$(SWIFT_LIB_NAME).swiftmodule ProseCore/ProseCore/$(SWIFT_LIB_NAME).xcframework/macos-arm64
@(cd BuildTools; SDKROOT=macosx; swift run -c release swiftformat ..)
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
"version" : "2.6.0"
}
},
{
"identity" : "prose-wrapper-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/prose-im/prose-wrapper-swift",
"state" : {
"branch" : "0.1.3",
"revision" : "34fc746602597e00be8833d012156d36a8caae2b"
}
},
{
"identity" : "swift-case-paths",
"kind" : "remoteSourceControl",
Expand Down
33 changes: 23 additions & 10 deletions Prose/ProseLib/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ let package = Package(
]),
],
dependencies: [
// .package(path: "../../ProseCore"),
.package(url: "https://github.com/sindresorhus/Preferences", .upToNextMajor(from: "2.5.0")),
.package(url: "https://github.com/apple/swift-collections.git", .upToNextMajor(from: "1.0.2")),
.package(
url: "https://github.com/pointfreeco/swift-composable-architecture",
.upToNextMajor(from: "0.33.1")
),
.package(url: "https://github.com/pointfreeco/swiftui-navigation", .upToNextMajor(from: "0.1.0")),
// https://github.com/prose-im/prose-wrapper-swift/issues/1
.package(url: "https://github.com/prose-im/prose-wrapper-swift", branch: "0.1.3"),
],
targets: [
.target(
Expand All @@ -42,7 +43,7 @@ let package = Package(
"CredentialsClient",
"TcaHelpers",
"UserDefaultsClient",
// "ProseCore",
"ProseCoreTCA",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
]
),
Expand All @@ -64,6 +65,7 @@ let package = Package(
"AddressBookFeature",
"ConversationFeature",
"UnreadFeature",
"ProseCoreTCA",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
]),
.target(name: "AddressBookFeature", dependencies: [
Expand All @@ -85,6 +87,7 @@ let package = Package(
"PreviewAssets",
"SharedModels",
"TcaHelpers",
"ProseCoreTCA",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
]
),
Expand All @@ -94,29 +97,28 @@ let package = Package(
"AppLocalization",
"Assets",
"ConversationInfoFeature",
"ProseCoreStub",
"ProseUI",
"PreviewAssets",
"SharedModels",
"ProseCoreTCA",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
.product(name: "OrderedCollections", package: "swift-collections"),
]
),
.target(name: "ConversationInfoFeature", dependencies: [
"PreviewAssets",
"ProseCoreStub",
"SharedModels",
"ProseCoreTCA",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
]),
.target(
name: "AuthenticationFeature",
dependencies: [
"AppLocalization",
"CredentialsClient",
// "ProseCore",
"ProseUI",
"SharedModels",
"TcaHelpers",
"ProseCoreTCA",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
.product(name: "SwiftUINavigation", package: "swiftui-navigation"),
]
Expand All @@ -128,14 +130,11 @@ let package = Package(
"ProseUI",
"PreviewAssets",
"SharedModels",
"ProseCoreTCA",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
.product(name: "OrderedCollections", package: "swift-collections"),
]
),
.target(name: "ProseCoreStub", dependencies: [
"SharedModels",
.product(name: "OrderedCollections", package: "swift-collections"),
]),

// MARK: Dependencies

Expand All @@ -146,5 +145,19 @@ let package = Package(
.target(name: "UserDefaultsClient", dependencies: [
"SharedModels",
]),
.target(
name: "ProseCore",
dependencies: [
.product(name: "ProseCoreClientFFI", package: "prose-wrapper-swift"),
]
),
.target(
name: "ProseCoreTCA",
dependencies: [
"ProseCore",
"SharedModels",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
]
),
]
)
55 changes: 18 additions & 37 deletions Prose/ProseLib/Sources/App/AppReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import ComposableArchitecture
import CredentialsClient
import Foundation
import MainWindowFeature
// import ProseCore
import ProseCoreStub
import ProseCoreTCA
import SharedModels
import UserDefaultsClient

Expand Down Expand Up @@ -59,7 +58,10 @@ public let appReducer: Reducer<

case let .authenticationResult(.success(.some(credentials))):
proceedToMainFlow(with: credentials)
return .none
return environment.proseClient.login(credentials.jid, credentials.password)
.receive(on: environment.mainQueue)
.catchToEffect()
.map(AppAction.connectionResult)

case .authenticationResult(.success(.none)):
proceedToLogin()
Expand Down Expand Up @@ -100,6 +102,14 @@ public let appReducer: Reducer<
proceedToLogin(jid: jid)
return .none

case .connectionResult(.success):
logger.info("Connection established.")
return .none

case .connectionResult(.failure):
proceedToLogin()
return .none

case .onAppear, .auth, .main:
return .none
}
Expand Down Expand Up @@ -150,6 +160,7 @@ public enum URLOpeningError: Error, Equatable {
public enum AppAction: Equatable {
case onAppear
case authenticationResult(Result<Credentials?, EquatableError>)
case connectionResult(Result<None, EquatableError>)
case auth(AuthenticationAction)
case main(MainScreenAction)
}
Expand All @@ -166,59 +177,29 @@ public struct AppEnvironment {
var userDefaults: UserDefaultsClient
var credentials: CredentialsClient

let userStore: UserStore
let messageStore: MessageStore
let statusStore: StatusStore
let securityStore: SecurityStore
var proseClient: ProseClient

var mainQueue: AnySchedulerOf<DispatchQueue>

var openURL: (URL, OpenURLConfiguration) -> Effect<Void, URLOpeningError>

var auth: AuthenticationEnvironment {
AuthenticationEnvironment(
proseClient: self.proseClient,
credentials: self.credentials,
mainQueue: self.mainQueue
)
}

var main: MainScreenEnvironment {
MainScreenEnvironment(
userStore: self.userStore,
messageStore: self.messageStore,
statusStore: self.statusStore,
securityStore: self.securityStore
)
}

private init(
userDefaults: UserDefaultsClient,
credentials: CredentialsClient,
userStore: UserStore,
messageStore: MessageStore,
statusStore: StatusStore,
securityStore: SecurityStore,
mainQueue: AnySchedulerOf<DispatchQueue>,
openURL: @escaping (URL, OpenURLConfiguration) -> Effect<Void, URLOpeningError>
) {
self.userDefaults = userDefaults
self.credentials = credentials
self.userStore = userStore
self.messageStore = messageStore
self.statusStore = statusStore
self.securityStore = securityStore
self.mainQueue = mainQueue
self.openURL = openURL
MainScreenEnvironment(proseClient: self.proseClient, mainQueue: self.mainQueue)
}

public static var live: Self {
Self(
userDefaults: .live(.standard),
credentials: .live(service: "org.prose.app"),
userStore: .stub,
messageStore: .stub,
statusStore: .stub,
securityStore: .stub,
proseClient: .live(),
mainQueue: .main,
openURL: { url, openConfig -> Effect<Void, URLOpeningError> in
Effect.future { callback in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,6 @@
import AppLocalization
import Foundation

public enum BasicAuthError: Error, Equatable {
case badCredentials
}

extension BasicAuthError: LocalizedError {
public var errorDescription: String? {
switch self {
case .badCredentials:
return L10n.Authentication.BasicAuth.Alert.BadCredentials.title
}
}
}

public enum MFAError: Error, Equatable {
case badCode
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import ComposableArchitecture
import CredentialsClient
import ProseCoreTCA
import SharedModels
import SwiftUI
import TcaHelpers
Expand Down Expand Up @@ -107,33 +108,19 @@ public enum AuthenticationAction: Equatable {
// MARK: Environment

public struct AuthenticationEnvironment {
var proseClient: ProseClient
var credentials: CredentialsClient

// var login: (String, String, ClientOrigin) -> Effect<Result<UserCredentials, EquatableError>, Never>
var mainQueue: AnySchedulerOf<DispatchQueue>

public init(
proseClient: ProseClient,
credentials: CredentialsClient,
mainQueue: AnySchedulerOf<DispatchQueue>
) {
self.proseClient = proseClient
self.credentials = credentials
self.mainQueue = mainQueue
}

// public init(login: @escaping (String, String, ClientOrigin)
// -> Effect<Result<UserCredentials, EquatableError>, Never>)
// {
// self.login = login
// }
}

public extension AuthenticationEnvironment {
static var placeholder: AuthenticationEnvironment {
AuthenticationEnvironment(
credentials: .placeholder,
mainQueue: .main
)
}
}

// MARK: - Previews
Expand All @@ -145,6 +132,7 @@ internal struct AuthenticationScreen_Previews: PreviewProvider {
initialState: AuthenticationState(route: .basicAuth(.init())),
reducer: authenticationReducer,
environment: AuthenticationEnvironment(
proseClient: .noop,
credentials: .live(service: "org.prose.app.preview.\(Self.self)"),
mainQueue: .main
)
Expand Down
Loading