Skip to content

Commit b60d80b

Browse files
authored
Add more logs to material design icons registration (#3616)
<!-- Thank you for submitting a Pull Request and helping to improve Home Assistant. Please complete the following sections to help the processing and review of your changes. Please do not delete anything from this template. --> ## Summary <!-- Provide a brief summary of the changes you have made and most importantly what they aim to achieve --> ## Screenshots <!-- If this is a user-facing change not in the frontend, please include screenshots in light and dark mode. --> ## Link to pull request in Documentation repository <!-- Pull requests that add, change or remove functionality must have a corresponding pull request in the Companion App Documentation repository (https://github.com/home-assistant/companion.home-assistant). Please add the number of this pull request after the "#" --> Documentation: home-assistant/companion.home-assistant# ## Any other notes <!-- If there is any other information of note, like if this Pull Request is part of a bigger change, please include it here. -->
1 parent c42ae1d commit b60d80b

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

Sources/Shared/Iconic/IconDrawable.swift

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,23 @@ extension IconDrawable {
168168

169169
// No need to register the font more than once
170170
if UIFont.familyNames.map({ $0.replacingOccurrences(of: " ", with: "") }).contains(familyName) {
171+
Current.Log.verbose(".register() called, but font '\(familyName)' is already registered.")
171172
return
172173
}
173174

174175
guard let url = resourceUrl() else {
175-
print("Unable to register font '\(familyName)' beacuse URL was nil!")
176+
let message = "Unable to register font '\(familyName)' beacuse URL was nil!"
177+
Current.Log.error(message)
178+
assertionFailure(message)
176179
return
177180
}
178181
var error: Unmanaged<CFError>? = nil
179182
let descriptors = CTFontManagerCreateFontDescriptorsFromURL(url as CFURL) as NSArray?
180183

181184
guard let descriptor = (descriptors as? [CTFontDescriptor])?.first else {
182-
assertionFailure("Could not retrieve font descriptors of font at path '\(url)',")
185+
let message = "Could not retrieve font descriptors of font at path '\(url)',"
186+
Current.Log.error(message)
187+
assertionFailure(message)
183188
return
184189
}
185190

@@ -191,31 +196,38 @@ extension IconDrawable {
191196
if let error = error?.takeUnretainedValue(), CFErrorGetDomain(error) == kCTFontManagerErrorDomain, CFErrorGetCode(error) == CTFontManagerError.alreadyRegistered.rawValue {
192197
// this is fine
193198
} else {
194-
assertionFailure("Failed registering font with the postscript name '\(fontName)' at path '\(url)' with error: \(String(describing: error)).")
199+
let message = "Failed registering font with the postscript name '\(fontName)' at path '\(url)' with error: \(String(describing: error))."
200+
Current.Log.error(message)
201+
assertionFailure(message)
195202
}
196203
}
197204

198-
print("Font '\(familyName)' registered successfully!")
205+
Current.Log.verbose("Font '\(familyName)' registered successfully!")
199206
}
200207

201208
public static func unregister() {
202209

203210
// No need to unregister if the font isn't registered
204211
if UIFont.familyNames.contains(familyName) == false {
212+
Current.Log.verbose(".unregister() called, but font '\(familyName)' is not registered.")
205213
return
206214
}
207215

208216
guard let url = resourceUrl() else {
209-
print("Unable to unregister font '\(familyName)' beacuse URL was nil!")
217+
let message = "Unable to unregister font '\(familyName)' beacuse URL was nil!"
218+
Current.Log.error(message)
219+
assertionFailure(message)
210220
return
211221
}
212222
var error: Unmanaged<CFError>? = nil
213223

214224
if CTFontManagerUnregisterFontsForURL(url as CFURL, .none, &error) == false || error != nil {
215-
assertionFailure("Failed unregistering font with name '\(familyName)' at path '\(url)' with error: \(String(describing: error)).")
225+
let message = "Failed unregistering font with name '\(familyName)' at path '\(url)' with error: \(String(describing: error))."
226+
Current.Log.error(message)
227+
assertionFailure(message)
216228
}
217229

218-
print("Font '\(familyName)' unregistered successfully!")
230+
Current.Log.verbose("Font '\(familyName)' unregistered successfully!")
219231
}
220232

221233
fileprivate static func resourceUrl() -> URL? {

0 commit comments

Comments
 (0)