Skip to content

Commit

Permalink
SWIFT_STRICT_CONCURRENCY = complete
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanzhong committed Apr 17, 2024
1 parent 9f4e217 commit 5341b44
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
8 changes: 8 additions & 0 deletions TextGrabber2.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
8737A24A2BBEC27700042E83 /* Services in Resources */ = {isa = PBXBuildFile; fileRef = 8737A2492BBEC27700042E83 /* Services */; };
8737A24C2BBECB8800042E83 /* Services.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8737A24B2BBECB8800042E83 /* Services.swift */; };
874D776C2BCF6DF90093662D /* Unchecked.swift in Sources */ = {isa = PBXBuildFile; fileRef = 874D776B2BCF6DF90093662D /* Unchecked.swift */; };
8772FAE92BAC743D00DBEAA0 /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = 8772FAE82BAC743D00DBEAA0 /* Localizable.xcstrings */; };
87E192C32BAADE1200A87A4E /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87E192C22BAADE1200A87A4E /* App.swift */; };
87E192C72BAADE1300A87A4E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 87E192C62BAADE1300A87A4E /* Assets.xcassets */; };
Expand All @@ -32,6 +33,7 @@
/* Begin PBXFileReference section */
8737A2492BBEC27700042E83 /* Services */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Services; sourceTree = "<group>"; };
8737A24B2BBECB8800042E83 /* Services.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Services.swift; sourceTree = "<group>"; };
874D776B2BCF6DF90093662D /* Unchecked.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Unchecked.swift; sourceTree = "<group>"; };
8772FAE82BAC743D00DBEAA0 /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = "<group>"; };
87E192BF2BAADE1200A87A4E /* TextGrabber2.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TextGrabber2.app; sourceTree = BUILT_PRODUCTS_DIR; };
87E192C22BAADE1200A87A4E /* App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = App.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -139,6 +141,7 @@
87E192F02BABB6EA00A87A4E /* Recognizer.swift */,
87E192E82BAAFF0200A87A4E /* Resources.swift */,
8737A24B2BBECB8800042E83 /* Services.swift */,
874D776B2BCF6DF90093662D /* Unchecked.swift */,
);
path = Sources;
sourceTree = "<group>";
Expand Down Expand Up @@ -224,6 +227,7 @@
87E192FD2BAC1BD600A87A4E /* NSWindow+Extension.swift in Sources */,
87E192D52BAAE12600A87A4E /* Bundle+Extension.swift in Sources */,
87E192FB2BAC044E00A87A4E /* NSObject+Extension.swift in Sources */,
874D776C2BCF6DF90093662D /* Unchecked.swift in Sources */,
87E192DE2BAAE38700A87A4E /* NSMenuItem+Extension.swift in Sources */,
87E192E52BAAFB1800A87A4E /* NSWorkspace+Extension.swift in Sources */,
87E192D82BAAE17200A87A4E /* main.swift in Sources */,
Expand Down Expand Up @@ -286,6 +290,7 @@
"DEBUG=1",
"$(inherited)",
);
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
Expand All @@ -301,6 +306,7 @@
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_STRICT_CONCURRENCY = complete;
};
name = Debug;
};
Expand Down Expand Up @@ -345,6 +351,7 @@
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu17;
GCC_NO_COMMON_BLOCKS = YES;
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
Expand All @@ -358,6 +365,7 @@
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_STRICT_CONCURRENCY = complete;
};
name = Release;
};
Expand Down
13 changes: 10 additions & 3 deletions TextGrabber2/Sources/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import AppKit
import ServiceManagement

@MainActor
final class App: NSObject, NSApplicationDelegate {
private var currentResult: Recognizer.ResultData?
private var pasteboardObserver: Timer?
Expand Down Expand Up @@ -163,11 +164,17 @@ extension App: NSMenuDelegate {

// For an edge case, we can capture the screen while the menu is shown.
let timer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { [weak self] _ in
guard let self, NSPasteboard.general.changeCount != self.pasteboardChangeCount else {
guard let self else {
return
}

DispatchQueue.main.async(execute: startDetection)
DispatchQueue.main.async {
guard NSPasteboard.general.changeCount != self.pasteboardChangeCount else {
return
}

self.startDetection()
}
}

pasteboardObserver = timer
Expand Down Expand Up @@ -196,7 +203,7 @@ private extension App {
statusItem.menu?.removeItems { $0 is ResultItem }
}

@MainActor func startDetection() {
func startDetection() {
guard let menu = statusItem.menu else {
return Logger.assertFail("Missing menu to proceed")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extension NSPasteboard {
return (readObjects(forClasses: [NSImage.self]) as? [NSImage])?.first
}

@MainActor
func saveImageAsFile() {
if #available(macOS 14.0, *) {
NSApp.activate()
Expand Down
2 changes: 1 addition & 1 deletion TextGrabber2/Sources/Recognizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import AppKit
import Vision
@preconcurrency import Vision

/**
https://developer.apple.com/documentation/vision/recognizing_text_in_images
Expand Down
12 changes: 12 additions & 0 deletions TextGrabber2/Sources/Unchecked.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Unchecked.swift
// TextGrabber2
//
// Created by cyan on 2024/4/17.
//

import AppKit
import os.log

extension NSMenuItem: @unchecked Sendable {}
extension os.Logger: @unchecked Sendable {}

0 comments on commit 5341b44

Please sign in to comment.