From aad6b48224f6b97b685c745cf1bc377c8be0ae22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E8=BF=9E=E8=BE=B0?= Date: Wed, 12 Apr 2023 21:39:56 +0800 Subject: [PATCH] Dynamic background add switch --- .../OSXChatGPT.xcodeproj/project.pbxproj | 4 +++ .../DataProvider/ProjectSettingManager.swift | 28 +++++++++++++++++++ .../OSXChatGPT/DataProvider/ViewModel.swift | 1 + .../OSXChatGPT/Interface/OSXChatGPTApp.swift | 16 +++++++++-- .../OSXChatGPT/WindowView/SessionsView.swift | 6 ++-- 5 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 OSXChatGPT/OSXChatGPT/DataProvider/ProjectSettingManager.swift diff --git a/OSXChatGPT/OSXChatGPT.xcodeproj/project.pbxproj b/OSXChatGPT/OSXChatGPT.xcodeproj/project.pbxproj index c013bdc..9f28cf8 100644 --- a/OSXChatGPT/OSXChatGPT.xcodeproj/project.pbxproj +++ b/OSXChatGPT/OSXChatGPT.xcodeproj/project.pbxproj @@ -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 = ""; }; CBC4B11D29B8D28D00650296 /* Message+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Message+CoreDataClass.swift"; sourceTree = ""; }; CBC4B11E29B8D28D00650296 /* Message+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Message+CoreDataProperties.swift"; sourceTree = ""; }; + CBD5AB6329E6DE9A007B6625 /* ProjectSettingManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProjectSettingManager.swift; sourceTree = ""; }; /* 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 */, diff --git a/OSXChatGPT/OSXChatGPT/DataProvider/ProjectSettingManager.swift b/OSXChatGPT/OSXChatGPT/DataProvider/ProjectSettingManager.swift new file mode 100644 index 0000000..6abe7d5 --- /dev/null +++ b/OSXChatGPT/OSXChatGPT/DataProvider/ProjectSettingManager.swift @@ -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") + } + } + + + + +} diff --git a/OSXChatGPT/OSXChatGPT/DataProvider/ViewModel.swift b/OSXChatGPT/OSXChatGPT/DataProvider/ViewModel.swift index 7cc13ed..f3efa6b 100644 --- a/OSXChatGPT/OSXChatGPT/DataProvider/ViewModel.swift +++ b/OSXChatGPT/OSXChatGPT/DataProvider/ViewModel.swift @@ -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//显示设置页 diff --git a/OSXChatGPT/OSXChatGPT/Interface/OSXChatGPTApp.swift b/OSXChatGPT/OSXChatGPT/Interface/OSXChatGPTApp.swift index 540b2ad..199e70b 100644 --- a/OSXChatGPT/OSXChatGPT/Interface/OSXChatGPTApp.swift +++ b/OSXChatGPT/OSXChatGPT/Interface/OSXChatGPTApp.swift @@ -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 + } + } + } } } diff --git a/OSXChatGPT/OSXChatGPT/WindowView/SessionsView.swift b/OSXChatGPT/OSXChatGPT/WindowView/SessionsView.swift index db7815d..45c2d7a 100644 --- a/OSXChatGPT/OSXChatGPT/WindowView/SessionsView.swift +++ b/OSXChatGPT/OSXChatGPT/WindowView/SessionsView.swift @@ -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) {