Skip to content

Commit

Permalink
Use #if compiler(>=6.0) instaed canImport
Browse files Browse the repository at this point in the history
  • Loading branch information
kishikawakatsumi committed Jun 21, 2024
1 parent 4af9801 commit 1113e79
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 28 deletions.
2 changes: 1 addition & 1 deletion TextChatTranslator/App.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SwiftUI

#if canImport(Synchronization)
#if compiler(>=6.0)
import Observation
import Translation

Expand Down
12 changes: 6 additions & 6 deletions TextChatTranslator/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import Translation

private let debounce = Debounce(delay: 0.2)

#if canImport(Synchronization)
#if compiler(>=6.0)
@available(macOS 15.0, *)
#endif
class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
#if canImport(Synchronization)
#if compiler(>=6.0)
private let menuController = MenuController(
startTranslationAction: #selector(toggleTranslationEnabled),
openSettingsAction: #selector(openSettings),
Expand All @@ -25,12 +25,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
private var service = TranslationService()

private var mainWindow: NSWindow?
#if !canImport(Synchronization)
#if compiler(<6.0)
typealias TranslationSession = AnyObject
#endif
var translationSession: TranslationSession? {
didSet {
#if canImport(Synchronization)
#if compiler(>=6.0)
guard let _ = translationSession else { return }
#endif
guard mainWindow == nil else { return }
Expand Down Expand Up @@ -129,7 +129,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
isTranslationEnabled.toggle()
}

#if canImport(Synchronization)
#if compiler(>=6.0)
@objc
private func openSettings() {
let openSettings = OpenSettings()
Expand All @@ -155,7 +155,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
overlayWindow.leadingMargin = message.textFrame.minX - message.frame.minX

Task { @MainActor in
#if canImport(Synchronization)
#if compiler(>=6.0)
overlayWindow.text = try await service.translate(
session: translationSession,
text: message.text
Expand Down
Binary file not shown.
15 changes: 0 additions & 15 deletions TextChatTranslator/Localizable.xcstrings
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"sourceLanguage" : "en",
"strings" : {
"Background Color:" : {

},
"Install Translation" : {

},
"Quit Text Chat Translator" : {
"localizations" : {
"ja" : {
Expand All @@ -19,9 +13,6 @@
},
"Settings…" : {

},
"Source Language:" : {

},
"Start Translation" : {
"localizations" : {
Expand All @@ -42,12 +33,6 @@
}
}
}
},
"Target Language:" : {

},
"Text Color:" : {

}
},
"version" : "1.0"
Expand Down
6 changes: 3 additions & 3 deletions TextChatTranslator/MenuController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import AppKit

class MenuController {
let startTranslation: NSMenuItem
#if canImport(Synchronization)
#if compiler(>=6.0)
let openSettings: NSMenuItem
#endif
let quitApplication: NSMenuItem
Expand All @@ -22,7 +22,7 @@ class MenuController {
}
}

#if canImport(Synchronization)
#if compiler(>=6.0)
init(startTranslationAction: Selector, openSettingsAction: Selector, quitApplicationAction: Selector) {
startTranslation = NSMenuItem(
title: NSLocalizedString("Start Translation", comment: ""),
Expand Down Expand Up @@ -68,7 +68,7 @@ class MenuController {
let menu = NSMenu()

menu.addItem(startTranslation)
#if canImport(Synchronization)
#if compiler(>=6.0)
menu.addItem(NSMenuItem.separator())
menu.addItem(openSettings)
#endif
Expand Down
2 changes: 1 addition & 1 deletion TextChatTranslator/SettingsView.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import SwiftUI
#if canImport(Synchronization)
#if compiler(>=6.0)
import Translation

@available(macOS 15, *)
Expand Down
2 changes: 1 addition & 1 deletion TextChatTranslator/TranslationContext.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if canImport(Synchronization)
#if compiler(>=6.0)
import SwiftUI
import Translation

Expand Down
2 changes: 1 addition & 1 deletion TextChatTranslator/TranslationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Translation
class TranslationService {
private let cache = NSCache<NSString, NSString>()

#if canImport(Synchronization)
#if compiler(>=6.0)
@available(macOS 15.0, *)
func translate(session: TranslationSession?, text: String) async throws -> String {
if let translation = cache.object(forKey: NSString(string: text)) {
Expand Down

0 comments on commit 1113e79

Please sign in to comment.