Widget.swift 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // NextcloudWidget.swift
  3. // NextcloudWidget
  4. //
  5. // Created by Marino Faggiana on 20/08/22.
  6. // Copyright © 2022 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import WidgetKit
  24. import SwiftUI
  25. @main
  26. struct NextcloudWidgetBundle: WidgetBundle {
  27. @WidgetBundleBuilder
  28. var body: some Widget {
  29. DashboardWidget()
  30. FilesWidget()
  31. ToolbarWidget()
  32. LockscreenWidget()
  33. }
  34. }
  35. struct DashboardWidget: Widget {
  36. let kind: String = "DashboardWidget"
  37. var body: some WidgetConfiguration {
  38. IntentConfiguration(kind: kind, intent: DashboardIntent.self, provider: DashboardWidgetProvider()) { entry in
  39. DashboardWidgetView(entry: entry)
  40. }
  41. .supportedFamilies([.systemLarge])
  42. .configurationDisplayName("Dashboard")
  43. .description(NSLocalizedString("_description_dashboardwidget_", comment: ""))
  44. }
  45. }
  46. struct FilesWidget: Widget {
  47. let kind: String = "FilesWidget"
  48. var body: some WidgetConfiguration {
  49. StaticConfiguration(kind: kind, provider: FilesWidgetProvider()) { entry in
  50. FilesWidgetView(entry: entry)
  51. }
  52. .supportedFamilies([.systemLarge])
  53. .configurationDisplayName("Files")
  54. .description(NSLocalizedString("_description_fileswidget_", comment: ""))
  55. }
  56. }
  57. struct ToolbarWidget: Widget {
  58. let kind: String = "ToolbarWidget"
  59. var body: some WidgetConfiguration {
  60. StaticConfiguration(kind: kind, provider: ToolbarWidgetProvider()) { entry in
  61. ToolbarWidgetView(entry: entry)
  62. }
  63. .supportedFamilies([.systemMedium])
  64. .configurationDisplayName("Toolbar")
  65. .description(NSLocalizedString("_description_toolbarwidget_", comment: ""))
  66. }
  67. }
  68. struct LockscreenWidget: Widget {
  69. let kind: String = "LockscreenWidget"
  70. var body: some WidgetConfiguration {
  71. if #available(iOSApplicationExtension 16.0, *) {
  72. return StaticConfiguration(kind: kind, provider: LockscreenWidgetProvider()) { entry in
  73. LockscreenWidgetView(entry: entry)
  74. }
  75. .supportedFamilies([.accessoryRectangular, .accessoryCircular])
  76. .configurationDisplayName(NSLocalizedString("_title_lockscreenwidget_", comment: ""))
  77. .description(NSLocalizedString("_description_lockscreenwidget_", comment: ""))
  78. } else {
  79. return EmptyWidgetConfiguration()
  80. }
  81. }
  82. }