Skip to content

Commit

Permalink
Migrated codebase to Swift 6 (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldavidw authored Oct 31, 2024
1 parent 3503f01 commit 891306c
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 60 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ jobs:
strategy:
matrix:
include:
- xcode: "15.4"
- xcode: "16.1"
ios: "17.5"
- xcode: "16.1"
ios: "18.1"
name: iOS (${{ matrix.ios }})
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
Expand Down
32 changes: 16 additions & 16 deletions Chronos.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 16.0;
MARKETING_VERSION = 17.0;
PRODUCT_BUNDLE_IDENTIFIER = com.joeldavidw.ChronosDevDebug;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -896,7 +896,7 @@
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = 1;
};
name = "Dev Debug";
Expand Down Expand Up @@ -934,7 +934,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 16.0;
MARKETING_VERSION = 17.0;
PRODUCT_BUNDLE_IDENTIFIER = com.joeldavidw.ChronosDevRelease;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -943,7 +943,7 @@
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = 1;
};
name = "Dev Release";
Expand Down Expand Up @@ -1260,7 +1260,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 16.0;
MARKETING_VERSION = 17.0;
PRODUCT_BUNDLE_IDENTIFIER = com.joeldavidw.Chronos;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -1269,7 +1269,7 @@
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = 1;
};
name = "Prod Release";
Expand Down Expand Up @@ -1315,7 +1315,7 @@
repositoryURL = "https://github.com/ggruen/CloudKitSyncMonitor";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 2.0.0;
minimumVersion = 3.0.0;
};
};
6B35A4C72B557EE50004D4C5 /* XCRemoteSwiftPackageReference "AlertKit" */ = {
Expand All @@ -1330,8 +1330,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/square/Valet";
requirement = {
kind = exactVersion;
version = 4.3.0;
kind = upToNextMajorVersion;
minimumVersion = 5.0.0;
};
};
6B3BB11E2B511A9E00DCEF0B /* XCRemoteSwiftPackageReference "SwiftOTP" */ = {
Expand All @@ -1347,7 +1347,7 @@
repositoryURL = "https://github.com/apple/swift-log.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.5.4;
minimumVersion = 1.6.1;
};
};
6B66D5EB2B526648006DB79D /* XCRemoteSwiftPackageReference "CodeScanner" */ = {
Expand All @@ -1363,23 +1363,23 @@
repositoryURL = "https://github.com/hmlongco/Factory";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 2.3.2;
minimumVersion = 2.4.1;
};
};
6B8ABEEA2B8F6A4F00F5B514 /* XCRemoteSwiftPackageReference "CryptoSwift" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/krzyzanowskim/CryptoSwift.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.8.2;
minimumVersion = 1.8.3;
};
};
6B96C8822CA7BFB3004ECB11 /* XCRemoteSwiftPackageReference "QRCode" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/dagronf/QRCode";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 21.0.3;
minimumVersion = 23.0.0;
};
};
6BB37D7F2C46C751008DA122 /* XCRemoteSwiftPackageReference "SwiftyJSON" */ = {
Expand All @@ -1395,23 +1395,23 @@
repositoryURL = "https://github.com/pointfreeco/swift-html";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.4.1;
minimumVersion = 0.5.0;
};
};
6BC5F0502C52429100BA106F /* XCRemoteSwiftPackageReference "swift-protobuf" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/apple/swift-protobuf.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.27.1;
minimumVersion = 1.28.2;
};
};
6BF53E4B2C31793100356461 /* XCRemoteSwiftPackageReference "ZipArchive" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/ZipArchive/ZipArchive";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 2.5.5;
minimumVersion = 2.6.0;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/ggruen/CloudKitSyncMonitor",
"state" : {
"revision" : "923c6b0b2360b3a70d3dd69a0c6c8320b075caa9",
"version" : "2.0.0"
"revision" : "c14a433b284526e29e0021f343bae9e61779164b",
"version" : "3.0.0"
}
},
{
Expand Down Expand Up @@ -51,8 +51,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/dagronf/QRCode",
"state" : {
"revision" : "d21e6135ec27e3aee0fa6ad14c9d88154d1dab25",
"version" : "21.2.0"
"revision" : "90bf2183e2eec226840751af42a2eaebfd53330b",
"version" : "23.0.0"
}
},
{
Expand Down Expand Up @@ -159,8 +159,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/square/Valet",
"state" : {
"revision" : "3df8eaa90e1fa0d80830733cdc3c9e098146af3d",
"version" : "4.3.0"
"revision" : "05c9e514fbd352a6866877ca31326b4e0b7d6d01",
"version" : "5.0.0"
}
},
{
Expand Down
34 changes: 18 additions & 16 deletions Chronos/App/Misc/PasswordReminder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ struct PasswordReminderView: View {
.disabled(verifyPressed)
.submitLabel(.done)
.onSubmit {
doSubmit()
Task {
await doSubmit()
}
}
}
}
Expand All @@ -57,7 +59,9 @@ struct PasswordReminderView: View {
}

Button {
doSubmit()
Task {
await doSubmit()
}
} label: {
if !verifyPressed {
Text("Verify")
Expand Down Expand Up @@ -100,24 +104,22 @@ struct PasswordReminderView: View {
.presentationDragIndicator(.visible)
}

func doSubmit() {
func doSubmit() async {
verifyPressed = true

Task {
let context = ModelContext(swiftDataService.getModelContainer())
let vault = vaultService.getVault(context: context)!

let passwordVerified = await cryptoService.unwrapMasterKeyWithUserPassword(vault: vault, password: Array(password.utf8))
let context = ModelContext(swiftDataService.getModelContainer())
let vault = vaultService.getVault(context: context)!

if passwordVerified {
dismiss()
await UINotificationFeedbackGenerator().notificationOccurred(.success)
} else {
passwordInvalid = true
await UINotificationFeedbackGenerator().notificationOccurred(.error)
}
let passwordVerified = await cryptoService.unwrapMasterKeyWithUserPassword(vault: vault, password: Array(password.utf8))

verifyPressed = false
if passwordVerified {
dismiss()
UINotificationFeedbackGenerator().notificationOccurred(.success)
} else {
passwordInvalid = true
UINotificationFeedbackGenerator().notificationOccurred(.error)
}

verifyPressed = false
}
}
2 changes: 1 addition & 1 deletion Chronos/App/Onboarding/PasswordSetupView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ extension PasswordSetupView {
let success = vaultService.createVaultCrypto(vaultName: vaultName, chronosCrypto: chronosCrypto)

if success {
await UINotificationFeedbackGenerator().notificationOccurred(.success)
UINotificationFeedbackGenerator().notificationOccurred(.success)
}

nextBtnPressed = success
Expand Down
30 changes: 16 additions & 14 deletions Chronos/App/Onboarding/Restore/RestoreBackupView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ struct RestoreBackupView: View {
.focused($focusedField, equals: .password)
.submitLabel(.done)
.onSubmit {
doSubmit()
Task {
await doSubmit()
}
}
}
.frame(height: 48)
Expand All @@ -60,7 +62,9 @@ struct RestoreBackupView: View {
Spacer()

Button {
doSubmit()
Task {
await doSubmit()
}
} label: {
if !restoreBtnPressed {
Text("Next")
Expand Down Expand Up @@ -90,7 +94,7 @@ struct RestoreBackupView: View {
}
}

func doSubmit() {
func doSubmit() async {
// Defaults to the first vault if the user is not coming from VaultSelectionView.
// Users will only come from VaultSelectionView if there are multiple vaults.
if vaults.count == 1 {
Expand All @@ -99,19 +103,17 @@ struct RestoreBackupView: View {

restoreBtnPressed = true

Task {
let vault = vaultService.getVaultWithoutContext(isRestore: true)
let vault = vaultService.getVaultWithoutContext(isRestore: true)

passwordVerified = await cryptoService.unwrapMasterKeyWithUserPassword(vault: vault, password: Array(password.utf8), isRestore: true)
restoreBtnPressed = false
passwordVerified = await cryptoService.unwrapMasterKeyWithUserPassword(vault: vault, password: Array(password.utf8), isRestore: true)
restoreBtnPressed = false

if passwordVerified {
isICloudEnabled = true
await UINotificationFeedbackGenerator().notificationOccurred(.success)
} else {
passwordInvalid = true
await UINotificationFeedbackGenerator().notificationOccurred(.error)
}
if passwordVerified {
isICloudEnabled = true
UINotificationFeedbackGenerator().notificationOccurred(.success)
} else {
passwordInvalid = true
UINotificationFeedbackGenerator().notificationOccurred(.error)
}
}
}
12 changes: 8 additions & 4 deletions Chronos/App/Onboarding/WelcomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,20 @@ struct WelcomeView: View {
iCloudSyncLastAttempt = 0

syncTimer = Timer.scheduledTimer(withTimeInterval: 2.5, repeats: false) { _ in
showProgressView = false
iCloudSyncLastAttempt = Date().timeIntervalSince1970
Task { @MainActor in
showProgressView = false
iCloudSyncLastAttempt = Date().timeIntervalSince1970
}
}
})
.onChange(of: syncMonitor.syncStateSummary) { _, newValue in
if newValue == .succeeded {
syncTimer?.invalidate()
syncTimer = Timer.scheduledTimer(withTimeInterval: 0.8, repeats: false) { _ in
showProgressView = false
iCloudSyncLastAttempt = Date().timeIntervalSince1970
Task { @MainActor in
showProgressView = false
iCloudSyncLastAttempt = Date().timeIntervalSince1970
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion Chronos/App/Tabs/Tokens/TokensTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ struct TokensTab: View {
.onChange(of: searchQuery) { _, _ in
debounceTimer?.invalidate()
debounceTimer = Timer.scheduledTimer(withTimeInterval: 0.15, repeats: false) { _ in
sortAndFilterTokenPairs()
Task {
await sortAndFilterTokenPairs()
}
}
}
.listStyle(.plain)
Expand Down
2 changes: 1 addition & 1 deletion Chronos/Extensions/ViewModifier.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SwiftUI

struct SheetHeightPreferenceKey: PreferenceKey {
static var defaultValue: CGFloat = .zero
static let defaultValue: CGFloat = .zero
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
value = nextValue()
}
Expand Down
2 changes: 2 additions & 0 deletions Chronos/Services/CryptoService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class CryptoService {
// scrypt paramaters - n: 2^17, r: 8, p: 1
private let kdfParams = KdfParams(type: 0, n: 1 << 17, r: 8, p: 1)

@MainActor
func wrapMasterKeyWithUserPassword(password: [UInt8]) async -> ChronosCrypto {
let passwordSalt = try! generateRandomSaltHexString()
let passwordParams = PasswordParams(salt: passwordSalt)
Expand All @@ -40,6 +41,7 @@ public class CryptoService {
}
}

@MainActor
func unwrapMasterKeyWithUserPassword(vault: Vault?, password: [UInt8], isRestore _: Bool = false) async -> Bool {
guard let vault = vault else {
return false
Expand Down

0 comments on commit 891306c

Please sign in to comment.