Added settings page, auto launch option, changed some stuff

This commit is contained in:
breadone 2024-07-03 20:38:54 +12:00
parent 64a066fb2a
commit 44e25bf25e
No known key found for this signature in database
4 changed files with 77 additions and 2 deletions

View File

@ -15,6 +15,7 @@
466989DB2C352776009884D1 /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 466989C82C34DC7A009884D1 /* MainView.swift */; }; 466989DB2C352776009884D1 /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 466989C82C34DC7A009884D1 /* MainView.swift */; };
466989DD2C35299D009884D1 /* ScanItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 466989DC2C35299D009884D1 /* ScanItemView.swift */; }; 466989DD2C35299D009884D1 /* ScanItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 466989DC2C35299D009884D1 /* ScanItemView.swift */; };
466989DF2C353FEC009884D1 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 466989DE2C353FEC009884D1 /* SettingsView.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 */ /* End PBXBuildFile section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
@ -27,6 +28,7 @@
466989D82C35206E009884D1 /* Scan.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Scan.swift; sourceTree = "<group>"; }; 466989D82C35206E009884D1 /* Scan.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Scan.swift; sourceTree = "<group>"; };
466989DC2C35299D009884D1 /* ScanItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScanItemView.swift; sourceTree = "<group>"; }; 466989DC2C35299D009884D1 /* ScanItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScanItemView.swift; sourceTree = "<group>"; };
466989DE2C353FEC009884D1 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; }; 466989DE2C353FEC009884D1 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
466989E02C3541A0009884D1 /* Preference.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Preference.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@ -89,6 +91,7 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
466989D82C35206E009884D1 /* Scan.swift */, 466989D82C35206E009884D1 /* Scan.swift */,
466989E02C3541A0009884D1 /* Preference.swift */,
); );
path = Model; path = Model;
sourceTree = "<group>"; sourceTree = "<group>";
@ -173,6 +176,7 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
466989E12C3541A0009884D1 /* Preference.swift in Sources */,
466989C72C34DC7A009884D1 /* JustScanItApp.swift in Sources */, 466989C72C34DC7A009884D1 /* JustScanItApp.swift in Sources */,
466989DB2C352776009884D1 /* MainView.swift in Sources */, 466989DB2C352776009884D1 /* MainView.swift in Sources */,
466989D92C35206E009884D1 /* Scan.swift in Sources */, 466989D92C35206E009884D1 /* Scan.swift in Sources */,

View File

@ -0,0 +1,12 @@
//
// Preference.swift
// JustScanIt
//
// Created by Pradyun Setti on 03/07/2024.
//
import Foundation
public struct Prefs {
static let autoLaunchCamera = "autolaunchcamera"
}

View File

@ -14,9 +14,12 @@ struct MainView: View {
@State private var scannedImages: [UIImage] = [] @State private var scannedImages: [UIImage] = []
@State private var isShowingVNDocumentCameraView = false @State private var isShowingVNDocumentCameraView = false
@State private var isShowingSettingsView = false
@Query var scans: [Scan] @Query var scans: [Scan]
@AppStorage(Prefs.autoLaunchCamera) var autolaunch = false
var isAuthorized: Bool { var isAuthorized: Bool {
get async { get async {
let status = AVCaptureDevice.authorizationStatus(for: .video) let status = AVCaptureDevice.authorizationStatus(for: .video)
@ -43,17 +46,27 @@ struct MainView: View {
ScanItemView(scan) ScanItemView(scan)
} }
} }
.onAppear {
if autolaunch {
isShowingVNDocumentCameraView = true
}
}
.navigationTitle("Just Scan It!") .navigationTitle("Just Scan It!")
.sheet(isPresented: $isShowingVNDocumentCameraView, onDismiss: saveImages) { .sheet(isPresented: $isShowingVNDocumentCameraView, onDismiss: saveImages) {
VNDocumentCameraViewControllerRepresentable(scanResult: $scannedImages) VNDocumentCameraViewControllerRepresentable(scanResult: $scannedImages)
} }
.sheet(isPresented: $isShowingSettingsView) {
SettingsView()
}
.toolbar { .toolbar {
ToolbarItem(placement: .topBarLeading) { ToolbarItem(placement: .topBarLeading) {
Button("clear") { try? ctx.delete(model: Scan.self) } Button(action: { isShowingSettingsView.toggle() }) {
Image(systemName: "gear")
}
} }
ToolbarItem { ToolbarItem {
Button(action: showVNDocumentCameraView) { Button(action: showVNDocumentCameraView) {
Image(systemName: "scanner") Image(systemName: "scanner.fill")
} }
} }
} }

View File

@ -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()
}