diff --git a/AutoCat2 (macOS).entitlements b/AutoCat2 (macOS).entitlements
new file mode 100644
index 0000000..ee95ab7
--- /dev/null
+++ b/AutoCat2 (macOS).entitlements
@@ -0,0 +1,10 @@
+
+
+
+
+ com.apple.security.app-sandbox
+
+ com.apple.security.network.client
+
+
+
diff --git a/AutoCat2.xcodeproj/project.pbxproj b/AutoCat2.xcodeproj/project.pbxproj
index 5f6e1a4..20183df 100644
--- a/AutoCat2.xcodeproj/project.pbxproj
+++ b/AutoCat2.xcodeproj/project.pbxproj
@@ -53,6 +53,8 @@
7A971F1E26AD8AEB007E527B /* Merging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A971F1426AD8AEB007E527B /* Merging.swift */; };
7A971F2026ADC351007E527B /* ApiError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A971F1F26ADC351007E527B /* ApiError.swift */; };
7A971F2126ADC351007E527B /* ApiError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A971F1F26ADC351007E527B /* ApiError.swift */; };
+ 7A971F2326ADF74B007E527B /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A971F2226ADF74B007E527B /* MainView.swift */; };
+ 7A971F2426ADF74B007E527B /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A971F2226ADF74B007E527B /* MainView.swift */; };
7ACD05D72695C08A00557667 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7ACD05D62695C08A00557667 /* Constants.swift */; };
7ACD05D82695C08A00557667 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7ACD05D62695C08A00557667 /* Constants.swift */; };
7AEFAEED26985A3400ED2C85 /* ACProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AEFAEEC26985A3400ED2C85 /* ACProgressView.swift */; };
@@ -140,6 +142,8 @@
7A971F1226AD8AEB007E527B /* JSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSON.swift; sourceTree = ""; };
7A971F1426AD8AEB007E527B /* Merging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Merging.swift; sourceTree = ""; };
7A971F1F26ADC351007E527B /* ApiError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApiError.swift; sourceTree = ""; };
+ 7A971F2226ADF74B007E527B /* MainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainView.swift; sourceTree = ""; };
+ 7A971F2526ADFD35007E527B /* AutoCat2 (macOS).entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "AutoCat2 (macOS).entitlements"; sourceTree = ""; };
7ACD05D62695C08A00557667 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = ""; };
7AEFAEEC26985A3400ED2C85 /* ACProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ACProgressView.swift; sourceTree = ""; };
7AF552D82696E5C100578083 /* ApiTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApiTests.swift; sourceTree = ""; };
@@ -187,6 +191,7 @@
7A40D5732691C6D6009B0BC4 = {
isa = PBXGroup;
children = (
+ 7A971F2526ADFD35007E527B /* AutoCat2 (macOS).entitlements */,
7A40D5782691C6D7009B0BC4 /* Shared */,
7A40D5912691C6D8009B0BC4 /* Tests iOS */,
7A40D59B2691C6D8009B0BC4 /* Tests macOS */,
@@ -207,7 +212,6 @@
7A40D5E626924BAA009B0BC4 /* Property Wrappers */,
7A40D5DF26924ADE009B0BC4 /* Models */,
7A40D57B2691C6D7009B0BC4 /* AutoCat2App.swift */,
- 7A40D57C2691C6D7009B0BC4 /* ContentView.swift */,
7A40D57D2691C6D7009B0BC4 /* Persistence.swift */,
7A40D57E2691C6D7009B0BC4 /* Assets.xcassets */,
7A40D5792691C6D7009B0BC4 /* AutoCat2.xcdatamodeld */,
@@ -270,8 +274,10 @@
7A40D5E726938BC8009B0BC4 /* Views */ = {
isa = PBXGroup;
children = (
- 7A40D5E826938BEC009B0BC4 /* AuthView.swift */,
7AEFAEEC26985A3400ED2C85 /* ACProgressView.swift */,
+ 7A40D57C2691C6D7009B0BC4 /* ContentView.swift */,
+ 7A40D5E826938BEC009B0BC4 /* AuthView.swift */,
+ 7A971F2226ADF74B007E527B /* MainView.swift */,
);
path = Views;
sourceTree = "";
@@ -323,19 +329,11 @@
sourceTree = "";
};
7A503C00269F370A002C1A0D /* Responses */ = {
- isa = PBXGroup;
- children = (
- 7A503C01269F3797002C1A0D /* Login */,
- );
- path = Responses;
- sourceTree = "";
- };
- 7A503C01269F3797002C1A0D /* Login */ = {
isa = PBXGroup;
children = (
7A503C02269F382F002C1A0D /* login_success.json */,
);
- path = Login;
+ path = Responses;
sourceTree = "";
};
7A971F0326AD6EA1007E527B /* Api */ = {
@@ -569,6 +567,7 @@
buildActionMask = 2147483647;
files = (
7A40D5E926938BEC009B0BC4 /* AuthView.swift in Sources */,
+ 7A971F2326ADF74B007E527B /* MainView.swift in Sources */,
7A971F0D26AD7D4C007E527B /* AnyEncodable.swift in Sources */,
7ACD05D72695C08A00557667 /* Constants.swift in Sources */,
7A971F1926AD8AEB007E527B /* JSON.swift in Sources */,
@@ -596,6 +595,7 @@
buildActionMask = 2147483647;
files = (
7A40D5EA26938BEC009B0BC4 /* AuthView.swift in Sources */,
+ 7A971F2426ADF74B007E527B /* MainView.swift in Sources */,
7A971F0E26AD7D4C007E527B /* AnyEncodable.swift in Sources */,
7ACD05D82695C08A00557667 /* Constants.swift in Sources */,
7A971F1A26AD8AEB007E527B /* JSON.swift in Sources */,
@@ -849,6 +849,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
+ CODE_SIGN_ENTITLEMENTS = "AutoCat2 (macOS).entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
@@ -878,6 +879,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
+ CODE_SIGN_ENTITLEMENTS = "AutoCat2 (macOS).entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
diff --git a/AutoCat2Tests/Api/Responses/Login/login_success.json b/AutoCat2Tests/Api/Responses/login_success.json
similarity index 100%
rename from AutoCat2Tests/Api/Responses/Login/login_success.json
rename to AutoCat2Tests/Api/Responses/login_success.json
diff --git a/Shared/Models/Settings.swift b/Shared/Models/Settings.swift
index b4757f5..e52beca 100644
--- a/Shared/Models/Settings.swift
+++ b/Shared/Models/Settings.swift
@@ -1,9 +1,10 @@
import Foundation
-public class Settings {
+public class Settings: ObservableObject {
private var defaults: UserDefaults
public static let shared = Settings()
+ @Published
public var user: User {
didSet {
if let json = try? JSONEncoder().encode(self.user) {
diff --git a/Shared/Views/AuthView.swift b/Shared/Views/AuthView.swift
index 5db7bc3..7d5c3ff 100644
--- a/Shared/Views/AuthView.swift
+++ b/Shared/Views/AuthView.swift
@@ -1,22 +1,39 @@
import SwiftUI
struct AuthView: View {
+
+ enum Field {
+ case email
+ case password
+ }
+
@ObservedObject var viewModel = AuthVM()
@State private var login: String = ""
@State private var password: String = ""
@State private var showProgress: Bool = false
@State private var alert: AlertMessage? = nil
+ @FocusState private var focus: Field?
var body: some View {
ZStack {
VStack(alignment: .center, spacing: 16) {
Spacer()
+ #if os(iOS)
TextField("Login", text: $login)
+ .focused($focus, equals: .email)
+ .textContentType(.emailAddress)
+ .keyboardType(.emailAddress)
+ #else
+ TextField("Login", text: $login)
+ .focused($focus, equals: .email)
+ #endif
SecureField("Password", text: $password)
+ .focused($focus, equals: .password)
Button("Login") {
- async {
+ Task.init {
do {
+ self.focus = nil
self.showProgress = true
try await self.viewModel.login(user: self.login, password: self.password)
self.showProgress = false
diff --git a/Shared/ContentView.swift b/Shared/Views/ContentView.swift
similarity index 68%
rename from Shared/ContentView.swift
rename to Shared/Views/ContentView.swift
index 92fe106..f1a3363 100644
--- a/Shared/ContentView.swift
+++ b/Shared/Views/ContentView.swift
@@ -2,11 +2,13 @@ import SwiftUI
import CoreData
struct ContentView: View {
+ @StateObject var settings = Settings.shared
+
var body: some View {
- if Settings.shared.user.token.isEmpty {
+ if settings.user.token.isEmpty {
AuthView()
} else {
- EmptyView()
+ MainView()
}
}
}
diff --git a/Shared/Views/MainView.swift b/Shared/Views/MainView.swift
new file mode 100644
index 0000000..0f696fb
--- /dev/null
+++ b/Shared/Views/MainView.swift
@@ -0,0 +1,13 @@
+import SwiftUI
+
+struct MainView: View {
+ var body: some View {
+ Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
+ }
+}
+
+struct MainView_Previews: PreviewProvider {
+ static var previews: some View {
+ MainView()
+ }
+}