Skip to content
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# macOS
._*
.DS_Store
_MACOSX

# Xcode
PCL.Mac.xcodeproj/xcuserdata
PCL.Mac.xcodeproj/project.xcworkspace/xcuserdata
PCL.Mac.xcodeproj/project.xcworkspace/xcuserdata
21 changes: 17 additions & 4 deletions PCL.Mac/Components/MyButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,22 @@ struct MyButton: View {
private let subLabel: String?
private let textPadding: EdgeInsets
private let type: `Type`
private let disabled: Bool
private let action: () -> Void

private var color: Color { hovered ? type.hoverColor : type.color }
private var color: Color {
if disabled {
return .colorGray4
}
return hovered ? type.hoverColor : type.color
}

init(_ label: String, subLabel: String? = nil, textPadding: EdgeInsets = .init(), type: `Type` = .normal, _ action: @escaping () -> Void) {
init(_ label: String, subLabel: String? = nil, textPadding: EdgeInsets = .init(), type: `Type` = .normal, disabled: Bool = false, _ action: @escaping () -> Void) {
self.label = label
self.subLabel = subLabel
self.textPadding = textPadding
self.type = type
self.disabled = disabled
self.action = action
}

Expand All @@ -46,8 +53,14 @@ struct MyButton: View {
.scaleEffect(isPressed ? 0.85 : 1.0)
.animation(.easeInOut(duration: 0.2), value: hovered)
.animation(.easeInOut(duration: 0.2), value: isPressed)
.contentShape(RoundedRectangle(cornerRadius: 4))
.onHover { hovered = $0 }
.animation(.easeInOut(duration: 0.2), value: disabled)
.contentShape(RoundedRectangle(cornerRadius: 4))
.allowsHitTesting(!disabled)
.onHover {
if !disabled {
hovered = $0
}
}
.gesture(
DragGesture(minimumDistance: 0)
.onChanged { _ in
Expand Down
6 changes: 6 additions & 0 deletions PCL.Mac/Views/Launch/LaunchPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ struct LaunchPage: View {
MyButton("红色按钮", subLabel: "但是两行文本", type: .red) {}
}
.frame(height: 60)
HStack {
MyButton("普通按钮", subLabel: "但是不可点击", disabled: true) {}
MyButton("高亮按钮", subLabel: "但是不可点击", type: .highlight, disabled: true) {}
MyButton("红色按钮", subLabel: "但是不可点击", type: .red, disabled: true) {}
}
.frame(height: 60)
MyList(items: listItems, selectable: true)
}
}
Expand Down
61 changes: 61 additions & 0 deletions PCL.Mac/Views/More/ToolboxPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import Core

struct ToolboxPage: View {
@StateObject private var viewModel: ToolboxViewModel = .init()
@State private var downloadURL: String = ""
@State private var savePath: String = ""
@State private var fileName: String = ""

var body: some View {
CardContainer {
Expand Down Expand Up @@ -62,6 +65,64 @@ struct ToolboxPage: View {
hint("加载回声洞消息列表失败:\(error.localizedDescription)", type: .critical)
}
}
MyCard("下载自定义文件", foldable: false) {
MyText("使用 PCL.Mac 的多线程下载引擎下载任意文件。请注意,部分网站(例如百度网盘)可能会报错(403)已禁止,无法正常下载。")
.frame(maxWidth: .infinity, alignment: .leading)

VStack(spacing: 8) {
HStack(spacing: 10) {
MyText("下载链接")
MyTextField(text: $downloadURL, placeholder: "输入文件直链地址")
.onChange(of: downloadURL) { newValue in
fileName = ""
if let lastComponent = newValue.split(separator: "/").last,
!lastComponent.isEmpty {
fileName = String(lastComponent)
}
}
}

HStack(spacing: 10) {
MyText("保存到")
.frame(width: 56, alignment: .leading)
MyTextField(text: $savePath, placeholder: "文件保存路径")
MyText("选择")
.contentShape(.rect)
.onTapGesture {
selectSavePath()
}
}

HStack(spacing: 10) {
MyText("文件名")
.frame(width: 56, alignment: .leading)
MyTextField(text: $fileName, placeholder: "文件下载之后的名字(包含后缀)")
}

HStack(spacing: 20) {
MyButton("开始下载", disabled: downloadURL.isEmpty || savePath.isEmpty || fileName.isEmpty) {}
.frame(width: 160)
MyButton("打开文件夹", disabled: savePath.isEmpty) {}
.frame(width: 160)
}
.frame(height: 50)
.padding(.top, 10)
}
}
}
}

private func selectSavePath() {
let panel = NSOpenPanel()
panel.canChooseDirectories = true
panel.canChooseFiles = false
panel.canCreateDirectories = true
panel.allowsMultipleSelection = false
panel.prompt = "选择保存位置"
panel.message = "选择文件下载后保存的文件夹"
let response = panel.runModal()
if response == .OK, let url = panel.url {
savePath = url.path
}
}
}
Expand Down