diff --git a/JustScanIt.xcodeproj/project.pbxproj b/JustScanIt.xcodeproj/project.pbxproj index cbcf239..2161308 100644 --- a/JustScanIt.xcodeproj/project.pbxproj +++ b/JustScanIt.xcodeproj/project.pbxproj @@ -15,6 +15,7 @@ 466989DB2C352776009884D1 /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 466989C82C34DC7A009884D1 /* MainView.swift */; }; 466989DD2C35299D009884D1 /* ScanItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 466989DC2C35299D009884D1 /* ScanItemView.swift */; }; 466989DF2C353FEC009884D1 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 466989DE2C353FEC009884D1 /* SettingsView.swift */; }; + 466989E12C3541A0009884D1 /* Preference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 466989E02C3541A0009884D1 /* Preference.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -27,6 +28,7 @@ 466989D82C35206E009884D1 /* Scan.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Scan.swift; sourceTree = ""; }; 466989DC2C35299D009884D1 /* ScanItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScanItemView.swift; sourceTree = ""; }; 466989DE2C353FEC009884D1 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = ""; }; + 466989E02C3541A0009884D1 /* Preference.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Preference.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -89,6 +91,7 @@ isa = PBXGroup; children = ( 466989D82C35206E009884D1 /* Scan.swift */, + 466989E02C3541A0009884D1 /* Preference.swift */, ); path = Model; sourceTree = ""; @@ -173,6 +176,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 466989E12C3541A0009884D1 /* Preference.swift in Sources */, 466989C72C34DC7A009884D1 /* JustScanItApp.swift in Sources */, 466989DB2C352776009884D1 /* MainView.swift in Sources */, 466989D92C35206E009884D1 /* Scan.swift in Sources */, diff --git a/JustScanIt/Model/Preference.swift b/JustScanIt/Model/Preference.swift new file mode 100644 index 0000000..ca03415 --- /dev/null +++ b/JustScanIt/Model/Preference.swift @@ -0,0 +1,12 @@ +// +// Preference.swift +// JustScanIt +// +// Created by Pradyun Setti on 03/07/2024. +// + +import Foundation + +public struct Prefs { + static let autoLaunchCamera = "autolaunchcamera" +} diff --git a/JustScanIt/View/MainView.swift b/JustScanIt/View/MainView.swift index 538c2d9..3324aeb 100644 --- a/JustScanIt/View/MainView.swift +++ b/JustScanIt/View/MainView.swift @@ -14,9 +14,12 @@ struct MainView: View { @State private var scannedImages: [UIImage] = [] @State private var isShowingVNDocumentCameraView = false + @State private var isShowingSettingsView = false @Query var scans: [Scan] + @AppStorage(Prefs.autoLaunchCamera) var autolaunch = false + var isAuthorized: Bool { get async { let status = AVCaptureDevice.authorizationStatus(for: .video) @@ -43,17 +46,27 @@ struct MainView: View { ScanItemView(scan) } } + .onAppear { + if autolaunch { + isShowingVNDocumentCameraView = true + } + } .navigationTitle("Just Scan It!") .sheet(isPresented: $isShowingVNDocumentCameraView, onDismiss: saveImages) { VNDocumentCameraViewControllerRepresentable(scanResult: $scannedImages) } + .sheet(isPresented: $isShowingSettingsView) { + SettingsView() + } .toolbar { ToolbarItem(placement: .topBarLeading) { - Button("clear") { try? ctx.delete(model: Scan.self) } + Button(action: { isShowingSettingsView.toggle() }) { + Image(systemName: "gear") + } } ToolbarItem { Button(action: showVNDocumentCameraView) { - Image(systemName: "scanner") + Image(systemName: "scanner.fill") } } } diff --git a/JustScanIt/View/SettingsView.swift b/JustScanIt/View/SettingsView.swift new file mode 100644 index 0000000..7e7a022 --- /dev/null +++ b/JustScanIt/View/SettingsView.swift @@ -0,0 +1,46 @@ +// +// SettingsView.swift +// JustScanIt +// +// Created by Pradyun Setti on 03/07/2024. +// + +import SwiftUI + +struct SettingsView: View { + @Environment(\.dismiss) var dismiss + + @AppStorage(Prefs.autoLaunchCamera) var autoLaunchCamera = false + + var body: some View { + NavigationView { + List { + generalSettings + aboutApp + } + .toolbar { + ToolbarItem(placement: .topBarTrailing) { + Button("Done") { dismiss() } + } + } + } + } + + var generalSettings: some View { + Section { + Toggle("Launch Camera on Startup", isOn: $autoLaunchCamera) + } header: { Text("General") } + } + + var aboutApp: some View { + Section { + LabeledContent("Version", value: "1.0.0") + + } header: { Text("About") } footer: { Text("Made by bread!") } + + } +} + +#Preview { + SettingsView() +}