SwiftPackages // Boost platform req. to macOS 11.

This commit is contained in:
ShikiSuen 2023-09-29 10:35:56 +08:00
parent 293582fa5d
commit 5b11ffec44
35 changed files with 97 additions and 123 deletions

View File

@ -4,7 +4,7 @@ import PackageDescription
let package = Package(
name: "FolderMonitor",
platforms: [
.macOS(.v10_11),
.macOS(.v11),
],
products: [
.library(

View File

@ -4,7 +4,7 @@ import PackageDescription
let package = Package(
name: "NSAttributedTextView",
platforms: [
.macOS(.v10_11),
.macOS(.v11),
],
products: [
.library(

View File

@ -4,7 +4,7 @@ import PackageDescription
let package = Package(
name: "BookmarkManager",
platforms: [
.macOS(.v10_11),
.macOS(.v11),
],
products: [
.library(

View File

@ -34,11 +34,9 @@ public class BookmarkManager {
if fileExists(url) {
do {
let fileData = try Data(contentsOf: url)
if let fileBookmarks = try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(fileData) as! [URL: Data]? {
for bookmark in fileBookmarks {
try (NSKeyedUnarchiver.unarchivedObject(ofClass: NSDictionary.self, from: fileData) as? [URL: Data])?.forEach { bookmark in
restoreBookmark(key: bookmark.key, value: bookmark.value)
}
}
} catch {
NSLog("Couldn't load bookmarks")
}
@ -82,12 +80,7 @@ public class BookmarkManager {
}
private func getBookmarkURL() -> URL? {
let urls = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)
if let appSupportURL = urls.last {
let url = appSupportURL.appendingPathComponent("Bookmarks.dict")
return url
}
return nil
FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).last?.appendingPathComponent("Bookmarks.dict")
}
private func fileExists(_ url: URL) -> Bool {

View File

@ -4,7 +4,7 @@ import PackageDescription
let package = Package(
name: "ShiftKeyUpChecker",
platforms: [
.macOS(.v10_11),
.macOS(.v11),
],
products: [
.library(

View File

@ -4,7 +4,7 @@ import PackageDescription
let package = Package(
name: "LineReader",
platforms: [
.macOS(.v10_11),
.macOS(.v11),
],
products: [
.library(

View File

@ -4,7 +4,7 @@ import PackageDescription
let package = Package(
name: "CandidateWindow",
platforms: [
.macOS(.v10_11),
.macOS(.v11),
],
products: [
.library(

View File

@ -17,7 +17,7 @@ open class CtlCandidate: NSWindowController, CtlCandidateProtocol {
open var reverseLookupResult: [String] = []
open func highlightedColor() -> NSColor {
var result = NSColor.alternateSelectedControlColor
var result = NSColor.controlAccentColor
var colorBlendAmount: Double = NSApplication.isDarkMode ? 0.3 : 0.0
if #available(macOS 10.14, *), !NSApplication.isDarkMode, locale == "zh-Hant" {
colorBlendAmount = 0.15

View File

@ -4,7 +4,7 @@ import PackageDescription
let package = Package(
name: "CocoaExtension",
platforms: [
.macOS(.v10_11),
.macOS(.v11),
],
products: [
.library(

View File

@ -4,7 +4,7 @@ import PackageDescription
let package = Package(
name: "Hotenka",
platforms: [
.macOS(.v10_11),
.macOS(.v11),
],
products: [
.library(

View File

@ -4,7 +4,7 @@ import PackageDescription
let package = Package(
name: "IMKUtils",
platforms: [
.macOS(.v10_11),
.macOS(.v11),
],
products: [
.library(

View File

@ -4,7 +4,7 @@ import PackageDescription
let package = Package(
name: "LangModelAssembly",
platforms: [
.macOS(.v10_11),
.macOS(.v11),
],
products: [
.library(

View File

@ -1,10 +1,10 @@
// swift-tools-version:5.3
// swift-tools-version:5.7
import PackageDescription
let package = Package(
name: "MainAssembly",
platforms: [
.macOS(.v10_13),
.macOS(.v11),
],
products: [
.library(

View File

@ -13,9 +13,10 @@ import FolderMonitor
import Shared
import Uninstaller
import UpdateSputnik
import UserNotifications
@objc(AppDelegate)
public class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDelegate {
public class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDelegate {
public static let shared = AppDelegate()
private var folderMonitor = FolderMonitor(
@ -58,12 +59,11 @@ extension AppDelegate {
// MARK: - Public Functions
public extension AppDelegate {
func userNotificationCenter(_: NSUserNotificationCenter, shouldPresent _: NSUserNotification) -> Bool {
true
}
func applicationWillFinishLaunching(_: Notification) {
NSUserNotificationCenter.default.delegate = self
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge], completionHandler: { _, _ in })
PrefMgr.shared.fixOddPreferences()
// 使
@ -72,14 +72,17 @@ public extension AppDelegate {
if PrefMgr.shared.failureFlagForUOMObservation {
LMMgr.relocateWreckedUOMData()
PrefMgr.shared.failureFlagForUOMObservation = false
let userNotification = NSUserNotification()
userNotification.title = NSLocalizedString("vChewing", comment: "")
userNotification.informativeText = NSLocalizedString(
let msgPackage = UNMutableNotificationContent()
msgPackage.title = NSLocalizedString("vChewing", comment: "")
msgPackage.body = NSLocalizedString(
"vChewing crashed while handling previously loaded UOM observation data. These data files are cleaned now to ensure the usability.",
comment: ""
)
userNotification.soundName = NSUserNotificationDefaultSoundName
NSUserNotificationCenter.default.deliver(userNotification)
msgPackage.sound = .defaultCritical
UNUserNotificationCenter.current().add(
.init(identifier: "vChewing.notification.uomCrash", content: msgPackage, trigger: nil),
withCompletionHandler: nil
)
}
if !PrefMgr.shared.onlyLoadFactoryLangModelsIfNeeded { LMMgr.loadDataModelsOnAppDelegate() }
@ -125,15 +128,16 @@ public extension AppDelegate {
alert.addButton(withTitle: NSLocalizedString("Not Now", comment: ""))
let result = alert.runModal()
NSApp.popup()
if result == NSApplication.ModalResponse.alertFirstButtonReturn {
NSWorkspace.shared.openFile(
LMMgr.dataFolderPath(isDefaultFolder: true), withApplication: "Finder"
)
guard result == NSApplication.ModalResponse.alertFirstButtonReturn else { return }
let url = URL(fileURLWithPath: LMMgr.dataFolderPath(isDefaultFolder: true))
guard let finderURL = NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.apple.finder") else { return }
let configuration = NSWorkspace.OpenConfiguration()
configuration.promptsUserIfNeeded = true
NSWorkspace.shared.open([url], withApplicationAt: finderURL, configuration: configuration)
Uninstaller.uninstall(
isSudo: false, selfKill: true, defaultDataFolderPath: LMMgr.dataFolderPath(isDefaultFolder: true)
)
}
}
///
/// - Returns: MiB
@ -143,13 +147,19 @@ public extension AppDelegate {
switch currentMemorySize {
case 768...:
vCLog("WARNING: EXCESSIVE MEMORY FOOTPRINT (\(currentMemorySize)MB).")
let userNotification = NSUserNotification()
userNotification.title = NSLocalizedString("vChewing", comment: "")
userNotification.informativeText = NSLocalizedString(
let msgPackage = UNMutableNotificationContent()
msgPackage.title = NSLocalizedString("vChewing", comment: "")
msgPackage.body = NSLocalizedString(
"vChewing is rebooted due to a memory-excessive-usage problem. If convenient, please inform the developer that you are having this issue, stating whether you are using an Intel Mac or Apple Silicon Mac. An NSLog is generated with the current memory footprint size.",
comment: ""
)
NSUserNotificationCenter.default.deliver(userNotification)
UNUserNotificationCenter.current().add(
.init(
identifier: "vChewing.notification.memoryExcessiveUsage",
content: msgPackage, trigger: nil
),
withCompletionHandler: nil
)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
NSApp.terminate(self)
}

View File

@ -17,8 +17,8 @@ import Shared
extension LMMgr: PhraseEditorDelegate {
public var currentInputMode: Shared.InputMode { IMEApp.currentInputMode }
public func openPhraseFile(mode: Shared.InputMode, type: vChewingLM.ReplacableUserDataType, app: String) {
Self.openPhraseFile(fromURL: Self.userDictDataURL(mode: mode, type: type), app: app)
public func openPhraseFile(mode: Shared.InputMode, type: vChewingLM.ReplacableUserDataType, appIdentifier: String) {
Self.openPhraseFile(fromURL: Self.userDictDataURL(mode: mode, type: type), appIdentifier: appIdentifier)
}
public func consolidate(text strProcessed: inout String, pragma shouldCheckPragma: Bool) {

View File

@ -311,50 +311,29 @@ public extension LMMgr {
}
static func openUserDictFile(type: vChewingLM.ReplacableUserDataType, dual: Bool = false, alt: Bool) {
let app: String = alt ? "" : "Finder"
openPhraseFile(fromURL: userDictDataURL(mode: IMEApp.currentInputMode, type: type), app: app)
let appIdentifier: String = alt ? "" : "Finder"
openPhraseFile(fromURL: userDictDataURL(mode: IMEApp.currentInputMode, type: type), appIdentifier: appIdentifier)
guard dual else { return }
openPhraseFile(fromURL: userDictDataURL(mode: IMEApp.currentInputMode.reversed, type: type), app: app)
openPhraseFile(fromURL: userDictDataURL(mode: IMEApp.currentInputMode.reversed, type: type), appIdentifier: appIdentifier)
}
///
/// - Remark: App Sandbox app "vim" Sandbox
/// - Parameters:
/// - url: URL
/// - app: App binary
static func openPhraseFile(fromURL url: URL, app: String = "") {
/// - appIdentifier: App bundle identifier
static func openPhraseFile(fromURL url: URL, appIdentifier: String = "") {
if !Self.checkIfUserFilesExistBeforeOpening() { return }
DispatchQueue.main.async {
switch app {
case "vim":
let process = Process()
let pipe = Pipe()
process.executableURL = URL(fileURLWithPath: "/bin/sh/")
process.arguments = ["-c", "open '/usr/bin/vim'", "'\(url.path)'"]
process.standardOutput = pipe
process.standardError = pipe
process.terminationHandler = { process in
vCLog("\ndidFinish: \(!process.isRunning)")
}
let fileHandle = pipe.fileHandleForReading
do {
try process.run()
} catch {
NSWorkspace.shared.openFile(url.path, withApplication: "TextEdit")
}
do {
if let theData = try fileHandle.readToEnd(),
let outStr = String(data: theData, encoding: .utf8)
{
vCLog(outStr)
}
} catch {}
switch appIdentifier {
case "Finder":
NSWorkspace.shared.activateFileViewerSelecting([url])
default:
if !NSWorkspace.shared.openFile(url.path, withApplication: app) {
NSWorkspace.shared.openFile(url.path, withApplication: "TextEdit")
}
guard let textEditURL = NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.apple.TextEdit") else { return }
let toolURL = NSWorkspace.shared.urlForApplication(withBundleIdentifier: appIdentifier) ?? textEditURL
let configuration = NSWorkspace.OpenConfiguration()
configuration.promptsUserIfNeeded = true
NSWorkspace.shared.open([url], withApplicationAt: toolURL, configuration: configuration)
}
}
}

View File

@ -4,7 +4,7 @@ import PackageDescription
let package = Package(
name: "Megrez",
platforms: [
.macOS(.v10_11),
.macOS(.v11),
],
products: [
.library(

View File

@ -4,7 +4,7 @@ import PackageDescription
let package = Package(
name: "NotifierUI",
platforms: [
.macOS(.v10_11),
.macOS(.v11),
],
products: [
.library(

View File

@ -4,7 +4,7 @@ import PackageDescription
let package = Package(
name: "PhraseEditorUI",
platforms: [
.macOS(.v10_11),
.macOS(.v11),
],
products: [
.library(

View File

@ -17,6 +17,6 @@ public protocol PhraseEditorDelegate {
-> String
func checkIfPhrasePairExists(userPhrase: String, mode: Shared.InputMode, key unigramKey: String) -> Bool
func consolidate(text strProcessed: inout String, pragma shouldCheckPragma: Bool)
func openPhraseFile(mode: Shared.InputMode, type: vChewingLM.ReplacableUserDataType, app: String)
func openPhraseFile(mode: Shared.InputMode, type: vChewingLM.ReplacableUserDataType, appIdentifier: String)
func tagOverrides(in strProcessed: inout String, mode: Shared.InputMode)
}

View File

@ -186,8 +186,8 @@ public struct VwrPhraseEditorUI: View {
}
private func callExternalAppToOpenPhraseFile() {
let app: String = NSEvent.keyModifierFlags.contains(.option) ? "TextEdit" : "Finder"
delegate?.openPhraseFile(mode: selInputMode, type: selUserDataType, app: app)
let app: String = NSEvent.keyModifierFlags.contains(.option) ? "com.apple.TextEdit" : "com.apple.finder"
delegate?.openPhraseFile(mode: selInputMode, type: selUserDataType, appIdentifier: app)
}
// MARK: - Main View.

View File

@ -4,7 +4,7 @@ import PackageDescription
let package = Package(
name: "PinyinPhonaConverter",
platforms: [
.macOS(.v10_11),
.macOS(.v11),
],
products: [
.library(

View File

@ -4,7 +4,7 @@ import PackageDescription
let package = Package(
name: "PopupCompositionBuffer",
platforms: [
.macOS(.v10_11),
.macOS(.v11),
],
products: [
.library(

View File

@ -4,7 +4,7 @@ import PackageDescription
let package = Package(
name: "Shared",
platforms: [
.macOS(.v10_11),
.macOS(.v11),
],
products: [
.library(

View File

@ -4,7 +4,7 @@ import PackageDescription
let package = Package(
name: "SwiftExtension",
platforms: [
.macOS(.v10_11),
.macOS(.v11),
],
products: [
.library(

View File

@ -223,19 +223,6 @@ public extension BinaryInteger {
}
}
// MARK: - File Handle API Compatibility for macOS 10.15.3 and Earlier.
@available(macOS, deprecated: 10.15.4)
extension FileHandle {
public func read(upToCount count: Int) throws -> Data? {
readData(ofLength: count)
}
public func readToEnd() throws -> Data? {
readDataToEndOfFile()
}
}
// MARK: - Index Revolver (only for Array)
// Further discussion: https://forums.swift.org/t/62847

View File

@ -32,7 +32,6 @@ public extension Binding {
// Ref: https://stackoverflow.com/a/63217861
@available(macOS 10.15, *)
@available(macOS, obsoleted: 11)
struct Tooltip: NSViewRepresentable {
let tooltip: String
@ -47,9 +46,8 @@ struct Tooltip: NSViewRepresentable {
}
@available(macOS 10.15, *)
@available(macOS, obsoleted: 11)
extension View {
public func help(_ tooltip: String) -> some View {
public extension View {
func help(_ tooltip: String) -> some View {
overlay(Tooltip(tooltip: tooltip))
}
}

View File

@ -4,7 +4,7 @@ import PackageDescription
let package = Package(
name: "Tekkon",
platforms: [
.macOS(.v10_11),
.macOS(.v11),
],
products: [
.library(

View File

@ -4,7 +4,7 @@ import PackageDescription
let package = Package(
name: "TooltipUI",
platforms: [
.macOS(.v10_11),
.macOS(.v11),
],
products: [
.library(

View File

@ -4,7 +4,7 @@ import PackageDescription
let package = Package(
name: "Uninstaller",
platforms: [
.macOS(.v10_11),
.macOS(.v11),
],
products: [
.library(

View File

@ -4,7 +4,7 @@ import PackageDescription
let package = Package(
name: "UpdateSputnik",
platforms: [
.macOS(.v10_11),
.macOS(.v11),
],
products: [
.library(

View File

@ -233,9 +233,10 @@ public extension SessionCtl {
@objc func showCheatSheet(_: Any? = nil) {
guard let url = Bundle.main.url(forResource: "shortcuts", withExtension: "html") else { return }
DispatchQueue.main.async {
NSWorkspace.shared.openFile(url.path, withApplication: "Safari")
}
guard let safariURL = NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.apple.Safari") else { return }
let configuration = NSWorkspace.OpenConfiguration()
configuration.promptsUserIfNeeded = true
NSWorkspace.shared.open([url], withApplicationAt: safariURL, configuration: configuration)
}
@objc func showClientListMgr(_: Any? = nil) {
@ -380,13 +381,18 @@ public extension SessionCtl {
if !LMMgr.userDataFolderExists {
return
}
NSWorkspace.shared.openFile(
LMMgr.dataFolderPath(isDefaultFolder: false), withApplication: "Finder"
)
let url = URL(fileURLWithPath: LMMgr.dataFolderPath(isDefaultFolder: false))
guard let finderURL = NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.apple.finder") else { return }
let configuration = NSWorkspace.OpenConfiguration()
configuration.promptsUserIfNeeded = true
NSWorkspace.shared.open([url], withApplicationAt: finderURL, configuration: configuration)
}
@objc func openAppSupportFolderFromContainer(_: Any? = nil) {
NSWorkspace.shared.openFile(LMMgr.appSupportURL.path, withApplication: "Finder")
guard let finderURL = NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.apple.finder") else { return }
let configuration = NSWorkspace.OpenConfiguration()
configuration.promptsUserIfNeeded = true
NSWorkspace.shared.open([LMMgr.appSupportURL], withApplicationAt: finderURL, configuration: configuration)
}
@objc func openUserPhrases(_: Any? = nil) {

View File

@ -8,6 +8,7 @@
import AppKit
import MainAssembly
import UniformTypeIdentifiers
class CtlClientListMgr: NSWindowController, NSTableViewDelegate, NSTableViewDataSource {
@IBOutlet var tblClients: NSTableView!
@ -33,7 +34,7 @@ class CtlClientListMgr: NSWindowController, NSTableViewDelegate, NSTableViewData
window?.setPosition(vertical: .center, horizontal: .right, padding: 20)
localize()
tblClients.delegate = self
tblClients.registerForDraggedTypes([.init(rawValue: kUTTypeFileURL as String)])
tblClients.registerForDraggedTypes([.fileURL])
tblClients.allowsMultipleSelection = true
tblClients.dataSource = self
tblClients.action = #selector(onItemClicked(_:))
@ -125,7 +126,7 @@ extension CtlClientListMgr {
)
dlgOpenPath.showsResizeIndicator = true
dlgOpenPath.allowsMultipleSelection = true
dlgOpenPath.allowedFileTypes = ["app"]
dlgOpenPath.allowedContentTypes = [UTType.applicationBundle]
dlgOpenPath.allowsOtherFileTypes = false
dlgOpenPath.showsHiddenFiles = true
dlgOpenPath.canChooseFiles = true
@ -240,7 +241,7 @@ extension CtlClientListMgr {
neta info: NSDraggingInfo, onError: @escaping () -> Void?, handler: (([URL]) -> Void)? = nil
) {
let board = info.draggingPasteboard
let type = NSPasteboard.PasteboardType(rawValue: kUTTypeApplicationBundle as String)
let type = UTType.applicationBundle
let options: [NSPasteboard.ReadingOptionKey: Any] = [
.urlReadingFileURLsOnly: true,
.urlReadingContentsConformToTypes: [type],

View File

@ -431,7 +431,7 @@ class CtlPrefWindow: NSWindowController, NSWindowDelegate {
dlgOpenFile.canChooseFiles = true
dlgOpenFile.canChooseDirectories = false
dlgOpenFile.allowsMultipleSelection = false
dlgOpenFile.allowedFileTypes = ["cin2", "vcin", "cin"]
dlgOpenFile.allowedContentTypes = ["cin2", "vcin", "cin"].compactMap { .init(filenameExtension: $0) }
dlgOpenFile.allowsOtherFileTypes = true
let bolPreviousPathValidity = LMMgr.checkCassettePathValidity(

View File

@ -198,7 +198,7 @@ extension CtlPrefWindow: NSTextViewDelegate, NSTextFieldDelegate {
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
let app: String = NSEvent.keyModifierFlags.contains(.option) ? "TextEdit" : "Finder"
LMMgr.shared.openPhraseFile(mode: self.selInputMode, type: self.selUserDataType, app: app)
LMMgr.shared.openPhraseFile(mode: self.selInputMode, type: self.selUserDataType, appIdentifier: app)
}
}