WidgetTemplates.swift 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. import CoreGraphics
  2. import Foundation
  3. struct WidgetAction: Identifiable, Hashable {
  4. let id: String
  5. let title: String
  6. let systemImage: String
  7. /// If nil, opens the app base URL.
  8. let urlPath: String?
  9. init(id: String, title: String, systemImage: String, urlPath: String? = nil) {
  10. self.id = id
  11. self.title = title
  12. self.systemImage = systemImage
  13. self.urlPath = urlPath
  14. }
  15. }
  16. enum GmailWidgetMode: Hashable, Sendable {
  17. /// Unread count (local placeholder) and quick compose.
  18. case compact
  19. /// Sample inbox rows with reply / archive-style shortcuts.
  20. case inboxPreview
  21. /// Embedded Gmail (`WKWebView`) with search, category chips, and folder shortcuts.
  22. case interactive
  23. }
  24. enum DriveWidgetMode: Hashable, Sendable {
  25. /// Sample recent files and shortcuts to Drive recent.
  26. case recentQuick
  27. /// Recent + starred sample rows with open / share.
  28. case filesPreview
  29. /// Shortcut hub: search, folders, quick find, create, and tools — open in app browser (no embedded Drive UI).
  30. case interactive
  31. }
  32. enum KeepWidgetMode: Hashable, Sendable {
  33. /// Recent note snippets and new-note shortcut.
  34. case compact
  35. /// Embedded Google Keep (`WKWebView`) with search, labels, and create options.
  36. case interactive
  37. }
  38. enum TranslateWidgetMode: Hashable, Sendable {
  39. /// Embedded Google Translate (`WKWebView`): text, voice, conversation, history.
  40. case interactive
  41. }
  42. enum EarthWidgetMode: Hashable, Sendable {
  43. /// Embedded Google Earth Web (`WKWebView`): globe, layers, Voyager, projects.
  44. case interactive
  45. }
  46. enum GoogleSearchWidgetMode: Hashable, Sendable {
  47. /// Embedded google.com (`WKWebView`): search, voice, trends, recents.
  48. case interactive
  49. }
  50. enum WidgetLayoutMode: Hashable {
  51. case iconOnly(title: String)
  52. case actionsRow
  53. case actionsGrid(columns: Int)
  54. /// Embedded Google Maps (`WKWebView`) with search, traffic, and navigation shortcuts.
  55. case interactiveMap
  56. /// Tiered Gmail: compact preview, inbox list, or full embedded inbox.
  57. case gmail(GmailWidgetMode)
  58. /// Tiered Google Drive: recent files, starred preview, or large shortcut hub.
  59. case drive(DriveWidgetMode)
  60. /// Tiered Google Keep: recent notes or full embedded Keep.
  61. case keep(KeepWidgetMode)
  62. /// Embedded Google Translate: full translator UI in-panel.
  63. case translate(TranslateWidgetMode)
  64. /// Embedded Google Earth Web: full globe UI in-panel.
  65. case earth(EarthWidgetMode)
  66. /// Embedded Google Search (`WKWebView`): full search experience in-panel.
  67. case googleSearch(GoogleSearchWidgetMode)
  68. }
  69. struct WidgetVariant: Identifiable, Hashable {
  70. let id: String
  71. let title: String
  72. let size: WidgetSize
  73. let showHeader: Bool
  74. let layoutMode: WidgetLayoutMode
  75. let actions: [WidgetAction]
  76. }
  77. enum WidgetTemplates {
  78. static func variants(for app: LauncherApp) -> [WidgetVariant] {
  79. func v(_ id: String, _ title: String, _ size: WidgetSize, _ showHeader: Bool, _ layout: WidgetLayoutMode, _ actions: [WidgetAction]) -> WidgetVariant {
  80. WidgetVariant(id: id, title: title, size: size, showHeader: showHeader, layoutMode: layout, actions: actions)
  81. }
  82. let profile = WidgetAppProfile.from(app: app)
  83. switch profile {
  84. case .photos:
  85. return [
  86. v("photos_small", "Photo", .small, false, .iconOnly(title: "Photo"), [a("photos", "Photos", "photo.on.rectangle", "/")]),
  87. v("photos_medium", "Google Photo", .medium, false, .iconOnly(title: "Google Photo"), [a("albums", "Albums", "rectangle.stack", "/albums")]),
  88. v("photos_large", "Photos Library", .large, true, .actionsGrid(columns: 2), [
  89. a("photos", "Photos", "photo.on.rectangle", "/"),
  90. a("albums", "Albums", "rectangle.stack", "/albums"),
  91. a("explore", "Explore", "magnifyingglass", "/search"),
  92. a("archive", "Archive", "archivebox", "/archive"),
  93. a("sharing", "Sharing", "person.2", "/sharing"),
  94. a("locked", "Locked Folder", "lock", "/lockedfolder"),
  95. a("favorites", "Favorites", "star", "/favorites"),
  96. a("trash", "Trash", "trash", "/trash"),
  97. ]),
  98. ]
  99. case .gmail:
  100. return [
  101. v("gmail_small", "Unread & compose", .small, false, .gmail(.compact), []),
  102. v("gmail_medium", "Inbox preview", .medium, false, .gmail(.inboxPreview), []),
  103. v("gmail_large", "Full inbox", .large, false, .gmail(.interactive), []),
  104. ]
  105. case .drive:
  106. return [
  107. v("drive_small", "Recent files", .small, false, .drive(.recentQuick), []),
  108. v("drive_medium", "Files & sharing", .medium, false, .drive(.filesPreview), []),
  109. v("drive_large", "Full Drive", .large, false, .drive(.interactive), []),
  110. ]
  111. case .docs:
  112. return [
  113. v("docs_small", "Docs", .small, false, .iconOnly(title: "Docs"), [a("home", "Open", "doc.text.fill", "/document/u/0/")]),
  114. v("docs_medium", "Docs Shortcuts", .medium, true, .actionsGrid(columns: 2), [
  115. a("recent", "Recent", "clock.arrow.circlepath", "/document/u/0/"),
  116. a("new", "New doc", "plus", "/document/create"),
  117. a("templates", "Templates", "square.grid.2x2", "/document/u/0/templates/home"),
  118. a("search", "Search", "magnifyingglass", "/document/u/0/search"),
  119. ]),
  120. v("docs_large", "Docs Hub", .large, true, .actionsGrid(columns: 2), [
  121. a("recent", "Recent", "clock.arrow.circlepath", "/document/u/0/"),
  122. a("new", "New doc", "plus", "/document/create"),
  123. a("templates", "Templates", "square.grid.2x2", "/document/u/0/templates/home"),
  124. a("starred", "Starred", "star", "/document/u/0/starred"),
  125. a("shared", "Shared", "person.2", "/document/u/0/shared-with-me"),
  126. a("trash", "Trash", "trash", "/document/u/0/trash"),
  127. a("search", "Search", "magnifyingglass", "/document/u/0/search"),
  128. a("offline", "Offline", "arrow.down.circle", "/document/u/0/offline"),
  129. ]),
  130. ]
  131. case .sheets:
  132. return [
  133. v("sheets_small", "Sheets", .small, false, .iconOnly(title: "Sheets"), [a("home", "Open", "tablecells.fill", "/spreadsheets/u/0/")]),
  134. v("sheets_medium", "Sheets Shortcuts", .medium, true, .actionsGrid(columns: 2), [
  135. a("recent", "Recent", "clock.arrow.circlepath", "/spreadsheets/u/0/"),
  136. a("new", "New sheet", "plus", "/spreadsheets/create"),
  137. a("templates", "Templates", "square.grid.2x2", "/spreadsheets/u/0/templates"),
  138. a("search", "Search", "magnifyingglass", "/spreadsheets/u/0/search"),
  139. ]),
  140. v("sheets_large", "Sheets Hub", .large, true, .actionsGrid(columns: 2), [
  141. a("recent", "Recent", "clock.arrow.circlepath", "/spreadsheets/u/0/"),
  142. a("new", "New sheet", "plus", "/spreadsheets/create"),
  143. a("templates", "Templates", "square.grid.2x2", "/spreadsheets/u/0/templates"),
  144. a("starred", "Starred", "star", "/spreadsheets/u/0/starred"),
  145. a("shared", "Shared", "person.2", "/spreadsheets/u/0/shared-with-me"),
  146. a("trash", "Trash", "trash", "/spreadsheets/u/0/trash"),
  147. a("search", "Search", "magnifyingglass", "/spreadsheets/u/0/search"),
  148. a("offline", "Offline", "arrow.down.circle", "/spreadsheets/u/0/offline"),
  149. ]),
  150. ]
  151. case .slides:
  152. return [
  153. v("slides_small", "Slides", .small, false, .iconOnly(title: "Slides"), [a("home", "Open", "rectangle.on.rectangle.fill", "/presentation/u/0/")]),
  154. v("slides_medium", "Slides Shortcuts", .medium, true, .actionsGrid(columns: 2), [
  155. a("recent", "Recent", "clock.arrow.circlepath", "/presentation/u/0/"),
  156. a("new", "New deck", "plus", "/presentation/create"),
  157. a("templates", "Templates", "square.grid.2x2", "/presentation/u/0/templates"),
  158. a("search", "Search", "magnifyingglass", "/presentation/u/0/search"),
  159. ]),
  160. v("slides_large", "Slides Hub", .large, true, .actionsGrid(columns: 2), [
  161. a("recent", "Recent", "clock.arrow.circlepath", "/presentation/u/0/"),
  162. a("new", "New deck", "plus", "/presentation/create"),
  163. a("templates", "Templates", "square.grid.2x2", "/presentation/u/0/templates"),
  164. a("starred", "Starred", "star", "/presentation/u/0/starred"),
  165. a("shared", "Shared", "person.2", "/presentation/u/0/shared-with-me"),
  166. a("trash", "Trash", "trash", "/presentation/u/0/trash"),
  167. a("search", "Search", "magnifyingglass", "/presentation/u/0/search"),
  168. a("offline", "Offline", "arrow.down.circle", "/presentation/u/0/offline"),
  169. ]),
  170. ]
  171. case .forms:
  172. return [
  173. v("forms_small", "Forms", .small, false, .iconOnly(title: "Forms"), [a("home", "Open", "list.bullet.rectangle.fill", "/forms/u/0/")]),
  174. v("forms_medium", "Forms Shortcuts", .medium, true, .actionsGrid(columns: 2), [
  175. a("recent", "Recent", "clock.arrow.circlepath", "/forms/u/0/"),
  176. a("new", "New form", "plus", "https://docs.google.com/forms/create"),
  177. a("contacts", "Contacts", "person.crop.circle", "/forms/u/0/contacts"),
  178. a("search", "Search", "magnifyingglass", "/forms/u/0/search"),
  179. ]),
  180. v("forms_large", "Forms Hub", .large, true, .actionsGrid(columns: 2), [
  181. a("recent", "Recent", "clock.arrow.circlepath", "/forms/u/0/"),
  182. a("new", "New form", "plus", "https://docs.google.com/forms/create"),
  183. a("starred", "Starred", "star", "/forms/u/0/starred"),
  184. a("shared", "Shared", "person.2", "/forms/u/0/shared-with-me"),
  185. a("trash", "Trash", "trash", "/forms/u/0/trash"),
  186. a("contacts", "Contacts", "person.crop.circle", "/forms/u/0/contacts"),
  187. a("search", "Search", "magnifyingglass", "/forms/u/0/search"),
  188. a("settings", "Settings", "gearshape", "/forms/u/0/settings"),
  189. ]),
  190. ]
  191. case .calendar:
  192. return [
  193. v("calendar_small", "Today", .small, false, .actionsRow, [
  194. a("today", "Today", "calendar", "/calendar/u/0/r"),
  195. a("create", "Create", "plus.circle", "/calendar/u/0/r/eventedit"),
  196. ]),
  197. v("calendar_medium", "Schedule", .medium, true, .actionsGrid(columns: 2), [
  198. a("today", "Today", "calendar", "/calendar/u/0/r"),
  199. a("week", "Week", "calendar.badge.clock", "/calendar/u/0/r/week"),
  200. a("create", "New Event", "plus.circle", "/calendar/u/0/r/eventedit"),
  201. a("tasks", "Tasks", "checkmark.square", "https://tasks.google.com/"),
  202. ]),
  203. v("calendar_large", "Calendar Hub", .large, true, .actionsGrid(columns: 2), [
  204. a("today", "Today", "calendar", "/calendar/u/0/r"),
  205. a("week", "Week", "calendar.badge.clock", "/calendar/u/0/r/week"),
  206. a("month", "Month", "calendar", "/calendar/u/0/r/month"),
  207. a("create", "New Event", "plus.circle", "/calendar/u/0/r/eventedit"),
  208. a("tasks", "Tasks", "checkmark.square", "https://tasks.google.com/"),
  209. a("settings", "Settings", "gearshape", "/calendar/u/0/r/settings"),
  210. a("search", "Search", "magnifyingglass", "/calendar/u/0/r/search"),
  211. a("print", "Print", "printer", "/calendar/u/0/r/print"),
  212. ]),
  213. ]
  214. case .maps:
  215. // Live map: `MapsInteractiveWidgetView` (embedded `WKWebView`); actions unused.
  216. return [
  217. v("maps_small", "Live map", .small, true, .interactiveMap, []),
  218. v("maps_medium", "Live map", .medium, true, .interactiveMap, []),
  219. v("maps_large", "Live map", .large, true, .interactiveMap, []),
  220. ]
  221. case .youtube:
  222. return [
  223. v("youtube_small", "Quick Watch", .small, false, .actionsRow, [
  224. a("home", "Home", "house", "/"),
  225. a("shorts", "Shorts", "bolt", "/shorts"),
  226. a("subs", "Subs", "play.rectangle", "/feed/subscriptions"),
  227. ]),
  228. v("youtube_medium", "Browse", .medium, true, .actionsGrid(columns: 2), [
  229. a("home", "Home", "house", "/"),
  230. a("trending", "Trending", "flame", "/feed/trending"),
  231. a("shorts", "Shorts", "bolt", "/shorts"),
  232. a("subs", "Subscriptions", "play.rectangle", "/feed/subscriptions"),
  233. ]),
  234. v("youtube_large", "Library", .large, true, .actionsGrid(columns: 2), [
  235. a("home", "Home", "house", "/"),
  236. a("shorts", "Shorts", "play.square", "/shorts"),
  237. a("subscriptions", "Subscriptions", "play.rectangle", "/feed/subscriptions"),
  238. a("history", "History", "clock", "/feed/history"),
  239. a("playlists", "Playlists", "list.bullet.rectangle", "/feed/playlists"),
  240. a("liked", "Liked videos", "hand.thumbsup", "/playlist?list=LL"),
  241. ]),
  242. ]
  243. case .translate:
  244. return [
  245. v("translate_small", "Translate", .small, false, .actionsRow, [
  246. a("open", "Translator", "character.bubble.fill", "/"),
  247. a("history", "History", "clock", "/m/"),
  248. a("saved", "Phrasebook", "bookmark", "/m/"),
  249. ]),
  250. v("translate_medium", "Translate Tools", .medium, true, .actionsGrid(columns: 2), [
  251. a("open", "Web translator", "globe", "/"),
  252. a("docs", "Documents", "doc.text", "https://translate.google.com/?tr=f&hl=en&tab=wT"),
  253. a("conversation", "Conversation", "bubble.left.and.bubble.right", "/m/"),
  254. a("history", "History", "clock", "/m/"),
  255. ]),
  256. v("translate_large", "Full Translate", .large, false, .translate(.interactive), []),
  257. ]
  258. case .search:
  259. return [
  260. v("search_medium", "Google Shortcuts", .medium, true, .actionsGrid(columns: 2), [
  261. a("web", "Web", "globe", "/"),
  262. a("images", "Images", "photo", "https://www.google.com/imghp"),
  263. a("shopping", "Shopping", "bag", "https://www.google.com/search?tbm=shop"),
  264. a("maps", "Maps", "map", "https://maps.google.com/maps"),
  265. ]),
  266. v("search_large", "Full Search", .large, false, .googleSearch(.interactive), []),
  267. ]
  268. case .earth:
  269. return [
  270. v("earth_medium", "Earth Explorer", .medium, true, .actionsGrid(columns: 2), [
  271. a("open", "Open", "globe.americas.fill", "/web/"),
  272. a("voyager", "Voyager", "sailboat", "/web/data/"),
  273. a("projects", "Projects", "folder", "/web/projects/"),
  274. a("search", "Search", "magnifyingglass", "/web/search"),
  275. ]),
  276. v("earth_large", "Full Earth", .large, false, .earth(.interactive), []),
  277. ]
  278. case .shopping:
  279. return [
  280. v("shopping_small", "Shopping", .small, false, .iconOnly(title: "Shopping"), [a("open", "Open", "bag.fill", "/")]),
  281. v("shopping_medium", "Shopping Browse", .medium, true, .actionsGrid(columns: 2), [
  282. a("home", "Home", "house", "/"),
  283. a("deals", "Deals", "tag", "/"),
  284. a("saved", "Saved", "bookmark", "/"),
  285. a("search", "Search", "magnifyingglass", "/"),
  286. ]),
  287. ]
  288. case .keep:
  289. return [
  290. v("keep_small", "Recent notes", .small, false, .keep(.compact), []),
  291. v("keep_large", "Full Keep", .large, false, .keep(.interactive), []),
  292. ]
  293. case .travel:
  294. return [
  295. v("travel_small", "Travel", .small, false, .iconOnly(title: "Travel"), [a("trips", "Trips", "airplane", "/travel")]),
  296. v("travel_medium", "Trip Planner", .medium, true, .actionsGrid(columns: 2), [
  297. a("trips", "Trips", "airplane", "/travel"),
  298. a("explore", "Explore", "globe", "/travel/explore"),
  299. a("flights", "Flights", "airplane.departure", "/flights"),
  300. a("hotels", "Hotels", "bed.double", "/hotels"),
  301. ]),
  302. ]
  303. case .meet:
  304. return [
  305. v("meet_small", "Meet", .small, false, .actionsRow, [
  306. a("join", "Join", "video.badge.plus", "/"),
  307. a("new", "New", "plus.circle", "/new"),
  308. a("landing", "Home", "house", "/landing"),
  309. ]),
  310. v("meet_large", "Meet Hub", .large, true, .actionsGrid(columns: 2), [
  311. a("new", "New meeting", "video.badge.plus", "/new"),
  312. a("join", "Join", "person.wave.2", "/"),
  313. a("landing", "Home", "house", "/landing"),
  314. a("schedule", "Schedule", "calendar", "https://calendar.google.com/calendar/u/0/r/eventedit"),
  315. ]),
  316. ]
  317. case .contacts:
  318. return [
  319. v("contacts_small", "Contacts", .small, false, .actionsRow, [
  320. a("contacts", "Contacts", "person.crop.circle", "/"),
  321. a("duplicates", "Duplicates", "person.2", "/duplicates"),
  322. a("labels", "Labels", "tag", "/"),
  323. ]),
  324. v("contacts_medium", "Contacts Hub", .medium, true, .actionsGrid(columns: 2), [
  325. a("contacts", "All", "person.crop.circle", "/"),
  326. a("frequent", "Frequent", "clock", "/"),
  327. a("duplicates", "Duplicates", "person.2", "/duplicates"),
  328. a("trash", "Trash", "trash", "/trash"),
  329. ]),
  330. ]
  331. case .blogger:
  332. return [
  333. v("blogger_small", "Blogger", .small, false, .iconOnly(title: "Blogger"), [a("home", "Open", "text.book.closed.fill", "/")]),
  334. v("blogger_medium", "Blogger Tools", .medium, true, .actionsGrid(columns: 2), [
  335. a("home", "Reading list", "list.bullet", "/"),
  336. a("create", "New post", "square.and.pencil", "/"),
  337. a("reading", "Reading list", "book", "/reading-list"),
  338. a("search", "Search", "magnifyingglass", "/"),
  339. ]),
  340. ]
  341. case .play:
  342. return [
  343. v("play_small", "Play", .small, false, .iconOnly(title: "Play"), [a("store", "Store", "play.circle.fill", "/store/apps")]),
  344. v("play_medium", "Play Store", .medium, true, .actionsGrid(columns: 2), [
  345. a("apps", "Apps", "app.badge", "/store/apps"),
  346. a("games", "Games", "gamecontroller", "/store/games"),
  347. a("movies", "Movies", "film", "/store/movies"),
  348. a("books", "Books", "book", "/store/books"),
  349. ]),
  350. ]
  351. case .news:
  352. return [
  353. v("news_small", "News", .small, false, .iconOnly(title: "News"), [a("home", "Headlines", "newspaper.fill", "/home")]),
  354. v("news_medium", "News Feeds", .medium, true, .actionsGrid(columns: 2), [
  355. a("foryou", "For you", "person.crop.circle", "/foryou"),
  356. a("headlines", "Headlines", "newspaper", "/topstories"),
  357. a("topics", "Topics", "square.grid.2x2", "/topics"),
  358. a("search", "Search", "magnifyingglass", "/search"),
  359. ]),
  360. ]
  361. case .chat:
  362. return [
  363. v("chat_small", "Chat", .small, false, .actionsRow, [
  364. a("home", "Home", "bubble.left.and.bubble.right.fill", "/u/0/"),
  365. a("spaces", "Spaces", "square.grid.3x3.fill", "/u/0/spaces"),
  366. a("meet", "Meet", "video", "https://meet.google.com/"),
  367. ]),
  368. v("chat_large", "Chat Hub", .large, true, .actionsGrid(columns: 2), [
  369. a("home", "Home", "house", "/u/0/"),
  370. a("spaces", "Spaces", "square.grid.3x3.fill", "/u/0/spaces"),
  371. a("browse", "Browse", "square.grid.2x2", "/u/0/browse"),
  372. a("meet", "Meet", "video", "https://meet.google.com/"),
  373. ]),
  374. ]
  375. case .finance:
  376. return [
  377. v("finance_small", "Finance", .small, false, .actionsRow, [
  378. a("home", "Markets", "chart.line.uptrend.xyaxis", "/finance"),
  379. a("markets", "Markets", "chart.bar", "/finance/markets"),
  380. a("portfolio", "Portfolio", "briefcase", "/finance/portfolio"),
  381. ]),
  382. v("finance_medium", "Finance Hub", .medium, true, .actionsGrid(columns: 2), [
  383. a("home", "Home", "house", "/finance"),
  384. a("markets", "Markets", "chart.bar", "/finance/markets"),
  385. a("portfolio", "Portfolio", "briefcase", "/finance/portfolio"),
  386. a("news", "News", "newspaper", "/finance/news"),
  387. ]),
  388. ]
  389. case .jamboard:
  390. return [
  391. v("jamboard_small", "Jamboard", .small, false, .actionsRow, [
  392. a("open", "Boards", "paintbrush.fill", "/"),
  393. a("create", "New jam", "plus", "/"),
  394. a("shared", "Shared", "person.2", "/"),
  395. ]),
  396. v("jamboard_large", "Jamboard", .large, true, .actionsGrid(columns: 2), [
  397. a("open", "Home", "house", "/"),
  398. a("create", "New jam", "plus", "/"),
  399. a("shared", "Shared with me", "person.2", "/"),
  400. a("trash", "Trash", "trash", "/"),
  401. ]),
  402. ]
  403. case .classroom:
  404. return [
  405. v("classroom_small", "Classroom", .small, false, .actionsRow, [
  406. a("home", "Classes", "graduationcap.fill", "/u/0/h/"),
  407. a("calendar", "Calendar", "calendar", "/u/0/calendar"),
  408. a("todo", "To-do", "checklist", "/u/0/notifications"),
  409. ]),
  410. v("classroom_large", "Classroom Hub", .large, true, .actionsGrid(columns: 2), [
  411. a("home", "Home", "house", "/u/0/h/"),
  412. a("calendar", "Calendar", "calendar", "/u/0/calendar"),
  413. a("archive", "Archive", "archivebox", "/u/0/archived"),
  414. a("settings", "Settings", "gearshape", "/u/0/settings"),
  415. ]),
  416. ]
  417. case .artsCulture:
  418. return [
  419. v("arts_small", "Arts & Culture", .small, false, .iconOnly(title: "Arts"), [a("home", "Explore", "building.columns.fill", "/")]),
  420. v("arts_medium", "Arts Browse", .medium, true, .actionsGrid(columns: 2), [
  421. a("home", "Home", "house", "/"),
  422. a("explore", "Explore", "globe", "/explore"),
  423. a("nearby", "Near you", "mappin.and.ellipse", "/nearby"),
  424. a("search", "Search", "magnifyingglass", "/search"),
  425. ]),
  426. ]
  427. case .voice:
  428. return [
  429. v("voice_small", "Voice", .small, false, .actionsRow, [
  430. a("messages", "Messages", "bubble.left", "/messages"),
  431. a("calls", "Calls", "phone", "/calls"),
  432. a("voicemail", "Voicemail", "recordingtape", "/voicemail"),
  433. ]),
  434. v("voice_large", "Voice Hub", .large, true, .actionsGrid(columns: 2), [
  435. a("messages", "Messages", "bubble.left", "/messages"),
  436. a("calls", "Calls", "phone", "/calls"),
  437. a("voicemail", "Voicemail", "recordingtape", "/voicemail"),
  438. a("settings", "Settings", "gearshape", "/settings"),
  439. ]),
  440. ]
  441. case .chromeWebStore:
  442. return [
  443. v("webstore_small", "Web Store", .small, false, .iconOnly(title: "Web Store"), [a("home", "Store", "bag.fill", "/webstore")]),
  444. v("webstore_medium", "Chrome Web Store", .medium, true, .actionsGrid(columns: 2), [
  445. a("extensions", "Extensions", "puzzlepiece.extension", "/webstore/category/extensions"),
  446. a("themes", "Themes", "paintpalette", "/webstore/category/themes"),
  447. a("home", "Home", "house", "/webstore"),
  448. a("search", "Search", "magnifyingglass", "/webstore/search"),
  449. ]),
  450. ]
  451. case .fi:
  452. return [
  453. v("fi_small", "Fi", .small, false, .actionsRow, [
  454. a("home", "Account", "antenna.radiowaves.left.and.right", "/"),
  455. a("billing", "Billing", "creditcard", "/billing"),
  456. a("coverage", "Coverage", "map", "/coverage"),
  457. ]),
  458. v("fi_medium", "Google Fi", .medium, true, .actionsGrid(columns: 2), [
  459. a("home", "Home", "house", "/"),
  460. a("billing", "Billing", "creditcard", "/billing"),
  461. a("coverage", "Coverage", "map", "/coverage"),
  462. a("support", "Support", "questionmark.circle", "/support"),
  463. ]),
  464. ]
  465. case .ads:
  466. return [
  467. v("ads_small", "Ads", .small, false, .actionsRow, [
  468. a("home", "Overview", "megaphone.fill", "/aw/"),
  469. a("campaigns", "Campaigns", "chart.bar", "/aw/campaigns"),
  470. a("reports", "Reports", "doc.text", "/aw/reports"),
  471. ]),
  472. v("ads_medium", "Google Ads", .medium, true, .actionsGrid(columns: 2), [
  473. a("home", "Home", "house", "/aw/"),
  474. a("campaigns", "Campaigns", "chart.bar", "/aw/campaigns"),
  475. a("tools", "Tools", "wrench", "/aw/tools"),
  476. a("billing", "Billing", "creditcard", "/aw/billing"),
  477. ]),
  478. ]
  479. case .remoteDesktop:
  480. return [
  481. v("remote_small", "Remote", .small, false, .actionsRow, [
  482. a("access", "Remote access", "desktopcomputer", "/access"),
  483. a("support", "Support", "person.crop.circle", "/support"),
  484. a("downloads", "Downloads", "arrow.down.circle", "/"),
  485. ]),
  486. v("remote_large", "Remote Desktop", .large, true, .actionsGrid(columns: 2), [
  487. a("access", "Remote access", "desktopcomputer", "/access"),
  488. a("support", "Support", "person.crop.circle", "/support"),
  489. a("downloads", "Downloads", "arrow.down.circle", "/"),
  490. a("help", "Help", "questionmark.circle", "/support"),
  491. ]),
  492. ]
  493. case .gemini:
  494. return [
  495. v("gemini_small", "Gemini", .small, false, .actionsRow, [
  496. a("app", "Gemini", "sparkles", "/app"),
  497. a("home", "Home", "house", "/"),
  498. a("extensions", "Extensions", "puzzlepiece", "/extensions"),
  499. ]),
  500. v("gemini_large", "Gemini Hub", .large, true, .actionsGrid(columns: 2), [
  501. a("app", "Chat", "sparkles", "/app"),
  502. a("home", "Home", "house", "/"),
  503. a("extensions", "Extensions", "puzzlepiece", "/extensions"),
  504. a("help", "Help", "questionmark.circle", "/help"),
  505. ]),
  506. ]
  507. case .books:
  508. return [
  509. v("books_small", "Books", .small, false, .iconOnly(title: "Books"), [a("home", "Library", "book.fill", "/ebooks")]),
  510. v("books_medium", "Google Books", .medium, true, .actionsGrid(columns: 2), [
  511. a("library", "My books", "books.vertical", "/ebooks/library"),
  512. a("shop", "Shop", "cart", "/ebooks"),
  513. a("audiobooks", "Audiobooks", "headphones", "/audiobooks"),
  514. a("search", "Search", "magnifyingglass", "/ebooks/search"),
  515. ]),
  516. ]
  517. case .unknown:
  518. return genericUtilityVariants(prefix: "generic", appName: app.name)
  519. }
  520. }
  521. static func variant(for app: LauncherApp, variantID: String?) -> WidgetVariant {
  522. let variants = variants(for: app)
  523. if let variantID, let match = variants.first(where: { $0.id == variantID }) {
  524. return match
  525. }
  526. return variants.first ?? WidgetVariant(
  527. id: "fallback_small",
  528. title: "Quick Access",
  529. size: .small,
  530. showHeader: false,
  531. layoutMode: .actionsRow,
  532. actions: [a("open", "Open", "arrow.up.right", nil)]
  533. )
  534. }
  535. }
  536. private extension WidgetTemplates {
  537. static func genericUtilityVariants(prefix: String, appName: String) -> [WidgetVariant] {
  538. [
  539. WidgetVariant(
  540. id: "\(prefix)_small",
  541. title: "Quick Access",
  542. size: .small,
  543. showHeader: false,
  544. layoutMode: .actionsRow,
  545. actions: [
  546. a("open", "Open", "arrow.up.right", "/"),
  547. a("search", "Search", "magnifyingglass", "/"),
  548. a("favorites", "Favorites", "star", "/"),
  549. ]
  550. ),
  551. WidgetVariant(
  552. id: "\(prefix)_medium",
  553. title: appName,
  554. size: .medium,
  555. showHeader: true,
  556. layoutMode: .actionsGrid(columns: 2),
  557. actions: [
  558. a("open", "Open", "arrow.up.right", "/"),
  559. a("search", "Search", "magnifyingglass", "/"),
  560. a("favorites", "Favorites", "star", "/"),
  561. a("recent", "Recent", "clock.arrow.circlepath", "/"),
  562. ]
  563. ),
  564. ]
  565. }
  566. static func a(_ id: String, _ title: String, _ image: String, _ path: String?) -> WidgetAction {
  567. WidgetAction(id: id, title: title, systemImage: image, urlPath: path)
  568. }
  569. }
  570. extension WidgetLayoutMode {
  571. /// Panels that embed interactive web content need to become key so text fields and the web view receive input.
  572. var needsKeyCapablePanel: Bool {
  573. switch self {
  574. case .interactiveMap: true
  575. case .gmail(.interactive): true
  576. case .drive(.interactive): true
  577. case .keep(.interactive): true
  578. case .translate(.interactive): true
  579. case .earth(.interactive): true
  580. case .googleSearch(.interactive): true
  581. default: false
  582. }
  583. }
  584. /// Fixed sizes for tiered Gmail / Drive widgets (variant size already matches the tier).
  585. func desktopPanelSizeOverride() -> CGSize? {
  586. switch self {
  587. case .gmail(let mode):
  588. switch mode {
  589. case .compact: return CGSize(width: 220, height: 220)
  590. case .inboxPreview: return CGSize(width: 420, height: 480)
  591. case .interactive: return CGSize(width: 540, height: 580)
  592. }
  593. case .drive(let mode):
  594. switch mode {
  595. case .recentQuick: return CGSize(width: 230, height: 260)
  596. case .filesPreview: return CGSize(width: 420, height: 480)
  597. case .interactive: return CGSize(width: 540, height: 580)
  598. }
  599. case .keep(let mode):
  600. switch mode {
  601. case .compact: return CGSize(width: 230, height: 260)
  602. case .interactive: return CGSize(width: 540, height: 580)
  603. }
  604. case .translate(.interactive):
  605. return CGSize(width: 560, height: 640)
  606. case .earth(.interactive):
  607. return CGSize(width: 580, height: 640)
  608. case .googleSearch(.interactive):
  609. return CGSize(width: 480, height: 220)
  610. default:
  611. return nil
  612. }
  613. }
  614. func widgetPreviewCardSize() -> CGSize? {
  615. switch self {
  616. case .gmail(let mode):
  617. switch mode {
  618. case .compact: return CGSize(width: 200, height: 200)
  619. case .inboxPreview: return CGSize(width: 380, height: 420)
  620. case .interactive: return CGSize(width: 480, height: 440)
  621. }
  622. case .drive(let mode):
  623. switch mode {
  624. case .recentQuick: return CGSize(width: 210, height: 230)
  625. case .filesPreview: return CGSize(width: 380, height: 420)
  626. case .interactive: return CGSize(width: 480, height: 440)
  627. }
  628. case .keep(let mode):
  629. switch mode {
  630. case .compact: return CGSize(width: 210, height: 230)
  631. case .interactive: return CGSize(width: 480, height: 440)
  632. }
  633. case .translate(.interactive):
  634. return CGSize(width: 480, height: 460)
  635. case .earth(.interactive):
  636. return CGSize(width: 490, height: 470)
  637. case .googleSearch(.interactive):
  638. return CGSize(width: 440, height: 210)
  639. default:
  640. return nil
  641. }
  642. }
  643. }