@@ -142,6 +142,15 @@ final class App: NSObject, NSApplicationDelegate {
142
142
item. setOn ( SMAppService . mainApp. isEnabled)
143
143
return item
144
144
} ( )
145
+
146
+ func statusItemPosition( ) -> ( CGRect , NSScreen ? ) ? {
147
+ guard let button = statusItem. button, let window = button. window else {
148
+ Logger . log ( . error, " Missing button or window to provide positioning info " )
149
+ return nil
150
+ }
151
+
152
+ return ( window. convertToScreen ( button. frame) , window. screen ?? . main)
153
+ }
145
154
}
146
155
147
156
// MARK: - Life Cycle
@@ -220,6 +229,7 @@ private extension App {
220
229
return Logger . assertFail ( " Missing menu to proceed " )
221
230
}
222
231
232
+ currentResult = nil
223
233
pasteboardChangeCount = NSPasteboard . general. changeCount
224
234
clipboardItem. isHidden = NSPasteboard . general. isEmpty
225
235
saveImageItem. isEnabled = false
@@ -232,23 +242,36 @@ private extension App {
232
242
howToItem. isHidden = true
233
243
234
244
Task {
235
- let resultData = await Recognizer . detect ( image: image)
236
- currentResult = resultData
237
-
238
- hintItem. title = resultData. candidates. isEmpty ? Localized . menuTitleHintCapture : Localized . menuTitleHintCopy
239
- howToItem. isHidden = !resultData. candidates. isEmpty
240
- copyAllItem. isHidden = resultData. candidates. count < 2
241
- saveImageItem. isEnabled = true
242
-
243
- let separator = NSMenuItem . separator ( )
244
- menu. insertItem ( separator, at: menu. index ( of: howToItem) + 1 )
245
- menu. removeItems { $0 is ResultItem }
246
-
247
- for text in resultData. candidates. reversed ( ) {
248
- let item = ResultItem ( title: text)
249
- item. addAction { NSPasteboard . general. string = text }
250
- menu. insertItem ( item, at: menu. index ( of: separator) + 1 )
251
- }
245
+ let fastResult = await Recognizer . detect ( image: image, level: . fast)
246
+ showResult ( fastResult, in: menu)
247
+
248
+ let accurateResult = await Recognizer . detect ( image: image, level: . accurate)
249
+ showResult ( accurateResult, in: menu)
250
+ }
251
+ }
252
+
253
+ func showResult( _ resultData: Recognizer . ResultData , in menu: NSMenu ) {
254
+ guard currentResult != resultData else {
255
+ #if DEBUG
256
+ Logger . log ( . debug, " No change in result data " )
257
+ #endif
258
+ return
259
+ }
260
+
261
+ currentResult = resultData
262
+ hintItem. title = resultData. candidates. isEmpty ? Localized . menuTitleHintCapture : Localized . menuTitleHintCopy
263
+ howToItem. isHidden = !resultData. candidates. isEmpty
264
+ copyAllItem. isHidden = resultData. candidates. count < 2
265
+ saveImageItem. isEnabled = true
266
+
267
+ let separator = NSMenuItem . separator ( )
268
+ menu. insertItem ( separator, at: menu. index ( of: howToItem) + 1 )
269
+ menu. removeItems { $0 is ResultItem }
270
+
271
+ for text in resultData. candidates. reversed ( ) {
272
+ let item = ResultItem ( title: text)
273
+ item. addAction { NSPasteboard . general. string = text }
274
+ menu. insertItem ( item, at: menu. index ( of: separator) + 1 )
252
275
}
253
276
}
254
277
}
0 commit comments