添加收集箱与快捷指令保存功能
This commit is contained in:
@@ -17,8 +17,9 @@ class ViewController: UIViewController {
|
||||
let title: String
|
||||
}
|
||||
|
||||
private let menuItems: [[MenuItem]] = [
|
||||
private var menuItems: [[MenuItem]] = [
|
||||
[
|
||||
MenuItem(icon: "tray.full", iconColor: .systemIndigo, title: "收集箱"),
|
||||
MenuItem(icon: "note.text", iconColor: .systemYellow, title: "打开备忘录"),
|
||||
MenuItem(icon: "doc.text", iconColor: .systemBlue, title: "格式化日志"),
|
||||
MenuItem(icon: "text.alignleft", iconColor: .systemGreen, title: "格式化笔记"),
|
||||
@@ -31,6 +32,11 @@ class ViewController: UIViewController {
|
||||
setupUI()
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
updateInboxBadge()
|
||||
}
|
||||
|
||||
private func setupUI() {
|
||||
title = "首页"
|
||||
navigationController?.navigationBar.prefersLargeTitles = true
|
||||
@@ -87,6 +93,9 @@ extension ViewController: UITableViewDelegate {
|
||||
|
||||
let item = menuItems[indexPath.section][indexPath.row]
|
||||
switch item.title {
|
||||
case "收集箱":
|
||||
let viewController = ClipInboxViewController()
|
||||
navigationController?.pushViewController(viewController, animated: true)
|
||||
case "打开备忘录":
|
||||
openSystemNotesApp()
|
||||
case "格式化日志":
|
||||
@@ -102,6 +111,37 @@ extension ViewController: UITableViewDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
private func updateInboxBadge() {
|
||||
Task {
|
||||
guard let count = try? await ClipStore.shared.count(), count > 0 else {
|
||||
await MainActor.run {
|
||||
self.updateInboxTitle("收集箱")
|
||||
}
|
||||
return
|
||||
}
|
||||
await MainActor.run {
|
||||
self.updateInboxTitle("收集箱(\(count))")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func updateInboxTitle(_ title: String) {
|
||||
for (sectionIndex, section) in menuItems.enumerated() {
|
||||
for (rowIndex, item) in section.enumerated() {
|
||||
if item.title.hasPrefix("收集箱") {
|
||||
menuItems[sectionIndex][rowIndex] = MenuItem(
|
||||
icon: item.icon,
|
||||
iconColor: item.iconColor,
|
||||
title: title
|
||||
)
|
||||
let indexPath = IndexPath(row: rowIndex, section: sectionIndex)
|
||||
tableView.reloadRows(at: [indexPath], with: .none)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func openSystemNotesApp() {
|
||||
openURLIfPossible("mobilenotes://")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user