shortcuts.swift 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import WidgetKit
  2. import SwiftUI
  3. struct Provider: TimelineProvider {
  4. func placeholder(in context: Context) -> SimpleEntry {
  5. SimpleEntry(date: Date())
  6. }
  7. func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) {
  8. let entry = SimpleEntry(date: Date())
  9. completion(entry)
  10. }
  11. func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
  12. let currentDate = Date()
  13. let entry = SimpleEntry(date: currentDate)
  14. let timeline = Timeline(entries: [entry], policy: .atEnd)
  15. completion(timeline)
  16. }
  17. }
  18. struct SimpleEntry: TimelineEntry {
  19. let date: Date
  20. }
  21. struct ShortcutsEntryView: View {
  22. var entry: Provider.Entry
  23. var body: some View {
  24. VStack(alignment: .leading, spacing: 0) {
  25. // Top heading
  26. Text("Logseq")
  27. .font(.headline)
  28. .bold()
  29. .foregroundColor(Color(hex: "#002b36"))
  30. // Middle text
  31. Text("I have an idea...")
  32. .font(.subheadline) // larger than subheadline
  33. .bold()
  34. .foregroundColor(.primary.opacity(0.8))
  35. Spacer(minLength: 0)
  36. // Bottom buttons row
  37. HStack(spacing: 8) {
  38. // Left button (audio waves)
  39. Link(destination: URL(string: "logseq://go/audio")!) {
  40. Image(systemName: "waveform")
  41. .font(.body) // smaller icon
  42. .foregroundColor(Color(hex: "#002b36"))
  43. .frame(maxWidth: .infinity, minHeight: 36)
  44. .background(Color.gray.opacity(0.05))
  45. .clipShape(Capsule())
  46. .contentShape(Capsule())
  47. }
  48. // Right button (quick add)
  49. Link(destination: URL(string: "logseq://go/quick-add")!) {
  50. Image(systemName: "plus")
  51. .font(.body) // smaller icon
  52. .foregroundColor(.white)
  53. .frame(maxWidth: .infinity, minHeight: 36)
  54. .background(Color(hex: "#002b36"))
  55. .clipShape(Capsule())
  56. .contentShape(Capsule())
  57. }
  58. }
  59. }
  60. .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
  61. .padding(-3)
  62. }
  63. }
  64. // Helper to support hex colors
  65. extension Color {
  66. init(hex: String) {
  67. let hex = hex.trimmingCharacters(in: CharacterSet.alphanumerics.inverted)
  68. var int: UInt64 = 0
  69. Scanner(string: hex).scanHexInt64(&int)
  70. let a, r, g, b: UInt64
  71. switch hex.count {
  72. case 3:
  73. (a, r, g, b) = (255,
  74. (int >> 8) * 17,
  75. (int >> 4 & 0xF) * 17,
  76. (int & 0xF) * 17)
  77. case 6:
  78. (a, r, g, b) = (255,
  79. int >> 16,
  80. int >> 8 & 0xFF,
  81. int & 0xFF)
  82. case 8:
  83. (a, r, g, b) = (int >> 24,
  84. int >> 16 & 0xFF,
  85. int >> 8 & 0xFF,
  86. int & 0xFF)
  87. default:
  88. (a, r, g, b) = (255, 0, 0, 0)
  89. }
  90. self.init(
  91. .sRGB,
  92. red: Double(r) / 255,
  93. green: Double(g) / 255,
  94. blue: Double(b) / 255,
  95. opacity: Double(a) / 255
  96. )
  97. }
  98. }
  99. struct Shortcuts: Widget {
  100. let kind: String = "shortcuts"
  101. var body: some WidgetConfiguration {
  102. StaticConfiguration(kind: kind, provider: Provider()) { entry in
  103. if #available(iOS 17.0, *) {
  104. ShortcutsEntryView(entry: entry)
  105. .containerBackground(.fill.tertiary, for: .widget)
  106. } else {
  107. ShortcutsEntryView(entry: entry)
  108. .background()
  109. }
  110. }
  111. .configurationDisplayName("Logseq Shortcuts")
  112. .description("Quick actions for Logseq")
  113. }
  114. }
  115. #Preview(as: .systemSmall) {
  116. Shortcuts()
  117. } timeline: {
  118. SimpleEntry(date: .now)
  119. }