Add logger + log console

This commit is contained in:
Shav Kinderlehrer 2023-12-12 19:51:54 -05:00
parent 9ccd37f754
commit 3994a6f408
6 changed files with 117 additions and 12 deletions

View File

@ -11,6 +11,9 @@
3D1015DC2B27F5D300F5C29A /* Model.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 3D1015DA2B27F5D300F5C29A /* Model.xcdatamodeld */; }; 3D1015DC2B27F5D300F5C29A /* Model.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 3D1015DA2B27F5D300F5C29A /* Model.xcdatamodeld */; };
3D1015DE2B27F79900F5C29A /* DatamodelController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D1015DD2B27F79900F5C29A /* DatamodelController.swift */; }; 3D1015DE2B27F79900F5C29A /* DatamodelController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D1015DD2B27F79900F5C29A /* DatamodelController.swift */; };
3D1015E42B28000E00F5C29A /* AuthStateController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D1015E32B28000E00F5C29A /* AuthStateController.swift */; }; 3D1015E42B28000E00F5C29A /* AuthStateController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D1015E32B28000E00F5C29A /* AuthStateController.swift */; };
3D7709392B29139700199889 /* Pulse in Frameworks */ = {isa = PBXBuildFile; productRef = 3D7709382B29139700199889 /* Pulse */; };
3D77093B2B29139700199889 /* PulseUI in Frameworks */ = {isa = PBXBuildFile; productRef = 3D77093A2B29139700199889 /* PulseUI */; };
3D77093D2B29350700199889 /* ConsoleSheetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D77093C2B29350700199889 /* ConsoleSheetView.swift */; };
3D9063CB2B279A310063DD2A /* JelApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D9063CA2B279A310063DD2A /* JelApp.swift */; }; 3D9063CB2B279A310063DD2A /* JelApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D9063CA2B279A310063DD2A /* JelApp.swift */; };
3D9063CD2B279A310063DD2A /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D9063CC2B279A310063DD2A /* ContentView.swift */; }; 3D9063CD2B279A310063DD2A /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D9063CC2B279A310063DD2A /* ContentView.swift */; };
3D9063CF2B279A320063DD2A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3D9063CE2B279A320063DD2A /* Assets.xcassets */; }; 3D9063CF2B279A320063DD2A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3D9063CE2B279A320063DD2A /* Assets.xcassets */; };
@ -61,6 +64,7 @@
3D1015DB2B27F5D300F5C29A /* Model.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Model.xcdatamodel; sourceTree = "<group>"; }; 3D1015DB2B27F5D300F5C29A /* Model.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Model.xcdatamodel; sourceTree = "<group>"; };
3D1015DD2B27F79900F5C29A /* DatamodelController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatamodelController.swift; sourceTree = "<group>"; }; 3D1015DD2B27F79900F5C29A /* DatamodelController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatamodelController.swift; sourceTree = "<group>"; };
3D1015E32B28000E00F5C29A /* AuthStateController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthStateController.swift; sourceTree = "<group>"; }; 3D1015E32B28000E00F5C29A /* AuthStateController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthStateController.swift; sourceTree = "<group>"; };
3D77093C2B29350700199889 /* ConsoleSheetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConsoleSheetView.swift; sourceTree = "<group>"; };
3D9063C72B279A310063DD2A /* Jel.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Jel.app; sourceTree = BUILT_PRODUCTS_DIR; }; 3D9063C72B279A310063DD2A /* Jel.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Jel.app; sourceTree = BUILT_PRODUCTS_DIR; };
3D9063CA2B279A310063DD2A /* JelApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JelApp.swift; sourceTree = "<group>"; }; 3D9063CA2B279A310063DD2A /* JelApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JelApp.swift; sourceTree = "<group>"; };
3D9063CC2B279A310063DD2A /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; }; 3D9063CC2B279A310063DD2A /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
@ -84,6 +88,8 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
3D77093B2B29139700199889 /* PulseUI in Frameworks */,
3D7709392B29139700199889 /* Pulse in Frameworks */,
3D9064592B27E4C70063DD2A /* JellyfinKit in Frameworks */, 3D9064592B27E4C70063DD2A /* JellyfinKit in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
@ -110,6 +116,7 @@
children = ( children = (
3D9063CC2B279A310063DD2A /* ContentView.swift */, 3D9063CC2B279A310063DD2A /* ContentView.swift */,
3D91FDC52B28C28900919017 /* SignIn */, 3D91FDC52B28C28900919017 /* SignIn */,
3D77093C2B29350700199889 /* ConsoleSheetView.swift */,
); );
path = Views; path = Views;
sourceTree = "<group>"; sourceTree = "<group>";
@ -223,6 +230,8 @@
name = Jel; name = Jel;
packageProductDependencies = ( packageProductDependencies = (
3D9064582B27E4C70063DD2A /* JellyfinKit */, 3D9064582B27E4C70063DD2A /* JellyfinKit */,
3D7709382B29139700199889 /* Pulse */,
3D77093A2B29139700199889 /* PulseUI */,
); );
productName = Jel; productName = Jel;
productReference = 3D9063C72B279A310063DD2A /* Jel.app */; productReference = 3D9063C72B279A310063DD2A /* Jel.app */;
@ -297,6 +306,7 @@
); );
mainGroup = 3D9063BE2B279A310063DD2A; mainGroup = 3D9063BE2B279A310063DD2A;
packageReferences = ( packageReferences = (
3D7709372B29139700199889 /* XCRemoteSwiftPackageReference "Pulse" */,
); );
productRefGroup = 3D9063C82B279A310063DD2A /* Products */; productRefGroup = 3D9063C82B279A310063DD2A /* Products */;
projectDirPath = ""; projectDirPath = "";
@ -346,6 +356,7 @@
3D1015D92B27F57400F5C29A /* AddServerView.swift in Sources */, 3D1015D92B27F57400F5C29A /* AddServerView.swift in Sources */,
3D9063CB2B279A310063DD2A /* JelApp.swift in Sources */, 3D9063CB2B279A310063DD2A /* JelApp.swift in Sources */,
3D91FDCD2B2907E800919017 /* JellyfinDateFormatter.swift in Sources */, 3D91FDCD2B2907E800919017 /* JellyfinDateFormatter.swift in Sources */,
3D77093D2B29350700199889 /* ConsoleSheetView.swift in Sources */,
3D1015DC2B27F5D300F5C29A /* Model.xcdatamodeld in Sources */, 3D1015DC2B27F5D300F5C29A /* Model.xcdatamodeld in Sources */,
3D91FDC92B28C62800919017 /* SignInView.swift in Sources */, 3D91FDC92B28C62800919017 /* SignInView.swift in Sources */,
3D91FDCB2B28CA2500919017 /* SignInToServerView.swift in Sources */, 3D91FDCB2B28CA2500919017 /* SignInToServerView.swift in Sources */,
@ -713,7 +724,28 @@
}; };
/* End XCConfigurationList section */ /* End XCConfigurationList section */
/* Begin XCRemoteSwiftPackageReference section */
3D7709372B29139700199889 /* XCRemoteSwiftPackageReference "Pulse" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/kean/Pulse";
requirement = {
kind = upToNextMinorVersion;
minimumVersion = 4.0.5;
};
};
/* End XCRemoteSwiftPackageReference section */
/* Begin XCSwiftPackageProductDependency section */ /* Begin XCSwiftPackageProductDependency section */
3D7709382B29139700199889 /* Pulse */ = {
isa = XCSwiftPackageProductDependency;
package = 3D7709372B29139700199889 /* XCRemoteSwiftPackageReference "Pulse" */;
productName = Pulse;
};
3D77093A2B29139700199889 /* PulseUI */ = {
isa = XCSwiftPackageProductDependency;
package = 3D7709372B29139700199889 /* XCRemoteSwiftPackageReference "Pulse" */;
productName = PulseUI;
};
3D9064582B27E4C70063DD2A /* JellyfinKit */ = { 3D9064582B27E4C70063DD2A /* JellyfinKit */ = {
isa = XCSwiftPackageProductDependency; isa = XCSwiftPackageProductDependency;
productName = JellyfinKit; productName = JellyfinKit;

View File

@ -10,6 +10,15 @@
"version": "2.1.6" "version": "2.1.6"
} }
}, },
{
"package": "Pulse",
"repositoryURL": "https://github.com/kean/Pulse",
"state": {
"branch": null,
"revision": "d647e99f06abc94d63579e335ad4ce368195c149",
"version": "4.0.5"
}
},
{ {
"package": "URLQueryEncoder", "package": "URLQueryEncoder",
"repositoryURL": "https://github.com/CreateAPI/URLQueryEncoder", "repositoryURL": "https://github.com/CreateAPI/URLQueryEncoder",

View File

@ -11,15 +11,17 @@ class AuthStateController: ObservableObject {
@Published var loggedIn: Bool @Published var loggedIn: Bool
@Published var serverUrl: URL? @Published var serverUrl: URL?
@Published var authToken: String? @Published var authToken: String?
@Published var userId: String?
private let defaults = UserDefaults.standard private let defaults = UserDefaults.standard
static let shared = AuthStateController() static let shared = AuthStateController()
init(loggedIn: Bool = false, serverUrl: URL? = nil, authToken: String? = nil) { init(loggedIn: Bool = false, serverUrl: URL? = nil, authToken: String? = nil, userId: String? = nil) {
self.loggedIn = loggedIn self.loggedIn = loggedIn
self.serverUrl = serverUrl self.serverUrl = serverUrl
self.authToken = authToken self.authToken = authToken
self.userId = userId
} }
func load() { func load() {
@ -30,11 +32,15 @@ class AuthStateController: ObservableObject {
if let oldAuthToken = defaults.string(forKey: "AuthState_authToken") { if let oldAuthToken = defaults.string(forKey: "AuthState_authToken") {
self.authToken = oldAuthToken self.authToken = oldAuthToken
} }
if let oldUserId = defaults.string(forKey: "AuthState_userId") {
self.userId = oldUserId
}
} }
func save() { func save() {
defaults.set(self.loggedIn, forKey: "AuthState_loggedIn") defaults.set(self.loggedIn, forKey: "AuthState_loggedIn")
defaults.set(self.serverUrl, forKey: "AuthState_serverUrl") defaults.set(self.serverUrl, forKey: "AuthState_serverUrl")
defaults.set(self.authToken, forKey: "AuthState_authToken") defaults.set(self.authToken, forKey: "AuthState_authToken")
defaults.set(self.userId, forKey: "AuthState_userId")
} }
} }

View File

@ -8,6 +8,7 @@
import Foundation import Foundation
import Get import Get
import JellyfinKit import JellyfinKit
import Pulse
struct AuthHeaders: Codable { struct AuthHeaders: Codable {
var Client: String var Client: String
@ -56,6 +57,8 @@ class JellyfinClientController: ObservableObject {
let decoder = JSONDecoder() let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .iso8601withFractionalSeconds decoder.dateDecodingStrategy = .iso8601withFractionalSeconds
$0.decoder = decoder $0.decoder = decoder
$0.sessionDelegate = Pulse.URLSessionProxyDelegate()
}) })
} }

View File

@ -0,0 +1,43 @@
//
// ConsoleSheetView.swift
// Jel
//
// Created by zerocool on 12/12/23.
//
import SwiftUI
import PulseUI
struct ConsoleSheetView: View {
@Binding var showingConsoleSheet: Bool
var body: some View {
NavigationStack {
List {
NavigationLink {
ConsoleView(mode: .network)
.closeButtonHidden()
} label: {
Text("Network Console")
}
NavigationLink {
ConsoleView(mode: .logs)
.closeButtonHidden()
} label: {
Text("Logs Console")
}
}
.toolbar {
Button {
showingConsoleSheet.toggle()
} label: {
Text("Done")
}
}
}
}
}
#Preview {
ConsoleSheetView(showingConsoleSheet: .constant(true))
}

View File

@ -6,11 +6,23 @@
// //
import SwiftUI import SwiftUI
import PulseUI
struct ContentView: View { struct ContentView: View {
@ObservedObject var authState: AuthStateController @ObservedObject var authState: AuthStateController
@State var showingConsoleSheet: Bool = false
var body: some View { var body: some View {
VStack { VStack {
Button {
showingConsoleSheet.toggle()
} label: {
Label("Console", systemImage: "network")
}
.sheet(isPresented: $showingConsoleSheet) {
ConsoleSheetView(showingConsoleSheet: $showingConsoleSheet)
}
if !authState.loggedIn { if !authState.loggedIn {
SignInView(authState: authState) SignInView(authState: authState)
} else { } else {