Dynamic background add switch

This commit is contained in:
陈连辰
2023-04-12 21:39:56 +08:00
parent 34e1f51681
commit aad6b48224
5 changed files with 51 additions and 4 deletions

View File

@@ -48,6 +48,7 @@
CB53A3BF29D48C8F00A5B8FC /* Prompt+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB53A3BD29D48C8F00A5B8FC /* Prompt+CoreDataProperties.swift */; };
CBC4B12329B8D28D00650296 /* Message+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBC4B11D29B8D28D00650296 /* Message+CoreDataClass.swift */; };
CBC4B12429B8D28D00650296 /* Message+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBC4B11E29B8D28D00650296 /* Message+CoreDataProperties.swift */; };
CBD5AB6429E6DE9A007B6625 /* ProjectSettingManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBD5AB6329E6DE9A007B6625 /* ProjectSettingManager.swift */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -91,6 +92,7 @@
CBC4B0FE29B8BF9600650296 /* OSXChatGPT.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = OSXChatGPT.xcdatamodel; sourceTree = "<group>"; };
CBC4B11D29B8D28D00650296 /* Message+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Message+CoreDataClass.swift"; sourceTree = "<group>"; };
CBC4B11E29B8D28D00650296 /* Message+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Message+CoreDataProperties.swift"; sourceTree = "<group>"; };
CBD5AB6329E6DE9A007B6625 /* ProjectSettingManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProjectSettingManager.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -160,6 +162,7 @@
182B437129BC5D1B00F06778 /* ChatGPTManager.swift */,
182B436F29BC5D1B00F06778 /* CoreDataManager.swift */,
182B437029BC5D1B00F06778 /* ViewModel.swift */,
CBD5AB6329E6DE9A007B6625 /* ProjectSettingManager.swift */,
CB28A52129C07BE500F0286A /* KeyboardMonitor.swift */,
CB27657229D30F1400897E0E /* AIPromptViewMdoel.swift */,
CB2449F729D721F3006EE829 /* SystemManager.swift */,
@@ -340,6 +343,7 @@
CB27657529D33D7A00897E0E /* AIPromptInputView.swift in Sources */,
182B437229BC5D1B00F06778 /* HTTPClient.swift in Sources */,
CB53A3BF29D48C8F00A5B8FC /* Prompt+CoreDataProperties.swift in Sources */,
CBD5AB6429E6DE9A007B6625 /* ProjectSettingManager.swift in Sources */,
182B436829BC5C8700F06778 /* MainContentView.swift in Sources */,
CB28A52829C1569900F0286A /* ThinkingAnimationView.swift in Sources */,
182B437529BC5D1B00F06778 /* ChatGPTManager.swift in Sources */,

View File

@@ -0,0 +1,28 @@
//
// ProjectSettingManager.swift
// OSXChatGPT
//
// Created by CoderChan on 2023/4/12.
//
import Foundation
class ProjectSettingManager {
static let shared = ProjectSettingManager()
private init() {}
///
var showDynamicBackground: Bool {
get {
let show = UserDefaults.standard.bool(forKey: "kshowDynamicBackground_key")
return show
}
set {
UserDefaults.standard.set(newValue, forKey: "kshowDynamicBackground_key")
}
}
}

View File

@@ -13,6 +13,7 @@ import Splash
@MainActor class ViewModel: ObservableObject {
@Published var showDynamicBackground: Bool = ProjectSettingManager.shared.showDynamicBackground//
@Published var conversations: [Conversation] = []//
@Published var messages: [Message] = []//
@Published var showUserInitialize: Bool = false//

View File

@@ -15,14 +15,26 @@ struct OSXChatGPTApp: App {
var body: some Scene {
WindowGroup {
ZStack {
ColorfulView(colors: [.accentColor], colorCount: 1)
.ignoresSafeArea()
if viewModel.showDynamicBackground {
ColorfulView(colors: [.accentColor], colorCount: 1)
.ignoresSafeArea()
}
MainContentView().environmentObject(viewModel).edgesIgnoringSafeArea(.top).frame(minWidth: 900, maxWidth: .infinity, minHeight: 600, maxHeight: .infinity)
}
}
.windowToolbarStyle(.unified)
.commands { SidebarCommands() }
.commands { CommandGroup(replacing: CommandGroupPlacement.newItem) {} }
.commands {
CommandMenu("Setting") {
Menu(viewModel.showDynamicBackground ? "隐藏动态背景" : "显示动态背景") {
Text(viewModel.showDynamicBackground ? "已显示" : "已隐藏")
} primaryAction: {
viewModel.showDynamicBackground.toggle()
ProjectSettingManager.shared.showDynamicBackground = viewModel.showDynamicBackground
}
}
}
}
}

View File

@@ -13,8 +13,10 @@ struct SessionsView: View {
@Environment(\.presentationMode) var presentationMode
var body: some View {
ZStack {
ColorfulView(colors: [.accentColor], colorCount: 1)
.ignoresSafeArea()
if viewModel.showDynamicBackground {
ColorfulView(colors: [.accentColor], colorCount: 1)
.ignoresSafeArea()
}
VStack {
HStack(spacing: 10, content: {
NavigationLink(destination: viewModel.getChatRoomView(conversation: viewModel.currentConversation).environmentObject(viewModel), isActive: $viewModel.createNewChat) {