Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions BookPlayer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@
C3FA301E20E0024900393DDA /* BPArtworkView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3FA301D20E0024900393DDA /* BPArtworkView.swift */; };
C3FE3F8220A090880055B9C6 /* limitPanAngle.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3FE3F8120A090880055B9C6 /* limitPanAngle.swift */; };
C451596D6866C856F3E5F7D1 /* IntegrationConnectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43D61F68F0A174C7CA44FE8A /* IntegrationConnectionView.swift */; };
B14881000000000000000001 /* IntegrationCustomHeadersSectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B14881000000000000000002 /* IntegrationCustomHeadersSectionView.swift */; };
C53864BEFAE4D1CEC668A6B3 /* IntegrationLibraryListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6F0D505E060FDAEB6DB68E3 /* IntegrationLibraryListView.swift */; };
CA3B408256F8458669106CF9 /* IntegrationConnectionViewModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D91D6855100BD1823B2674F /* IntegrationConnectionViewModelProtocol.swift */; };
D080B0A77D9844C3A0737170 /* IntegrationConnectionFormViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FB91B577BC77F45EDB2AAAA /* IntegrationConnectionFormViewModel.swift */; };
Expand Down Expand Up @@ -1226,6 +1227,7 @@
41FCA32625E87EC600BFB9E6 /* Audiobook Player 4.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Audiobook Player 4.xcdatamodel"; sourceTree = "<group>"; };
424AE6DFF6B641DB69DF3D78 /* IntegrationAudiobookDetailsView.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = IntegrationAudiobookDetailsView.swift; sourceTree = "<group>"; };
43D61F68F0A174C7CA44FE8A /* IntegrationConnectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntegrationConnectionView.swift; sourceTree = "<group>"; };
B14881000000000000000002 /* IntegrationCustomHeadersSectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntegrationCustomHeadersSectionView.swift; sourceTree = "<group>"; };
4645F9FC2D1E46AC00A04257 /* SwipeInlineTip.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwipeInlineTip.swift; sourceTree = "<group>"; };
465D87512D3195D600A4AA47 /* BookmarksView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarksView.swift; sourceTree = "<group>"; };
465D87532D31965100A4AA47 /* BookmarksViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarksViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1835,6 +1837,7 @@
35C564A7BDE3A2D98E02BF8B /* IntegrationConnectedView.swift */,
A5F919ABFCEF9B58EFE9D82E /* IntegrationServerInformationSectionView.swift */,
6FB91B577BC77F45EDB2AAAA /* IntegrationConnectionFormViewModel.swift */,
B14881000000000000000002 /* IntegrationCustomHeadersSectionView.swift */,
);
path = "Connection Screen";
sourceTree = "<group>";
Expand Down Expand Up @@ -4312,6 +4315,7 @@
buildActionMask = 2147483647;
files = (
C451596D6866C856F3E5F7D1 /* IntegrationConnectionView.swift in Sources */,
B14881000000000000000001 /* IntegrationCustomHeadersSectionView.swift in Sources */,
98BA9BA4D6A94BC8BCCE5F8B /* IntegrationSettingsView.swift in Sources */,
66DF1F3E6AFECB623A558F04 /* IntegrationDisconnectedView.swift in Sources */,
17239057BBE31E405AFFBBCD /* IntegrationServerFoundView.swift in Sources */,
Expand Down Expand Up @@ -5527,7 +5531,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
IPHONEOS_DEPLOYMENT_TARGET = 18.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_NAME = BookPlayer;
Expand All @@ -5536,7 +5540,7 @@
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
TARGETED_DEVICE_FAMILY = "1,2";
WATCHOS_DEPLOYMENT_TARGET = 7.0;
WATCHOS_DEPLOYMENT_TARGET = 10.0;
};
name = Debug;
};
Expand Down Expand Up @@ -5584,7 +5588,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
IPHONEOS_DEPLOYMENT_TARGET = 18.0;
MTL_ENABLE_DEBUG_INFO = NO;
PRODUCT_NAME = BookPlayer;
SDKROOT = iphoneos;
Expand All @@ -5593,7 +5597,7 @@
SWIFT_OPTIMIZATION_LEVEL = "-O";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
WATCHOS_DEPLOYMENT_TARGET = 7.0;
WATCHOS_DEPLOYMENT_TARGET = 10.0;
};
name = Release;
};
Expand Down Expand Up @@ -6132,7 +6136,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
IPHONEOS_DEPLOYMENT_TARGET = 18.0;
MTL_ENABLE_DEBUG_INFO = NO;
PRODUCT_NAME = BookPlayer;
SDKROOT = iphoneos;
Expand All @@ -6141,7 +6145,7 @@
SWIFT_OPTIMIZATION_LEVEL = "-O";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
WATCHOS_DEPLOYMENT_TARGET = 7.0;
WATCHOS_DEPLOYMENT_TARGET = 10.0;
};
name = Beta;
};
Expand Down
9 changes: 4 additions & 5 deletions BookPlayer/AudiobookShelf/AudiobookShelfRootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,12 @@ private struct AudiobookShelfTabRoot: View {
.tint(theme.linkColor)
.sheet(isPresented: $showConnectionDetails) {
NavigationStack {
IntegrationSettingsView(
viewModel: AudiobookShelfConnectionViewModel(
IntegrationSettingsView(integrationName: "AudiobookShelf") {
AudiobookShelfConnectionViewModel(
connectionService: connectionService,
mode: .viewDetails
),
integrationName: "AudiobookShelf"
)
)
}
.toolbar {
if connectionService.connection == nil {
ToolbarItemGroup(placement: .cancellationAction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ final class AudiobookShelfConnectionViewModel: IntegrationConnectionViewModelPro
let form = IntegrationConnectionFormViewModel()

if let data = connectionService.connection {
form.setValues(url: data.url.absoluteString, serverName: data.serverName, userName: data.userName)
form.setValues(
url: data.url.absoluteString,
serverName: data.serverName,
userName: data.userName,
customHeaders: data.customHeaders
)
self._connectionState = .init(initialValue: .connected)
} else {
self._connectionState = .init(initialValue: .disconnected)
Expand All @@ -40,7 +45,10 @@ final class AudiobookShelfConnectionViewModel: IntegrationConnectionViewModelPro

@MainActor
func handleConnectAction() async throws {
let serverName = try await connectionService.pingServer(at: form.serverUrl)
let serverName = try await connectionService.pingServer(
at: form.serverUrl,
customHeaders: form.customHeadersDictionary()
)
connectionState = .foundServer
form.serverName = serverName
}
Expand All @@ -52,7 +60,8 @@ final class AudiobookShelfConnectionViewModel: IntegrationConnectionViewModelPro
username: form.username,
password: form.password,
serverUrl: form.serverUrl,
serverName: form.serverName
serverName: form.serverName,
customHeaders: form.customHeadersDictionary()
)

connectionState = .connected
Expand All @@ -69,4 +78,9 @@ final class AudiobookShelfConnectionViewModel: IntegrationConnectionViewModelPro
form = IntegrationConnectionFormViewModel()
connectionState = .disconnected
}

@MainActor
func handleCustomHeadersUpdate() {
connectionService.updateCustomHeaders(form.customHeadersDictionary())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct AudiobookShelfLibraryItemImageView: View {
AudiobookShelfLibraryItemImageViewWrapper(
item: item,
url: connectionService.createItemImageURL(item, size: imageSize),
customHeaders: connectionService.connection?.customHeaders ?? [:],
imageSize: imageSize
)
.cornerRadius(max(3, min(proxy.size.width, proxy.size.height) * 0.02))
Expand All @@ -33,13 +34,21 @@ struct AudiobookShelfLibraryItemImageView: View {
fileprivate struct AudiobookShelfLibraryItemImageViewWrapper: View, Equatable {
let item: AudiobookShelfLibraryItem
let url: URL?
let customHeaders: [String: String]
let imageSize: CGSize

@EnvironmentObject var themeViewModel: ThemeViewModel

var body: some View {
KFImage
.url(url)
.requestModifier(AnyModifier { request in
var request = request
for (key, value) in customHeaders {
request.setValue(value, forHTTPHeaderField: key)
}
return request
})
.cancelOnDisappear(true)
.cacheMemoryOnly()
.resizable()
Expand All @@ -48,7 +57,9 @@ fileprivate struct AudiobookShelfLibraryItemImageViewWrapper: View, Equatable {
}

static func == (lhs: Self, rhs: Self) -> Bool {
return lhs.item.id == rhs.item.id && lhs.url == rhs.url
return lhs.item.id == rhs.item.id
&& lhs.url == rhs.url
&& lhs.customHeaders == rhs.customHeaders
}

@ViewBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,18 @@ final class AudiobookShelfLibraryViewModel: IntegrationLibraryViewModelProtocol,
self.items.first(where: { $0.id == id && $0.isDownloadable })
}

var urls = [URL]()
var requests = [URLRequest]()
for item in items {
do {
let url = try connectionService.createItemDownloadUrl(item)
urls.append(url)
let request = try connectionService.createItemDownloadRequest(item)
requests.append(request)
} catch {
self.error = error
}
}

guard !urls.isEmpty else { return }
singleFileDownloadService.handleDownload(urls)
guard !requests.isEmpty else { return }
singleFileDownloadService.handleDownload(requests)
navigation.dismiss?()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class AudiobookShelfAudiobookDetailsViewModel: IntegrationDetailsViewModelProtoc

@MainActor
func beginDownloadAudiobook(_ item: AudiobookShelfLibraryItem) throws {
let url = try connectionService.createItemDownloadUrl(item)
singleFileDownloadService.handleDownload(url)
let request = try connectionService.createItemDownloadRequest(item)
singleFileDownloadService.handleDownload(request)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,40 @@ struct AudiobookShelfConnectionData: Codable {
let userName: String
let apiToken: String
var selectedLibraryId: String?
var customHeaders: [String: String] = [:]

enum CodingKeys: String, CodingKey {
case url, serverName, userID, userName, apiToken, selectedLibraryId, customHeaders
}

init(
url: URL,
serverName: String,
userID: String,
userName: String,
apiToken: String,
selectedLibraryId: String? = nil,
customHeaders: [String: String] = [:]
) {
self.url = url
self.serverName = serverName
self.userID = userID
self.userName = userName
self.apiToken = apiToken
self.selectedLibraryId = selectedLibraryId
self.customHeaders = customHeaders
}

init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.url = try container.decode(URL.self, forKey: .url)
self.serverName = try container.decode(String.self, forKey: .serverName)
self.userID = try container.decode(String.self, forKey: .userID)
self.userName = try container.decode(String.self, forKey: .userName)
self.apiToken = try container.decode(String.self, forKey: .apiToken)
self.selectedLibraryId = try container.decodeIfPresent(String.self, forKey: .selectedLibraryId)
self.customHeaders = try container.decodeIfPresent([String: String].self, forKey: .customHeaders) ?? [:]
}
}

extension AudiobookShelfConnectionData: CustomDebugStringConvertible {
Expand Down
Loading
Loading