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
4 changes: 4 additions & 0 deletions BitDream.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
4E2000014000000000C1D2E3 /* SpeedLimitsSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E2000044000000000C1D2E3 /* SpeedLimitsSettings.swift */; };
4E2000024000000000C1D2E3 /* NetworkSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E2000054000000000C1D2E3 /* NetworkSettings.swift */; };
4E2000034000000000C1D2E3 /* TorrentSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E2000064000000000C1D2E3 /* TorrentSettings.swift */; };
4E2000084000000000C1D2E3 /* SettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E2000094000000000C1D2E3 /* SettingsViewModel.swift */; };
4F7000024000000000A1B2C3 /* iOSTorrentFileRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F7000014000000000A1B2C3 /* iOSTorrentFileRow.swift */; };
4F8000044000000000A1B2C3 /* macOSContentSidebar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F8000014000000000A1B2C3 /* macOSContentSidebar.swift */; };
4F8000054000000000A1B2C3 /* macOSContentDetail.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F8000024000000000A1B2C3 /* macOSContentDetail.swift */; };
Expand Down Expand Up @@ -233,6 +234,7 @@
4E2000044000000000C1D2E3 /* SpeedLimitsSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpeedLimitsSettings.swift; sourceTree = "<group>"; };
4E2000054000000000C1D2E3 /* NetworkSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkSettings.swift; sourceTree = "<group>"; };
4E2000064000000000C1D2E3 /* TorrentSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TorrentSettings.swift; sourceTree = "<group>"; };
4E2000094000000000C1D2E3 /* SettingsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewModel.swift; sourceTree = "<group>"; };
4F7000014000000000A1B2C3 /* iOSTorrentFileRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSTorrentFileRow.swift; sourceTree = "<group>"; };
4F8000014000000000A1B2C3 /* macOSContentSidebar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = macOSContentSidebar.swift; sourceTree = "<group>"; };
4F8000024000000000A1B2C3 /* macOSContentDetail.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = macOSContentDetail.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -583,6 +585,7 @@
isa = PBXGroup;
children = (
4B6F1EA52D82BD4A003D8F6E /* SettingsView.swift */,
4E2000094000000000C1D2E3 /* SettingsViewModel.swift */,
4E2000054000000000C1D2E3 /* NetworkSettings.swift */,
4E2000044000000000C1D2E3 /* SpeedLimitsSettings.swift */,
4E2000064000000000C1D2E3 /* TorrentSettings.swift */,
Expand Down Expand Up @@ -768,6 +771,7 @@
4B1DAE0E295E6FFB0037E9FB /* ErrorDialog.swift in Sources */,
4B1DAE0A295E6FE10037E9FB /* ServerDetail.swift in Sources */,
4B6F1EA62D82BD4A003D8F6E /* SettingsView.swift in Sources */,
4E2000084000000000C1D2E3 /* SettingsViewModel.swift in Sources */,
4B1DAE0C295E6FEF0037E9FB /* ServerList.swift in Sources */,
4E2000024000000000C1D2E3 /* NetworkSettings.swift in Sources */,
4E2000014000000000C1D2E3 /* SpeedLimitsSettings.swift in Sources */,
Expand Down
147 changes: 0 additions & 147 deletions BitDream/Transmission/TransmissionFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,6 @@ internal struct TransmissionLegacyAdapter: Sendable {
}
}

func fetchSessionSettings(
config: TransmissionConfig,
auth: TransmissionAuth
) async -> Result<TransmissionSessionResponseArguments, Error> {
await performQuery(config: config, auth: auth) { connection in
try await connection.fetchSessionSettings()
}
}

private func connection(
for config: TransmissionConfig,
auth: TransmissionAuth
Expand Down Expand Up @@ -274,39 +265,6 @@ public func deleteTorrent(torrent: Torrent, erase: Bool, config: TransmissionCon
)
}

/// Model representing session information from the server
public struct SessionInfo {
let downloadDir: String
let version: String

init(downloadDir: String = "unknown", version: String = "unknown") {
self.downloadDir = downloadDir
self.version = version
}
}

/// Get the server's session configuration and information
/// - Parameter config: The server's config
/// - Parameter auth: The username and password for the server
/// - Parameter onResponse: An escaping function that receives session information from the server
public func getSession(
config: TransmissionConfig,
auth: TransmissionAuth,
onResponse: @MainActor @escaping (TransmissionSessionResponseArguments) -> Void,
onError: @MainActor @escaping (String) -> Void
) {
Task {
let result = await legacyTransmissionAdapter.fetchSessionSettings(config: config, auth: auth)

switch result {
case .success(let response):
await onResponse(response)
case .failure(let error):
await onError(error.localizedDescription)
}
}
}

public func playPauseTorrent(torrent: Torrent, config: TransmissionConfig, auth: TransmissionAuth, onResponse: @MainActor @escaping (TransmissionResponse) -> Void) {
// If the torrent already has `stopped` status, start it. Otherwise, stop it.
let actionMethod = torrent.status == TorrentStatus.stopped.rawValue ? "torrent-start" : "torrent-stop"
Expand Down Expand Up @@ -558,111 +516,6 @@ public func queueMoveBottom(
)
}

// MARK: - Session Configuration Functions

/// Update session configuration settings using the session-set method
/// - Parameters:
/// - args: TransmissionSessionSetRequestArgs containing the properties to update
/// - config: Server configuration
/// - auth: Authentication credentials
/// - completion: Called when the server's response is received
public func setSession(
args: TransmissionSessionSetRequestArgs,
config: TransmissionConfig,
auth: TransmissionAuth,
completion: @MainActor @escaping (TransmissionResponse) -> Void
) {
performTransmissionStatusRequest(
method: "session-set",
args: args,
config: config,
auth: auth,
completion: completion
)
}

// MARK: - Utility Functions

/// Check free space available in a directory
/// - Parameters:
/// - path: The directory path to check
/// - config: Server configuration
/// - auth: Authentication credentials
/// - completion: Result containing free space info or error
public func checkFreeSpace(
path: String,
config: TransmissionConfig,
auth: TransmissionAuth,
completion: @MainActor @escaping (Result<FreeSpaceResponse, Error>) -> Void
) {
performTransmissionDataRequest(
method: "free-space",
args: ["path": path] as [String: String],
config: config,
auth: auth
) { (result: Result<FreeSpaceResponse, Error>) in
switch result {
case .success(let response):
completion(.success(response))
case .failure(let error):
completion(.failure(error))
}
}
}

/// Test if the peer listening port is accessible from the outside world
/// - Parameters:
/// - ipProtocol: Optional IP protocol to test ("ipv4" or "ipv6"). If nil, uses OS default.
/// - config: Server configuration
/// - auth: Authentication credentials
/// - completion: Result containing port test response or error
public func testPort(
ipProtocol: String? = nil,
config: TransmissionConfig,
auth: TransmissionAuth,
completion: @MainActor @escaping (Result<PortTestResponse, Error>) -> Void
) {
let args = PortTestRequestArgs(ipProtocol: ipProtocol)
performTransmissionDataRequest(
method: "port-test",
args: args,
config: config,
auth: auth
) { (result: Result<PortTestResponse, Error>) in
switch result {
case .success(let response):
completion(.success(response))
case .failure(let error):
completion(.failure(error))
}
}
}

/// Update the blocklist from the configured blocklist URL
/// - Parameters:
/// - config: Server configuration
/// - auth: Authentication credentials
/// - completion: Result containing the new blocklist size or error
public func updateBlocklist(
config: TransmissionConfig,
auth: TransmissionAuth,
completion: @MainActor @escaping (Result<BlocklistUpdateResponse, Error>) -> Void
) {
performTransmissionDataRequest(
method: "blocklist-update",
args: EmptyArguments(),
config: config,
auth: auth
) { (result: Result<BlocklistUpdateResponse, Error>) in
switch result {
case .success(let response):
completion(.success(response))
case .failure(let error):
completion(.failure(error))
}
}
}

// MARK: - Peer Queries

/// Gets the list of peers (and peersFrom breakdown) for a torrent
Expand Down
24 changes: 14 additions & 10 deletions BitDream/Transmission/TransmissionLegacyConnectionInfo.swift
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import Foundation

// TODO: Remove this file in phases 4/5 once write-side callers stop depending on
// `makeConfig(store:)` and `TransmissionStore.currentServerInfo`.
struct LegacyTransmissionContext {
var config: TransmissionConfig
var auth: TransmissionAuth
}

// TODO: Remove this file in phase 5 once write-side callers stop depending on
// `makeConfig(store:)`.
/// Temporary compatibility helper for legacy write-side call sites.
/// Phase 3 removes the read-side dependency on this helper, but phases 4-5 still use it.
/// Phase 4 removes settings/session use of this helper, but torrent actions still depend on it.
@MainActor
func makeConfig(store: TransmissionStore) -> (config: TransmissionConfig, auth: TransmissionAuth) {
guard let serverInfo = store.currentServerInfo else {
guard let host = store.host else {
return (TransmissionConfig(), TransmissionAuth(username: "", password: ""))
}

return serverInfo
var config = TransmissionConfig()
config.host = host.server
config.port = Int(host.port)
config.scheme = host.isSSL ? "https" : "http"

let auth = TransmissionAuth(
username: host.username ?? "",
password: store.readPassword(for: host)
)
return (config, auth)
}
31 changes: 31 additions & 0 deletions BitDream/Transmission/TransmissionSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,35 @@ internal extension TransmissionConnection {
responseType: TransmissionSessionResponseArguments.self
)
}

func setSession(_ args: TransmissionSessionSetRequestArgs) async throws {
try await sendStatusRequest(
method: "session-set",
arguments: args
)
}

func checkFreeSpace(path: String) async throws -> FreeSpaceResponse {
try await sendRequiredArguments(
method: "free-space",
arguments: ["path": path] as [String: String],
responseType: FreeSpaceResponse.self
)
}

func testPort(ipProtocol: String? = nil) async throws -> PortTestResponse {
try await sendRequiredArguments(
method: "port-test",
arguments: PortTestRequestArgs(ipProtocol: ipProtocol),
responseType: PortTestResponse.self
)
}

func updateBlocklist() async throws -> BlocklistUpdateResponse {
try await sendRequiredArguments(
method: "blocklist-update",
arguments: EmptyArguments(),
responseType: BlocklistUpdateResponse.self
)
}
}
Loading