Skip to content

Commit 60826bc

Browse files
Fix error when getting font smoothing state (#38)
* Ensure valid font smoothing option is found * Update errors to be more specific and descriptive * Bump version numbers Co-authored-by: Alastair Byrne <alastairbyrne@gmail.com>
1 parent e33b711 commit 60826bc

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

Big Sur Font Smoothing Toggler/FontSmoothingDefaults.swift

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,33 @@ class FontSmoothingDefaults {
3535
CFPreferencesSetValue(key, value, applicationID, userName, hostName)
3636
let result = CFPreferencesSynchronize(applicationID, userName, hostName)
3737
guard result else {
38-
throw FontSmoothingDefaultsError.unknownError
38+
throw FontSmoothingDefaultsError.snychronisingCFPreferencesFailed
3939
}
4040
}
4141

4242
func getFontSmoothingState() throws -> FontSmoothingOptions {
4343
let value = CFPreferencesCopyAppValue(CFPreferencesConstants.key, CFPreferencesConstants.applicationID) as? Int ?? FontSmoothingOptions.enabled.rawValue
4444

45-
guard let option = FontSmoothingOptions(rawValue: value) else {
46-
throw FontSmoothingDefaultsError.unknownError
45+
let fontSmoothingOptionValue = getValidFontSmoothingOptionValue(value)
46+
47+
guard let option = FontSmoothingOptions(rawValue: fontSmoothingOptionValue) else {
48+
throw FontSmoothingDefaultsError.invalidFontSmoothingOptionFound
4749
}
4850

4951
return option
5052
}
5153

54+
private func getValidFontSmoothingOptionValue(_ value: Int) -> Int {
55+
if value == 0 {
56+
return FontSmoothingOptions.disabled.rawValue
57+
} else {
58+
return FontSmoothingOptions.enabled.rawValue
59+
}
60+
}
61+
5262
private enum FontSmoothingDefaultsError: Error {
53-
case unknownError
63+
case invalidFontSmoothingOptionFound
64+
case snychronisingCFPreferencesFailed
5465
}
5566

5667
private struct CFPreferencesConstants {

Font Smoothing Adjuster.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@
555555
CODE_SIGN_IDENTITY = "Apple Development";
556556
CODE_SIGN_STYLE = Automatic;
557557
COMBINE_HIDPI_IMAGES = YES;
558-
CURRENT_PROJECT_VERSION = 1.3.1;
558+
CURRENT_PROJECT_VERSION = 1.3.2;
559559
DEVELOPMENT_TEAM = 4YNZUF26AM;
560560
ENABLE_HARDENED_RUNTIME = YES;
561561
FRAMEWORK_SEARCH_PATHS = (
@@ -567,7 +567,7 @@
567567
"$(inherited)",
568568
"@executable_path/../Frameworks",
569569
);
570-
MARKETING_VERSION = 1.3.1;
570+
MARKETING_VERSION = 1.3.2;
571571
PRODUCT_BUNDLE_IDENTIFIER = "com.bouncetechnologies.Font-Smoothing-Adjuster";
572572
PRODUCT_NAME = "$(TARGET_NAME)";
573573
SWIFT_VERSION = 5.0;
@@ -583,7 +583,7 @@
583583
CODE_SIGN_IDENTITY = "Apple Development";
584584
CODE_SIGN_STYLE = Automatic;
585585
COMBINE_HIDPI_IMAGES = YES;
586-
CURRENT_PROJECT_VERSION = 1.3.1;
586+
CURRENT_PROJECT_VERSION = 1.3.2;
587587
DEVELOPMENT_TEAM = 4YNZUF26AM;
588588
ENABLE_HARDENED_RUNTIME = YES;
589589
FRAMEWORK_SEARCH_PATHS = (
@@ -595,7 +595,7 @@
595595
"$(inherited)",
596596
"@executable_path/../Frameworks",
597597
);
598-
MARKETING_VERSION = 1.3.1;
598+
MARKETING_VERSION = 1.3.2;
599599
PRODUCT_BUNDLE_IDENTIFIER = "com.bouncetechnologies.Font-Smoothing-Adjuster";
600600
PRODUCT_NAME = "$(TARGET_NAME)";
601601
SWIFT_VERSION = 5.0;

0 commit comments

Comments
 (0)