Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(iOS): change hardcoded config path when using custom config file for auto register plugins #7540

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ios/Capacitor/Capacitor/CAPInstanceConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ NS_SWIFT_NAME(InstanceConfiguration)
@property (nonatomic, readonly, nonnull) NSArray<NSString*> *allowedNavigationHostnames;
@property (nonatomic, readonly, nonnull) NSURL *localURL;
@property (nonatomic, readonly, nonnull) NSURL *serverURL;
@property (nonatomic, readonly, nullable) NSURL *configURL;
@property (nonatomic, readonly, nullable) NSString *errorPath;
@property (nonatomic, readonly, nonnull) NSDictionary *pluginConfigurations;
@property (nonatomic, readonly) BOOL loggingEnabled;
Expand Down
7 changes: 7 additions & 0 deletions ios/Capacitor/Capacitor/CAPInstanceConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ - (instancetype)initWithDescriptor:(CAPInstanceDescriptor *)descriptor isDebug:(
else {
_serverURL = _localURL;
}

if (descriptor.configUrl != nil) {
_configURL = descriptor.configUrl;
}
else {
_configURL = [[NSURL alloc] initWithString:(@"capacitor.config.json")];
}
_errorPath = descriptor.errorPath;
// extract the one value we care about from the cordova configuration
_cordovaDeployDisabled = [descriptor cordovaDeployDisabled];
Expand Down
5 changes: 5 additions & 0 deletions ios/Capacitor/Capacitor/CAPInstanceDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ NS_SWIFT_NAME(InstanceDescriptor)
@discussion Defaults to nil, in which case the server URL will be constructed from @c urlScheme and @c urlHostname. If set, it will override the other properties. Set by @c server.url in the configuration file.
*/
@property (nonatomic, copy, nullable) NSString *serverURL;
/**
@brief The file URL from which Capacitor will load configuration
@discussion Defaults to @c capacitor.config.json located at the root of the application bundle.
*/
@property (nonatomic, copy, nullable) NSURL *configUrl;
/**
@brief The JSON dictionary that contains the plugin-specific configuration information.
@discussion Set by @c plugins in the configuration file.
Expand Down
2 changes: 2 additions & 0 deletions ios/Capacitor/Capacitor/CAPInstanceDescriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ internal extension InstanceDescriptor {
// swiftlint:disable function_body_length
// swiftlint:disable:next identifier_name
@objc func _parseConfiguration(at capacitorURL: URL?, cordovaConfiguration cordovaURL: URL?) {
configUrl = capacitorURL

// sanity check that the app directory is valid
var isDirectory: ObjCBool = ObjCBool(false)
if warnings.contains(.missingAppDir) == false,
Expand Down
5 changes: 2 additions & 3 deletions ios/Capacitor/Capacitor/CapacitorBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,9 @@ open class CapacitorBridge: NSObject, CAPBridgeProtocol {
*/
func registerPlugins() {
var pluginList: [AnyClass] = [CAPHttpPlugin.self, CAPConsolePlugin.self, CAPWebViewPlugin.self, CAPCookiesPlugin.self]

if autoRegisterPlugins {
if autoRegisterPlugins && config.configURL != nil {
do {
if let pluginJSON = Bundle.main.url(forResource: "capacitor.config", withExtension: "json") {
if let pluginJSON = Bundle.main.url(forResource: (config.configURL!.path as NSString).deletingPathExtension, withExtension: "json") {
let pluginData = try Data(contentsOf: pluginJSON)
let registrationList = try JSONDecoder().decode(RegistrationList.self, from: pluginData)

Expand Down