Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add force refresh widgets to debug tools #2723

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Sources/App/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -847,4 +847,5 @@ Home Assistant is free and open source home automation software with a focus on
"widgets.open_page.description" = "Open a frontend page in Home Assistant.";
"widgets.open_page.not_configured" = "No Pages Available";
"widgets.open_page.title" = "Open Page";
"widgets.button.reload_timeline" = "Reload all widgets";
"yes_label" = "Yes";
12 changes: 12 additions & 0 deletions Sources/App/Settings/DebugSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import RealmSwift
import Shared
import SwiftUI
import WebKit
import WidgetKit
import XCGLogger

class DebugSettingsViewController: HAFormViewController {
Expand Down Expand Up @@ -139,6 +140,15 @@ class DebugSettingsViewController: HAFormViewController {
Section() <<< SettingsRootDataSource.Row.thread.row
}

private var reloadWidgetsButton: ButtonRow {
ButtonRow {
$0.title = L10n.Widgets.Button.reloadTimeline
$0.onCellSelection { _, _ in
WidgetCenter.shared.reloadAllTimelines()
}
}
}

private func logs() -> Eureka.Section {
let section = Section()

Expand Down Expand Up @@ -250,6 +260,8 @@ class DebugSettingsViewController: HAFormViewController {
$0.tag = "developerOptions"
}

section <<< reloadWidgetsButton

section <<< ButtonRow("onboardTest") {
$0.title = "Onboard (Initial)"
$0.presentationMode = .presentModally(controllerProvider: .callback(builder: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ struct WidgetActionsAppIntentTimelineProvider: AppIntentTimelineProvider {
}

func timeline(for configuration: Intent, in context: Context) async -> Timeline<Entry> {
.init(entries: [Self.entry(for: configuration, in: context)], policy: .never)
.init(
entries: [Self.entry(for: configuration, in: context)],
policy: .after(Current.date().addingTimeInterval(expiration.converted(to: .seconds).value))
)
}

func placeholder(in context: Context) -> WidgetActionsEntry {
Expand All @@ -27,6 +30,10 @@ struct WidgetActionsAppIntentTimelineProvider: AppIntentTimelineProvider {
return WidgetActionsEntry(actions: actions)
}

private var expiration: Measurement<UnitDuration> {
.init(value: 24, unit: .hours)
}

private static func entry(for configuration: Intent, in context: Context) -> Entry {
if let existing = configuration.actions?.compactMap({ $0.asAction() }), !existing.isEmpty {
return .init(actions: existing)
Expand Down
4 changes: 4 additions & 0 deletions Sources/Shared/Resources/Swiftgen/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2834,6 +2834,10 @@ public enum L10n {
/// Configure
public static var unknownConfiguration: String { return L10n.tr("Localizable", "widgets.assist.unknown_configuration") }
}
public enum Button {
/// Reload all widgets
public static var reloadTimeline: String { return L10n.tr("Localizable", "widgets.button.reload_timeline") }
}
public enum OpenPage {
/// Open a frontend page in Home Assistant.
public static var description: String { return L10n.tr("Localizable", "widgets.open_page.description") }
Expand Down