├── .gitignore ├── Demo ├── MacSettingsDemo.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── MacSettingsDemo │ ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── ContentView.swift │ ├── Info.plist │ ├── MacSettingsDemo.entitlements │ ├── MacSettingsDemoApp.swift │ └── Preview Content │ └── Preview Assets.xcassets │ └── Contents.json ├── LICENSE ├── Package.swift ├── README.md ├── Resources └── settings.gif ├── Sources └── MacSettings │ └── MacSettings.swift └── Tests ├── LinuxMain.swift └── MacSettingsTests ├── MacSettingsTests.swift └── XCTestManifests.swift /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.xcodeproj 3 | xcuserdata/ 4 | 5 | Packages/ 6 | .build/ 7 | .swiftpm 8 | -------------------------------------------------------------------------------- /Demo/MacSettingsDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 52; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 39FAA98724BA272700286A49 /* MacSettingsDemoApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39FAA98624BA272700286A49 /* MacSettingsDemoApp.swift */; }; 11 | 39FAA98924BA272700286A49 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39FAA98824BA272700286A49 /* ContentView.swift */; }; 12 | 39FAA98B24BA272800286A49 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 39FAA98A24BA272800286A49 /* Assets.xcassets */; }; 13 | 39FAA98E24BA272800286A49 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 39FAA98D24BA272800286A49 /* Preview Assets.xcassets */; }; 14 | 39FAA99E24BA2B3400286A49 /* MacSettings in Frameworks */ = {isa = PBXBuildFile; productRef = 39FAA99D24BA2B3400286A49 /* MacSettings */; }; 15 | /* End PBXBuildFile section */ 16 | 17 | /* Begin PBXFileReference section */ 18 | 39FAA98324BA272700286A49 /* MacSettingsDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MacSettingsDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 19 | 39FAA98624BA272700286A49 /* MacSettingsDemoApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacSettingsDemoApp.swift; sourceTree = ""; }; 20 | 39FAA98824BA272700286A49 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 21 | 39FAA98A24BA272800286A49 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 22 | 39FAA98D24BA272800286A49 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 23 | 39FAA98F24BA272800286A49 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 24 | 39FAA99024BA272800286A49 /* MacSettingsDemo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MacSettingsDemo.entitlements; sourceTree = ""; }; 25 | 39FAA99C24BA2B1B00286A49 /* MacSettings */ = {isa = PBXFileReference; lastKnownFileType = folder; name = MacSettings; path = ..; sourceTree = ""; }; 26 | /* End PBXFileReference section */ 27 | 28 | /* Begin PBXFrameworksBuildPhase section */ 29 | 39FAA98024BA272700286A49 /* Frameworks */ = { 30 | isa = PBXFrameworksBuildPhase; 31 | buildActionMask = 2147483647; 32 | files = ( 33 | 39FAA99E24BA2B3400286A49 /* MacSettings in Frameworks */, 34 | ); 35 | runOnlyForDeploymentPostprocessing = 0; 36 | }; 37 | /* End PBXFrameworksBuildPhase section */ 38 | 39 | /* Begin PBXGroup section */ 40 | 39FAA97A24BA272700286A49 = { 41 | isa = PBXGroup; 42 | children = ( 43 | 39FAA98524BA272700286A49 /* MacSettingsDemo */, 44 | 39FAA98424BA272700286A49 /* Products */, 45 | 39FAA99724BA290700286A49 /* Frameworks */, 46 | 39FAA99C24BA2B1B00286A49 /* MacSettings */, 47 | ); 48 | sourceTree = ""; 49 | }; 50 | 39FAA98424BA272700286A49 /* Products */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | 39FAA98324BA272700286A49 /* MacSettingsDemo.app */, 54 | ); 55 | name = Products; 56 | sourceTree = ""; 57 | }; 58 | 39FAA98524BA272700286A49 /* MacSettingsDemo */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 39FAA98624BA272700286A49 /* MacSettingsDemoApp.swift */, 62 | 39FAA98824BA272700286A49 /* ContentView.swift */, 63 | 39FAA98A24BA272800286A49 /* Assets.xcassets */, 64 | 39FAA98F24BA272800286A49 /* Info.plist */, 65 | 39FAA99024BA272800286A49 /* MacSettingsDemo.entitlements */, 66 | 39FAA98C24BA272800286A49 /* Preview Content */, 67 | ); 68 | path = MacSettingsDemo; 69 | sourceTree = ""; 70 | }; 71 | 39FAA98C24BA272800286A49 /* Preview Content */ = { 72 | isa = PBXGroup; 73 | children = ( 74 | 39FAA98D24BA272800286A49 /* Preview Assets.xcassets */, 75 | ); 76 | path = "Preview Content"; 77 | sourceTree = ""; 78 | }; 79 | 39FAA99724BA290700286A49 /* Frameworks */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | ); 83 | name = Frameworks; 84 | sourceTree = ""; 85 | }; 86 | /* End PBXGroup section */ 87 | 88 | /* Begin PBXNativeTarget section */ 89 | 39FAA98224BA272700286A49 /* MacSettingsDemo */ = { 90 | isa = PBXNativeTarget; 91 | buildConfigurationList = 39FAA99324BA272800286A49 /* Build configuration list for PBXNativeTarget "MacSettingsDemo" */; 92 | buildPhases = ( 93 | 39FAA97F24BA272700286A49 /* Sources */, 94 | 39FAA98024BA272700286A49 /* Frameworks */, 95 | 39FAA98124BA272700286A49 /* Resources */, 96 | ); 97 | buildRules = ( 98 | ); 99 | dependencies = ( 100 | ); 101 | name = MacSettingsDemo; 102 | packageProductDependencies = ( 103 | 39FAA99D24BA2B3400286A49 /* MacSettings */, 104 | ); 105 | productName = MacSettingsDemo; 106 | productReference = 39FAA98324BA272700286A49 /* MacSettingsDemo.app */; 107 | productType = "com.apple.product-type.application"; 108 | }; 109 | /* End PBXNativeTarget section */ 110 | 111 | /* Begin PBXProject section */ 112 | 39FAA97B24BA272700286A49 /* Project object */ = { 113 | isa = PBXProject; 114 | attributes = { 115 | LastSwiftUpdateCheck = 1200; 116 | LastUpgradeCheck = 1200; 117 | TargetAttributes = { 118 | 39FAA98224BA272700286A49 = { 119 | CreatedOnToolsVersion = 12.0; 120 | }; 121 | }; 122 | }; 123 | buildConfigurationList = 39FAA97E24BA272700286A49 /* Build configuration list for PBXProject "MacSettingsDemo" */; 124 | compatibilityVersion = "Xcode 9.3"; 125 | developmentRegion = en; 126 | hasScannedForEncodings = 0; 127 | knownRegions = ( 128 | en, 129 | Base, 130 | ); 131 | mainGroup = 39FAA97A24BA272700286A49; 132 | productRefGroup = 39FAA98424BA272700286A49 /* Products */; 133 | projectDirPath = ""; 134 | projectRoot = ""; 135 | targets = ( 136 | 39FAA98224BA272700286A49 /* MacSettingsDemo */, 137 | ); 138 | }; 139 | /* End PBXProject section */ 140 | 141 | /* Begin PBXResourcesBuildPhase section */ 142 | 39FAA98124BA272700286A49 /* Resources */ = { 143 | isa = PBXResourcesBuildPhase; 144 | buildActionMask = 2147483647; 145 | files = ( 146 | 39FAA98E24BA272800286A49 /* Preview Assets.xcassets in Resources */, 147 | 39FAA98B24BA272800286A49 /* Assets.xcassets in Resources */, 148 | ); 149 | runOnlyForDeploymentPostprocessing = 0; 150 | }; 151 | /* End PBXResourcesBuildPhase section */ 152 | 153 | /* Begin PBXSourcesBuildPhase section */ 154 | 39FAA97F24BA272700286A49 /* Sources */ = { 155 | isa = PBXSourcesBuildPhase; 156 | buildActionMask = 2147483647; 157 | files = ( 158 | 39FAA98924BA272700286A49 /* ContentView.swift in Sources */, 159 | 39FAA98724BA272700286A49 /* MacSettingsDemoApp.swift in Sources */, 160 | ); 161 | runOnlyForDeploymentPostprocessing = 0; 162 | }; 163 | /* End PBXSourcesBuildPhase section */ 164 | 165 | /* Begin XCBuildConfiguration section */ 166 | 39FAA99124BA272800286A49 /* Debug */ = { 167 | isa = XCBuildConfiguration; 168 | buildSettings = { 169 | ALWAYS_SEARCH_USER_PATHS = NO; 170 | CLANG_ANALYZER_NONNULL = YES; 171 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 172 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 173 | CLANG_CXX_LIBRARY = "libc++"; 174 | CLANG_ENABLE_MODULES = YES; 175 | CLANG_ENABLE_OBJC_ARC = YES; 176 | CLANG_ENABLE_OBJC_WEAK = YES; 177 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 178 | CLANG_WARN_BOOL_CONVERSION = YES; 179 | CLANG_WARN_COMMA = YES; 180 | CLANG_WARN_CONSTANT_CONVERSION = YES; 181 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 182 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 183 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 184 | CLANG_WARN_EMPTY_BODY = YES; 185 | CLANG_WARN_ENUM_CONVERSION = YES; 186 | CLANG_WARN_INFINITE_RECURSION = YES; 187 | CLANG_WARN_INT_CONVERSION = YES; 188 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 189 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 190 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 191 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 192 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 193 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 194 | CLANG_WARN_STRICT_PROTOTYPES = YES; 195 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 196 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 197 | CLANG_WARN_UNREACHABLE_CODE = YES; 198 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 199 | COPY_PHASE_STRIP = NO; 200 | DEBUG_INFORMATION_FORMAT = dwarf; 201 | ENABLE_STRICT_OBJC_MSGSEND = YES; 202 | ENABLE_TESTABILITY = YES; 203 | GCC_C_LANGUAGE_STANDARD = gnu11; 204 | GCC_DYNAMIC_NO_PIC = NO; 205 | GCC_NO_COMMON_BLOCKS = YES; 206 | GCC_OPTIMIZATION_LEVEL = 0; 207 | GCC_PREPROCESSOR_DEFINITIONS = ( 208 | "DEBUG=1", 209 | "$(inherited)", 210 | ); 211 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 212 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 213 | GCC_WARN_UNDECLARED_SELECTOR = YES; 214 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 215 | GCC_WARN_UNUSED_FUNCTION = YES; 216 | GCC_WARN_UNUSED_VARIABLE = YES; 217 | MACOSX_DEPLOYMENT_TARGET = 11.0; 218 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 219 | MTL_FAST_MATH = YES; 220 | ONLY_ACTIVE_ARCH = YES; 221 | SDKROOT = macosx; 222 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 223 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 224 | }; 225 | name = Debug; 226 | }; 227 | 39FAA99224BA272800286A49 /* Release */ = { 228 | isa = XCBuildConfiguration; 229 | buildSettings = { 230 | ALWAYS_SEARCH_USER_PATHS = NO; 231 | CLANG_ANALYZER_NONNULL = YES; 232 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 233 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 234 | CLANG_CXX_LIBRARY = "libc++"; 235 | CLANG_ENABLE_MODULES = YES; 236 | CLANG_ENABLE_OBJC_ARC = YES; 237 | CLANG_ENABLE_OBJC_WEAK = YES; 238 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 239 | CLANG_WARN_BOOL_CONVERSION = YES; 240 | CLANG_WARN_COMMA = YES; 241 | CLANG_WARN_CONSTANT_CONVERSION = YES; 242 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 243 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 244 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 245 | CLANG_WARN_EMPTY_BODY = YES; 246 | CLANG_WARN_ENUM_CONVERSION = YES; 247 | CLANG_WARN_INFINITE_RECURSION = YES; 248 | CLANG_WARN_INT_CONVERSION = YES; 249 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 250 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 251 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 252 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 253 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 254 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 255 | CLANG_WARN_STRICT_PROTOTYPES = YES; 256 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 257 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 258 | CLANG_WARN_UNREACHABLE_CODE = YES; 259 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 260 | COPY_PHASE_STRIP = NO; 261 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 262 | ENABLE_NS_ASSERTIONS = NO; 263 | ENABLE_STRICT_OBJC_MSGSEND = YES; 264 | GCC_C_LANGUAGE_STANDARD = gnu11; 265 | GCC_NO_COMMON_BLOCKS = YES; 266 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 267 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 268 | GCC_WARN_UNDECLARED_SELECTOR = YES; 269 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 270 | GCC_WARN_UNUSED_FUNCTION = YES; 271 | GCC_WARN_UNUSED_VARIABLE = YES; 272 | MACOSX_DEPLOYMENT_TARGET = 11.0; 273 | MTL_ENABLE_DEBUG_INFO = NO; 274 | MTL_FAST_MATH = YES; 275 | SDKROOT = macosx; 276 | SWIFT_COMPILATION_MODE = wholemodule; 277 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 278 | }; 279 | name = Release; 280 | }; 281 | 39FAA99424BA272800286A49 /* Debug */ = { 282 | isa = XCBuildConfiguration; 283 | buildSettings = { 284 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 285 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 286 | CODE_SIGN_ENTITLEMENTS = MacSettingsDemo/MacSettingsDemo.entitlements; 287 | CODE_SIGN_STYLE = Automatic; 288 | COMBINE_HIDPI_IMAGES = YES; 289 | DEVELOPMENT_ASSET_PATHS = "\"MacSettingsDemo/Preview Content\""; 290 | DEVELOPMENT_TEAM = H3ZG35D27G; 291 | ENABLE_HARDENED_RUNTIME = YES; 292 | ENABLE_PREVIEWS = YES; 293 | INFOPLIST_FILE = MacSettingsDemo/Info.plist; 294 | LD_RUNPATH_SEARCH_PATHS = ( 295 | "$(inherited)", 296 | "@executable_path/../Frameworks", 297 | ); 298 | PRODUCT_BUNDLE_IDENTIFIER = com.khairullin.timur.MacSettingsDemo; 299 | PRODUCT_NAME = "$(TARGET_NAME)"; 300 | SWIFT_VERSION = 5.0; 301 | }; 302 | name = Debug; 303 | }; 304 | 39FAA99524BA272800286A49 /* Release */ = { 305 | isa = XCBuildConfiguration; 306 | buildSettings = { 307 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 308 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 309 | CODE_SIGN_ENTITLEMENTS = MacSettingsDemo/MacSettingsDemo.entitlements; 310 | CODE_SIGN_STYLE = Automatic; 311 | COMBINE_HIDPI_IMAGES = YES; 312 | DEVELOPMENT_ASSET_PATHS = "\"MacSettingsDemo/Preview Content\""; 313 | DEVELOPMENT_TEAM = H3ZG35D27G; 314 | ENABLE_HARDENED_RUNTIME = YES; 315 | ENABLE_PREVIEWS = YES; 316 | INFOPLIST_FILE = MacSettingsDemo/Info.plist; 317 | LD_RUNPATH_SEARCH_PATHS = ( 318 | "$(inherited)", 319 | "@executable_path/../Frameworks", 320 | ); 321 | PRODUCT_BUNDLE_IDENTIFIER = com.khairullin.timur.MacSettingsDemo; 322 | PRODUCT_NAME = "$(TARGET_NAME)"; 323 | SWIFT_VERSION = 5.0; 324 | }; 325 | name = Release; 326 | }; 327 | /* End XCBuildConfiguration section */ 328 | 329 | /* Begin XCConfigurationList section */ 330 | 39FAA97E24BA272700286A49 /* Build configuration list for PBXProject "MacSettingsDemo" */ = { 331 | isa = XCConfigurationList; 332 | buildConfigurations = ( 333 | 39FAA99124BA272800286A49 /* Debug */, 334 | 39FAA99224BA272800286A49 /* Release */, 335 | ); 336 | defaultConfigurationIsVisible = 0; 337 | defaultConfigurationName = Release; 338 | }; 339 | 39FAA99324BA272800286A49 /* Build configuration list for PBXNativeTarget "MacSettingsDemo" */ = { 340 | isa = XCConfigurationList; 341 | buildConfigurations = ( 342 | 39FAA99424BA272800286A49 /* Debug */, 343 | 39FAA99524BA272800286A49 /* Release */, 344 | ); 345 | defaultConfigurationIsVisible = 0; 346 | defaultConfigurationName = Release; 347 | }; 348 | /* End XCConfigurationList section */ 349 | 350 | /* Begin XCSwiftPackageProductDependency section */ 351 | 39FAA99D24BA2B3400286A49 /* MacSettings */ = { 352 | isa = XCSwiftPackageProductDependency; 353 | productName = MacSettings; 354 | }; 355 | /* End XCSwiftPackageProductDependency section */ 356 | }; 357 | rootObject = 39FAA97B24BA272700286A49 /* Project object */; 358 | } 359 | -------------------------------------------------------------------------------- /Demo/MacSettingsDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Demo/MacSettingsDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Demo/MacSettingsDemo/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Demo/MacSettingsDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "mac", 5 | "scale" : "1x", 6 | "size" : "16x16" 7 | }, 8 | { 9 | "idiom" : "mac", 10 | "scale" : "2x", 11 | "size" : "16x16" 12 | }, 13 | { 14 | "idiom" : "mac", 15 | "scale" : "1x", 16 | "size" : "32x32" 17 | }, 18 | { 19 | "idiom" : "mac", 20 | "scale" : "2x", 21 | "size" : "32x32" 22 | }, 23 | { 24 | "idiom" : "mac", 25 | "scale" : "1x", 26 | "size" : "128x128" 27 | }, 28 | { 29 | "idiom" : "mac", 30 | "scale" : "2x", 31 | "size" : "128x128" 32 | }, 33 | { 34 | "idiom" : "mac", 35 | "scale" : "1x", 36 | "size" : "256x256" 37 | }, 38 | { 39 | "idiom" : "mac", 40 | "scale" : "2x", 41 | "size" : "256x256" 42 | }, 43 | { 44 | "idiom" : "mac", 45 | "scale" : "1x", 46 | "size" : "512x512" 47 | }, 48 | { 49 | "idiom" : "mac", 50 | "scale" : "2x", 51 | "size" : "512x512" 52 | } 53 | ], 54 | "info" : { 55 | "author" : "xcode", 56 | "version" : 1 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Demo/MacSettingsDemo/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Demo/MacSettingsDemo/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // MacSettingsDemo 4 | // 5 | // Created by Timur Khairullin on 11.07.2020. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct ContentView: View { 11 | var body: some View { 12 | HStack { 13 | Text("Cmd").bold() 14 | Text("+") 15 | Text(",").bold() 16 | } 17 | .frame(minWidth: 200, maxWidth: .infinity, minHeight: 200, maxHeight: .infinity) 18 | } 19 | } 20 | 21 | struct ContentView_Previews: PreviewProvider { 22 | static var previews: some View { 23 | ContentView() 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Demo/MacSettingsDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSMinimumSystemVersion 22 | $(MACOSX_DEPLOYMENT_TARGET) 23 | 24 | 25 | -------------------------------------------------------------------------------- /Demo/MacSettingsDemo/MacSettingsDemo.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.files.user-selected.read-only 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Demo/MacSettingsDemo/MacSettingsDemoApp.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MacSettingsDemoApp.swift 3 | // MacSettingsDemo 4 | // 5 | // Created by Timur Khairullin on 11.07.2020. 6 | // 7 | 8 | import SwiftUI 9 | import MacSettings 10 | 11 | @main 12 | struct MacSettingsDemoApp: App { 13 | @SceneBuilder 14 | var body: some Scene { 15 | WindowGroup { 16 | ContentView() 17 | } 18 | Settings { 19 | MacSettings { 20 | MacSettingsItem(title: "General", 21 | image: "gearshape", 22 | content: GeneralSettings()) 23 | MacSettingsItem(title: "Appearance", 24 | image: "flame", 25 | content: AppearanceSettings()) 26 | MacSettingsItem(title: "Content", 27 | image: "heart", 28 | content: ContentSettings()) 29 | } 30 | } 31 | } 32 | } 33 | 34 | struct GeneralSettings: View { 35 | @State var one: Bool = true 36 | @State var two: Bool = true 37 | @State var three: Bool = true 38 | 39 | var body: some View { 40 | VStack(alignment: .leading) { 41 | Toggle("100% SwiftUI", isOn: $one) 42 | Toggle("Nested in Settings Scene", isOn: $two) 43 | Toggle("Available in macOS BigSur", isOn: $three) 44 | }.padding() 45 | } 46 | } 47 | 48 | struct AppearanceSettings: View { 49 | @State var one: Bool = true 50 | @State var two: Bool = true 51 | @State var three: Bool = true 52 | 53 | var body: some View { 54 | VStack(alignment: .leading) { 55 | Toggle("Dark Mode", isOn: $one) 56 | Toggle("Accent Color", isOn: $two) 57 | Toggle("Adaptive size", isOn: $three) 58 | }.padding() 59 | } 60 | } 61 | 62 | struct ContentSettings: View { 63 | @Environment(\.colorScheme) var colorScheme 64 | 65 | var body: some View { 66 | ZStack { 67 | LinearGradient(gradient: Gradient(colors: [.red, .orange, .yellow, .green, .blue, .purple]), startPoint: .topLeading, endPoint: .bottomTrailing) 68 | .frame(width: 300) 69 | Text("Any content is possible") 70 | .font(.headline) 71 | .foregroundColor(colorScheme == .dark ? .black : .white) 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Demo/MacSettingsDemo/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 TimurKhay 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.3 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "MacSettings", 8 | platforms: [ 9 | .macOS(.v11) 10 | ], 11 | products: [ 12 | .library(name: "MacSettings", targets: ["MacSettings"]) 13 | ], 14 | targets: [ 15 | .target(name: "MacSettings", dependencies: [], exclude: ["Demo", "Resources"]), 16 | .testTarget(name: "MacSettingsTests", dependencies: ["MacSettings"], exclude: ["Demo", "Resources"]) 17 | ] 18 | ) 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## MacSettings 2 | 3 | Mac Settings SwiftUI View 4 | 5 | ## Example 6 | 7 |

8 | 9 |

10 | 11 | ## Usage 12 | 13 | ```swift 14 | import SwiftUI 15 | import MacSettings 16 | 17 | @main 18 | struct MainApp: App { 19 | @SceneBuilder 20 | var body: some Scene { 21 | WindowGroup { 22 | ContentView() 23 | } 24 | Settings { 25 | MacSettings { 26 | MacSettingsItem(title: "General", 27 | image: "gearshape", 28 | content: generalSettings) 29 | MacSettingsItem(title: "Appearance", 30 | image: "flame", 31 | content: appearanceSettings) 32 | MacSettingsItem(title: "Content", 33 | image: "heart", 34 | content: contentSettings) 35 | } 36 | } 37 | } 38 | 39 | var generalSettings: some View { ... } 40 | var appearanceSettings: some View { ... } 41 | var contentSettings: some View { ... } 42 | } 43 | ``` 44 | -------------------------------------------------------------------------------- /Resources/settings.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TimurKhay/MacSettings/7d74e152ddef16ffe3bf766bbee6ab77c9ac3707/Resources/settings.gif -------------------------------------------------------------------------------- /Sources/MacSettings/MacSettings.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MacSettings.swift 3 | // 4 | // 5 | // Created by Timur Khairullin on 11.07.2020. 6 | // 7 | 8 | import SwiftUI 9 | 10 | // MARK: - MacSettings 11 | 12 | public struct MacSettings: View { 13 | let items: [MacSettingsItem] 14 | 15 | public init(@MacSettingsBuilder items: () -> [MacSettingsItem]) { 16 | self.items = items() 17 | } 18 | 19 | // MARK: - selected, hovered 20 | 21 | @State private var selected: Int = 0 22 | 23 | @State private var hovered: Int? = nil 24 | private func set(isHovered: Bool, index: Int) { 25 | let newHovered = isHovered ? index : nil 26 | if newHovered == nil && hovered != index { return } 27 | guard hovered != newHovered else { return } 28 | hovered = newHovered 29 | } 30 | 31 | // MARK: - heights, widths 32 | 33 | @State private var contentHeights: [ContentHeightsPreference] = [] 34 | @State private var toolbarWidth: CGFloat? 35 | @State private var maxContentWidth: CGFloat? 36 | 37 | private func height(index: Int) -> CGFloat? { 38 | let height = contentHeights.first { $0.index == index }?.height 39 | return height 40 | } 41 | 42 | private var width: CGFloat? { 43 | if toolbarWidth == nil && maxContentWidth == nil { return nil } 44 | return max(toolbarWidth ?? 0 + .toolbarPadding, maxContentWidth ?? 0) 45 | } 46 | 47 | // MARK: - View 48 | 49 | public var body: some View { 50 | ZStack { 51 | ForEach(0.. some View { 78 | VStack(spacing: .toolbarItemSpacing) { 79 | Image(systemName: items[index].image) 80 | .resizable() 81 | .aspectRatio(contentMode: .fit) 82 | .frame(height: .toolbarImageHeight, alignment: .center) 83 | .foregroundColor(toolbarImageColor(index: index)) 84 | Text(items[index].title) 85 | .font(.subheadline) 86 | .foregroundColor(.secondaryLabelColor) 87 | } 88 | .padding(.toolbarItemPadding) 89 | .background(toolbarItemBackground(index: index)) 90 | .contentShape(Rectangle()) 91 | .onTapGesture { 92 | selected = index 93 | } 94 | // Q: currently when using button as ToolbarItem, mouse hover + size of the items are not correct 95 | .onHover { isHovered in 96 | set(isHovered: isHovered, index: index) 97 | } 98 | } 99 | 100 | private func toolbarItemBackground(index: Int) -> some View { 101 | let isSelected = selected == index 102 | let isHovered = hovered == index 103 | return RoundedRectangle(cornerRadius: .toolbarItemBackgroundCornerRadius) 104 | .foregroundColor(isSelected ? .controlColor : (isHovered ? .separatorColor : .clear)) 105 | .shadow(color: .shadow, radius: isSelected ? .toolbarItemBackgroundShadowRadius : 0.0) 106 | } 107 | 108 | private func toolbarImageColor(index: Int) -> Color { 109 | let isSelected = selected == index 110 | let isHovered = hovered == index 111 | return isSelected ? ( isHovered ? .selectedContentBackgroundColor : .accentColor) : .secondaryLabelColor 112 | } 113 | } 114 | 115 | // MARK: - MacSettingsItem 116 | 117 | public struct MacSettingsItem { 118 | let title: String 119 | let image: String 120 | let content: AnyView 121 | 122 | public init(title: String, image: String, content: Content) { 123 | self.title = title 124 | self.image = image 125 | self.content = AnyView(content) 126 | } 127 | } 128 | 129 | // MARK: - MacSettingsBuilder 130 | 131 | @_functionBuilder public struct MacSettingsBuilder { 132 | public static func buildBlock(_ partialResults: MacSettingsItem...) -> [MacSettingsItem] { 133 | partialResults.reduce([MacSettingsItem]()) { result, element in result + [element] } 134 | } 135 | } 136 | 137 | // MARK: - PreferenceKeys 138 | 139 | fileprivate struct ToolbarWidthKey: PreferenceKey { 140 | static let defaultValue: CGFloat? = nil 141 | static func reduce(value: inout CGFloat?, nextValue: () -> CGFloat?) { 142 | value = value ?? nextValue() 143 | } 144 | } 145 | 146 | fileprivate struct MaxContentWidthKey: PreferenceKey { 147 | static let defaultValue: CGFloat? = nil 148 | static func reduce(value: inout CGFloat?, nextValue: () -> CGFloat?) { 149 | value = value ?? nextValue() 150 | } 151 | } 152 | 153 | fileprivate struct ContentHeightsKey: PreferenceKey { 154 | static let defaultValue: [ContentHeightsPreference] = [] 155 | static func reduce(value: inout [ContentHeightsPreference], nextValue: () -> [ContentHeightsPreference]) { 156 | value.append(contentsOf: nextValue()) 157 | } 158 | } 159 | 160 | fileprivate struct ContentHeightsPreference: Equatable { 161 | let index: Int 162 | let height: CGFloat 163 | } 164 | 165 | // MARK: - PreferenceFromGeometry 166 | 167 | fileprivate extension View { 168 | func preferenceFromGeometry( 169 | key: Key.Type, 170 | transform: @escaping (GeometryProxy) -> Key.Value) -> some View { 171 | background(GeometryReader { proxy in 172 | Color.clear.preference(key: Key.self, value: transform(proxy)) 173 | }) 174 | } 175 | } 176 | 177 | fileprivate extension View { 178 | func preferenceFromGeometry( 179 | key: Key.Type, 180 | transform: @escaping (GeometryProxy) -> Value, 181 | onChange value: Binding) -> some View where Key.Value == Value { 182 | preferenceFromGeometry(key: key, transform: transform) 183 | .onPreferenceChange(Key.self) { value.wrappedValue = $0 } 184 | } 185 | } 186 | 187 | // MARK: - Hidden 188 | 189 | fileprivate extension View { 190 | func isHidden(_ isHidden: Bool) -> some View { 191 | Group { 192 | if isHidden { 193 | self.hidden() 194 | } else { 195 | self 196 | } 197 | } 198 | } 199 | } 200 | 201 | // MARK: - Colors 202 | 203 | fileprivate extension Color { 204 | static var controlColor: Color { 205 | Color(.controlColor) 206 | } 207 | 208 | static var secondaryLabelColor: Color { 209 | Color(.secondaryLabelColor) 210 | } 211 | 212 | static var selectedContentBackgroundColor: Color { 213 | Color(NSColor.selectedContentBackgroundColor) 214 | } 215 | 216 | static var separatorColor: Color { 217 | Color(.separatorColor) 218 | } 219 | 220 | static var shadow: Color { 221 | Color(NSColor.shadowColor.withAlphaComponent(0.1)) 222 | } 223 | } 224 | 225 | // MARK: - Constants 226 | 227 | fileprivate extension CGFloat { 228 | static let toolbarPadding: CGFloat = 22 229 | static let toolbarItemSpacing: CGFloat = 3 230 | static let toolbarImageHeight: CGFloat = 18 231 | static let toolbarItemBackgroundCornerRadius: CGFloat = 6.0 232 | static let toolbarItemBackgroundShadowRadius: CGFloat = 1.0 233 | } 234 | 235 | fileprivate extension EdgeInsets { 236 | static let toolbarItemPadding: EdgeInsets = EdgeInsets(top: 6, leading: 6, bottom: 4, trailing: 6) 237 | } 238 | -------------------------------------------------------------------------------- /Tests/LinuxMain.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | import MacSettingsTests 4 | 5 | var tests = [XCTestCaseEntry]() 6 | tests += MacSettingsTests.allTests() 7 | XCTMain(tests) 8 | -------------------------------------------------------------------------------- /Tests/MacSettingsTests/MacSettingsTests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | @testable import MacSettings 3 | 4 | final class MacSettingsTests: XCTestCase { 5 | func testExample() { 6 | // This is an example of a functional test case. 7 | // Use XCTAssert and related functions to verify your tests produce the correct 8 | // results. 9 | } 10 | 11 | static var allTests = [ 12 | ("testExample", testExample), 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /Tests/MacSettingsTests/XCTestManifests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | #if !canImport(ObjectiveC) 4 | public func allTests() -> [XCTestCaseEntry] { 5 | return [ 6 | testCase(MacSettingsTests.allTests), 7 | ] 8 | } 9 | #endif 10 | --------------------------------------------------------------------------------