Skip to content

知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.

feat(ios): copy a meeting's notes with their formatting, and edit the summary, conclusions and to-dos

wquguru516354f8d19f
diff --git a/Sources/Cicada/NotesEditing.swift b/Sources/Cicada/NotesEditing.swift
index b9a2cc4..cd1a1d5 100644
--- a/Sources/Cicada/NotesEditing.swift
+++ b/Sources/Cicada/NotesEditing.swift
@@ -46,6 +46,7 @@ extension MeetingNotes {
}
}
+#if !CICADA_IOS
extension AppModel {
/// Not while the meeting is being written (the next pass would redo the notes), nor while an
/// import is still transcribing.
@@ -68,3 +69,4 @@ extension AppModel {
debugLog("notes edit: saved \(target) in \(id)")
}
}
+#endif
diff --git a/Sources/Cicada/RichCopy.swift b/Sources/Cicada/RichCopy.swift
index 9f38293..7341aea 100644
--- a/Sources/Cicada/RichCopy.swift
+++ b/Sources/Cicada/RichCopy.swift
@@ -1,4 +1,6 @@
+#if os(macOS)
import AppKit
+#endif
import SwiftUI
/// 复制纪要 as rich text: one copy puts HTML (document apps: Feishu, DingTalk, Notion, web
@@ -76,6 +78,7 @@ extension TranscriptExport {
}
}
+#if os(macOS)
@MainActor
enum RichCopy {
/// Puts `markdown` as plain text and `html` as HTML and RTFD on the general pasteboard.
@@ -144,3 +147,4 @@ enum RichCopy {
return .init(png: png, width: pictureWidth)
}
}
+#endif
diff --git a/ios/Sources/Cicada/NotesEdit.swift b/ios/Sources/Cicada/NotesEdit.swift
new file mode 100644
index 0000000..c04a33f
--- /dev/null
+++ b/ios/Sources/Cicada/NotesEdit.swift
@@ -0,0 +1,99 @@
+import SwiftUI
+import UIKit
+import UniformTypeIdentifiers
+
+/// 复制纪要 and changing a finished meeting's notes in place, as on the Mac (RichCopy.swift,
+/// NotesEditing.swift): the summary, a conclusion or a to-do; topics are the AI's to rewrite.
+extension AppModel {
+ /// Not while the meeting is being written, nor while an import is still transcribing.
+ func canEditNotes(_ s: Session) -> Bool {
+ s.id != store.liveID && importer.current?.id != s.id && !(s.notes?.isEmpty ?? true)
+ }
+
+ func editHooks(_ s: Session) -> NotesEditHooks? {
+ guard canEditNotes(s) else { return nil }
+ return NotesEditHooks(
+ current: noteEdit?.session == s.id ? noteEdit?.target : nil,
+ open: { [weak self] t in self?.noteEdit = t.map { NoteEdit(session: s.id, target: $0) } },
+ save: { [weak self] t, text, owner in self?.saveNote(s.id, t, text: text, owner: owner) })
+ }
+
+ func saveNote(_ id: String, _ target: NoteEdit.Target, text: String, owner: String?? = nil) {
+ guard var next = store.session(id)?.notes?.editing(target, text: text, owner: owner) else { return }
+ next.updatedAt = Date()
+ store.setNotes(id, next)
+ notes.applyEdited(next, id: id)
+ noteEdit = nil
+ debugLog("notes edit: saved \(target) in \(id)")
+ }
+
+ /// 复制纪要: HTML for document apps (Feishu, DingTalk, Notion, Notes), the Markdown as plain text
+ /// for chats; each app takes the one it reads.
+ func copyNotes(_ s: Session) {
+ let n = s.notes.map { SpeakerLabels.named($0, SpeakerLabels.names(s)) }
+ let html = TranscriptExport.htmlDocument("<h1>\(TranscriptExport.esc(s.displayTitle))</h1>\n" + TranscriptExport.notesHTML(n))
+ let markdown = "# \(s.displayTitle)\n\n" + TranscriptExport.notesMarkdown(n)
+ UIPasteboard.general.setItems([[UTType.html.identifier: html, UTType.utf8PlainText.identifier: markdown]])
+ copiedNotes = s.id
+ debugLog("notes: copied \(html.count) chars of HTML, \(markdown.count) of Markdown")
+ Task { @MainActor in
+ try? await Task.sleep(for: .seconds(3))
+ if self.copiedNotes == s.id { self.copiedNotes = nil }
+ }
+ }
+}
+
+/// One editable piece of the notes: the text, a tap opens a field in place with 取消 and 完成.
+struct EditableNote<Label: View>: View {
+ let target: NoteEdit.Target
+ let text: String
+ let hooks: NotesEditHooks?
+ @ViewBuilder let label: () -> Label
+ @State private var draft = ""
+ @FocusState private var focused: Bool
+
+ var body: some View {
+ if let hooks, hooks.current == target {
+ VStack(alignment: .trailing, spacing: 8) {
+ TextField(text: $draft, axis: .vertical) { Text(verbatim: "") }
+ .focused($focused)
+ .padding(.horizontal, 12).padding(.vertical, 10)
+ .overlay { RoundedRectangle(cornerRadius: 12, style: .continuous).strokeBorder(Ink.ink, lineWidth: 1.5) }
+ .onAppear { draft = text; focused = true }
+ HStack(spacing: 8) {
+ Button { hooks.open(nil) } label: {
+ Text("取消").font(.subheadline).foregroundStyle(Ink.ink)
+ .padding(.horizontal, 14).frame(minHeight: 36).background(Ink.ground, in: Capsule())
+ }
+ Button { hooks.save(target, draft, nil) } label: {
+ Text("完成").font(.subheadline.weight(.semibold)).foregroundStyle(.white)
+ .padding(.horizontal, 14).frame(minHeight: 36).background(Ink.ink, in: Capsule())
+ }
+ }
+ .buttonStyle(.plain)
+ }
+ } else if let hooks {
+ label()
+ .contentShape(Rectangle())
+ .onTapGesture { hooks.open(target) }
+ .accessibilityAddTraits(.isButton)
+ .accessibilityHint(Text("改这一条"))
+ } else {
+ label()
+ }
+ }
+}
+
+/// 已复制纪要, dark above the player for a few seconds.
+struct CopiedToast: View {
+ var body: some View {
+ HStack(spacing: 10) {
+ Image(systemName: "checkmark").font(.subheadline.weight(.bold)).foregroundStyle(Color(hex: 0x7DD3A0))
+ Text("已复制纪要,贴进飞书、钉钉、Notion 就是排好的").font(.subheadline).foregroundStyle(.white)
+ .fixedSize(horizontal: false, vertical: true)
+ Spacer(minLength: 0)
+ }
+ .padding(.horizontal, 16).padding(.vertical, 12)
+ .background(Ink.ink, in: RoundedRectangle(cornerRadius: 16, style: .continuous))
+ }
+}
diff --git a/ios/Sources/Cicada/RecordView.swift b/ios/Sources/Cicada/RecordView.swift
index cf5e588..c8928e6 100644
--- a/ios/Sources/Cicada/RecordView.swift
+++ b/ios/Sources/Cicada/RecordView.swift
@@ -75,7 +75,8 @@ struct RecordView: View {
.frame(maxWidth: .infinity).padding(.top, 40)
} else {
// Ling wrote "说话人 6" before anyone was named; show the names since given.
- NotesPage(notes: session.notes.map { SpeakerLabels.named($0, SpeakerLabels.names(session)) })
+ NotesPage(notes: session.notes.map { SpeakerLabels.named($0, SpeakerLabels.names(session)) },
+ edit: model.editHooks(session))
.padding(.top, 18)
}
}
@@ -102,6 +103,12 @@ struct RecordView: View {
}
.disabled(notes.generatingID != nil || session.lines.isEmpty)
.accessibilityLabel(Text("生成纪要"))
+ if session.notes.map({ !$0.isEmpty }) == true {
+ Button { model.copyNotes(session) } label: {
+ Image(systemName: model.copiedNotes == session.id ? "checkmark" : "doc.on.doc")
+ }
+ .accessibilityLabel(Text("复制纪要"))
+ }
Button { model.exporting = session.id } label: { Image(systemName: "square.and.arrow.up") }
.disabled(session.lines.isEmpty)
.accessibilityLabel(Text("导出"))
@@ -121,6 +128,7 @@ struct RecordView: View {
if let u = model.speakerUndo, u.session == session.id, !u.text.isEmpty, !player.available {
SpeakerUndoBar(text: u.text) { model.undoSpeakerEdit() }.padding(.horizontal, 16).padding(.bottom, 8)
}
+ if model.copiedNotes == session.id { CopiedToast().padding(.horizontal, 16).padding(.bottom, player.available ? 0 : 8) }
if !player.available { FixToast(fixes: model.fixes).padding(.horizontal, 16).padding(.bottom, 8) }
if player.available {
VStack(spacing: 8) {
@@ -141,6 +149,7 @@ struct RecordView: View {
}
}
.animation(.snappy(duration: 0.2), value: model.speakerUndo?.id)
+ .animation(.snappy(duration: 0.2), value: model.copiedNotes)
.animation(.snappy(duration: 0.2), value: model.fixes.toast)
.sheet(item: Binding(get: { model.editingLine.flatMap { $0.session == session.id ? $0 : nil } },
set: { model.editingLine = $0 })) { e in
@@ -382,6 +391,8 @@ struct TranscriptList: View {
struct NotesPage: View {
let notes: MeetingNotes?
+ /// A finished meeting's: the summary, conclusions and to-dos open in place on a tap.
+ var edit: NotesEditHooks? = nil
/// The design's 16 pt notes text, as the transcript's translation.
@ScaledMetric(relativeTo: .callout) private var size: CGFloat = 16
@@ -389,7 +400,11 @@ struct NotesPage: View {
if let n = notes, !n.summary.isEmpty || !n.topics.isEmpty {
VStack(alignment: .leading, spacing: 22) {
if !n.summary.isEmpty {
- block("总结") { Text(n.summary).font(.system(size: size)).lineSpacing(5) }
+ block("总结") {
+ EditableNote(target: .summary, text: n.summary, hooks: edit) {
+ Text(n.summary).font(.system(size: size)).lineSpacing(5)
+ }
+ }
}
if !n.topics.isEmpty {
block("议题") {
@@ -417,19 +432,23 @@ struct NotesPage: View {
if !n.conclusions.isEmpty {
block("结论") {
ForEach(Array(n.conclusions.enumerated()), id: \.element.id) { i, c in
- HStack(alignment: .firstTextBaseline, spacing: 10) {
- Text("\(i + 1)").font(.system(size: size, weight: .bold)).foregroundStyle(Ink.link)
- Text(c.text).font(.system(size: size)).lineSpacing(3)
+ EditableNote(target: .item(i), text: c.text, hooks: edit) {
+ HStack(alignment: .firstTextBaseline, spacing: 10) {
+ Text("\(i + 1)").font(.system(size: size, weight: .bold)).foregroundStyle(Ink.link)
+ Text(c.text).font(.system(size: size)).lineSpacing(3)
+ }
}
}
}
}
if !n.todos.isEmpty {
block("待办") {
- ForEach(n.todos) { t in
- HStack(alignment: .firstTextBaseline, spacing: 10) {
- Image(systemName: "square").font(.system(size: size)).foregroundStyle(Ink.tertiary)
- Text((t.owner.map { "\($0):" } ?? "") + t.text).font(.system(size: size)).lineSpacing(3)
+ ForEach(Array(n.todos.enumerated()), id: \.element.id) { i, t in
+ EditableNote(target: .item(n.conclusions.count + i), text: t.text, hooks: edit) {
+ HStack(alignment: .firstTextBaseline, spacing: 10) {
+ Image(systemName: "square").font(.system(size: size)).foregroundStyle(Ink.tertiary)
+ Text((t.owner.map { "\($0):" } ?? "") + t.text).font(.system(size: size)).lineSpacing(3)
+ }
}
}
}