diff --git a/Packages/vChewing_PhraseEditorUI/Sources/PhraseEditorUI/PhraseEditorUI.swift b/Packages/vChewing_PhraseEditorUI/Sources/PhraseEditorUI/PhraseEditorUI.swift index e1c3cc69..4dd177e2 100644 --- a/Packages/vChewing_PhraseEditorUI/Sources/PhraseEditorUI/PhraseEditorUI.swift +++ b/Packages/vChewing_PhraseEditorUI/Sources/PhraseEditorUI/PhraseEditorUI.swift @@ -13,18 +13,17 @@ import LangModelAssembly import Shared import SwiftExtension import SwiftUI -import SwiftUIBackports private let loc: String = (UserDefaults.current.array(forKey: UserDef.kAppleLanguages.rawValue) as? [String] ?? ["auto"])[0] -@available(macOS 10.15, *) +@available(macOS 13, *) extension VwrPhraseEditorUI { - @Backport.AppStorage("PhraseEditorAutoReloadExternalModifications") + @AppStorage("PhraseEditorAutoReloadExternalModifications") private static var autoReloadExternalModifications: Bool = true } -@available(macOS 10.15, *) +@available(macOS 13, *) public struct VwrPhraseEditorUI: View { static var txtContentStorage: String = NSLocalizedString( "Please select Simplified / Traditional Chinese mode above.", comment: "" @@ -235,16 +234,10 @@ public struct VwrPhraseEditorUI: View { Button("Consolidate") { consolidate() }.disabled(selInputMode == .imeModeNULL || isLoading) - if #available(macOS 11.0, *) { - Button("Save") { - DispatchQueue.main.async { saveAndReload() } - }.keyboardShortcut("s", modifiers: [.command]) - .disabled(delegate == nil) - } else { - Button("Save") { - DispatchQueue.main.async { saveAndReload() } - } - } + Button("Save") { + DispatchQueue.main.async { saveAndReload() } + }.keyboardShortcut("s", modifiers: [.command]) + .disabled(delegate == nil) Button("...") { DispatchQueue.main.async { saveAndReload() @@ -256,7 +249,7 @@ public struct VwrPhraseEditorUI: View { TextEditorEX(text: $txtContent) .disabled(selInputMode == .imeModeNULL || isLoading) .frame(minWidth: 320, minHeight: 240) - .backport.onChange(of: fileChangeIndicator.id) { _ in + .onChange(of: fileChangeIndicator.id) { _ in if Self.autoReloadExternalModifications { update() } } @@ -291,18 +284,13 @@ public struct VwrPhraseEditorUI: View { } }.disabled(selInputMode == Shared.InputMode.imeModeNULL || isLoading) HStack { - if #available(macOS 12, *) { - Toggle( - LocalizedStringKey("This editor only: Auto-reload modifications happened outside of this editor"), - isOn: $selAutoReloadExternalModifications.onChange { - Self.autoReloadExternalModifications = selAutoReloadExternalModifications - } - ) - .controlSize(.small) - } else { - Text("Some features are unavailable for macOS 10.15 and macOS 11 due to API limitations.") - .font(.system(size: 11.0)).foregroundColor(.secondary) - } + Toggle( + LocalizedStringKey("This editor only: Auto-reload modifications happened outside of this editor"), + isOn: $selAutoReloadExternalModifications.onChange { + Self.autoReloadExternalModifications = selAutoReloadExternalModifications + } + ) + .controlSize(.small) Spacer() } }.onDisappear { @@ -319,7 +307,7 @@ public struct VwrPhraseEditorUI: View { } } -@available(macOS 10.15, *) +@available(macOS 13, *) struct ContentView_Previews: PreviewProvider { static var previews: some View { VwrPhraseEditorUI() diff --git a/Source/Modules/UIModules/PrefUI/CtlPrefUI.swift b/Source/Modules/UIModules/PrefUI/CtlPrefUI.swift index 2a3f497c..98d203bb 100644 --- a/Source/Modules/UIModules/PrefUI/CtlPrefUI.swift +++ b/Source/Modules/UIModules/PrefUI/CtlPrefUI.swift @@ -16,7 +16,7 @@ private let kWindowTitleHeight: Double = 78 // InputMethodServerPreferencesWindowControllerClass 非必需。 -@available(macOS 10.15, *) +@available(macOS 13, *) class CtlPrefUI: NSWindowController, NSWindowDelegate { public static var shared: CtlPrefUI? @@ -47,13 +47,11 @@ class CtlPrefUI: NSWindowController, NSWindowDelegate { override func windowDidLoad() { super.windowDidLoad() window?.setPosition(vertical: .top, horizontal: .right, padding: 20) - if #available(macOS 13, *) { - window?.contentView = NSHostingView( - rootView: VwrSettingsUI() - .fixedSize(horizontal: true, vertical: false) - .ignoresSafeArea() - ) - } + window?.contentView = NSHostingView( + rootView: VwrSettingsUI() + .fixedSize(horizontal: true, vertical: false) + .ignoresSafeArea() + ) let toolbar = NSToolbar(identifier: "preference toolbar") toolbar.allowsUserCustomization = false toolbar.autosavesConfiguration = false @@ -61,9 +59,7 @@ class CtlPrefUI: NSWindowController, NSWindowDelegate { toolbar.delegate = self toolbar.selectedItemIdentifier = nil toolbar.showsBaselineSeparator = true - if #available(macOS 11, *) { - window?.toolbarStyle = .unifiedCompact - } + window?.toolbarStyle = .unifiedCompact window?.toolbar = toolbar var preferencesTitleName = NSLocalizedString("vChewing Preferences…", comment: "") preferencesTitleName.removeLast() @@ -73,7 +69,7 @@ class CtlPrefUI: NSWindowController, NSWindowDelegate { // MARK: - NSToolbarDelegate. -@available(macOS 10.15, *) +@available(macOS 13, *) extension CtlPrefUI: NSToolbarDelegate { var toolbarIdentifiers: [NSToolbarItem.Identifier] { [.init("Collapse or Expand Sidebar")] @@ -96,9 +92,7 @@ extension CtlPrefUI: NSToolbarDelegate { willBeInsertedIntoToolbar _: Bool ) -> NSToolbarItem? { let item = NSToolbarItem(itemIdentifier: itemIdentifier) - if #available(macOS 11.0, *) { - item.isNavigational = true - } + item.isNavigational = true item.target = window?.firstResponder item.image = NSImage(named: "NSTouchBarSidebarTemplate") ?? .init() item.tag = 0 @@ -106,3 +100,40 @@ extension CtlPrefUI: NSToolbarDelegate { return item } } + +// MARK: - Shared Static Variables and Constants + +@available(macOS 13, *) +extension CtlPrefUI { + static let sentenceSeparator: String = { + switch PrefMgr.shared.appleLanguages[0] { + case "ja": + return "" + default: + if PrefMgr.shared.appleLanguages[0].contains("zh-Han") { + return "" + } else { + return " " + } + } + }() + + static let contentMaxHeight: Double = 490 + + static let formWidth: Double = { + switch PrefMgr.shared.appleLanguages[0] { + case "ja": + return 520 + default: + if PrefMgr.shared.appleLanguages[0].contains("zh-Han") { + return 500 + } else { + return 580 + } + } + }() + + static var isCJKInterface: Bool { + PrefMgr.shared.appleLanguages[0].contains("zh-Han") || PrefMgr.shared.appleLanguages[0] == "ja" + } +} diff --git a/Source/Modules/UIModules/PrefUI/CtlPrefUIShared.swift b/Source/Modules/UIModules/PrefUI/CtlPrefUIShared.swift index 7168af10..a5de9131 100644 --- a/Source/Modules/UIModules/PrefUI/CtlPrefUIShared.swift +++ b/Source/Modules/UIModules/PrefUI/CtlPrefUIShared.swift @@ -10,7 +10,7 @@ import MainAssembly import SwiftExtension import SwiftUI -@available(macOS 10.15, *) +@available(macOS 13, *) extension PrefUITabs { @ViewBuilder var suiView: some View { @@ -28,46 +28,6 @@ extension PrefUITabs { } } -@available(macOS 10.15, *) -class CtlPrefUIShared { - static var sharedWindow: NSWindow? { - CtlPrefUI.shared?.window - } - - static let shared = CtlPrefUIShared() - static let sentenceSeparator: String = { - switch PrefMgr.shared.appleLanguages[0] { - case "ja": - return "" - default: - if PrefMgr.shared.appleLanguages[0].contains("zh-Han") { - return "" - } else { - return " " - } - } - }() - - static let contentMaxHeight: Double = 490 - - static let formWidth: Double = { - switch PrefMgr.shared.appleLanguages[0] { - case "ja": - return 520 - default: - if PrefMgr.shared.appleLanguages[0].contains("zh-Han") { - return 500 - } else { - return 580 - } - } - }() - - static var isCJKInterface: Bool { - PrefMgr.shared.appleLanguages[0].contains("zh-Han") || PrefMgr.shared.appleLanguages[0] == "ja" - } -} - @available(macOS 10.15, *) public extension View { func settingsDescription(maxWidth: CGFloat? = .infinity) -> some View { diff --git a/Source/Modules/UIModules/PrefUI/VwrPrefPaneBehavior.swift b/Source/Modules/UIModules/PrefUI/VwrPrefPaneBehavior.swift index dab08aaf..ae4b9aae 100644 --- a/Source/Modules/UIModules/PrefUI/VwrPrefPaneBehavior.swift +++ b/Source/Modules/UIModules/PrefUI/VwrPrefPaneBehavior.swift @@ -12,7 +12,7 @@ import SwiftExtension import SwiftUI import SwiftUIBackports -@available(macOS 10.15, *) +@available(macOS 13, *) struct VwrPrefPaneBehavior: View { // MARK: - AppStorage Variables @@ -217,7 +217,7 @@ struct VwrPrefPaneBehavior: View { ) Spacer() Text( - "This feature requires macOS 10.15 and above.".localized + CtlPrefUIShared.sentenceSeparator + "This feature requires macOS 10.15 and above.".localized + CtlPrefUI.sentenceSeparator + "This feature only needs to parse consecutive NSEvents passed by macOS built-in InputMethodKit framework, hence no necessity of asking end-users for extra privileges of monitoring global keyboard inputs. You are free to investigate our codebase or reverse-engineer this input method to see whether the above statement is trustable.".localized ) .settingsDescription() @@ -251,13 +251,13 @@ struct VwrPrefPaneBehavior: View { .settingsDescription() } } - }.formStyled().frame(minWidth: CtlPrefUIShared.formWidth, maxWidth: ceil(CtlPrefUIShared.formWidth * 1.2)) + }.formStyled().frame(minWidth: CtlPrefUI.formWidth, maxWidth: ceil(CtlPrefUI.formWidth * 1.2)) } - .frame(maxHeight: CtlPrefUIShared.contentMaxHeight) + .frame(maxHeight: CtlPrefUI.contentMaxHeight) } } -@available(macOS 11.0, *) +@available(macOS 13, *) struct VwrPrefPaneBehavior_Previews: PreviewProvider { static var previews: some View { VwrPrefPaneBehavior() diff --git a/Source/Modules/UIModules/PrefUI/VwrPrefPaneCandidates.swift b/Source/Modules/UIModules/PrefUI/VwrPrefPaneCandidates.swift index cee1cf20..c10b83e3 100644 --- a/Source/Modules/UIModules/PrefUI/VwrPrefPaneCandidates.swift +++ b/Source/Modules/UIModules/PrefUI/VwrPrefPaneCandidates.swift @@ -12,7 +12,7 @@ import SwiftExtension import SwiftUI import SwiftUIBackports -@available(macOS 10.15, *) +@available(macOS 13, *) struct VwrPrefPaneCandidates: View { // MARK: - AppStorage Variables @@ -190,13 +190,13 @@ struct VwrPrefPaneCandidates: View { isOn: $enableMouseScrollingForTDKCandidatesCocoa ) } - }.formStyled().frame(minWidth: CtlPrefUIShared.formWidth, maxWidth: ceil(CtlPrefUIShared.formWidth * 1.2)) + }.formStyled().frame(minWidth: CtlPrefUI.formWidth, maxWidth: ceil(CtlPrefUI.formWidth * 1.2)) } - .frame(maxHeight: CtlPrefUIShared.contentMaxHeight) + .frame(maxHeight: CtlPrefUI.contentMaxHeight) } } -@available(macOS 11.0, *) +@available(macOS 13, *) struct VwrPrefPaneCandidates_Previews: PreviewProvider { static var previews: some View { VwrPrefPaneCandidates() @@ -205,7 +205,7 @@ struct VwrPrefPaneCandidates_Previews: PreviewProvider { // MARK: - Selection Key Preferences (View) -@available(macOS 10.15, *) +@available(macOS 13, *) private struct VwrPrefPaneCandidates_SelectionKeys: View { // MARK: - AppStorage Variables diff --git a/Source/Modules/UIModules/PrefUI/VwrPrefPaneCassette.swift b/Source/Modules/UIModules/PrefUI/VwrPrefPaneCassette.swift index 85cbe824..af20623e 100644 --- a/Source/Modules/UIModules/PrefUI/VwrPrefPaneCassette.swift +++ b/Source/Modules/UIModules/PrefUI/VwrPrefPaneCassette.swift @@ -13,7 +13,7 @@ import SwiftExtension import SwiftUI import SwiftUIBackports -@available(macOS 10.15, *) +@available(macOS 13, *) struct VwrPrefPaneCassette: View { // MARK: - AppStorage Variables @@ -185,13 +185,13 @@ struct VwrPrefPaneCassette: View { .settingsDescription() } } - }.formStyled().frame(minWidth: CtlPrefUIShared.formWidth, maxWidth: ceil(CtlPrefUIShared.formWidth * 1.2)) + }.formStyled().frame(minWidth: CtlPrefUI.formWidth, maxWidth: ceil(CtlPrefUI.formWidth * 1.2)) } - .frame(maxHeight: CtlPrefUIShared.contentMaxHeight) + .frame(maxHeight: CtlPrefUI.contentMaxHeight) } } -@available(macOS 11.0, *) +@available(macOS 13, *) struct VwrPrefPaneCassette_Previews: PreviewProvider { static var previews: some View { VwrPrefPaneDictionary() diff --git a/Source/Modules/UIModules/PrefUI/VwrPrefPaneDevZone.swift b/Source/Modules/UIModules/PrefUI/VwrPrefPaneDevZone.swift index 577af25c..5d6e6a3d 100644 --- a/Source/Modules/UIModules/PrefUI/VwrPrefPaneDevZone.swift +++ b/Source/Modules/UIModules/PrefUI/VwrPrefPaneDevZone.swift @@ -11,7 +11,7 @@ import SwiftExtension import SwiftUI import SwiftUIBackports -@available(macOS 10.15, *) +@available(macOS 13, *) struct VwrPrefPaneDevZone: View { // MARK: - AppStorage Variables @@ -56,13 +56,13 @@ struct VwrPrefPaneDevZone: View { .settingsDescription() } } - }.formStyled().frame(minWidth: CtlPrefUIShared.formWidth, maxWidth: ceil(CtlPrefUIShared.formWidth * 1.2)) + }.formStyled().frame(minWidth: CtlPrefUI.formWidth, maxWidth: ceil(CtlPrefUI.formWidth * 1.2)) } - .frame(maxHeight: CtlPrefUIShared.contentMaxHeight) + .frame(maxHeight: CtlPrefUI.contentMaxHeight) } } -@available(macOS 11.0, *) +@available(macOS 13, *) struct VwrPrefPaneDevZone_Previews: PreviewProvider { static var previews: some View { VwrPrefPaneDevZone() diff --git a/Source/Modules/UIModules/PrefUI/VwrPrefPaneDictionary.swift b/Source/Modules/UIModules/PrefUI/VwrPrefPaneDictionary.swift index deba01d9..d7679f1b 100644 --- a/Source/Modules/UIModules/PrefUI/VwrPrefPaneDictionary.swift +++ b/Source/Modules/UIModules/PrefUI/VwrPrefPaneDictionary.swift @@ -14,7 +14,7 @@ import SwiftExtension import SwiftUI import SwiftUIBackports -@available(macOS 10.15, *) +@available(macOS 13, *) struct VwrPrefPaneDictionary: View { // MARK: - AppStorage Variables @@ -232,13 +232,13 @@ struct VwrPrefPaneDictionary: View { .settingsDescription() } } - }.formStyled().frame(minWidth: CtlPrefUIShared.formWidth, maxWidth: ceil(CtlPrefUIShared.formWidth * 1.2)) + }.formStyled().frame(minWidth: CtlPrefUI.formWidth, maxWidth: ceil(CtlPrefUI.formWidth * 1.2)) } - .frame(maxHeight: CtlPrefUIShared.contentMaxHeight) + .frame(maxHeight: CtlPrefUI.contentMaxHeight) } } -@available(macOS 11.0, *) +@available(macOS 13, *) struct VwrPrefPaneDictionary_Previews: PreviewProvider { static var previews: some View { VwrPrefPaneDictionary() diff --git a/Source/Modules/UIModules/PrefUI/VwrPrefPaneGeneral.swift b/Source/Modules/UIModules/PrefUI/VwrPrefPaneGeneral.swift index e5c7e204..a123815f 100644 --- a/Source/Modules/UIModules/PrefUI/VwrPrefPaneGeneral.swift +++ b/Source/Modules/UIModules/PrefUI/VwrPrefPaneGeneral.swift @@ -12,7 +12,7 @@ import SwiftExtension import SwiftUI import SwiftUIBackports -@available(macOS 10.15, *) +@available(macOS 13, *) struct VwrPrefPaneGeneral: View { @Binding var appleLanguageTag: String @@ -137,10 +137,8 @@ struct VwrPrefPaneGeneral: View { let alert = NSAlert(error: NSLocalizedString("Warning", comment: "")) alert.informativeText = content alert.addButton(withTitle: NSLocalizedString("Uncheck", comment: "")) - if #available(macOS 11, *) { - alert.buttons.forEach { button in - button.hasDestructiveAction = true - } + alert.buttons.forEach { button in + button.hasDestructiveAction = true } alert.addButton(withTitle: NSLocalizedString("Leave it checked", comment: "")) if let window = CtlPrefUI.shared?.window, !shouldNotFartInLieuOfBeep { @@ -175,13 +173,13 @@ struct VwrPrefPaneGeneral: View { isOn: $isDebugModeEnabled ) } - }.formStyled().frame(minWidth: CtlPrefUIShared.formWidth, maxWidth: ceil(CtlPrefUIShared.formWidth * 1.2)) + }.formStyled().frame(minWidth: CtlPrefUI.formWidth, maxWidth: ceil(CtlPrefUI.formWidth * 1.2)) } - .frame(maxHeight: CtlPrefUIShared.contentMaxHeight) + .frame(maxHeight: CtlPrefUI.contentMaxHeight) } } -@available(macOS 11.0, *) +@available(macOS 13, *) struct VwrPrefPaneGeneral_Previews: PreviewProvider { static var previews: some View { VwrPrefPaneGeneral() diff --git a/Source/Modules/UIModules/PrefUI/VwrPrefPaneKeyboard.swift b/Source/Modules/UIModules/PrefUI/VwrPrefPaneKeyboard.swift index 52f10d71..bf2f0195 100644 --- a/Source/Modules/UIModules/PrefUI/VwrPrefPaneKeyboard.swift +++ b/Source/Modules/UIModules/PrefUI/VwrPrefPaneKeyboard.swift @@ -13,7 +13,7 @@ import SwiftExtension import SwiftUI import SwiftUIBackports -@available(macOS 10.15, *) +@available(macOS 13, *) struct VwrPrefPaneKeyboard: View { // MARK: - AppStorage Variables @@ -125,13 +125,13 @@ struct VwrPrefPaneKeyboard: View { Section(header: Text("Keyboard Shortcuts:")) { VwrPrefPaneKeyboard_KeyboardShortcuts() } - }.formStyled().frame(minWidth: CtlPrefUIShared.formWidth, maxWidth: ceil(CtlPrefUIShared.formWidth * 1.2)) + }.formStyled().frame(minWidth: CtlPrefUI.formWidth, maxWidth: ceil(CtlPrefUI.formWidth * 1.2)) } - .frame(maxHeight: CtlPrefUIShared.contentMaxHeight) + .frame(maxHeight: CtlPrefUI.contentMaxHeight) } } -@available(macOS 10.15, *) +@available(macOS 13, *) private struct VwrPrefPaneKeyboard_KeyboardShortcuts: View { // MARK: - AppStorage Variables @@ -218,7 +218,7 @@ private struct VwrPrefPaneKeyboard_KeyboardShortcuts: View { } } -@available(macOS 11.0, *) +@available(macOS 13, *) struct VwrPrefPaneKeyboard_Previews: PreviewProvider { static var previews: some View { VwrPrefPaneKeyboard() diff --git a/Source/Modules/UIModules/PrefUI/VwrPrefPaneOutput.swift b/Source/Modules/UIModules/PrefUI/VwrPrefPaneOutput.swift index 0a057113..5c9be4bd 100644 --- a/Source/Modules/UIModules/PrefUI/VwrPrefPaneOutput.swift +++ b/Source/Modules/UIModules/PrefUI/VwrPrefPaneOutput.swift @@ -11,7 +11,7 @@ import SwiftExtension import SwiftUI import SwiftUIBackports -@available(macOS 10.15, *) +@available(macOS 13, *) struct VwrPrefPaneOutput: View { // MARK: - AppStorage Variables @@ -73,13 +73,13 @@ struct VwrPrefPaneOutput: View { .settingsDescription() } } - }.formStyled().frame(minWidth: CtlPrefUIShared.formWidth, maxWidth: ceil(CtlPrefUIShared.formWidth * 1.2)) + }.formStyled().frame(minWidth: CtlPrefUI.formWidth, maxWidth: ceil(CtlPrefUI.formWidth * 1.2)) } - .frame(maxHeight: CtlPrefUIShared.contentMaxHeight) + .frame(maxHeight: CtlPrefUI.contentMaxHeight) } } -@available(macOS 11.0, *) +@available(macOS 13, *) struct VwrPrefPaneOutput_Previews: PreviewProvider { static var previews: some View { VwrPrefPaneOutput() diff --git a/Source/Modules/UIModules/PrefUI/VwrPrefPanePhrases.swift b/Source/Modules/UIModules/PrefUI/VwrPrefPanePhrases.swift index c4fceeea..0489832c 100644 --- a/Source/Modules/UIModules/PrefUI/VwrPrefPanePhrases.swift +++ b/Source/Modules/UIModules/PrefUI/VwrPrefPanePhrases.swift @@ -12,7 +12,7 @@ import Shared import SwiftExtension import SwiftUI -@available(macOS 10.15, *) +@available(macOS 13, *) struct VwrPrefPanePhrases: View { var body: some View { ScrollView { @@ -26,13 +26,13 @@ struct VwrPrefPanePhrases: View { } .padding(4) .padding() - .frame(minWidth: CtlPrefUIShared.formWidth, maxWidth: ceil(CtlPrefUIShared.formWidth * 1.2)) + .frame(minWidth: CtlPrefUI.formWidth, maxWidth: ceil(CtlPrefUI.formWidth * 1.2)) } - .frame(maxHeight: CtlPrefUIShared.contentMaxHeight) + .frame(maxHeight: CtlPrefUI.contentMaxHeight) } } -@available(macOS 11.0, *) +@available(macOS 13, *) struct VwrPrefPanePhrases_Previews: PreviewProvider { static var previews: some View { VwrPrefPanePhrases() diff --git a/Source/Modules/UIModules/PrefUI/VwrSettingsUI.swift b/Source/Modules/UIModules/PrefUI/VwrSettingsUI.swift index d8999fef..14a3c0dd 100644 --- a/Source/Modules/UIModules/PrefUI/VwrSettingsUI.swift +++ b/Source/Modules/UIModules/PrefUI/VwrSettingsUI.swift @@ -47,6 +47,6 @@ public struct VwrSettingsUI: View { .frame(minWidth: 128, idealWidth: 128, maxWidth: 128) PrefUITabs.tabGeneral.suiView } - .frame(width: CtlPrefUIShared.formWidth + 140, height: CtlPrefUIShared.contentMaxHeight) + .frame(width: CtlPrefUI.formWidth + 140, height: CtlPrefUI.contentMaxHeight) } }