Skip to content

Commit

Permalink
Adding unlockWithBiometrics and CI-tests.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
N3v1 committed Dec 16, 2023
1 parent 965a106 commit e55a647
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 28 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/CI-run-tests.yml

This file was deleted.

18 changes: 18 additions & 0 deletions .github/workflows/CI-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: CI-tests
on:
workflow_dispatch:
jobs:
run-unit-tests:
name: Run Unit Tests
runs-on: macos-13
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
- name: List Xcode Versions 📋
run: ls /Applications | grep Xcode
- name: Select Xcode ✨
run: sudo xcode-select -switch /Applications/Xcode_15.0.1.app/Contents/Developer
- name: List SDKs 🎊
run: xcodebuild -showsdks
- name: Run tests (UI & Unit tests) ✅
run: xcodebuild -scheme ScribbleLab -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPad Pro (12.9-inch)' test
4 changes: 4 additions & 0 deletions ScribbleLab.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
385ABC5C2B2DF0B9005F90E6 /* ScribbleLabApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38AE9C9B2AD0750F00B761E8 /* ScribbleLabApp.swift */; };
385ABC5D2B2DF0C1005F90E6 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 380BC6472B2652A900DCF442 /* SceneDelegate.swift */; };
385ABC5E2B2DF0C4005F90E6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 383D238C2B2363490094001E /* AppDelegate.swift */; };
385ABC602B2E0AAD005F90E6 /* Security.swift in Sources */ = {isa = PBXBuildFile; fileRef = 385ABC5F2B2E0AAC005F90E6 /* Security.swift */; };
385F468E2AD31CD100D85410 /* SignUpView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 385F468D2AD31CD100D85410 /* SignUpView.swift */; };
385F788E2AD5C56E0096E504 /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = 385F788D2AD5C56E0096E504 /* Localizable.xcstrings */; };
385F788F2AD5C5D60096E504 /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = 385F788D2AD5C56E0096E504 /* Localizable.xcstrings */; };
Expand Down Expand Up @@ -281,6 +282,7 @@
3852D7202B054DBF007FAFF1 /* Particle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Particle.swift; sourceTree = "<group>"; };
3858A7772AD14C9E00FC6319 /* HomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeView.swift; sourceTree = "<group>"; };
3858A77D2AD15E8900FC6319 /* NotificationSheetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationSheetView.swift; sourceTree = "<group>"; };
385ABC5F2B2E0AAC005F90E6 /* Security.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Security.swift; sourceTree = "<group>"; };
385F468D2AD31CD100D85410 /* SignUpView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpView.swift; sourceTree = "<group>"; };
385F788A2AD5C4410096E504 /* Beta.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Beta.xcconfig; sourceTree = "<group>"; };
385F788B2AD5C4530096E504 /* RC.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = RC.xcconfig; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1327,6 +1329,7 @@
isa = PBXGroup;
children = (
38E5BBB62AE4244600FFFE7C /* User.swift */,
385ABC5F2B2E0AAC005F90E6 /* Security.swift */,
);
path = Extension;
sourceTree = "<group>";
Expand Down Expand Up @@ -1748,6 +1751,7 @@
3836C2962AF144DC008F475F /* WaitView.swift in Sources */,
38066B522AFEA235001A88D5 /* WaitSheetView.swift in Sources */,
38D5C68D2AD28D6F00D943A5 /* SLUpdateView.swift in Sources */,
385ABC602B2E0AAD005F90E6 /* Security.swift in Sources */,
38AE9C9C2AD0750F00B761E8 /* ScribbleLabApp.swift in Sources */,
38140A692AE3F81900753FB6 /* UserService.swift in Sources */,
3868A3DE2AD2DBA300D4CAEC /* ImageView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@
<key>EndingColumnNumber</key>
<string>0</string>
<key>EndingLineNumber</key>
<string>58</string>
<string>72</string>
<key>StartingColumnNumber</key>
<string>0</string>
<key>StartingLineNumber</key>
<string>57</string>
<string>71</string>
<key>Timestamp</key>
<string>723914404.660797</string>
<string>724436392.016798</string>
</dict>
<key>rebasable-url</key>
<dict>
Expand Down Expand Up @@ -192,6 +192,53 @@
<key>type</key>
<string>bookmark</string>
</dict>
<dict>
<key>destination</key>
<dict>
<key>location-parameters</key>
<dict>
<key>EndingColumnNumber</key>
<string>0</string>
<key>EndingLineNumber</key>
<string>51</string>
<key>StartingColumnNumber</key>
<string>0</string>
<key>StartingLineNumber</key>
<string>50</string>
<key>Timestamp</key>
<string>724436392.016821</string>
</dict>
<key>rebasable-url</key>
<dict>
<key>base</key>
<string>workspace</string>
<key>payload</key>
<dict>
<key>relative-path</key>
<string>ScribbleLab/ScribbleLab/Core/Home/HomeView.swift</string>
</dict>
</dict>
</dict>
<key>text-context</key>
<dict>
<key>focused</key>
<string> print("DEBUG: Create new document from Templates")
</string>
<key>leading</key>
<string> }
Button("Create from Template") {
</string>
<key>trailing</key>
<string> }
} message: {
Text("Select how you'd like to create a new document.")
</string>
</dict>
<key>title</key>
<string>TODO: Adding slCreateDocument from Template</string>
<key>type</key>
<string>bookmark</string>
</dict>
</array>
</dict>
</plist>
2 changes: 1 addition & 1 deletion ScribbleLab/App/ScribbleLabApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct ScribbleLabApp: App {
// SignUpView()
// .environmentObject(RegistrationViewModel())
// .environmentObject(SignInWithGoogleModel())
.preferredColorScheme(isDarkMode ? .dark : .light)
// .preferredColorScheme(isDarkMode ? .dark : .light)
}
}

Expand Down
15 changes: 15 additions & 0 deletions ScribbleLab/Core/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,23 @@ struct HomeView: View {
ToolbarItem(placement: .navigationBarTrailing) {
Button {
Task { await CreateNewDocumentTip.createNewDocumentEvent.donate() }
viewModifier.createDialogDisplayed.toggle()
} label: {
Image(systemName: "plus")
}
.confirmationDialog(
"How do you like to create a new document?",
isPresented: $viewModifier.createDialogDisplayed
) {
Button("Scan document") {
print("DEBUG: Scan document")
}
Button("Create from Template") {
print("DEBUG: Create new document from Templates")
}
} message: {
Text("Select how you'd like to create a new document.")
}
.popoverTip(createFirstDocumentTip)
}
ToolbarItem(placement: .navigationBarTrailing) {
Expand All @@ -62,6 +76,7 @@ struct HomeView: View {
.popoverTip(showNotificationTip)
.sheet(isPresented: $viewModifier.notificationSheetisPresented, content: {
NotificationSheetView()
.presentationDragIndicator(.visible)
})
}

Expand Down
1 change: 1 addition & 0 deletions ScribbleLab/Core/Home/Models/HomeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class HomeViewModel: ObservableObject {
@Published var notificationSheetisPresented = false
@Published var settingsViewSheetisPresented = false
@Published var allowNotificationsIsGarnted = false
@Published var createDialogDisplayed = false

// DEV
@Published var newNotification = false
Expand Down
20 changes: 20 additions & 0 deletions ScribbleLab/Core/Settings/View/Help/View/SLHelpView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ struct SLHelpView: View {
// .onTapGesture {
// openURL(URL(string: "https://github.com/ScribbleLabApp/ScribbleLab/issues/new?assignees=&labels=bug&projects=&template=bug_report.yml&title=%F0%9F%94%B4+%3Cbug+name%3E")!)
// }
.tint(.black)
Button {

} label: {
Label("Report a crash", systemImage: "laptopcomputer.trianglebadge.exclamationmark")
}
.tint(.black)
Button {
openURL(URL(string: "https://github.com/ScribbleLabApp/ScribbleLab/issues/new?assignees=&labels=bug&projects=&template=bug_report.yml&title=%F0%9F%94%B4+%3Cbug+name%3E")!)
Expand All @@ -42,12 +48,26 @@ struct SLHelpView: View {
Label("Ask a question", systemImage: "questionmark.bubble")
Label("Q&A", systemImage: "bubble.left.and.text.bubble.right.rtl")
Label("Documentation", systemImage: "book.and.wrench") // books.vertical
Button {

} label: {
Label("Guide", systemImage: "character.book.closed")
}
.tint(.black)
} header: {
Text("Help")
} footer: {
Text("")
}

Section() {
NavigationLink {

} label: {
Label("Troubleshooting", systemImage: "exclamationmark.triangle")
}
}

Section {
Toggle(isOn: $securityModeIsEnabled) {
Text("Enable Security mode (BETA)")
Expand Down
59 changes: 59 additions & 0 deletions ScribbleLab/Extension/Security.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// Security.swift
// ScribbleLab
//
// Created by Nevio Hirani on 16.12.23.
//

import Foundation
import LocalAuthentication

/// Typealias for biometric authentication completion handler
typealias BiometricUnlockCompletion = (Bool, Error?) -> Void

/// Performs biometric authentication using Face ID/Touch ID.
///
/// - Parameters:
/// - completion: A closure indicating the result of the authentication.
/// The closure has two parameters:
/// - success: A Boolean value indicating whether the authentication was successful.
/// - error: An optional `Error` object containing details in case of failure.
///
/// ## Example Usage:
/// ```swift
/// // Calling unlockWithBiometrics
/// unlockWithBiometrics { success, error in
/// if success {
/// // Biometric authentication succeeded
/// // Perform actions after successful authentication
/// } else if let error = error {
/// // Handle authentication error
/// } else {
/// // Handle generic authentication failure
/// }
/// }
/// ```
func unlockWithBiometrics(completion: @escaping BiometricUnlockCompletion) {
let context = LAContext()
var error: NSError?

// Check whether biometric authentication is possible
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
let reason = "Unlock with Face ID/Touch ID to open ScribbleLab"

context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { success, authenticationError in
DispatchQueue.main.async {
if success {
completion(true, nil)
} else if let error = authenticationError {
completion(false, error)
} else {
completion(false, NSError(domain: "ScribbleLab", code: -1, userInfo: [NSLocalizedDescriptionKey: "Biometric authentication failed."]))
}
}
}
} else {
// Biometrics not enabled or available
completion(false, error)
}
}

0 comments on commit e55a647

Please sign in to comment.