Skip to content

Commit 45bcc45

Browse files
authored
fix: non-rgb slider (#233)
1 parent ecc195c commit 45bcc45

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242

4343
- uses: maxim-lobanov/setup-xcode@v1
4444
with:
45-
xcode-version: latest
45+
xcode-version: 16.2
4646

4747
- uses: actions/setup-node@v4
4848
with:

src/config/optionmodels.swift

+10-7
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,16 @@ private func stringToColor(_ hex: String) -> Color {
202202

203203
private func colorToString(_ color: Color) -> String {
204204
let resolved = NSColor(color)
205-
let components = resolved.cgColor.components!
206-
let red = UInt8(round(components[0] * 255.0))
207-
let green = UInt8(round(components[1] * 255.0))
208-
let blue = UInt8(round(components[2] * 255.0))
209-
let alpha = UInt8(round(components[3] * 255.0))
210-
211-
return String(format: "#%02X%02X%02X%02X", red, green, blue, alpha)
205+
if let rgbColor = resolved.usingColorSpace(.sRGB) {
206+
let red = UInt8(round(rgbColor.redComponent * 255.0))
207+
let green = UInt8(round(rgbColor.greenComponent * 255.0))
208+
let blue = UInt8(round(rgbColor.blueComponent * 255.0))
209+
let alpha = UInt8(round(rgbColor.alphaComponent * 255.0))
210+
return String(format: "#%02X%02X%02X%02X", red, green, blue, alpha)
211+
} else {
212+
FCITX_ERROR("Can't convert color \(color) to RGB")
213+
return "#000000FF"
214+
}
212215
}
213216

214217
extension Color: FcitxCodable {

0 commit comments

Comments
 (0)