LauncherRootView.swift 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. import SwiftUI
  2. import AppKit
  3. struct LauncherRootView: View {
  4. enum LayoutMode {
  5. case grid
  6. case panel
  7. }
  8. @State private var query = ""
  9. @State private var selectedApp: LauncherApp?
  10. @State private var showingPremiumScreen = false
  11. @State private var layoutMode: LayoutMode = .grid
  12. private let apps = LauncherApp.sampleApps
  13. private var columns: [GridItem] {
  14. [GridItem(.adaptive(minimum: 120, maximum: 145), spacing: 22)]
  15. }
  16. private var filteredApps: [LauncherApp] {
  17. let q = query.trimmingCharacters(in: .whitespacesAndNewlines)
  18. guard !q.isEmpty else { return apps }
  19. return apps.filter { $0.name.localizedCaseInsensitiveContains(q) }
  20. }
  21. var body: some View {
  22. ZStack {
  23. VisualEffectBlur(material: .hudWindow, blendingMode: .behindWindow)
  24. .ignoresSafeArea()
  25. Color.black.opacity(0.22)
  26. .ignoresSafeArea()
  27. VStack(spacing: 16) {
  28. SearchHeader(
  29. query: $query,
  30. isPanelMode: layoutMode == .panel,
  31. onToggleLayout: {
  32. layoutMode = layoutMode == .grid ? .panel : .grid
  33. },
  34. onOpenPremium: {
  35. showingPremiumScreen = true
  36. },
  37. onOpenGoogle: {
  38. if let url = URL(string: "https://www.google.com") {
  39. NSWorkspace.shared.open(url)
  40. }
  41. }
  42. )
  43. .padding(.top, 12)
  44. PromoBanner(
  45. onCloseTap: { showingPremiumScreen = true },
  46. onUpgradeTap: { showingPremiumScreen = true }
  47. )
  48. if filteredApps.isEmpty {
  49. ContentUnavailableView(
  50. "No apps found",
  51. systemImage: "magnifyingglass",
  52. description: Text("Try a different search term.")
  53. )
  54. .foregroundStyle(.white.opacity(0.85))
  55. .frame(maxWidth: .infinity, maxHeight: .infinity)
  56. } else {
  57. if layoutMode == .panel {
  58. IconPanelView(apps: filteredApps) { app in
  59. handleAppTap(app)
  60. }
  61. } else {
  62. ScrollView {
  63. LazyVGrid(columns: columns, spacing: 20) {
  64. ForEach(filteredApps) { app in
  65. AppTileView(app: app) {
  66. handleAppTap(app)
  67. }
  68. }
  69. }
  70. .padding(.horizontal, 14)
  71. .padding(.bottom, 18)
  72. }
  73. }
  74. }
  75. }
  76. .padding(.horizontal, 10)
  77. .padding(.bottom, 8)
  78. }
  79. .sheet(item: $selectedApp) { app in
  80. AppDetailView(app: app)
  81. .frame(minWidth: 360, minHeight: 220)
  82. }
  83. .sheet(isPresented: $showingPremiumScreen) {
  84. PremiumFeaturesView()
  85. .frame(minWidth: 560, minHeight: 690)
  86. }
  87. }
  88. private func handleAppTap(_ app: LauncherApp) {
  89. if let webURL = app.webURL {
  90. NSWorkspace.shared.open(webURL)
  91. return
  92. }
  93. selectedApp = app
  94. }
  95. }
  96. private struct SearchHeader: View {
  97. @Binding var query: String
  98. let isPanelMode: Bool
  99. let onToggleLayout: () -> Void
  100. let onOpenPremium: () -> Void
  101. let onOpenGoogle: () -> Void
  102. var body: some View {
  103. HStack {
  104. HStack(spacing: 10) {
  105. Image(systemName: "magnifyingglass")
  106. .foregroundStyle(.white.opacity(0.82))
  107. TextField("Search", text: $query)
  108. .textFieldStyle(.plain)
  109. .foregroundStyle(.white.opacity(0.94))
  110. }
  111. .padding(.horizontal, 12)
  112. .padding(.vertical, 8)
  113. .background(
  114. RoundedRectangle(cornerRadius: 15, style: .continuous)
  115. .fill(Color.black.opacity(0.28))
  116. )
  117. .overlay(
  118. RoundedRectangle(cornerRadius: 15, style: .continuous)
  119. .stroke(Color.white.opacity(0.08), lineWidth: 1)
  120. )
  121. Spacer(minLength: 8)
  122. HStack(spacing: 12) {
  123. Button(action: onToggleLayout) {
  124. Image(systemName: isPanelMode ? "square.grid.2x2" : "list.bullet")
  125. }
  126. .buttonStyle(.plain)
  127. Menu {
  128. Button("Clear Search") {
  129. query = ""
  130. }
  131. Button("Open Premium") {
  132. onOpenPremium()
  133. }
  134. Button("Open Google") {
  135. onOpenGoogle()
  136. }
  137. } label: {
  138. Image(systemName: "ellipsis")
  139. }
  140. .menuStyle(.borderlessButton)
  141. }
  142. .font(.system(size: 15, weight: .semibold))
  143. .foregroundStyle(.white.opacity(0.82))
  144. .padding(.trailing, 4)
  145. }
  146. }
  147. }
  148. private struct IconPanelView: View {
  149. let apps: [LauncherApp]
  150. let onAppTap: (LauncherApp) -> Void
  151. private let actions = [
  152. "house", "magnifyingglass", "target", "map", "heart", "person.2", "clock",
  153. "star", "exclamationmark.circle", "trash", "paperplane", "doc", "lock",
  154. ]
  155. var body: some View {
  156. ScrollView {
  157. HStack(alignment: .top, spacing: 20) {
  158. VStack(alignment: .leading, spacing: 12) {
  159. ForEach(Array(apps.prefix(10))) { app in
  160. Button(action: { onAppTap(app) }) {
  161. HStack(spacing: 14) {
  162. AppIconGlyph(app: app)
  163. Text(app.name)
  164. .font(.system(size: 18, weight: .medium))
  165. .foregroundStyle(.white.opacity(0.94))
  166. .lineLimit(1)
  167. .truncationMode(.tail)
  168. Spacer(minLength: 0)
  169. }
  170. .padding(.vertical, 3)
  171. }
  172. .buttonStyle(.plain)
  173. }
  174. Spacer(minLength: 0)
  175. }
  176. .frame(width: 320, alignment: .topLeading)
  177. VStack(alignment: .trailing, spacing: 14) {
  178. ForEach(Array(apps.prefix(10).enumerated()), id: \.offset) { index, _ in
  179. HStack(spacing: 12) {
  180. ForEach(0..<8, id: \.self) { col in
  181. let symbol = actions[(index * 3 + col) % actions.count]
  182. ActionBubble(symbol: symbol, highlighted: col == 0 && index % 3 == 0)
  183. }
  184. Image(systemName: "info.circle")
  185. .foregroundStyle(.white.opacity(0.6))
  186. .font(.system(size: 17))
  187. .frame(width: 20)
  188. }
  189. }
  190. }
  191. .frame(maxWidth: .infinity, alignment: .topTrailing)
  192. }
  193. .padding(.horizontal, 10)
  194. .padding(.bottom, 18)
  195. }
  196. }
  197. }
  198. private struct AppIconGlyph: View {
  199. let app: LauncherApp
  200. var body: some View {
  201. ZStack {
  202. RoundedRectangle(cornerRadius: 12, style: .continuous)
  203. .fill(Color.white.opacity(0.08))
  204. .frame(width: 48, height: 48)
  205. if let icon = NSImage(named: app.assetIconName) {
  206. Image(nsImage: icon)
  207. .resizable()
  208. .scaledToFit()
  209. .frame(width: 32, height: 32)
  210. } else {
  211. Image(systemName: app.fallbackSymbolName)
  212. .font(.system(size: 20, weight: .semibold))
  213. .foregroundStyle(.white)
  214. }
  215. }
  216. }
  217. }
  218. private struct ActionBubble: View {
  219. let symbol: String
  220. let highlighted: Bool
  221. var body: some View {
  222. Circle()
  223. .fill(highlighted ? Color.cyan.opacity(0.22) : Color.white.opacity(0.08))
  224. .overlay(
  225. Image(systemName: symbol)
  226. .foregroundStyle(.white.opacity(0.9))
  227. .font(.system(size: 15, weight: .medium))
  228. )
  229. .frame(width: 42, height: 42)
  230. }
  231. }
  232. private struct PromoBanner: View {
  233. let onCloseTap: () -> Void
  234. let onUpgradeTap: () -> Void
  235. var body: some View {
  236. HStack(spacing: 10) {
  237. Button(action: onCloseTap) {
  238. Image(systemName: "xmark")
  239. .foregroundStyle(.blue.opacity(0.95))
  240. .font(.system(size: 14, weight: .semibold))
  241. }
  242. .buttonStyle(.plain)
  243. Text("Update to Premium to unlock all features and remove ads")
  244. .font(.system(size: 13, weight: .medium))
  245. .foregroundStyle(.blue.opacity(0.95))
  246. .lineLimit(1)
  247. Spacer()
  248. Button(action: onUpgradeTap) {
  249. Text("Upgrade")
  250. .font(.system(size: 13, weight: .semibold))
  251. .foregroundStyle(.white)
  252. .padding(.horizontal, 12)
  253. .padding(.vertical, 6)
  254. .background(
  255. Capsule(style: .continuous)
  256. .fill(Color.blue.opacity(0.92))
  257. )
  258. }
  259. .buttonStyle(.plain)
  260. }
  261. .padding(.horizontal, 11)
  262. .padding(.vertical, 8)
  263. .background(
  264. RoundedRectangle(cornerRadius: 12, style: .continuous)
  265. .fill(Color.white.opacity(0.03))
  266. )
  267. .overlay(
  268. RoundedRectangle(cornerRadius: 12, style: .continuous)
  269. .stroke(Color.white.opacity(0.05), lineWidth: 1)
  270. )
  271. }
  272. }
  273. #Preview {
  274. LauncherRootView()
  275. }
  276. private struct VisualEffectBlur: NSViewRepresentable {
  277. let material: NSVisualEffectView.Material
  278. let blendingMode: NSVisualEffectView.BlendingMode
  279. func makeNSView(context: Context) -> NSVisualEffectView {
  280. let view = NSVisualEffectView()
  281. view.state = .active
  282. view.material = material
  283. view.blendingMode = blendingMode
  284. return view
  285. }
  286. func updateNSView(_ nsView: NSVisualEffectView, context: Context) {
  287. nsView.material = material
  288. nsView.blendingMode = blendingMode
  289. }
  290. }