From 950b8c124c04dcd8ad09b4b2f2f3aa32976235b2 Mon Sep 17 00:00:00 2001 From: breadone Date: Wed, 3 Jul 2024 20:54:16 +1200 Subject: [PATCH] Added an auto copy setting --- JustScanIt/Model/Preference.swift | 1 + JustScanIt/Model/Scan.swift | 3 +++ JustScanIt/View/MainView.swift | 3 +++ JustScanIt/View/ScanItemView.swift | 6 +----- JustScanIt/View/SettingsView.swift | 2 ++ 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/JustScanIt/Model/Preference.swift b/JustScanIt/Model/Preference.swift index ca03415..049e611 100644 --- a/JustScanIt/Model/Preference.swift +++ b/JustScanIt/Model/Preference.swift @@ -9,4 +9,5 @@ import Foundation public struct Prefs { static let autoLaunchCamera = "autolaunchcamera" + static let autoCopy = "autocopy" } diff --git a/JustScanIt/Model/Scan.swift b/JustScanIt/Model/Scan.swift index 573aae5..7fc2297 100644 --- a/JustScanIt/Model/Scan.swift +++ b/JustScanIt/Model/Scan.swift @@ -39,4 +39,7 @@ final class Scan { self.images = images.map{ $0.pngData() ?? Data() } } + public func copyImages() { + UIPasteboard.general.images = self.uiImages + } } diff --git a/JustScanIt/View/MainView.swift b/JustScanIt/View/MainView.swift index 3324aeb..117aac8 100644 --- a/JustScanIt/View/MainView.swift +++ b/JustScanIt/View/MainView.swift @@ -19,6 +19,7 @@ struct MainView: View { @Query var scans: [Scan] @AppStorage(Prefs.autoLaunchCamera) var autolaunch = false + @AppStorage(Prefs.autoCopy) var autoCopy = false var isAuthorized: Bool { get async { @@ -89,6 +90,8 @@ struct MainView: View { try? ctx.save() } + if autoCopy { newScan.copyImages() } + scannedImages = [] } } diff --git a/JustScanIt/View/ScanItemView.swift b/JustScanIt/View/ScanItemView.swift index 6997377..ca8e2da 100644 --- a/JustScanIt/View/ScanItemView.swift +++ b/JustScanIt/View/ScanItemView.swift @@ -37,7 +37,7 @@ struct ScanItemView: View { Spacer() if scan.images.count == 1 { - Button { copy() } label: { + Button { scan.copyImages() } label: { Image(systemName: "doc.on.doc.fill").tint(.white) .padding(8) .background(Color(red: 1, green: 1, blue: 1, opacity: 0.4)) @@ -72,10 +72,6 @@ struct ScanItemView: View { .padding(.horizontal, 12) } - func copy() { - UIPasteboard.general.images = scan.uiImages - } - func delete() { withAnimation(.easeOut) { ctx.delete(scan) diff --git a/JustScanIt/View/SettingsView.swift b/JustScanIt/View/SettingsView.swift index 7e7a022..48726be 100644 --- a/JustScanIt/View/SettingsView.swift +++ b/JustScanIt/View/SettingsView.swift @@ -11,6 +11,7 @@ struct SettingsView: View { @Environment(\.dismiss) var dismiss @AppStorage(Prefs.autoLaunchCamera) var autoLaunchCamera = false + @AppStorage(Prefs.autoCopy) var autoCopy = false var body: some View { NavigationView { @@ -29,6 +30,7 @@ struct SettingsView: View { var generalSettings: some View { Section { Toggle("Launch Camera on Startup", isOn: $autoLaunchCamera) + Toggle("Auto-Copy on Save", isOn: $autoCopy) } header: { Text("General") } }