From 5facd05609f0a07c6604171f80ce031b8b15097b Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Thu, 18 Jan 2024 18:36:56 -0800 Subject: [PATCH] [path_provider_foundation] Run swift-format on Swift files --- .../darwin/Classes/PathProviderPlugin.swift | 65 ++++++++++--------- .../darwin/RunnerTests/RunnerTests.swift | 41 ++++++------ 2 files changed, 54 insertions(+), 52 deletions(-) diff --git a/packages/path_provider/path_provider_foundation/darwin/Classes/PathProviderPlugin.swift b/packages/path_provider/path_provider_foundation/darwin/Classes/PathProviderPlugin.swift index 5530b8be026..16f2edb84c9 100644 --- a/packages/path_provider/path_provider_foundation/darwin/Classes/PathProviderPlugin.swift +++ b/packages/path_provider/path_provider_foundation/darwin/Classes/PathProviderPlugin.swift @@ -5,62 +5,63 @@ import Foundation #if os(iOS) -import Flutter + import Flutter #elseif os(macOS) -import FlutterMacOS + import FlutterMacOS #endif public class PathProviderPlugin: NSObject, FlutterPlugin, PathProviderApi { public static func register(with registrar: FlutterPluginRegistrar) { let instance = PathProviderPlugin() // Workaround for https://github.com/flutter/flutter/issues/118103. -#if os(iOS) - let messenger = registrar.messenger() -#else - let messenger = registrar.messenger -#endif + #if os(iOS) + let messenger = registrar.messenger() + #else + let messenger = registrar.messenger + #endif PathProviderApiSetup.setUp(binaryMessenger: messenger, api: instance) } func getDirectoryPath(type: DirectoryType) -> String? { var path = getDirectory(ofType: fileManagerDirectoryForType(type)) - #if os(macOS) - // In a non-sandboxed app, these are shared directories where applications are - // expected to use its bundle ID as a subdirectory. (For non-sandboxed apps, - // adding the extra path is harmless). - // This is not done for iOS, for compatibility with older versions of the - // plugin. - if type == .applicationSupport || type == .applicationCache { - if let basePath = path { - let basePathURL = URL.init(fileURLWithPath: basePath) - path = basePathURL.appendingPathComponent(Bundle.main.bundleIdentifier!).path + #if os(macOS) + // In a non-sandboxed app, these are shared directories where applications are + // expected to use its bundle ID as a subdirectory. (For non-sandboxed apps, + // adding the extra path is harmless). + // This is not done for iOS, for compatibility with older versions of the + // plugin. + if type == .applicationSupport || type == .applicationCache { + if let basePath = path { + let basePathURL = URL.init(fileURLWithPath: basePath) + path = basePathURL.appendingPathComponent(Bundle.main.bundleIdentifier!).path + } } - } - #endif + #endif return path } // Returns the path for the container of the specified app group. func getContainerPath(appGroupIdentifier: String) -> String? { - return FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupIdentifier)?.path + return FileManager.default.containerURL( + forSecurityApplicationGroupIdentifier: appGroupIdentifier)?.path } } /// Returns the FileManager constant corresponding to the given type. private func fileManagerDirectoryForType(_ type: DirectoryType) -> FileManager.SearchPathDirectory { switch type { - case .applicationCache: - return FileManager.SearchPathDirectory.cachesDirectory - case .applicationDocuments: - return FileManager.SearchPathDirectory.documentDirectory - case .applicationSupport: - return FileManager.SearchPathDirectory.applicationSupportDirectory - case .downloads: - return FileManager.SearchPathDirectory.downloadsDirectory - case .library: - return FileManager.SearchPathDirectory.libraryDirectory - case .temp: - return FileManager.SearchPathDirectory.cachesDirectory + case .applicationCache: + return FileManager.SearchPathDirectory.cachesDirectory + case .applicationDocuments: + return FileManager.SearchPathDirectory.documentDirectory + case .applicationSupport: + return FileManager.SearchPathDirectory.applicationSupportDirectory + case .downloads: + return FileManager.SearchPathDirectory.downloadsDirectory + case .library: + return FileManager.SearchPathDirectory.libraryDirectory + case .temp: + return FileManager.SearchPathDirectory.cachesDirectory } } diff --git a/packages/path_provider/path_provider_foundation/darwin/RunnerTests/RunnerTests.swift b/packages/path_provider/path_provider_foundation/darwin/RunnerTests/RunnerTests.swift index 99a56f2bfeb..67ee981673a 100644 --- a/packages/path_provider/path_provider_foundation/darwin/RunnerTests/RunnerTests.swift +++ b/packages/path_provider/path_provider_foundation/darwin/RunnerTests/RunnerTests.swift @@ -3,12 +3,13 @@ // found in the LICENSE file. import XCTest + @testable import path_provider_foundation #if os(iOS) -import Flutter + import Flutter #elseif os(macOS) -import FlutterMacOS + import FlutterMacOS #endif class RunnerTests: XCTestCase { @@ -39,28 +40,28 @@ class RunnerTests: XCTestCase { func testGetApplicationSupportDirectory() throws { let plugin = PathProviderPlugin() let path = plugin.getDirectoryPath(type: .applicationSupport) -#if os(iOS) - // On iOS, the application support directory path should be just the system application - // support path. - XCTAssertEqual( - path, - NSSearchPathForDirectoriesInDomains( - FileManager.SearchPathDirectory.applicationSupportDirectory, - FileManager.SearchPathDomainMask.userDomainMask, - true - ).first) -#else - // On macOS, the application support directory path should be the system application - // support path with an added subdirectory based on the app name. - XCTAssert( - path!.hasPrefix( + #if os(iOS) + // On iOS, the application support directory path should be just the system application + // support path. + XCTAssertEqual( + path, NSSearchPathForDirectoriesInDomains( FileManager.SearchPathDirectory.applicationSupportDirectory, FileManager.SearchPathDomainMask.userDomainMask, true - ).first!)) - XCTAssert(path!.hasSuffix("Example")) -#endif + ).first) + #else + // On macOS, the application support directory path should be the system application + // support path with an added subdirectory based on the app name. + XCTAssert( + path!.hasPrefix( + NSSearchPathForDirectoriesInDomains( + FileManager.SearchPathDirectory.applicationSupportDirectory, + FileManager.SearchPathDomainMask.userDomainMask, + true + ).first!)) + XCTAssert(path!.hasSuffix("Example")) + #endif } func testGetLibraryDirectory() throws {