Skip to content

Commit 7fbc911

Browse files
committed
[Fix] When color_scheme_dark is not available, use color_scheme
1 parent e706910 commit 7fbc911

File tree

3 files changed

+53
-51
lines changed

3 files changed

+53
-51
lines changed

sources/SquirrelPanel.swift

+2-3
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,8 @@ private extension SquirrelPanel {
335335
func show() {
336336
currentScreen()
337337
let theme = view.currentTheme
338-
let requestedAppearance: NSAppearance? = theme.native ? nil : NSAppearance(named: .aqua)
339-
if self.appearance != requestedAppearance {
340-
self.appearance = requestedAppearance
338+
if !view.darkTheme.available {
339+
self.appearance = NSAppearance(named: .aqua)
341340
}
342341

343342
// Break line if the text is too long, based on screen size.

sources/SquirrelTheme.swift

+50-47
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ final class SquirrelTheme {
2727
}
2828
}
2929

30-
var native = true
31-
var memorizeSize = true
30+
private(set) var available = true
31+
private(set) var native = true
32+
private(set) var memorizeSize = true
3233
private var colorSpace: RimeColorSpace = .sRGB
3334

3435
var backgroundColor: NSColor = .windowBackgroundColor
@@ -213,55 +214,57 @@ final class SquirrelTheme {
213214
var commentFontSize = config.getDouble("style/comment_font_point")
214215

215216
let colorSchemeOption = dark ? "style/color_scheme_dark" : "style/color_scheme"
216-
if let colorScheme = config.getString(colorSchemeOption), colorScheme != "native" {
217-
native = false
218-
let prefix = "preset_color_schemes/\(colorScheme)"
219-
colorSpace = .from(name: config.getString("\(prefix)/color_space") ?? "")
220-
backgroundColor ?= config.getColor("\(prefix)/back_color", inSpace: colorSpace)
221-
highlightedPreeditColor = config.getColor("\(prefix)/hilited_back_color", inSpace: colorSpace)
222-
highlightedBackColor = config.getColor("\(prefix)/hilited_candidate_back_color", inSpace: colorSpace) ?? highlightedPreeditColor
223-
preeditBackgroundColor = config.getColor("\(prefix)/preedit_back_color", inSpace: colorSpace)
224-
candidateBackColor = config.getColor("\(prefix)/candidate_back_color", inSpace: colorSpace)
225-
borderColor = config.getColor("\(prefix)/border_color", inSpace: colorSpace)
217+
if let colorScheme = config.getString(colorSchemeOption) {
218+
if colorScheme != "native" {
219+
native = false
220+
let prefix = "preset_color_schemes/\(colorScheme)"
221+
colorSpace = .from(name: config.getString("\(prefix)/color_space") ?? "")
222+
backgroundColor ?= config.getColor("\(prefix)/back_color", inSpace: colorSpace)
223+
highlightedPreeditColor = config.getColor("\(prefix)/hilited_back_color", inSpace: colorSpace)
224+
highlightedBackColor = config.getColor("\(prefix)/hilited_candidate_back_color", inSpace: colorSpace) ?? highlightedPreeditColor
225+
preeditBackgroundColor = config.getColor("\(prefix)/preedit_back_color", inSpace: colorSpace)
226+
candidateBackColor = config.getColor("\(prefix)/candidate_back_color", inSpace: colorSpace)
227+
borderColor = config.getColor("\(prefix)/border_color", inSpace: colorSpace)
226228

227-
textColor ?= config.getColor("\(prefix)/text_color", inSpace: colorSpace)
228-
highlightedTextColor = config.getColor("\(prefix)/hilited_text_color", inSpace: colorSpace) ?? textColor
229-
candidateTextColor = config.getColor("\(prefix)/candidate_text_color", inSpace: colorSpace) ?? textColor
230-
highlightedCandidateTextColor = config.getColor("\(prefix)/hilited_candidate_text_color", inSpace: colorSpace) ?? highlightedTextColor
231-
candidateLabelColor = config.getColor("\(prefix)/label_color", inSpace: colorSpace)
232-
highlightedCandidateLabelColor = config.getColor("\(prefix)/hilited_candidate_label_color", inSpace: colorSpace)
233-
commentTextColor = config.getColor("\(prefix)/comment_text_color", inSpace: colorSpace)
234-
highlightedCommentTextColor = config.getColor("\(prefix)/hilited_comment_text_color", inSpace: colorSpace)
229+
textColor ?= config.getColor("\(prefix)/text_color", inSpace: colorSpace)
230+
highlightedTextColor = config.getColor("\(prefix)/hilited_text_color", inSpace: colorSpace) ?? textColor
231+
candidateTextColor = config.getColor("\(prefix)/candidate_text_color", inSpace: colorSpace) ?? textColor
232+
highlightedCandidateTextColor = config.getColor("\(prefix)/hilited_candidate_text_color", inSpace: colorSpace) ?? highlightedTextColor
233+
candidateLabelColor = config.getColor("\(prefix)/label_color", inSpace: colorSpace)
234+
highlightedCandidateLabelColor = config.getColor("\(prefix)/hilited_candidate_label_color", inSpace: colorSpace)
235+
commentTextColor = config.getColor("\(prefix)/comment_text_color", inSpace: colorSpace)
236+
highlightedCommentTextColor = config.getColor("\(prefix)/hilited_comment_text_color", inSpace: colorSpace)
235237

236-
// the following per-color-scheme configurations, if exist, will
237-
// override configurations with the same name under the global 'style'
238-
// section
239-
linear ?= config.getString("\(prefix)/candidate_list_layout").map { $0 == "linear" }
240-
vertical ?= config.getString("\(prefix)/text_orientation").map { $0 == "vertical" }
241-
inlinePreedit ?= config.getBool("\(prefix)/inline_preedit")
242-
inlineCandidate ?= config.getBool("\(prefix)/inline_candidate")
243-
translucency ?= config.getBool("\(prefix)/translucency")
244-
mutualExclusive ?= config.getBool("\(prefix)/mutual_exclusive")
245-
candidateFormat ?= config.getString("\(prefix)/candidate_format")
246-
fontName ?= config.getString("\(prefix)/font_face")
247-
fontSize ?= config.getDouble("\(prefix)/font_point")
248-
labelFontName ?= config.getString("\(prefix)/label_font_face")
249-
labelFontSize ?= config.getDouble("\(prefix)/label_font_point")
250-
commentFontName ?= config.getString("\(prefix)/comment_font_face")
251-
commentFontSize ?= config.getDouble("\(prefix)/comment_font_point")
238+
// the following per-color-scheme configurations, if exist, will
239+
// override configurations with the same name under the global 'style'
240+
// section
241+
linear ?= config.getString("\(prefix)/candidate_list_layout").map { $0 == "linear" }
242+
vertical ?= config.getString("\(prefix)/text_orientation").map { $0 == "vertical" }
243+
inlinePreedit ?= config.getBool("\(prefix)/inline_preedit")
244+
inlineCandidate ?= config.getBool("\(prefix)/inline_candidate")
245+
translucency ?= config.getBool("\(prefix)/translucency")
246+
mutualExclusive ?= config.getBool("\(prefix)/mutual_exclusive")
247+
candidateFormat ?= config.getString("\(prefix)/candidate_format")
248+
fontName ?= config.getString("\(prefix)/font_face")
249+
fontSize ?= config.getDouble("\(prefix)/font_point")
250+
labelFontName ?= config.getString("\(prefix)/label_font_face")
251+
labelFontSize ?= config.getDouble("\(prefix)/label_font_point")
252+
commentFontName ?= config.getString("\(prefix)/comment_font_face")
253+
commentFontSize ?= config.getDouble("\(prefix)/comment_font_point")
252254

253-
alpha ?= config.getDouble("\(prefix)/alpha").map { max(0, min(1, $0)) }
254-
cornerRadius ?= config.getDouble("\(prefix)/corner_radius")
255-
hilitedCornerRadius ?= config.getDouble("\(prefix)/hilited_corner_radius")
256-
surroundingExtraExpansion ?= config.getDouble("\(prefix)/surrounding_extra_expansion")
257-
borderHeight ?= config.getDouble("\(prefix)/border_height")
258-
borderWidth ?= config.getDouble("\(prefix)/border_width")
259-
linespace ?= config.getDouble("\(prefix)/line_spacing")
260-
preeditLinespace ?= config.getDouble("\(prefix)/spacing")
261-
baseOffset ?= config.getDouble("\(prefix)/base_offset")
262-
shadowSize ?= config.getDouble("\(prefix)/shadow_size").map { max(0, $0) }
255+
alpha ?= config.getDouble("\(prefix)/alpha").map { max(0, min(1, $0)) }
256+
cornerRadius ?= config.getDouble("\(prefix)/corner_radius")
257+
hilitedCornerRadius ?= config.getDouble("\(prefix)/hilited_corner_radius")
258+
surroundingExtraExpansion ?= config.getDouble("\(prefix)/surrounding_extra_expansion")
259+
borderHeight ?= config.getDouble("\(prefix)/border_height")
260+
borderWidth ?= config.getDouble("\(prefix)/border_width")
261+
linespace ?= config.getDouble("\(prefix)/line_spacing")
262+
preeditLinespace ?= config.getDouble("\(prefix)/spacing")
263+
baseOffset ?= config.getDouble("\(prefix)/base_offset")
264+
shadowSize ?= config.getDouble("\(prefix)/shadow_size").map { max(0, $0) }
265+
}
263266
} else {
264-
native = true
267+
available = false
265268
}
266269

267270
fonts = decodeFonts(from: fontName)

sources/SquirrelView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ final class SquirrelView: NSView {
3636
var lightTheme = SquirrelTheme()
3737
var darkTheme = SquirrelTheme()
3838
var currentTheme: SquirrelTheme {
39-
isDark ? darkTheme : lightTheme
39+
if isDark && darkTheme.available { darkTheme } else { lightTheme }
4040
}
4141
var textLayoutManager: NSTextLayoutManager {
4242
textView.textLayoutManager!

0 commit comments

Comments
 (0)