From 8c70327d900d1c3c26dd17bf2eeb785d18b06446 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Mon, 27 Nov 2023 19:20:27 +0800 Subject: [PATCH] SessionCtl // Add .clientAccentColor(). --- .../MainAssembly/SessionCtl_Delegates.swift | 22 +++++++++++++++++++ .../Protocols/CtlCandidateProtocol.swift | 1 + 2 files changed, 23 insertions(+) diff --git a/Packages/vChewing_MainAssembly/Sources/MainAssembly/SessionCtl_Delegates.swift b/Packages/vChewing_MainAssembly/Sources/MainAssembly/SessionCtl_Delegates.swift index 4b690c16..bb1d62b2 100644 --- a/Packages/vChewing_MainAssembly/Sources/MainAssembly/SessionCtl_Delegates.swift +++ b/Packages/vChewing_MainAssembly/Sources/MainAssembly/SessionCtl_Delegates.swift @@ -81,6 +81,28 @@ extension SessionCtl: InputHandlerDelegate { extension SessionCtl: CtlCandidateDelegate { public var isCandidateState: Bool { state.isCandidateContainer } + public var clientAccentColor: NSColor? { + var nullResponse = !PrefMgr.shared.respectClientAccentColor + nullResponse = nullResponse || PrefMgr.shared.shiftJISShinjitaiOutputEnabled + nullResponse = nullResponse || PrefMgr.shared.chineseConversionEnabled + guard !nullResponse else { return nil } + let fallbackValue = NSColor.accentColor + if #unavailable(macOS 10.14) { + return fallbackValue + } + // 此處因為沒有對 client() 的強引用,所以不會耽誤很多時間。 + let urls = NSRunningApplication.runningApplications( + withBundleIdentifier: client()?.bundleIdentifier() ?? "" + ).compactMap(\.bundleURL) + let bundles = urls.compactMap { Bundle(url: $0) } + for bundle in bundles { + let bundleAccentColor = bundle.getAccentColor() + guard bundleAccentColor != .accentColor else { continue } + return bundleAccentColor + } + return fallbackValue + } + public var shouldAutoExpandCandidates: Bool { guard !PrefMgr.shared.alwaysExpandCandidateWindow else { return true } guard state.type == .ofSymbolTable else { return state.type == .ofAssociates } diff --git a/Packages/vChewing_Shared/Sources/Shared/Protocols/CtlCandidateProtocol.swift b/Packages/vChewing_Shared/Sources/Shared/Protocols/CtlCandidateProtocol.swift index 113a5297..b74b09bc 100644 --- a/Packages/vChewing_Shared/Sources/Shared/Protocols/CtlCandidateProtocol.swift +++ b/Packages/vChewing_Shared/Sources/Shared/Protocols/CtlCandidateProtocol.swift @@ -22,6 +22,7 @@ public protocol CtlCandidateDelegate { var shouldAutoExpandCandidates: Bool { get } var isCandidateContextMenuEnabled: Bool { get } var showReverseLookupResult: Bool { get } + var clientAccentColor: NSColor? { get } } public protocol CtlCandidateProtocol {