Skip to content

Commit

Permalink
support dark Scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
CoderLineChan committed Apr 1, 2023
1 parent 624041f commit de32b9a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 20 deletions.
20 changes: 17 additions & 3 deletions OSXChatGPT/OSXChatGPT/DataProvider/ViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,24 @@ import Splash

private var allChatRoomViews: [String:ChatRoomView] = [:]

@Environment(\.colorScheme) private var colorScheme

var theme: Splash.Theme {

// return .wwdc18(withFont: .init(size: 16))
return .sunset(withFont: .init(size: 16))
switch colorScheme {
case .dark:
return .wwdc17(withFont: .init(size: 16))
default:
return .sunset(withFont: .init(size: 16))
}
}

func codeTheme(scheme: ColorScheme) -> Splash.Theme {
switch scheme {
case .dark:
return .wwdc17(withFont: .init(size: 16))
default:
return .sunset(withFont: .init(size: 16))
}
}

init() {
Expand Down
13 changes: 7 additions & 6 deletions OSXChatGPT/OSXChatGPT/WindowView/AIPromptInputView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct AIPromptInputView: View {
@State private var prompt: String = ""
@State private var author: String = ""
@State private var isToggleOn: Bool = true
@Environment(\.colorScheme) private var colorScheme
func cancelAction() {
self.isPresented = false
}
Expand All @@ -23,11 +24,11 @@ struct AIPromptInputView: View {
Spacer()
Text("自定义提示")
.font(.title3)
.foregroundColor(.black.opacity(0.9))
.foregroundColor((colorScheme == .dark) ? .white.opacity(0.9) :.black.opacity(0.9))
Spacer()
}.frame(height: 40)
.frame(minWidth: 0, maxWidth: .infinity)
.background(.white)
.background((colorScheme == .dark) ? .gray.opacity(0.1) : .white)

VStack {
HStack {
Expand All @@ -50,7 +51,7 @@ struct AIPromptInputView: View {
.textFieldStyle(PlainTextFieldStyle())
.font(Font.system(size: 14))
.padding(10)
.background(Color.white)
.background((colorScheme == .dark) ? .gray.opacity(0.1) :.white.opacity(0.9))
.cornerRadius(8)
.frame(minWidth: 0, maxWidth: .infinity)
}.padding(.leading, 20)
Expand All @@ -75,7 +76,7 @@ struct AIPromptInputView: View {
TextEditor(text: $prompt)
.font(Font.system(size: 13))
.padding(8)
.background(Color.white)
.background((colorScheme == .dark) ? .gray.opacity(0.1) :.white.opacity(0.9))
.cornerRadius(8)
.frame(height: 90)
.frame(minWidth: 0, maxWidth: .infinity)
Expand Down Expand Up @@ -107,7 +108,7 @@ struct AIPromptInputView: View {
.textFieldStyle(PlainTextFieldStyle())
.font(Font.system(size: 14))
.padding(10)
.background(Color.white)
.background((colorScheme == .dark) ? .gray.opacity(0.1) :.white.opacity(0.9))
.cornerRadius(8)
.frame(minWidth: 0, maxWidth: .infinity)
}.padding(.leading, 20)
Expand Down Expand Up @@ -143,7 +144,7 @@ struct AIPromptInputView: View {

}.frame(height: 44)
.frame(minWidth: 0, maxWidth: .infinity)
.background(.white)
.background((colorScheme == .dark) ? .gray.opacity(0.1) : .white)



Expand Down
27 changes: 19 additions & 8 deletions OSXChatGPT/OSXChatGPT/WindowView/AIPromptView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,29 @@ struct AIPromptView: View {
}

struct AIPromptPopView: View {
@Environment(\.colorScheme) private var colorScheme
@EnvironmentObject var viewModel: ViewModel
@StateObject var data = AIPromptSessionViewMdoel()
@Binding var showInputView: Bool
@Binding var showPopover: Bool
@State private var isPresented = false

var titleColor: Color {
switch colorScheme {
case .dark:
return Color.white.opacity(0.9)
default:
return Color.black.opacity(0.9)
}
}

var body: some View {
ZStack {
VStack {
Spacer()
Text("选择提示")
.font(.title3)
.foregroundColor(.black.opacity(0.9))
.foregroundColor(titleColor)
Spacer()

}
Expand Down Expand Up @@ -75,6 +85,7 @@ struct AIPromptPopView: View {
}

struct AIPromptPopCellView: View {
@Environment(\.colorScheme) private var colorScheme
let item: Prompt
let isSelected: Bool
let action: () -> Void
Expand All @@ -86,7 +97,7 @@ struct AIPromptPopCellView: View {
.resizable()
.scaledToFit()
.frame(width: 20, height: 20)
.foregroundColor(.white)
.foregroundColor((colorScheme == .dark) ? .white.opacity(0.8) : .white)
.background(Color.blue)
.clipShape(Circle())
.padding(5)
Expand All @@ -102,28 +113,28 @@ struct AIPromptPopCellView: View {
HStack {
Text("【默认无修饰语】")
.font(Font.system(size: 15))
.foregroundColor(.white)
.foregroundColor((colorScheme == .dark) ? .white.opacity(0.8) : .white)
.padding(.trailing, 6)
.padding(.bottom, 6)
Text("当前选中的修饰语")
.font(Font.system(size: 14))
.foregroundColor(.white)
.foregroundColor((colorScheme == .dark) ? .white.opacity(0.8) : .white)
.padding(.bottom, 6)
}
Text("每个会话只能选择一个修饰语, 也可以自定义添加修饰语")
.font(.subheadline)
.foregroundColor(.white.opacity(1))
.foregroundColor((colorScheme == .dark) ? .white.opacity(0.6) : .white)
}.padding(.leading, 2)
}else {
VStack(alignment: .leading, spacing: 4) {
Text(item.title ?? "")
.font(.headline)
.foregroundColor(.white)
.foregroundColor((colorScheme == .dark) ? .white.opacity(0.8) : .white)
.foregroundColor(.primary)
.padding(.bottom, 6)
Text(item.prompt ?? "")
.font(.subheadline)
.foregroundColor(.white.opacity(1))
.foregroundColor((colorScheme == .dark) ? .white.opacity(0.6) : .white)
}.padding(.leading, 2)
}

Expand All @@ -133,7 +144,7 @@ struct AIPromptPopCellView: View {
.padding(.vertical, 5)
.padding(.horizontal, 10)
.background(
item.color
item.color.brightness((self.colorScheme == .dark) ? -0.5 : -0.2)
)
.cornerRadius(6)
.onTapGesture {
Expand Down
14 changes: 11 additions & 3 deletions OSXChatGPT/OSXChatGPT/WindowView/ChatRoomView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,15 @@ struct ChatRoomView: View {
struct ChatRoomCellView: View {
let message: Message
@EnvironmentObject var viewModel: ViewModel
private let theme: Theme = .basic
@Environment(\.colorScheme) private var colorScheme
var gptBubbleColor: Color {
switch colorScheme {
case .dark:
return Color.gray.opacity(0.1)
default:
return Color.white.opacity(0.9)
}
}
var body: some View {
HStack {
if message.role != ChatGPTManager.shared.gptRoleString {
Expand Down Expand Up @@ -171,8 +179,8 @@ struct ChatRoomCellView: View {
Markdown(message.text ?? "")
.padding(12)
.textSelection(.enabled)
.markdownCodeSyntaxHighlighter(.splash(theme: viewModel.theme))
.background(Color.white.opacity(0.8))
.markdownCodeSyntaxHighlighter(.splash(theme: viewModel.codeTheme(scheme: colorScheme)))
.background(gptBubbleColor)
.cornerRadius(6)
}.id(message.id)
.contextMenu {
Expand Down

0 comments on commit de32b9a

Please sign in to comment.