Compare commits

..

18 Commits

Author SHA1 Message Date
fish 1a525c763e 归档笔记保留 Note 格式化操作
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-07-17 22:33:41 +08:00
fish a0dffdc715 增大收集箱列表文案与时间间距 2026-07-16 21:46:43 +08:00
fish 4765d48021 收集箱列表展示完整文案 2026-07-16 21:44:51 +08:00
fish f888e28d15 添加简体中文本地化支持 2026-07-16 21:38:07 +08:00
fish c934dbad84 调整完成按钮与键盘的间距 2026-07-16 21:35:40 +08:00
fish 4088db8ec0 编辑页完成按钮改为玻璃浮动效果 2026-07-16 21:26:36 +08:00
fish 255f171aa8 编辑页键盘增加完成按钮 2026-07-16 21:19:29 +08:00
fish 70870e1ec2 编辑页增加键盘遮挡处理 2026-07-16 21:13:52 +08:00
fish f1a380d105 保存失败时返回具体错误信息 2026-07-15 23:55:36 +08:00
fish 01ad237af3 修复 TextFormatter actor 隔离警告 2026-07-15 23:47:47 +08:00
fish 7d49f7d5a4 预置快捷指令自动读取剪贴板 2026-07-15 23:43:22 +08:00
fish 87eb958869 添加预置快捷指令 2026-07-15 23:39:15 +08:00
fish 4340fd3635 修复编译警告 2026-07-15 23:33:33 +08:00
fish ac2eac5fcd 修复收集箱后台返回不刷新 2026-07-15 23:22:37 +08:00
fish a386802a55 快捷指令预处理去掉标题前缀 2026-07-15 23:19:32 +08:00
fish 1f94b9884c 快捷指令保存文案前使用 iCloud 格式化预处理 2026-07-15 23:15:55 +08:00
fish 58a8d27315 归档增加标题并统一分隔符 2026-07-15 23:11:05 +08:00
fish 7f4fc34dbf 收集箱增加归档功能 2026-07-15 23:04:20 +08:00
9 changed files with 205 additions and 26 deletions
+1
View File
@@ -184,6 +184,7 @@
knownRegions = (
en,
Base,
"zh-Hans",
);
mainGroup = CFD40B073003C283009C9F2A;
minimizedProjectReferenceProxies = 1;
+70 -3
View File
@@ -10,6 +10,8 @@ import UIKit
class ClipEditViewController: UIViewController {
private var textView: UITextView!
private var floatingDoneButton: UIButton!
private var floatingDoneButtonBottomConstraint: NSLayoutConstraint!
private var clip: Clip
init(clip: Clip) {
@@ -29,6 +31,45 @@ class ClipEditViewController: UIViewController {
setupNavigationBar()
setupTextView()
setupKeyboardObservers()
}
deinit {
NotificationCenter.default.removeObserver(self)
}
private func setupKeyboardObservers() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
}
@objc private func keyboardWillShow(_ notification: Notification) {
guard let keyboardFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { return }
let keyboardFrameInView = view.convert(keyboardFrame, from: nil)
let intersection = keyboardFrameInView.intersection(view.bounds)
let keyboardHeight = intersection.height
let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? TimeInterval ?? 0.25
UIView.animate(withDuration: duration, delay: 0, options: .beginFromCurrentState) {
self.textView.contentInset.bottom = keyboardHeight
self.textView.verticalScrollIndicatorInsets.bottom = keyboardHeight
self.floatingDoneButtonBottomConstraint.constant = -(keyboardHeight + 8)
self.floatingDoneButton.alpha = 1
self.view.layoutIfNeeded()
}
}
@objc private func keyboardWillHide(_ notification: Notification) {
let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? TimeInterval ?? 0.25
UIView.animate(withDuration: duration, delay: 0, options: .beginFromCurrentState) {
self.textView.contentInset.bottom = 0
self.textView.verticalScrollIndicatorInsets.bottom = 0
self.floatingDoneButtonBottomConstraint.constant = -16
self.floatingDoneButton.alpha = 0
self.view.layoutIfNeeded()
}
}
override func viewDidAppear(_ animated: Bool) {
@@ -39,7 +80,7 @@ class ClipEditViewController: UIViewController {
private func setupNavigationBar() {
let saveButton = UIBarButtonItem(
title: "保存",
style: .done,
style: .prominent,
target: self,
action: #selector(didTapSaveButton)
)
@@ -61,15 +102,40 @@ class ClipEditViewController: UIViewController {
textView.text = clip.text
view.addSubview(textView)
var doneConfig = UIButton.Configuration.glass()
doneConfig.title = "完成"
doneConfig.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { incoming in
var outgoing = incoming
outgoing.font = UIFont.systemFont(ofSize: 17, weight: .semibold)
return outgoing
}
doneConfig.baseForegroundColor = .label
doneConfig.cornerStyle = .capsule
doneConfig.contentInsets = NSDirectionalEdgeInsets(top: 15, leading: 22, bottom: 15, trailing: 22)
floatingDoneButton = UIButton(configuration: doneConfig)
floatingDoneButton.translatesAutoresizingMaskIntoConstraints = false
floatingDoneButton.alpha = 0
floatingDoneButton.addTarget(self, action: #selector(didTapFloatingDoneButton), for: .touchUpInside)
view.addSubview(floatingDoneButton)
let safeArea = view.safeAreaLayoutGuide
floatingDoneButtonBottomConstraint = floatingDoneButton.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -16)
NSLayoutConstraint.activate([
textView.topAnchor.constraint(equalTo: safeArea.topAnchor, constant: 16),
textView.leadingAnchor.constraint(equalTo: safeArea.leadingAnchor, constant: 16),
textView.trailingAnchor.constraint(equalTo: safeArea.trailingAnchor, constant: -16),
textView.bottomAnchor.constraint(equalTo: safeArea.bottomAnchor, constant: -16)
textView.bottomAnchor.constraint(equalTo: safeArea.bottomAnchor, constant: -16),
floatingDoneButton.trailingAnchor.constraint(equalTo: safeArea.trailingAnchor, constant: -16),
floatingDoneButtonBottomConstraint
])
}
@objc private func didTapFloatingDoneButton() {
textView.resignFirstResponder()
}
@objc private func didTapSaveButton() {
let updatedText = textView.text ?? ""
guard !updatedText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
@@ -85,8 +151,9 @@ class ClipEditViewController: UIViewController {
Task {
do {
try await ClipStore.shared.update(updatedClip)
await MainActor.run {
_ = await MainActor.run {
self.navigationController?.popViewController(animated: true)
return ()
}
} catch {
await MainActor.run {
+73 -4
View File
@@ -11,6 +11,7 @@ class ClipInboxViewController: UIViewController {
private var tableView: UITableView!
private var emptyLabel: UILabel!
private var archiveButton: UIButton!
private var clips: [Clip] = []
override func viewDidLoad() {
@@ -20,8 +21,10 @@ class ClipInboxViewController: UIViewController {
view.backgroundColor = .systemGroupedBackground
setupNavigationBar()
setupArchiveButton()
setupTableView()
setupEmptyLabel()
setupAppStateObserver()
}
override func viewWillAppear(_ animated: Bool) {
@@ -29,6 +32,23 @@ class ClipInboxViewController: UIViewController {
loadClips()
}
deinit {
NotificationCenter.default.removeObserver(self)
}
private func setupAppStateObserver() {
NotificationCenter.default.addObserver(
self,
selector: #selector(appDidBecomeActive),
name: UIApplication.didBecomeActiveNotification,
object: nil
)
}
@objc private func appDidBecomeActive() {
loadClips()
}
private func setupNavigationBar() {
let clearButton = UIBarButtonItem(
title: "清空",
@@ -53,10 +73,58 @@ class ClipInboxViewController: UIViewController {
tableView.topAnchor.constraint(equalTo: view.topAnchor),
tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
tableView.bottomAnchor.constraint(equalTo: archiveButton.topAnchor, constant: -16)
])
}
private func setupArchiveButton() {
var config = UIButton.Configuration.filled()
config.title = "归档"
config.baseBackgroundColor = .systemBlue
config.baseForegroundColor = .white
config.cornerStyle = .medium
config.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 16)
archiveButton = UIButton(configuration: config)
archiveButton.translatesAutoresizingMaskIntoConstraints = false
archiveButton.addTarget(self, action: #selector(didTapArchiveButton), for: .touchUpInside)
view.addSubview(archiveButton)
NSLayoutConstraint.activate([
archiveButton.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 16),
archiveButton.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -16),
archiveButton.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -16),
archiveButton.heightAnchor.constraint(equalToConstant: 52)
])
}
@objc private func didTapArchiveButton() {
guard clips.count >= 2 else {
let alert = UIAlertController(title: "提示", message: "至少需要两条文案才能归档。", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "确定", style: .default))
present(alert, animated: true)
return
}
let title = self.archiveTitle()
let itemsText = clips.map { "\($0.text)\n\n---" }.joined(separator: "\n\n")
let archivedText = "\(title)\n\n\(itemsText)"
let viewController = FormatNoteViewController()
viewController.initialText = archivedText
navigationController?.pushViewController(viewController, animated: true)
}
private func archiveTitle() -> String {
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "zh_CN")
dateFormatter.dateFormat = "yyyy年MM月dd日"
let dateString = dateFormatter.string(from: Date())
let weekdays = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]
let weekdayIndex = Calendar.current.component(.weekday, from: Date()) - 1
let weekday = (weekdayIndex >= 0 && weekdayIndex < weekdays.count) ? weekdays[weekdayIndex] : ""
return "【读书摘抄】\(dateString) \(weekday)"
}
private func setupEmptyLabel() {
emptyLabel = UILabel()
emptyLabel.translatesAutoresizingMaskIntoConstraints = false
@@ -96,6 +164,7 @@ class ClipInboxViewController: UIViewController {
let isEmpty = clips.isEmpty
emptyLabel.isHidden = !isEmpty
tableView.isHidden = isEmpty
archiveButton.isHidden = isEmpty
}
@objc private func didTapClearButton() {
@@ -177,8 +246,10 @@ extension ClipInboxViewController: UITableViewDataSource {
var config = cell.defaultContentConfiguration()
config.text = previewText(for: clip.text)
config.textProperties.numberOfLines = 0
config.secondaryText = formattedDate(clip.createdAt)
config.secondaryTextProperties.color = .secondaryLabel
config.textToSecondaryTextVerticalPadding = 12
cell.contentConfiguration = config
cell.accessoryType = .disclosureIndicator
@@ -186,9 +257,7 @@ extension ClipInboxViewController: UITableViewDataSource {
}
private func previewText(for text: String) -> String {
let lines = text.components(separatedBy: .newlines)
let firstTwoLines = Array(lines.prefix(2))
let preview = firstTwoLines.joined(separator: " ").trimmingCharacters(in: .whitespaces)
let preview = text.trimmingCharacters(in: .whitespacesAndNewlines)
if preview.isEmpty {
return "(无内容)"
}
+16 -5
View File
@@ -21,6 +21,17 @@ struct Clip: Codable, Identifiable, Equatable, Sendable {
}
}
enum ClipStoreError: Error, LocalizedError {
case appGroupUnavailable
var errorDescription: String? {
switch self {
case .appGroupUnavailable:
return "无法访问 App Group 容器,请检查签名和 entitlements 配置。"
}
}
}
actor ClipStore {
static let shared = ClipStore()
@@ -31,13 +42,13 @@ actor ClipStore {
private var cachedClips: [Clip]?
private var fileURL: URL {
private func fileURL() throws -> URL {
let fileManager = FileManager.default
guard let containerURL = fileManager.containerURL(forSecurityApplicationGroupIdentifier: appGroupIdentifier) else {
fatalError("无法访问 App Group 容器: \(appGroupIdentifier)")
throw ClipStoreError.appGroupUnavailable
}
let directoryURL = containerURL.appendingPathComponent(subdirectory, isDirectory: true)
try? fileManager.createDirectory(at: directoryURL, withIntermediateDirectories: true)
try fileManager.createDirectory(at: directoryURL, withIntermediateDirectories: true)
return directoryURL.appendingPathComponent(fileName)
}
@@ -55,7 +66,7 @@ actor ClipStore {
return cached
}
let url = fileURL
let url = try fileURL()
let fileManager = FileManager.default
guard fileManager.fileExists(atPath: url.path) else {
cachedClips = []
@@ -93,7 +104,7 @@ actor ClipStore {
}
private func persist(_ clips: [Clip]) async throws {
let url = fileURL
let url = try fileURL()
let data = try JSONEncoder().encode(clips)
try data.write(to: url, options: .atomic)
cachedClips = clips
-4
View File
@@ -35,10 +35,6 @@ class FormatNoteViewController: UIViewController {
setupUI()
if let initialText = initialText {
textView.text = initialText
isNoteFormatted = true
noteButton.setTitle("复制并打开备忘录", for: .normal)
rightBarButtonMode = .reset
updateRightBarButtonItem()
}
setupKeyboardObservers()
}
+20
View File
@@ -0,0 +1,20 @@
//
// NoteAppShortcuts.swift
// Note
//
// Created by Kimi Code CLI on 2026/7/15.
//
import AppIntents
struct NoteAppShortcuts: AppShortcutsProvider {
static var appShortcuts: [AppShortcut] {
AppShortcut(
intent: SaveClipIntent(),
phrases: ["保存剪贴板到 ${applicationName}"],
shortTitle: "保存剪贴板",
systemImageName: "doc.text"
)
}
}
+12 -3
View File
@@ -6,13 +6,14 @@
//
import AppIntents
import UIKit
struct SaveClipIntent: AppIntent {
static var title: LocalizedStringResource = "保存剪贴板到 Note"
static var description: IntentDescription? = "将一段文本保存到 Note App 的收集箱,稍后统一处理。"
@Parameter(title: "文案", description: "要保存的文本内容", requestValueDialog: "请提供要保存的文案")
@Parameter(title: "文案", description: "要保存的文本内容", default: "")
var text: String
@Parameter(title: "来源", description: "文案来源,例如应用名称", default: "快捷指令")
@@ -26,7 +27,14 @@ struct SaveClipIntent: AppIntent {
}
func perform() async throws -> some IntentResult & ReturnsValue<String> {
let trimmed = text.trimmingCharacters(in: .whitespacesAndNewlines)
var inputText = text
if inputText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
inputText = await MainActor.run {
UIPasteboard.general.string ?? ""
}
}
let trimmed = inputText.trimmingCharacters(in: .whitespacesAndNewlines)
guard !trimmed.isEmpty else {
return .result(value: "文案为空,未保存。")
}
@@ -35,7 +43,8 @@ struct SaveClipIntent: AppIntent {
return .result(value: "剪贴板没有有效文本,未保存。")
}
try await ClipStore.shared.save(text: trimmed, source: source)
let formattedText = TextFormatter.formatForShortcut(trimmed)
try await ClipStore.shared.save(text: formattedText, source: source)
return .result(value: "已保存到收集箱。")
}
+12 -7
View File
@@ -9,7 +9,7 @@ import Foundation
enum TextFormatter {
static func formatLog(_ text: String) -> String {
static nonisolated func formatLog(_ text: String) -> String {
var content = text
content = content.replacingOccurrences(of: "# ", with: "")
@@ -31,7 +31,14 @@ enum TextFormatter {
return content
}
static func formatForCloud(_ text: String) -> String {
static nonisolated func formatForCloud(_ text: String) -> String {
var content = formatForShortcut(text)
content = "# " + content
content = insertEmptyLineAfterFirstLine(content)
return content
}
static nonisolated func formatForShortcut(_ text: String) -> String {
var content = text
content = content.replacingOccurrences(of: " ", with: "")
content = content.replacingOccurrences(of: " ", with: "")
@@ -71,12 +78,10 @@ enum TextFormatter {
content = content.replacingOccurrences(of: " ", with: "")
content = content.replacingOccurrences(of: "---", with: "---\n")
content = content.replacingOccurrences(of: "日星期", with: "日 星期")
content = "# " + content
content = insertEmptyLineAfterFirstLine(content)
return content
}
static func formatForNote(_ text: String) -> String {
static nonisolated func formatForNote(_ text: String) -> String {
var content = text
content = content.replacingOccurrences(of: "# ", with: "")
content = content.replacingOccurrences(of: "#", with: "")
@@ -111,13 +116,13 @@ enum TextFormatter {
return result.trimmingCharacters(in: .whitespacesAndNewlines)
}
static func removeEmptyLines(_ text: String) -> String {
static nonisolated func removeEmptyLines(_ text: String) -> String {
let lines = text.components(separatedBy: .newlines)
let nonEmptyLines = lines.filter { !$0.trimmingCharacters(in: .whitespaces).isEmpty }
return nonEmptyLines.joined(separator: "\n")
}
static func insertEmptyLineAfterFirstLine(_ text: String) -> String {
static nonisolated func insertEmptyLineAfterFirstLine(_ text: String) -> String {
var lines = text.components(separatedBy: .newlines)
if !lines.isEmpty {
lines.insert("", at: 1)
+1
View File
@@ -0,0 +1 @@
/* Simplified Chinese localization */