Skip to content

Commit

Permalink
WIP auto generate Assist complication for all sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
bgoncal committed Nov 8, 2023
1 parent c5268db commit fb5bd42
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class ComplicationListViewController: HAFormViewController {
$0.value = URL(string: "https://companion.home-assistant.io/app/ios/apple-watch")!
}

enableAssistComplication()

Check warning on line 52 in Sources/App/Settings/AppleWatch/ComplicationListViewController.swift

View check run for this annotation

Codecov / codecov/patch

Sources/App/Settings/AppleWatch/ComplicationListViewController.swift#L51-L52

Added lines #L51 - L52 were not covered by tests
form +++ Section(
header: L10n.Watch.Configurator.List.ManualUpdates.title,
footer: L10n.Watch.Configurator.List.ManualUpdates.footer
Expand Down Expand Up @@ -151,4 +153,35 @@ class ComplicationListViewController: HAFormViewController {
)
}
}

private func enableAssistComplication() {
let realm = Current.realm()

// TODO reduce complexity
realm.reentrantWrite {
ComplicationGroup.allCases.sorted().forEach { group in
group.members.forEach { family in
Current.servers.all.forEach { server in
let config = WatchComplication()
config.name = "Assist on \(server.info.name)"
config.identifier = "assist-\(server.identifier.rawValue)-\(family.rawValue)"
config.IsPublic = true
config.Family = family
config.Template = family.templates.first!
config.serverIdentifier = server.identifier.rawValue
config.Data = [
"icon": [
"icon": "microphone_message",
"icon_color": "#17bcf2"
]
]
Current.Log.verbose("COMPLICATION \(config)")
realm.add(config, update: .all)
}
}
}
}.done {
Current.apis.forEach({ $0.updateComplications(passively: false) })
}.cauterize()
}

Check warning on line 186 in Sources/App/Settings/AppleWatch/ComplicationListViewController.swift

View check run for this annotation

Codecov / codecov/patch

Sources/App/Settings/AppleWatch/ComplicationListViewController.swift#L157-L186

Added lines #L157 - L186 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class AssistInterfaceController: WKInterfaceController {
}
}

@available(watchOSApplicationExtension 6, *)
extension AssistInterfaceController: AVAudioRecorderDelegate {
func audioRecorderDidFinishRecording(_ audioRecorder: AVAudioRecorder, successfully success: Bool) {
if success {
Expand Down
1 change: 1 addition & 0 deletions Sources/Shared/API/WatchHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public extension HomeAssistantAPI {
return nil
}

@discardableResult
func updateComplications(passively: Bool) -> Promise<Void> {
#if os(iOS)
guard case .paired = Communicator.shared.currentWatchState else {
Expand Down
1 change: 0 additions & 1 deletion Sources/Shared/Resources/Swiftgen/SharedPlist.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ internal enum SharedPlistFiles {
internal static let cfBundlePackageType: String = _document["CFBundlePackageType"]
internal static let cfBundleShortVersionString: String = _document["CFBundleShortVersionString"]
internal static let cfBundleVersion: String = _document["CFBundleVersion"]
internal static let nsMicrophoneUsageDescription: String = _document["NSMicrophoneUsageDescription"]
internal static let nsPrincipalClass: String = _document["NSPrincipalClass"]
}
}
Expand Down
2 changes: 0 additions & 2 deletions Sources/WatchApp/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSMicrophoneUsageDescription</key>
<string>Record audio using your Home Assistant frontend.</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
Expand Down

0 comments on commit fb5bd42

Please sign in to comment.