Skip to content

Commit

Permalink
Dynamic background add switch
Browse files Browse the repository at this point in the history
  • Loading branch information
CoderLineChan committed Apr 12, 2023
1 parent 34e1f51 commit aad6b48
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 deletions.
4 changes: 4 additions & 0 deletions OSXChatGPT/OSXChatGPT.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
28 changes: 28 additions & 0 deletions OSXChatGPT/OSXChatGPT/DataProvider/ProjectSettingManager.swift
Original file line number Diff line number Diff line change
@@ -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")
}
}




}
1 change: 1 addition & 0 deletions OSXChatGPT/OSXChatGPT/DataProvider/ViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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//显示设置页
Expand Down
16 changes: 14 additions & 2 deletions OSXChatGPT/OSXChatGPT/Interface/OSXChatGPTApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
}

6 changes: 4 additions & 2 deletions OSXChatGPT/OSXChatGPT/WindowView/SessionsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit aad6b48

Please sign in to comment.