mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-26 02:27:14 +00:00
Add engine settings page
This commit is contained in:
@@ -57,6 +57,32 @@ final class Aria2DownloadEngine {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static func versionString() -> String? {
|
||||||
|
guard let executableURL = findExecutable() else { return nil }
|
||||||
|
|
||||||
|
let process = Process()
|
||||||
|
let outputPipe = Pipe()
|
||||||
|
process.executableURL = executableURL
|
||||||
|
process.arguments = ["--version"]
|
||||||
|
process.standardOutput = outputPipe
|
||||||
|
process.standardError = Pipe()
|
||||||
|
|
||||||
|
do {
|
||||||
|
try process.run()
|
||||||
|
process.waitUntilExit()
|
||||||
|
guard process.terminationStatus == 0 else { return nil }
|
||||||
|
|
||||||
|
let data = outputPipe.fileHandleForReading.readDataToEndOfFile()
|
||||||
|
let output = String(data: data, encoding: .utf8) ?? ""
|
||||||
|
return output
|
||||||
|
.split(whereSeparator: { $0 == "\n" || $0 == "\r" })
|
||||||
|
.first
|
||||||
|
.map(String.init)
|
||||||
|
} catch {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func start(
|
func start(
|
||||||
item: DownloadItem,
|
item: DownloadItem,
|
||||||
proxyConfiguration: DownloadProxyConfiguration,
|
proxyConfiguration: DownloadProxyConfiguration,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ private enum SettingsSection: String, CaseIterable, Hashable {
|
|||||||
case locations = "Locations"
|
case locations = "Locations"
|
||||||
case siteLogins = "Site Logins"
|
case siteLogins = "Site Logins"
|
||||||
case power = "Power"
|
case power = "Power"
|
||||||
|
case engine = "Engine"
|
||||||
|
|
||||||
var symbolName: String {
|
var symbolName: String {
|
||||||
switch self {
|
switch self {
|
||||||
@@ -14,6 +15,7 @@ private enum SettingsSection: String, CaseIterable, Hashable {
|
|||||||
case .locations: "folder"
|
case .locations: "folder"
|
||||||
case .siteLogins: "key.fill"
|
case .siteLogins: "key.fill"
|
||||||
case .power: "moon.zzz"
|
case .power: "moon.zzz"
|
||||||
|
case .engine: "terminal"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,10 +75,55 @@ struct SettingsView: View {
|
|||||||
SiteLoginsSettingsPane()
|
SiteLoginsSettingsPane()
|
||||||
case .power:
|
case .power:
|
||||||
PowerSettingsPane()
|
PowerSettingsPane()
|
||||||
|
case .engine:
|
||||||
|
EngineSettingsPane()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private struct EngineSettingsPane: View {
|
||||||
|
private var executableURL: URL? {
|
||||||
|
Aria2DownloadEngine.findExecutable()
|
||||||
|
}
|
||||||
|
|
||||||
|
private var version: String {
|
||||||
|
Aria2DownloadEngine.versionString() ?? "Unavailable"
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
Form {
|
||||||
|
Section {
|
||||||
|
LabeledContent("Status") {
|
||||||
|
Label(
|
||||||
|
executableURL == nil ? "Missing" : "Ready",
|
||||||
|
systemImage: executableURL == nil ? "exclamationmark.triangle.fill" : "checkmark.seal.fill"
|
||||||
|
)
|
||||||
|
.foregroundStyle(executableURL == nil ? .orange : .green)
|
||||||
|
}
|
||||||
|
|
||||||
|
LabeledContent("Binary") {
|
||||||
|
Text(executableURL?.path ?? "Not found")
|
||||||
|
.font(.system(.body, design: .monospaced))
|
||||||
|
.textSelection(.enabled)
|
||||||
|
}
|
||||||
|
|
||||||
|
LabeledContent("Version") {
|
||||||
|
Text(version)
|
||||||
|
.font(.system(.body, design: .monospaced))
|
||||||
|
.textSelection(.enabled)
|
||||||
|
}
|
||||||
|
|
||||||
|
if executableURL == nil {
|
||||||
|
Text("Install aria2 with Homebrew or bundle aria2c inside the app resources.")
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.formStyle(.grouped)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private struct NetworkSettingsPane: View {
|
private struct NetworkSettingsPane: View {
|
||||||
@EnvironmentObject private var settings: AppSettings
|
@EnvironmentObject private var settings: AppSettings
|
||||||
|
|
||||||
|
|||||||
@@ -56,14 +56,6 @@ struct SidebarView: View {
|
|||||||
.tag(SidebarSelection.downloads(.category(category)))
|
.tag(SidebarSelection.downloads(.category(category)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Section("Engine") {
|
|
||||||
HStack {
|
|
||||||
Image(systemName: controller.hasAria2 ? "checkmark.seal.fill" : "exclamationmark.triangle.fill")
|
|
||||||
.foregroundStyle(controller.hasAria2 ? .green : .orange)
|
|
||||||
Text(controller.hasAria2 ? "aria2c ready" : "aria2c missing")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.listStyle(.sidebar)
|
.listStyle(.sidebar)
|
||||||
.safeAreaInset(edge: .bottom) {
|
.safeAreaInset(edge: .bottom) {
|
||||||
|
|||||||
Reference in New Issue
Block a user