WidgetTemplates.swift 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  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_small", "Search", .small, false, .actionsRow, [
  261. a("web", "Web", "globe", "/"),
  262. a("images", "Images", "photo", "https://www.google.com/imghp"),
  263. a("maps", "Maps", "map", "https://maps.google.com/maps"),
  264. ]),
  265. v("search_medium", "Google Shortcuts", .medium, true, .actionsGrid(columns: 2), [
  266. a("web", "Web", "globe", "/"),
  267. a("images", "Images", "photo", "https://www.google.com/imghp"),
  268. a("shopping", "Shopping", "bag", "https://www.google.com/search?tbm=shop"),
  269. a("maps", "Maps", "map", "https://maps.google.com/maps"),
  270. ]),
  271. v("search_large", "Full Search", .large, false, .googleSearch(.interactive), []),
  272. ]
  273. case .earth:
  274. return [
  275. v("earth_medium", "Earth Explorer", .medium, true, .actionsGrid(columns: 2), [
  276. a("open", "Open", "globe.americas.fill", "/web/"),
  277. a("voyager", "Voyager", "sailboat", "/web/data/"),
  278. a("projects", "Projects", "folder", "/web/projects/"),
  279. a("search", "Search", "magnifyingglass", "/web/search"),
  280. ]),
  281. v("earth_large", "Full Earth", .large, false, .earth(.interactive), []),
  282. ]
  283. case .shopping:
  284. return [
  285. v("shopping_small", "Shopping", .small, false, .iconOnly(title: "Shopping"), [a("open", "Open", "bag.fill", "/")]),
  286. v("shopping_medium", "Shopping Browse", .medium, true, .actionsGrid(columns: 2), [
  287. a("home", "Home", "house", "/"),
  288. a("deals", "Deals", "tag", "/"),
  289. a("saved", "Saved", "bookmark", "/"),
  290. a("search", "Search", "magnifyingglass", "/"),
  291. ]),
  292. ]
  293. case .keep:
  294. return [
  295. v("keep_small", "Recent notes", .small, false, .keep(.compact), []),
  296. v("keep_large", "Full Keep", .large, false, .keep(.interactive), []),
  297. ]
  298. case .travel:
  299. return [
  300. v("travel_small", "Travel", .small, false, .iconOnly(title: "Travel"), [a("trips", "Trips", "airplane", "/travel")]),
  301. v("travel_medium", "Trip Planner", .medium, true, .actionsGrid(columns: 2), [
  302. a("trips", "Trips", "airplane", "/travel"),
  303. a("explore", "Explore", "globe", "/travel/explore"),
  304. a("flights", "Flights", "airplane.departure", "/flights"),
  305. a("hotels", "Hotels", "bed.double", "/hotels"),
  306. ]),
  307. ]
  308. case .meet:
  309. return [
  310. v("meet_small", "Meet", .small, false, .actionsRow, [
  311. a("join", "Join", "video.badge.plus", "/"),
  312. a("new", "New", "plus.circle", "/new"),
  313. a("landing", "Home", "house", "/landing"),
  314. ]),
  315. v("meet_large", "Meet Hub", .large, true, .actionsGrid(columns: 2), [
  316. a("new", "New meeting", "video.badge.plus", "/new"),
  317. a("join", "Join", "person.wave.2", "/"),
  318. a("landing", "Home", "house", "/landing"),
  319. a("schedule", "Schedule", "calendar", "https://calendar.google.com/calendar/u/0/r/eventedit"),
  320. ]),
  321. ]
  322. case .contacts:
  323. return [
  324. v("contacts_small", "Contacts", .small, false, .actionsRow, [
  325. a("contacts", "Contacts", "person.crop.circle", "/"),
  326. a("duplicates", "Duplicates", "person.2", "/duplicates"),
  327. a("labels", "Labels", "tag", "/"),
  328. ]),
  329. v("contacts_medium", "Contacts Hub", .medium, true, .actionsGrid(columns: 2), [
  330. a("contacts", "All", "person.crop.circle", "/"),
  331. a("frequent", "Frequent", "clock", "/"),
  332. a("duplicates", "Duplicates", "person.2", "/duplicates"),
  333. a("trash", "Trash", "trash", "/trash"),
  334. ]),
  335. ]
  336. case .blogger:
  337. return [
  338. v("blogger_small", "Blogger", .small, false, .iconOnly(title: "Blogger"), [a("home", "Open", "text.book.closed.fill", "/")]),
  339. v("blogger_medium", "Blogger Tools", .medium, true, .actionsGrid(columns: 2), [
  340. a("home", "Reading list", "list.bullet", "/"),
  341. a("create", "New post", "square.and.pencil", "/"),
  342. a("reading", "Reading list", "book", "/reading-list"),
  343. a("search", "Search", "magnifyingglass", "/"),
  344. ]),
  345. ]
  346. case .play:
  347. return [
  348. v("play_small", "Play", .small, false, .iconOnly(title: "Play"), [a("store", "Store", "play.circle.fill", "/store/apps")]),
  349. v("play_medium", "Play Store", .medium, true, .actionsGrid(columns: 2), [
  350. a("apps", "Apps", "app.badge", "/store/apps"),
  351. a("games", "Games", "gamecontroller", "/store/games"),
  352. a("movies", "Movies", "film", "/store/movies"),
  353. a("books", "Books", "book", "/store/books"),
  354. ]),
  355. ]
  356. case .news:
  357. return [
  358. v("news_small", "News", .small, false, .iconOnly(title: "News"), [a("home", "Headlines", "newspaper.fill", "/home")]),
  359. v("news_medium", "News Feeds", .medium, true, .actionsGrid(columns: 2), [
  360. a("foryou", "For you", "person.crop.circle", "/foryou"),
  361. a("headlines", "Headlines", "newspaper", "/topstories"),
  362. a("topics", "Topics", "square.grid.2x2", "/topics"),
  363. a("search", "Search", "magnifyingglass", "/search"),
  364. ]),
  365. ]
  366. case .chat:
  367. return [
  368. v("chat_small", "Chat", .small, false, .actionsRow, [
  369. a("home", "Home", "bubble.left.and.bubble.right.fill", "/u/0/"),
  370. a("spaces", "Spaces", "square.grid.3x3.fill", "/u/0/spaces"),
  371. a("meet", "Meet", "video", "https://meet.google.com/"),
  372. ]),
  373. v("chat_large", "Chat Hub", .large, true, .actionsGrid(columns: 2), [
  374. a("home", "Home", "house", "/u/0/"),
  375. a("spaces", "Spaces", "square.grid.3x3.fill", "/u/0/spaces"),
  376. a("browse", "Browse", "square.grid.2x2", "/u/0/browse"),
  377. a("meet", "Meet", "video", "https://meet.google.com/"),
  378. ]),
  379. ]
  380. case .finance:
  381. return [
  382. v("finance_small", "Finance", .small, false, .actionsRow, [
  383. a("home", "Markets", "chart.line.uptrend.xyaxis", "/finance"),
  384. a("markets", "Markets", "chart.bar", "/finance/markets"),
  385. a("portfolio", "Portfolio", "briefcase", "/finance/portfolio"),
  386. ]),
  387. v("finance_medium", "Finance Hub", .medium, true, .actionsGrid(columns: 2), [
  388. a("home", "Home", "house", "/finance"),
  389. a("markets", "Markets", "chart.bar", "/finance/markets"),
  390. a("portfolio", "Portfolio", "briefcase", "/finance/portfolio"),
  391. a("news", "News", "newspaper", "/finance/news"),
  392. ]),
  393. ]
  394. case .jamboard:
  395. return [
  396. v("jamboard_small", "Jamboard", .small, false, .actionsRow, [
  397. a("open", "Boards", "paintbrush.fill", "/"),
  398. a("create", "New jam", "plus", "/"),
  399. a("shared", "Shared", "person.2", "/"),
  400. ]),
  401. v("jamboard_large", "Jamboard", .large, true, .actionsGrid(columns: 2), [
  402. a("open", "Home", "house", "/"),
  403. a("create", "New jam", "plus", "/"),
  404. a("shared", "Shared with me", "person.2", "/"),
  405. a("trash", "Trash", "trash", "/"),
  406. ]),
  407. ]
  408. case .classroom:
  409. return [
  410. v("classroom_small", "Classroom", .small, false, .actionsRow, [
  411. a("home", "Classes", "graduationcap.fill", "/u/0/h/"),
  412. a("calendar", "Calendar", "calendar", "/u/0/calendar"),
  413. a("todo", "To-do", "checklist", "/u/0/notifications"),
  414. ]),
  415. v("classroom_large", "Classroom Hub", .large, true, .actionsGrid(columns: 2), [
  416. a("home", "Home", "house", "/u/0/h/"),
  417. a("calendar", "Calendar", "calendar", "/u/0/calendar"),
  418. a("archive", "Archive", "archivebox", "/u/0/archived"),
  419. a("settings", "Settings", "gearshape", "/u/0/settings"),
  420. ]),
  421. ]
  422. case .artsCulture:
  423. return [
  424. v("arts_small", "Arts & Culture", .small, false, .iconOnly(title: "Arts"), [a("home", "Explore", "building.columns.fill", "/")]),
  425. v("arts_medium", "Arts Browse", .medium, true, .actionsGrid(columns: 2), [
  426. a("home", "Home", "house", "/"),
  427. a("explore", "Explore", "globe", "/explore"),
  428. a("nearby", "Near you", "mappin.and.ellipse", "/nearby"),
  429. a("search", "Search", "magnifyingglass", "/search"),
  430. ]),
  431. ]
  432. case .voice:
  433. return [
  434. v("voice_small", "Voice", .small, false, .actionsRow, [
  435. a("messages", "Messages", "bubble.left", "/messages"),
  436. a("calls", "Calls", "phone", "/calls"),
  437. a("voicemail", "Voicemail", "recordingtape", "/voicemail"),
  438. ]),
  439. v("voice_large", "Voice Hub", .large, true, .actionsGrid(columns: 2), [
  440. a("messages", "Messages", "bubble.left", "/messages"),
  441. a("calls", "Calls", "phone", "/calls"),
  442. a("voicemail", "Voicemail", "recordingtape", "/voicemail"),
  443. a("settings", "Settings", "gearshape", "/settings"),
  444. ]),
  445. ]
  446. case .chromeWebStore:
  447. return [
  448. v("webstore_small", "Web Store", .small, false, .iconOnly(title: "Web Store"), [a("home", "Store", "bag.fill", "/webstore")]),
  449. v("webstore_medium", "Chrome Web Store", .medium, true, .actionsGrid(columns: 2), [
  450. a("extensions", "Extensions", "puzzlepiece.extension", "/webstore/category/extensions"),
  451. a("themes", "Themes", "paintpalette", "/webstore/category/themes"),
  452. a("home", "Home", "house", "/webstore"),
  453. a("search", "Search", "magnifyingglass", "/webstore/search"),
  454. ]),
  455. ]
  456. case .fi:
  457. return [
  458. v("fi_small", "Fi", .small, false, .actionsRow, [
  459. a("home", "Account", "antenna.radiowaves.left.and.right", "/"),
  460. a("billing", "Billing", "creditcard", "/billing"),
  461. a("coverage", "Coverage", "map", "/coverage"),
  462. ]),
  463. v("fi_medium", "Google Fi", .medium, true, .actionsGrid(columns: 2), [
  464. a("home", "Home", "house", "/"),
  465. a("billing", "Billing", "creditcard", "/billing"),
  466. a("coverage", "Coverage", "map", "/coverage"),
  467. a("support", "Support", "questionmark.circle", "/support"),
  468. ]),
  469. ]
  470. case .ads:
  471. return [
  472. v("ads_small", "Ads", .small, false, .actionsRow, [
  473. a("home", "Overview", "megaphone.fill", "/aw/"),
  474. a("campaigns", "Campaigns", "chart.bar", "/aw/campaigns"),
  475. a("reports", "Reports", "doc.text", "/aw/reports"),
  476. ]),
  477. v("ads_medium", "Google Ads", .medium, true, .actionsGrid(columns: 2), [
  478. a("home", "Home", "house", "/aw/"),
  479. a("campaigns", "Campaigns", "chart.bar", "/aw/campaigns"),
  480. a("tools", "Tools", "wrench", "/aw/tools"),
  481. a("billing", "Billing", "creditcard", "/aw/billing"),
  482. ]),
  483. ]
  484. case .remoteDesktop:
  485. return [
  486. v("remote_small", "Remote", .small, false, .actionsRow, [
  487. a("access", "Remote access", "desktopcomputer", "/access"),
  488. a("support", "Support", "person.crop.circle", "/support"),
  489. a("downloads", "Downloads", "arrow.down.circle", "/"),
  490. ]),
  491. v("remote_large", "Remote Desktop", .large, true, .actionsGrid(columns: 2), [
  492. a("access", "Remote access", "desktopcomputer", "/access"),
  493. a("support", "Support", "person.crop.circle", "/support"),
  494. a("downloads", "Downloads", "arrow.down.circle", "/"),
  495. a("help", "Help", "questionmark.circle", "/support"),
  496. ]),
  497. ]
  498. case .gemini:
  499. return [
  500. v("gemini_small", "Gemini", .small, false, .actionsRow, [
  501. a("app", "Gemini", "sparkles", "/app"),
  502. a("home", "Home", "house", "/"),
  503. a("extensions", "Extensions", "puzzlepiece", "/extensions"),
  504. ]),
  505. v("gemini_large", "Gemini Hub", .large, true, .actionsGrid(columns: 2), [
  506. a("app", "Chat", "sparkles", "/app"),
  507. a("home", "Home", "house", "/"),
  508. a("extensions", "Extensions", "puzzlepiece", "/extensions"),
  509. a("help", "Help", "questionmark.circle", "/help"),
  510. ]),
  511. ]
  512. case .books:
  513. return [
  514. v("books_small", "Books", .small, false, .iconOnly(title: "Books"), [a("home", "Library", "book.fill", "/ebooks")]),
  515. v("books_medium", "Google Books", .medium, true, .actionsGrid(columns: 2), [
  516. a("library", "My books", "books.vertical", "/ebooks/library"),
  517. a("shop", "Shop", "cart", "/ebooks"),
  518. a("audiobooks", "Audiobooks", "headphones", "/audiobooks"),
  519. a("search", "Search", "magnifyingglass", "/ebooks/search"),
  520. ]),
  521. ]
  522. case .unknown:
  523. return genericUtilityVariants(prefix: "generic", appName: app.name)
  524. }
  525. }
  526. static func variant(for app: LauncherApp, variantID: String?) -> WidgetVariant {
  527. let variants = variants(for: app)
  528. if let variantID, let match = variants.first(where: { $0.id == variantID }) {
  529. return match
  530. }
  531. return variants.first ?? WidgetVariant(
  532. id: "fallback_small",
  533. title: "Quick Access",
  534. size: .small,
  535. showHeader: false,
  536. layoutMode: .actionsRow,
  537. actions: [a("open", "Open", "arrow.up.right", nil)]
  538. )
  539. }
  540. }
  541. private extension WidgetTemplates {
  542. static func genericUtilityVariants(prefix: String, appName: String) -> [WidgetVariant] {
  543. [
  544. WidgetVariant(
  545. id: "\(prefix)_small",
  546. title: "Quick Access",
  547. size: .small,
  548. showHeader: false,
  549. layoutMode: .actionsRow,
  550. actions: [
  551. a("open", "Open", "arrow.up.right", "/"),
  552. a("search", "Search", "magnifyingglass", "/"),
  553. a("favorites", "Favorites", "star", "/"),
  554. ]
  555. ),
  556. WidgetVariant(
  557. id: "\(prefix)_medium",
  558. title: appName,
  559. size: .medium,
  560. showHeader: true,
  561. layoutMode: .actionsGrid(columns: 2),
  562. actions: [
  563. a("open", "Open", "arrow.up.right", "/"),
  564. a("search", "Search", "magnifyingglass", "/"),
  565. a("favorites", "Favorites", "star", "/"),
  566. a("recent", "Recent", "clock.arrow.circlepath", "/"),
  567. ]
  568. ),
  569. ]
  570. }
  571. static func a(_ id: String, _ title: String, _ image: String, _ path: String?) -> WidgetAction {
  572. WidgetAction(id: id, title: title, systemImage: image, urlPath: path)
  573. }
  574. }
  575. extension WidgetLayoutMode {
  576. /// Panels that embed interactive web content need to become key so text fields and the web view receive input.
  577. var needsKeyCapablePanel: Bool {
  578. switch self {
  579. case .interactiveMap: true
  580. case .gmail(.interactive): true
  581. case .drive(.interactive): true
  582. case .keep(.interactive): true
  583. case .translate(.interactive): true
  584. case .earth(.interactive): true
  585. case .googleSearch(.interactive): true
  586. default: false
  587. }
  588. }
  589. /// Fixed sizes for tiered Gmail / Drive widgets (variant size already matches the tier).
  590. func desktopPanelSizeOverride() -> CGSize? {
  591. switch self {
  592. case .gmail(let mode):
  593. switch mode {
  594. case .compact: return CGSize(width: 220, height: 220)
  595. case .inboxPreview: return CGSize(width: 420, height: 480)
  596. case .interactive: return CGSize(width: 540, height: 580)
  597. }
  598. case .drive(let mode):
  599. switch mode {
  600. case .recentQuick: return CGSize(width: 230, height: 260)
  601. case .filesPreview: return CGSize(width: 420, height: 480)
  602. case .interactive: return CGSize(width: 540, height: 580)
  603. }
  604. case .keep(let mode):
  605. switch mode {
  606. case .compact: return CGSize(width: 230, height: 260)
  607. case .interactive: return CGSize(width: 540, height: 580)
  608. }
  609. case .translate(.interactive):
  610. return CGSize(width: 560, height: 640)
  611. case .earth(.interactive):
  612. return CGSize(width: 580, height: 640)
  613. case .googleSearch(.interactive):
  614. return CGSize(width: 480, height: 220)
  615. default:
  616. return nil
  617. }
  618. }
  619. func widgetPreviewCardSize() -> CGSize? {
  620. switch self {
  621. case .gmail(let mode):
  622. switch mode {
  623. case .compact: return CGSize(width: 200, height: 200)
  624. case .inboxPreview: return CGSize(width: 380, height: 420)
  625. case .interactive: return CGSize(width: 480, height: 440)
  626. }
  627. case .drive(let mode):
  628. switch mode {
  629. case .recentQuick: return CGSize(width: 210, height: 230)
  630. case .filesPreview: return CGSize(width: 380, height: 420)
  631. case .interactive: return CGSize(width: 480, height: 440)
  632. }
  633. case .keep(let mode):
  634. switch mode {
  635. case .compact: return CGSize(width: 210, height: 230)
  636. case .interactive: return CGSize(width: 480, height: 440)
  637. }
  638. case .translate(.interactive):
  639. return CGSize(width: 480, height: 460)
  640. case .earth(.interactive):
  641. return CGSize(width: 490, height: 470)
  642. case .googleSearch(.interactive):
  643. return CGSize(width: 440, height: 210)
  644. default:
  645. return nil
  646. }
  647. }
  648. }