Skip to content

Commit

Permalink
Fixed bugs, improved searching, and added a new sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanLipnik committed Sep 18, 2021
1 parent 9044d5d commit 0f2f652
Show file tree
Hide file tree
Showing 20 changed files with 295 additions and 117 deletions.
51 changes: 36 additions & 15 deletions OpenSesame.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
"version": "4.2.2"
}
},
{
"package": "ScreenCorners",
"repositoryURL": "https://github.com/kylebshr/ScreenCorners.git",
"state": {
"branch": null,
"revision": "1b71897c8d9091cad34bf10a47e3810c0c10e1e8",
"version": "1.0.1"
}
},
{
"package": "DomainParser",
"repositoryURL": "https://github.com/Dashlane/SwiftDomainParser.git",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,4 @@ OpenSesame depends on the following open-source projects:
* [DomainParser](https://github.com/Dashlane/SwiftDomainParser.git) by [Dashlane](https://github.com/Dashlane) ([License](https://github.com/Dashlane/SwiftDomainParser/blob/master/LICENSE))
* [CSV.swift](https://github.com/yaslab/CSV.swift.git) by [yaslab](https://github.com/yaslab) ([License](https://github.com/yaslab/CSV.swift/blob/master/LICENSE))
* [CodeScanner](https://github.com/twostraws/CodeScanner.git) by [twostraws](https://github.com/twostraws) ([License](https://github.com/twostraws/CodeScanner/blob/main/LICENSE))
* [ScreenCorners](https://github.com/kylebshr/ScreenCorners.git) by [kylebshr](https://github.com/kylebshr) ([License](https://github.com/kylebshr/ScreenCorners/blob/main/LICENSE))
5 changes: 4 additions & 1 deletion Shared/AutoFill/AutoFillView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ struct AutoFillView: View {
.lineLimit(1)
.blur(radius: CommandLine.arguments.contains("-marketing") ? 5 : 0)
}
}.buttonStyle(.plain)
}
#if os(macOS)
.buttonStyle(.plain)
#endif
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Shared/Credits.rtf
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ Third party frameworks:\
{\listtext \uc0\u8226 }{\field{\*\fldinst{HYPERLINK "https://github.com/Dashlane/SwiftDomainParser"}}{\fldrslt DomainParser}}\
{\listtext \uc0\u8226 }{\field{\*\fldinst{HYPERLINK "https://github.com/yaslab/CSV.swift"}}{\fldrslt CSV.swift}}\
{\listtext \uc0\u8226 }{\field{\*\fldinst{HYPERLINK "https://github.com/twostraws/CodeScanner"}}{\fldrslt CodeScanner}}\
{\listtext \uc0\u8226 }{\field{\*\fldinst{HYPERLINK "https://github.com/kylebshr/ScreenCorners"}}{\fldrslt ScreenCorners}}\
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<relationship name="vault" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Vault" inverseName="accounts" inverseEntity="Vault"/>
</entity>
<entity name="Card" representedClassName="Card" syncable="YES" codeGenerationType="class">
<attribute name="expirationDate" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="expirationDate" optional="YES" attributeType="String"/>
<attribute name="holder" optional="YES" attributeType="String"/>
<attribute name="isPinned" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="name" optional="YES" attributeType="String"/>
Expand All @@ -39,7 +39,7 @@
<elements>
<element name="Account" positionX="-36" positionY="18" width="128" height="209"/>
<element name="Card" positionX="-9" positionY="117" width="128" height="134"/>
<element name="Vault" positionX="-63" positionY="-18" width="128" height="89"/>
<element name="Note" positionX="-36" positionY="99" width="128" height="104"/>
<element name="Vault" positionX="-63" positionY="-18" width="128" height="89"/>
</elements>
</model>
5 changes: 3 additions & 2 deletions Shared/Persistence/Persistence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ class PersistenceController {

container = NSPersistentContainer.create(inMemory: inMemory)

if let coreDataVersion = UserDefaults(suiteName: OpenSesameConfig.APP_GROUP)?.float(forKey: "coreDataVersion"), coreDataVersion < 1.2 {
let coreDataVersion = UserDefaults.group.float(forKey: "coreDataVersion")
if coreDataVersion < 1.3 {
try? FileManager.default.removeItem(at: PersistenceController.storeURL)

UserDefaults(suiteName: OpenSesameConfig.APP_GROUP)?.set(1.2, forKey: "coreDataVersion")
UserDefaults(suiteName: OpenSesameConfig.APP_GROUP)?.set(1.3, forKey: "coreDataVersion")

do {
try self.downloadStoreFrom(.iCloud)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ extension AccountView.AccountDetailsView {
} label: {
Image(systemName: "qrcode.viewfinder")
}
// .bottomSheet(isPresented: $isScanningQRCode) {
// CodeScannerView(codeTypes: [.qr]) { result in
// switch result {
// case .success(let code):
// isScanningQRCode = false
// addVerificationCode(code)
// case .failure(let error):
// print(error)
// }
// }
// .clipShape(RoundedRectangle(cornerRadius: 15, style: .continuous))
// .padding()
// .shadow(radius: 15)
// }
.halfSheet(showSheet: $isScanningQRCode) {
CodeScannerView(codeTypes: [.qr]) { result in
switch result {
Expand Down
5 changes: 4 additions & 1 deletion Shared/Views/AuthenticationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct AuthenticationView: View {
@State private var authenticatedPassword: String = ""
var message: String? = nil
let onSuccess: (_ password: String) -> Void
var onCancel: () -> Void = {}

var body: some View {
VStack(spacing: 20) {
Expand All @@ -24,6 +25,7 @@ struct AuthenticationView: View {
.onSubmit(didAuthenticate)
.textFieldStyle(.plain)
.frame(maxWidth: 400)
Button("Cancel", action: onCancel)
Button(action: didAuthenticate) {
Image(systemName: "key.fill")
}
Expand All @@ -33,7 +35,8 @@ struct AuthenticationView: View {
Text(message)
.foregroundColor(Color.red)
}
}.padding()
}
.padding()
}

func didAuthenticate() {
Expand Down
88 changes: 88 additions & 0 deletions Shared/Views/BottomSheet.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//
// BottomSheet.swift
// OpenSesame
//
// Created by Ethan Lipnik on 9/18/21.
//

import SwiftUI
import ScreenCorners

struct BottomSheet<ContentView: View>: ViewModifier {
@Binding var isPresented: Bool
let isInteractiveDismissEnabled: Bool
let contentView: ContentView

init(isPresented: Binding<Bool>, isInteractiveDismissEnabled: Bool, @ViewBuilder content: @escaping () -> ContentView) {
self._isPresented = isPresented
self.isInteractiveDismissEnabled = isInteractiveDismissEnabled
self.contentView = content()
}

@State private var offset: CGSize = .zero

func body(content: Content) -> some View {
let cornerRadius = UIScreen.main.displayCornerRadius

return content
.overlay(
isPresented ?
VStack {
RoundedRectangle(cornerRadius: 4)
.fill(Color.secondary.opacity(0.5))
.frame(width: 40, height: 8)
contentView
}
.padding()
.background(RoundedRectangle(cornerRadius: cornerRadius == 0 ? 10 : cornerRadius, style: .continuous)
.fill(Color("Tertiary"))
.shadow(radius: 30, y: 10))
.frame(maxWidth: 600, minHeight: 300)
.padding()
.offset(offset)
.animation(.spring(), value: offset)
.gesture(DragGesture()
.onChanged({ value in
let height: CGFloat = {
if offset.height > 0 {
return value.translation.height
} else {
return value.translation.height / 10
}
}()

offset = CGSize(width: value.translation.width / 10, height: height)
})
.onEnded({ value in
if value.translation.height > 100 && isInteractiveDismissEnabled {
withAnimation(.default) {
isPresented = false
}
}

offset = .zero
}))
.transition(.move(edge: .bottom))
: nil,
alignment: .bottom)
.animation(.spring(), value: isPresented)
}
}

extension View {
func bottomSheet<ContentView: View>(isPresented: Binding<Bool>, isInteractiveDismissEnabled: Bool = true, @ViewBuilder content: @escaping () -> ContentView) -> some View {
self.modifier(BottomSheet(isPresented: isPresented, isInteractiveDismissEnabled: isInteractiveDismissEnabled, content: content))
}
}

struct BottomSheet_Previews: PreviewProvider {
static var previews: some View {
Rectangle()
.bottomSheet(isPresented: .constant(true)) {
VStack {
Text("Hey")
}
}
}
}

9 changes: 3 additions & 6 deletions Shared/Views/CardView/CardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ struct CardView: View {

// MARK: - View
var body: some View {
let calendar = Calendar.current
let expirationDate = "\(calendar.component(.month, from: card.expirationDate!))/" + "\(calendar.component(.year, from: card.expirationDate!))".suffix(2)

return ScrollView {
ScrollView {
VStack {
RoundedRectangle(cornerRadius: 5, style: .continuous)
.fill(Color.secondary.opacity(0.25))
Expand Down Expand Up @@ -101,11 +98,11 @@ struct CardView: View {
Text("Valid Thru")
.font(.caption)
.foregroundColor(.secondary)
Text(expirationDate)
Text(card.expirationDate ?? "")
.font(.system(.title3, design: .monospaced).bold())
.contextMenu {
Button {
expirationDate.copyToPasteboard()
card.expirationDate?.copyToPasteboard()
} label: {
Label("Copy expiration date", systemImage: "doc.on.doc")
}
Expand Down
4 changes: 2 additions & 2 deletions Shared/Views/HalfSheetModal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct HalfSheetHelper<SheetView: View>: UIViewControllerRepresentable{

if showSheet{

if uiViewController.presentedViewController == nil{
if uiViewController.presentedViewController == nil {

// presenting Modal View....

Expand All @@ -67,7 +67,7 @@ struct HalfSheetHelper<SheetView: View>: UIViewControllerRepresentable{
}
else{
// closing view when showSheet toggled again...
if uiViewController.presentedViewController != nil{
if uiViewController.presentedViewController != nil {
uiViewController.dismiss(animated: true)
}
}
Expand Down
8 changes: 6 additions & 2 deletions Shared/Views/LockView/LockView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ struct LockView: View {
shouldShowCreatePassword = encryptionTest == nil && !isShowingBoardingScreen
#endif

DispatchQueue.main.asyncAfter(deadline: .now() + 0.8) {
isTextFieldFocussed = true
if !isLocked {
isTextFieldFocussed = false
}
}
.task {
Expand All @@ -169,6 +169,10 @@ struct LockView: View {
#else
unlockWithBiometrics()
#endif
} else if isLocked {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.8) {
isTextFieldFocussed = true
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Shared/Views/SettingsView/CreditsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct CreditsView: View {
Text("[DomainParser](https://github.com/Dashlane/SwiftDomainParser.git) by [Dashlane](https://github.com/Dashlane) ([License](https://github.com/Dashlane/SwiftDomainParser/blob/master/LICENSE))")
Text("[CSV.swift](https://github.com/yaslab/CSV.swift.git) by [yaslab](https://github.com/yaslab) ([License](https://github.com/yaslab/CSV.swift/blob/master/LICENSE))")
Text("[CodeScanner](https://github.com/twostraws/CodeScanner.git) by [twostraws](https://github.com/twostraws) ([License](https://github.com/twostraws/CodeScanner/blob/main/LICENSE))")
Text("[ScreenCorners](https://github.com/kylebshr/ScreenCorners.git) by [kylebshr](https://github.com/kylebshr) ([License](https://github.com/kylebshr/ScreenCorners/blob/main/LICENSE))")
}
}.navigationTitle("Acknowledgements")
}
Expand Down
17 changes: 15 additions & 2 deletions Shared/Views/SettingsView/iOS/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ struct SettingsView: View {
} label: {
Label("Acknowledgements", systemImage: "list.star")
}

}

#if DEBUG
Expand Down Expand Up @@ -247,8 +246,22 @@ struct SettingsView: View {
shouldAuthenticate = true
}
}
// .bottomSheet(isPresented: $shouldAuthenticate, isInteractiveDismissEnabled: false) {
// AuthenticationView(onSuccess: didAuthenticate) {
// shouldResetBiometrics = false
// userSettings.shouldUseBiometrics = false
// shouldAuthenticate = false
// }
// }
.halfSheet(showSheet: $shouldAuthenticate, supportsLargeView: false) {
AuthenticationView(onSuccess: didAuthenticate)
AuthenticationView(onSuccess: didAuthenticate) {
shouldResetBiometrics = false
shouldAuthenticate = false

withAnimation {
userSettings.shouldUseBiometrics = false
}
}
} onEnd: {
shouldResetBiometrics = false
}
Expand Down
7 changes: 4 additions & 3 deletions Shared/Views/Vault/ExportElements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ struct ExportButtons: View {
Label("Export".addElipsis(platformSpecific: true), systemImage: "tray.and.arrow.up.fill")
}
#if os(iOS)
.halfSheet(showSheet: $shouldAuthenticate, supportsLargeView: false) {
AuthenticationView(message: "You are exporting your passwords without any encryption. Do this at your own risk.", onSuccess: didAuthenticate)
}
#warning("Add bottom sheet")
// .halfSheet(showSheet: $shouldAuthenticate, supportsLargeView: false) {
// AuthenticationView(message: "You are exporting your passwords without any encryption. Do this at your own risk.", onSuccess: didAuthenticate)
// }
#endif
}

Expand Down
15 changes: 7 additions & 8 deletions Shared/Views/Vault/NewAccountView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import DomainParser
struct NewAccountView: View {
// MARK: - Environment
@Environment(\.managedObjectContext) private var viewContext
@Environment(\.dismiss) var dismiss

// MARK: - Variables
@State private var website: String = ""
@State private var username: String = ""
@State private var password: String = ""

@Binding var isPresented: Bool
let selectedVault: Vault

// MARK: - View
Expand Down Expand Up @@ -91,11 +92,9 @@ struct NewAccountView: View {
.padding(5)
#endif
}
.padding([.top, .horizontal])
Spacer()
HStack {
Button("Cancel") {
dismiss.callAsFunction()
isPresented = false
}
.keyboardShortcut(.cancelAction)
#if os(iOS)
Expand Down Expand Up @@ -123,8 +122,8 @@ struct NewAccountView: View {
let encryptedPassword = try CryptoSecurityService.encrypt(password)
print("Encrypted password")

let domainParser = try DomainParser()
let domain = domainParser.parse(host: URL(string: website)?.host ?? website)?.domain
let domainParser = try? DomainParser()
let domain = domainParser?.parse(host: URL(string: website)?.host ?? website)?.domain

let newAccount = Account(context: viewContext)
newAccount.dateAdded = Date()
Expand Down Expand Up @@ -154,7 +153,7 @@ struct NewAccountView: View {
}
}

dismiss.callAsFunction()
isPresented = false
} catch {
print(error)

Expand All @@ -167,6 +166,6 @@ struct NewAccountView: View {

struct NewAccountView_Previews: PreviewProvider {
static var previews: some View {
NewAccountView(selectedVault: .init())
NewAccountView(isPresented: .constant(true), selectedVault: .init())
}
}
Loading

0 comments on commit 0f2f652

Please sign in to comment.