From 18da02e5a19740effe788296f7221cb152345ba3 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Thu, 29 Jul 2021 16:55:10 +0200 Subject: [PATCH] Update SwiftGen --- .../App/macOS/Global/SwiftGen+Assets.swift | 10 ++++-- .../App/macOS/Global/SwiftGen+Scenes.swift | 34 +++++++++++++++++-- .../App/macOS/Global/SwiftGen+Segues.swift | 8 ----- .../App/macOS/Global/SwiftGen+Strings.swift | 10 ++++-- 4 files changed, 47 insertions(+), 15 deletions(-) diff --git a/Passepartout/App/macOS/Global/SwiftGen+Assets.swift b/Passepartout/App/macOS/Global/SwiftGen+Assets.swift index b66117ed..72f83eba 100644 --- a/Passepartout/App/macOS/Global/SwiftGen+Assets.swift +++ b/Passepartout/App/macOS/Global/SwiftGen+Assets.swift @@ -289,6 +289,7 @@ internal enum Asset { internal static let pia = ImageAsset(name: "pia") internal static let placeholder = ImageAsset(name: "placeholder") internal static let protonvpn = ImageAsset(name: "protonvpn") + internal static let surfshark = ImageAsset(name: "surfshark") internal static let torguard = ImageAsset(name: "torguard") internal static let tunnelbear = ImageAsset(name: "tunnelbear") internal static let vyprvpn = ImageAsset(name: "vyprvpn") @@ -313,7 +314,8 @@ internal struct ImageAsset { #if os(iOS) || os(tvOS) let image = Image(named: name, in: bundle, compatibleWith: nil) #elseif os(macOS) - let image = bundle.image(forResource: NSImage.Name(name)) + let name = NSImage.Name(self.name) + let image = (bundle == .main) ? NSImage(named: name) : bundle.image(forResource: name) #elseif os(watchOS) let image = Image(named: name) #endif @@ -342,7 +344,11 @@ internal extension ImageAsset.Image { // swiftlint:disable convenience_type private final class BundleToken { static let bundle: Bundle = { - Bundle(for: BundleToken.self) + #if SWIFT_PACKAGE + return Bundle.module + #else + return Bundle(for: BundleToken.self) + #endif }() } // swiftlint:enable convenience_type diff --git a/Passepartout/App/macOS/Global/SwiftGen+Scenes.swift b/Passepartout/App/macOS/Global/SwiftGen+Scenes.swift index 3a9b4028..d2cfbe90 100644 --- a/Passepartout/App/macOS/Global/SwiftGen+Scenes.swift +++ b/Passepartout/App/macOS/Global/SwiftGen+Scenes.swift @@ -6,7 +6,7 @@ import Foundation import AppKit // swiftlint:disable superfluous_disable_command -// swiftlint:disable file_length +// swiftlint:disable file_length implicit_return // MARK: - Storyboard Scenes @@ -67,6 +67,16 @@ internal struct SceneType { } return controller } + + @available(macOS 10.15, *) + internal func instantiate(creator block: @escaping (NSCoder) -> T?) -> T where T: NSViewController { + return storyboard.storyboard.instantiateController(identifier: identifier, creator: block) + } + + @available(macOS 10.15, *) + internal func instantiate(creator block: @escaping (NSCoder) -> T?) -> T where T: NSWindowController { + return storyboard.storyboard.instantiateController(identifier: identifier, creator: block) + } } internal struct InitialSceneType { @@ -78,12 +88,32 @@ internal struct InitialSceneType { } return controller } + + @available(macOS 10.15, *) + internal func instantiate(creator block: @escaping (NSCoder) -> T?) -> T where T: NSViewController { + guard let controller = storyboard.storyboard.instantiateInitialController(creator: block) else { + fatalError("Storyboard \(storyboard.storyboardName) does not have an initial scene.") + } + return controller + } + + @available(macOS 10.15, *) + internal func instantiate(creator block: @escaping (NSCoder) -> T?) -> T where T: NSWindowController { + guard let controller = storyboard.storyboard.instantiateInitialController(creator: block) else { + fatalError("Storyboard \(storyboard.storyboardName) does not have an initial scene.") + } + return controller + } } // swiftlint:disable convenience_type private final class BundleToken { static let bundle: Bundle = { - Bundle(for: BundleToken.self) + #if SWIFT_PACKAGE + return Bundle.module + #else + return Bundle(for: BundleToken.self) + #endif }() } // swiftlint:enable convenience_type diff --git a/Passepartout/App/macOS/Global/SwiftGen+Segues.swift b/Passepartout/App/macOS/Global/SwiftGen+Segues.swift index 73b423ef..9cff6586 100644 --- a/Passepartout/App/macOS/Global/SwiftGen+Segues.swift +++ b/Passepartout/App/macOS/Global/SwiftGen+Segues.swift @@ -45,11 +45,3 @@ internal extension SegueType where RawValue == String { self.init(rawValue: identifier) } } - -// swiftlint:disable convenience_type -private final class BundleToken { - static let bundle: Bundle = { - Bundle(for: BundleToken.self) - }() -} -// swiftlint:enable convenience_type diff --git a/Passepartout/App/macOS/Global/SwiftGen+Strings.swift b/Passepartout/App/macOS/Global/SwiftGen+Strings.swift index 6b57f85e..8ed2306f 100644 --- a/Passepartout/App/macOS/Global/SwiftGen+Strings.swift +++ b/Passepartout/App/macOS/Global/SwiftGen+Strings.swift @@ -8,7 +8,7 @@ import Foundation // MARK: - Strings // swiftlint:disable explicit_type_interface function_parameter_count identifier_name line_length -// swiftlint:disable nesting type_body_length type_name +// swiftlint:disable nesting type_body_length type_name vertical_whitespace_opening_braces internal enum L10n { internal enum App { internal enum Configuration { @@ -1140,7 +1140,7 @@ internal enum L10n { } } // swiftlint:enable explicit_type_interface function_parameter_count identifier_name line_length -// swiftlint:enable nesting type_body_length type_name +// swiftlint:enable nesting type_body_length type_name vertical_whitespace_opening_braces // MARK: - Implementation Details @@ -1154,7 +1154,11 @@ extension L10n { // swiftlint:disable convenience_type private final class BundleToken { static let bundle: Bundle = { - Bundle(for: BundleToken.self) + #if SWIFT_PACKAGE + return Bundle.module + #else + return Bundle(for: BundleToken.self) + #endif }() } // swiftlint:enable convenience_type