Skip to content

Commit

Permalink
add QR code clear button
Browse files Browse the repository at this point in the history
  • Loading branch information
ObuchiYuki committed Sep 18, 2022
1 parent 01c01b6 commit 3502c4d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions DevToys/DevToys.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@
"$(PROJECT_DIR)/DevToys/Body/Media/Image\\ Optimizer",
"$(PROJECT_DIR)/DevToys/Body/Media/Image\\ Optimizer",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 0.0.10;
PRODUCT_BUNDLE_IDENTIFIER = com.yuki.DevToys;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -1445,7 +1445,7 @@
"$(PROJECT_DIR)/DevToys/Body/Media/Image\\ Optimizer",
"$(PROJECT_DIR)/DevToys/Body/Media/Image\\ Optimizer",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 0.0.10;
PRODUCT_BUNDLE_IDENTIFIER = com.yuki.DevToys;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
1 change: 0 additions & 1 deletion DevToys/DevToys/App/AppWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import AppKit
final class AppWindowController: NSWindowController {
private let appModel = AppModel()

@available(macOS 11.0, *)
private lazy var separatorItem = NSTrackingSeparatorToolbarItem(
identifier: AppWindowController.separatorItemIdentifier, splitView: splitViewController.splitView, dividerIndex: 0
)
Expand Down
15 changes: 12 additions & 3 deletions DevToys/DevToys/Body/Graphic/QRCodeReaderView+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ final class QRCodeReaderViewController: NSViewController {
.sink{[unowned self] in self.image = $0.image.ciImage; updateDetection() }.store(in: &objectBag)
self.cell.inputTypePicker.itemPublisher
.sink{[unowned self] in self.inputType = $0; updateCameraState() }.store(in: &objectBag)
self.cell.inputClearButton.actionPublisher
.sink{[unowned self] in self.image = nil; resetDetectionState() }.store(in: &objectBag)

self.$image.map{ $0.map{ NSImage(ciImage: $0) } }
.sink{[unowned self] in self.cell.imageDropView.image = $0 }.store(in: &objectBag)
Expand Down Expand Up @@ -59,9 +61,14 @@ final class QRCodeReaderViewController: NSViewController {
self.cameraManager.stopSession()
}

private func resetDetectionState() {
self.detectedBound = nil
self.detectedMessage = ""
}

private func updateDetection() {
guard abs(lastUpdate.timeIntervalSinceNow) > 1 else { return }
guard let image = image else { detectedBound = nil; return }
guard let image = image else { resetDetectionState(); return }

self.lastUpdate = Date()
self.readQRCode(image)
Expand Down Expand Up @@ -101,6 +108,7 @@ enum QRCodeInputType: String, TextItem {
final private class QRCodeReaderView: Page {

let inputTypePicker = EnumPopupButton<QRCodeInputType>()
let inputClearButton = SectionButton(image: R.Image.clear)
let imageDropView = QRImageDropView()
let outputTextView = TextViewSection(title: "Output".localized(), options: .defaultOutput)

Expand All @@ -113,11 +121,12 @@ final private class QRCodeReaderView: Page {
}

override func onAwake() {
self.addSection(Section(title: "Configuration".localized(), items: [
self.addSection(Section(
title: "Configuration".localized(), items: [
Area(icon: R.Image.paramators, title: "QR Code Input Type", control: inputTypePicker)
]))
self.addSection2(
Section(title: "Input".localized(), items: [imageDropView]),
Section(title: "Input".localized(), items: [imageDropView], toolbarItems: [inputClearButton]),
outputTextView
)

Expand Down

0 comments on commit 3502c4d

Please sign in to comment.