Initialize SessionView & UserWelcomeView & Enter API key

This commit is contained in:
MustangYM
2023-03-11 03:59:59 +08:00
parent 8228ca2fd9
commit 35e762f2c3
10 changed files with 304 additions and 40 deletions

View File

@@ -7,6 +7,11 @@
objects = {
/* Begin PBXBuildFile section */
182B42B629BBA82800F06778 /* Storyboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 182B42B529BBA82800F06778 /* Storyboard.storyboard */; };
182B42BB29BBAE5F00F06778 /* SessionsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 182B42BA29BBAE5F00F06778 /* SessionsView.swift */; };
182B42BD29BBAEAA00F06778 /* UserInitializeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 182B42BC29BBAEAA00F06778 /* UserInitializeView.swift */; };
182B42C929BBB1C500F06778 /* Colorful in Frameworks */ = {isa = PBXBuildFile; productRef = 182B42C829BBB1C500F06778 /* Colorful */; };
182B42CB29BBBCE800F06778 /* View.swift in Sources */ = {isa = PBXBuildFile; fileRef = 182B42CA29BBBCE800F06778 /* View.swift */; };
CB1DCAC229B4F09D00B1D4E1 /* OSXChatGPTApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB1DCAC129B4F09D00B1D4E1 /* OSXChatGPTApp.swift */; };
CB1DCAC629B4F09F00B1D4E1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CB1DCAC529B4F09F00B1D4E1 /* Assets.xcassets */; };
CB1DCAC929B4F09F00B1D4E1 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CB1DCAC829B4F09F00B1D4E1 /* Preview Assets.xcassets */; };
@@ -25,6 +30,11 @@
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
182B42B529BBA82800F06778 /* Storyboard.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Storyboard.storyboard; sourceTree = "<group>"; };
182B42BA29BBAE5F00F06778 /* SessionsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SessionsView.swift; sourceTree = "<group>"; };
182B42BC29BBAEAA00F06778 /* UserInitializeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserInitializeView.swift; sourceTree = "<group>"; };
182B42C329BBB00500F06778 /* Colorful */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = Colorful; path = Third/Colorful; sourceTree = "<group>"; };
182B42CA29BBBCE800F06778 /* View.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = View.swift; sourceTree = "<group>"; };
CB1DCABE29B4F09D00B1D4E1 /* OSXChatGPT.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OSXChatGPT.app; sourceTree = BUILT_PRODUCTS_DIR; };
CB1DCAC129B4F09D00B1D4E1 /* OSXChatGPTApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSXChatGPTApp.swift; sourceTree = "<group>"; };
CB1DCAC529B4F09F00B1D4E1 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@@ -49,17 +59,37 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
182B42C929BBB1C500F06778 /* Colorful in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
182B42B929BBAE5F00F06778 /* InterfaceView */ = {
isa = PBXGroup;
children = (
182B42BA29BBAE5F00F06778 /* SessionsView.swift */,
182B42BC29BBAEAA00F06778 /* UserInitializeView.swift */,
182B42CA29BBBCE800F06778 /* View.swift */,
);
path = InterfaceView;
sourceTree = "<group>";
};
182B42C229BBB00500F06778 /* Frameworks */ = {
isa = PBXGroup;
children = (
182B42C329BBB00500F06778 /* Colorful */,
);
name = Frameworks;
sourceTree = "<group>";
};
CB1DCAB529B4F09D00B1D4E1 = {
isa = PBXGroup;
children = (
CB1DCAC029B4F09D00B1D4E1 /* OSXChatGPT */,
CB1DCABF29B4F09D00B1D4E1 /* Products */,
182B42C229BBB00500F06778 /* Frameworks */,
);
sourceTree = "<group>";
};
@@ -74,8 +104,10 @@
CB1DCAC029B4F09D00B1D4E1 /* OSXChatGPT */ = {
isa = PBXGroup;
children = (
182B42B929BBAE5F00F06778 /* InterfaceView */,
CBC4B11429B8CB1B00650296 /* Models */,
CB1DCAC129B4F09D00B1D4E1 /* OSXChatGPTApp.swift */,
182B42B529BBA82800F06778 /* Storyboard.storyboard */,
CB1DCAD029B4F0C800B1D4E1 /* ChatMessageView.swift */,
CB1DCAD229B4F0EF00B1D4E1 /* ChatGPTManager.swift */,
CBC4B11929B8D11500650296 /* CoreDataManager.swift */,
@@ -126,6 +158,9 @@
dependencies = (
);
name = OSXChatGPT;
packageProductDependencies = (
182B42C829BBB1C500F06778 /* Colorful */,
);
productName = OSXChatGPT;
productReference = CB1DCABE29B4F09D00B1D4E1 /* OSXChatGPT.app */;
productType = "com.apple.product-type.application";
@@ -154,6 +189,9 @@
Base,
);
mainGroup = CB1DCAB529B4F09D00B1D4E1;
packageReferences = (
182B42C729BBB1C500F06778 /* XCRemoteSwiftPackageReference "Colorful" */,
);
productRefGroup = CB1DCABF29B4F09D00B1D4E1 /* Products */;
projectDirPath = "";
projectRoot = "";
@@ -170,6 +208,7 @@
files = (
CB1DCAC929B4F09F00B1D4E1 /* Preview Assets.xcassets in Resources */,
CB1DCAC629B4F09F00B1D4E1 /* Assets.xcassets in Resources */,
182B42B629BBA82800F06778 /* Storyboard.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -180,15 +219,18 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
182B42CB29BBBCE800F06778 /* View.swift in Sources */,
CBC4B12829B8D28D00650296 /* UserRole+CoreDataProperties.swift in Sources */,
CBC4B12729B8D28D00650296 /* UserRole+CoreDataClass.swift in Sources */,
CBC4B11A29B8D11500650296 /* CoreDataManager.swift in Sources */,
CBC4B0FF29B8BF9600650296 /* OSXChatGPT.xcdatamodeld in Sources */,
182B42BD29BBAEAA00F06778 /* UserInitializeView.swift in Sources */,
CBC4B11629B8CB5300650296 /* HTTPClient.swift in Sources */,
CB1DCAD329B4F0EF00B1D4E1 /* ChatGPTManager.swift in Sources */,
CB1DCAD129B4F0C800B1D4E1 /* ChatMessageView.swift in Sources */,
CBC4B12429B8D28D00650296 /* Message+CoreDataProperties.swift in Sources */,
CB1DCAC229B4F09D00B1D4E1 /* OSXChatGPTApp.swift in Sources */,
182B42BB29BBAE5F00F06778 /* SessionsView.swift in Sources */,
CBC4B12629B8D28D00650296 /* Conversation+CoreDataProperties.swift in Sources */,
CBC4B11C29B8D23C00650296 /* ViewModel.swift in Sources */,
CBC4B12529B8D28D00650296 /* Conversation+CoreDataClass.swift in Sources */,
@@ -391,6 +433,25 @@
};
/* End XCConfigurationList section */
/* Begin XCRemoteSwiftPackageReference section */
182B42C729BBB1C500F06778 /* XCRemoteSwiftPackageReference "Colorful" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/Lakr233/Colorful";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.0.0;
};
};
/* End XCRemoteSwiftPackageReference section */
/* Begin XCSwiftPackageProductDependency section */
182B42C829BBB1C500F06778 /* Colorful */ = {
isa = XCSwiftPackageProductDependency;
package = 182B42C729BBB1C500F06778 /* XCRemoteSwiftPackageReference "Colorful" */;
productName = Colorful;
};
/* End XCSwiftPackageProductDependency section */
/* Begin XCVersionGroup section */
CBC4B0FD29B8BF9600650296 /* OSXChatGPT.xcdatamodeld */ = {
isa = XCVersionGroup;

View File

@@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "colorful",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Lakr233/Colorful",
"state" : {
"revision" : "0bcf960c856d9f7cde10a0b464208585736c5e47",
"version" : "1.1.0"
}
}
],
"version" : 2
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

View File

@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "App_Icon.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -9,46 +9,10 @@ import SwiftUI
import AppKit
/// main View
struct ContentView: View {
@EnvironmentObject var viewModel: ViewModel
@State private var searchText = ""
@State private var shouldNavigate = false
var body: some View {
NavigationView {
VStack {
HStack {
SearchBar(text: $searchText)
.frame(minWidth: 100, idealWidth: 200, maxWidth: 200, minHeight: 40, idealHeight: 40, maxHeight: 40)
.padding(.init(top: 10, leading: 10, bottom: 0, trailing: 0))
NavigationLink(destination: ChatView(sesstionId: viewModel.createSesstionId()).environmentObject(viewModel), isActive: $shouldNavigate) {
Button {
self.shouldNavigate = true
} label: {
Text("New")
.padding(5)
Spacer()
}.background(Color.clear)
}.frame(minWidth: 30, idealWidth: 30, maxWidth: 30, minHeight: 30, idealHeight: 30, maxHeight: 30)
.padding(.init(top: 10, leading: 0, bottom: 0, trailing: 10))
}.frame(minHeight: 40, idealHeight: 40, maxHeight: 50)
Divider()
List(viewModel.conversations.filter({ searchText.isEmpty ? true : $0.sesstionId.localizedCaseInsensitiveContains(searchText) })) { chat in
NavigationLink(destination: ChatView(sesstionId: chat.sesstionId).environmentObject(viewModel)) {
ChatRowContent(chat: chat)
}
}
.listStyle(SidebarListStyle())
.padding(.top, 1)
Spacer()
}
.frame(minWidth: 250, idealWidth: 300, maxWidth: 300)
Text("请选择一个会话")
.frame(maxWidth: .infinity, maxHeight: .infinity)
SessionsView()
UserInitializeView()
}
}
}

View File

@@ -0,0 +1,55 @@
//
// SessionsView.swift
// OSXChatGPT
//
// Created by MustangYM on 2023/3/11.
//
import SwiftUI
struct SessionsView: View {
@EnvironmentObject var viewModel: ViewModel
@State private var searchText = ""
@State private var shouldNavigate = false
var body: some View {
VStack {
HStack {
SearchBar(text: $searchText)
.frame(minWidth: 100, idealWidth: 200, maxWidth: 200, minHeight: 40, idealHeight: 40, maxHeight: 40)
.padding(.init(top: 10, leading: 10, bottom: 0, trailing: 0))
NavigationLink(destination: ChatView(sesstionId: viewModel.createSesstionId()).environmentObject(viewModel), isActive: $shouldNavigate) {
Button {
self.shouldNavigate = true
} label: {
Text("New")
.padding(5)
Spacer()
}.background(Color.clear)
}.frame(minWidth: 30, idealWidth: 30, maxWidth: 30, minHeight: 30, idealHeight: 30, maxHeight: 30)
.padding(.init(top: 10, leading: 0, bottom: 0, trailing: 10))
}.frame(minHeight: 40, idealHeight: 40, maxHeight: 50)
Divider()
List(viewModel.conversations.filter({ searchText.isEmpty ? true : $0.sesstionId.localizedCaseInsensitiveContains(searchText) })) { chat in
NavigationLink(destination: ChatView(sesstionId: chat.sesstionId).environmentObject(viewModel)) {
ChatRowContent(chat: chat)
}
}
.listStyle(SidebarListStyle())
.padding(.top, 1)
Spacer()
}
.frame(minWidth: 250, idealWidth: 300, maxWidth: 300)
}
}
struct SessionsView_Previews: PreviewProvider {
static var previews: some View {
SessionsView()
}
}

View File

@@ -0,0 +1,93 @@
//
// UserInitializeView.swift
// OSXChatGPT
//
// Created by MustangYM on 2023/3/11.
//
import Colorful
import SwiftUI
struct UserInitializeView: View {
var body: some View {
ColorfulView(colors: [.accentColor], colorCount: 4)
.ignoresSafeArea()
ZStack {
VStack(spacing: 20) {
Image("App_Icon")
.antialiased(true)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 80, height: 80)
HStack(spacing: 0) {
Text("OSXChatGPT")
.font(.system(size: 30, weight: .semibold, design: .rounded))
.foregroundColor(Color.clear)
.background(
LinearGradient(
gradient: Gradient(colors: [.pink, .blue]),
startPoint: .topLeading,
endPoint: .bottomTrailing
)
)
.mask(Text("OSXChatGPT")
.font(.system(size: 30, weight: .semibold, design: .rounded))
.foregroundColor(.white)
)
}
Text("A Better macOS application For ChatGPT")
.font(.system(.body, design: .rounded))
// API
Button(action: {
// apiKeyTapped.toggle()
}) {
HStack(spacing: 8) {
Image(systemName: "key.radiowaves.forward.fill")
Text("Enter API Key")
}
.foregroundColor(.white)
.padding(.horizontal, 16)
.padding(.vertical, 8)
.background(Color.blue)
.cornerRadius(10)
}
.buttonStyle(PlainButtonStyle()) //
}
}
.padding(.top,100)
.padding(.bottom,300)
.padding(.leading,200)
.padding(.trailing,200)
VStack {
Spacer()
Text("v1.0.0")
.font(.system(size: 12, weight: .light, design: .rounded))
.opacity(0.5)
Spacer().frame(height: 30)
}
}
}
extension Color {
static func gradient(
_ gradient: Gradient,
startPoint: UnitPoint = .top,
endPoint: UnitPoint = .bottom
) -> LinearGradient {
LinearGradient(
gradient: gradient,
startPoint: startPoint,
endPoint: endPoint
)
}
}
struct UserInitializeView_Previews: PreviewProvider {
static var previews: some View {
UserInitializeView()
}
}

View File

@@ -0,0 +1,19 @@
//
// View.swift
// OSXChatGPT
//
// Created by MustangYM on 2023/3/11.
//
import SwiftUI
extension View {
func usePreferredContentSize() -> some View {
frame(
minWidth: 400, idealWidth: 500, maxWidth: .infinity,
minHeight: 300, idealHeight: 350, maxHeight: .infinity,
alignment: .center
)
}
}

View File

@@ -13,7 +13,9 @@ struct OSXChatGPTApp: App {
var body: some Scene {
WindowGroup {
ContentView().environmentObject(viewModel)
// ContentView().environment(\.managedObjectContext, CoreDataManager.shared.container.viewContext).environmentObject(viewModel)
}
}//toolBar
.windowToolbarStyle(.expanded)
.commands { SidebarCommands() }
.commands { CommandGroup(replacing: CommandGroupPlacement.newItem) {} }
}
}

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="21507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="PEd-7d-5j0">
<objects>
<viewController id="bU7-R8-ocO" sceneMemberID="viewController">
<view key="view" id="tOy-S4-hL0">
<rect key="frame" x="0.0" y="0.0" width="450" height="300"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="obK-b7-uuc">
<rect key="frame" x="60" y="212" width="75" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Button" bezelStyle="rounded" image="key.radiowaves.forward.fill" catalog="system" imagePosition="overlaps" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="2Un-2f-eoO">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
</subviews>
</view>
</viewController>
<customObject id="9uD-mB-xHs" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="88" y="118"/>
</scene>
</scenes>
<resources>
<image name="key.radiowaves.forward.fill" catalog="system" width="17" height="19"/>
</resources>
</document>