Skip to content

Commit

Permalink
[path_provider_foundation] Run swift-format on Swift files (#5935)
Browse files Browse the repository at this point in the history
Run `swift-format` linter/formatter on Swift files.

Part of turning on swift-format CI formatting #5928
  • Loading branch information
jmagman committed Jan 19, 2024
1 parent 76a6fd2 commit 9379e4a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 9379e4a

Please sign in to comment.