shortcuts.swift 4.3 KB

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