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

[Work in Progress]: Optional Cordova (currently iOS Only) #7479

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
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
411 changes: 14 additions & 397 deletions cli/src/ios/update.ts

Large diffs are not rendered by default.

412 changes: 412 additions & 0 deletions cli/src/util/cordova-ios.ts

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion ios/Capacitor.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ Pod::Spec.new do |s|
s.source_files = "#{prefix}Capacitor/Capacitor/**/*.{swift,h,m}"
s.module_map = "#{prefix}Capacitor/Capacitor/Capacitor.modulemap"
s.resources = ["#{prefix}Capacitor/Capacitor/assets/native-bridge.js", "#{prefix}Capacitor/Capacitor/PrivacyInfo.xcprivacy"]
s.dependency 'CapacitorCordova'
s.swift_version = '5.1'
end
8 changes: 0 additions & 8 deletions ios/Capacitor/Capacitor.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
/* Begin PBXBuildFile section */
0F83E885285A332E006C43CB /* AppUUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F83E884285A332D006C43CB /* AppUUID.swift */; };
0F8F33B327DA980A003F49D6 /* PluginConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F8F33B127DA980A003F49D6 /* PluginConfig.swift */; };
2F81F5C926FB7CB400DD35BE /* CAPBridgeViewController+CDVScreenOrientationDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 2F81F5C726FB7CB400DD35BE /* CAPBridgeViewController+CDVScreenOrientationDelegate.h */; };
2F81F5CA26FB7CB400DD35BE /* CAPBridgeViewController+CDVScreenOrientationDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 2F81F5C826FB7CB400DD35BE /* CAPBridgeViewController+CDVScreenOrientationDelegate.m */; };
373A69C1255C9360000A6F44 /* NotificationHandlerProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373A69C0255C9360000A6F44 /* NotificationHandlerProtocol.swift */; };
373A69F2255C95D0000A6F44 /* NotificationRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373A69F1255C95D0000A6F44 /* NotificationRouter.swift */; };
501CBAA71FC0A723009B0D4D /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 501CBAA61FC0A723009B0D4D /* WebKit.framework */; };
Expand Down Expand Up @@ -153,8 +151,6 @@
/* Begin PBXFileReference section */
0F83E884285A332D006C43CB /* AppUUID.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppUUID.swift; sourceTree = "<group>"; };
0F8F33B127DA980A003F49D6 /* PluginConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PluginConfig.swift; sourceTree = "<group>"; };
2F81F5C726FB7CB400DD35BE /* CAPBridgeViewController+CDVScreenOrientationDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CAPBridgeViewController+CDVScreenOrientationDelegate.h"; sourceTree = "<group>"; };
2F81F5C826FB7CB400DD35BE /* CAPBridgeViewController+CDVScreenOrientationDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "CAPBridgeViewController+CDVScreenOrientationDelegate.m"; sourceTree = "<group>"; };
373A69C0255C9360000A6F44 /* NotificationHandlerProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationHandlerProtocol.swift; sourceTree = "<group>"; };
373A69F1255C95D0000A6F44 /* NotificationRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationRouter.swift; sourceTree = "<group>"; };
501CBAA61FC0A723009B0D4D /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -392,8 +388,6 @@
62FABD1925AE5C01007B3814 /* Array+Capacitor.swift */,
62D43AEF2581817500673C24 /* WKWebView+Capacitor.swift */,
62D43B642582A13D00673C24 /* WKWebView+Capacitor.m */,
2F81F5C726FB7CB400DD35BE /* CAPBridgeViewController+CDVScreenOrientationDelegate.h */,
2F81F5C826FB7CB400DD35BE /* CAPBridgeViewController+CDVScreenOrientationDelegate.m */,
62959AE92524DA7700A3D7F1 /* UIColor.swift */,
62959AFE2524DA7700A3D7F1 /* UIStatusBarManager+CAPHandleTapAction.m */,
62959B122524DA7700A3D7F1 /* Info.plist */,
Expand Down Expand Up @@ -500,7 +494,6 @@
623D6909254C6FDF002D01D1 /* CAPInstanceDescriptor.h in Headers */,
62959B192524DA7800A3D7F1 /* CAPBridgedPlugin.h in Headers */,
621ECCB82542045900D3D615 /* CAPBridgedJSTypes.h in Headers */,
2F81F5C926FB7CB400DD35BE /* CAPBridgeViewController+CDVScreenOrientationDelegate.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -712,7 +705,6 @@
62959B1D2524DA7800A3D7F1 /* UIColor.swift in Sources */,
62959B332524DA7800A3D7F1 /* CAPPlugin.m in Sources */,
62959B1C2524DA7800A3D7F1 /* CAPPluginMethod.m in Sources */,
2F81F5CA26FB7CB400DD35BE /* CAPBridgeViewController+CDVScreenOrientationDelegate.m in Sources */,
62ADC0CA25CB678000E914DE /* PluginCallResult.swift in Sources */,
62959B472524DA7800A3D7F1 /* CAPNotifications.swift in Sources */,
62D43B652582A13D00673C24 /* WKWebView+Capacitor.m in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion ios/Capacitor/Capacitor/CAPApplicationDelegateProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ApplicationDelegateProxy: NSObject, UIApplicationDelegate {
"url": url,
"options": options
])
NotificationCenter.default.post(name: NSNotification.Name.CDVPluginHandleOpenURL, object: url)
//NotificationCenter.default.post(name: NSNotification.Name.CDVPluginHandleOpenURL, object: url)
lastURL = url
return true
}
Expand Down
3 changes: 3 additions & 0 deletions ios/Capacitor/Capacitor/CAPBridgeProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ import WebKit
func registerPluginType(_ pluginType: CAPPlugin.Type)
func registerPluginInstance(_ pluginInstance: CAPPlugin)

// MARK: - Interceptors
func registerCallInterceptor(_ name: String, handler: @escaping ([String: Any]) -> Void)

// MARK: - View Presentation
func showAlertWith(title: String, message: String, buttonTitle: String)
func presentVC(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)?)
Expand Down

This file was deleted.

This file was deleted.

18 changes: 12 additions & 6 deletions ios/Capacitor/Capacitor/CAPBridgeViewController.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import UIKit
import WebKit
import Cordova

@objc open class CAPBridgeViewController: UIViewController {
private var capacitorBridge: CapacitorBridge?
Expand Down Expand Up @@ -47,10 +46,10 @@ import Cordova
// create the bridge
capacitorBridge = CapacitorBridge(with: configuration,
delegate: self,
cordovaConfiguration: configDescriptor.cordovaConfiguration,
assetHandler: assetHandler,
delegationHandler: delegationHandler)
capacitorDidLoad()
updateAppLocationIfNeeded()

if configDescriptor.instanceType == .fixed {
updateBinaryVersion()
Expand All @@ -77,18 +76,25 @@ import Cordova
- Note: This is called early in the View Controller's lifecycle. Not all properties will be set at invocation.
*/
open func instanceDescriptor() -> InstanceDescriptor {
let descriptor = InstanceDescriptor.init()
if !isNewBinary && !descriptor.cordovaDeployDisabled {
return InstanceDescriptor()
}

/// This function must be called after plugins are loaded or it will have no effect.
open func updateAppLocationIfNeeded() {
let cordovaPlugin = bridge?.plugin(withName: "__CordovaPlugin")
let cordovaDeployDisabled = cordovaPlugin?.perform(Selector(("cordovaDeployDisabled"))).takeUnretainedValue() as? Bool ?? false

if !isNewBinary && !cordovaDeployDisabled {
if let persistedPath = KeyValueStore.standard["serverBasePath", as: String.self], !persistedPath.isEmpty {
if let libPath = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true).first {
descriptor.appLocation = URL(fileURLWithPath: libPath, isDirectory: true)
let serverBasePath = URL(fileURLWithPath: libPath, isDirectory: true)
.appendingPathComponent("NoCloud")
.appendingPathComponent("ionic_built_snapshots")
.appendingPathComponent(URL(fileURLWithPath: persistedPath, isDirectory: true).lastPathComponent)
setServerBasePath(path: serverBasePath.path)
}
}
}
return descriptor
}

open func router() -> Router {
Expand Down
4 changes: 2 additions & 2 deletions ios/Capacitor/Capacitor/CAPInstanceDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define CAPInstanceDescriptor_h

@import UIKit;
@import Cordova;


typedef NS_ENUM(NSInteger, CAPInstanceType) {
CAPInstanceTypeFixed NS_SWIFT_NAME(fixed),
Expand Down Expand Up @@ -131,7 +131,7 @@ NS_SWIFT_NAME(InstanceDescriptor)
/**
@brief The parser used to load the cofiguration for Cordova plugins.
*/
@property (nonatomic, copy, nonnull) CDVConfigParser *cordovaConfiguration;
@property (nonatomic, copy, nonnull) NSObject *cordovaConfiguration;
/**
@brief Warnings generated during initialization.
*/
Expand Down
2 changes: 1 addition & 1 deletion ios/Capacitor/Capacitor/CAPInstanceDescriptor.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ - (void)_setDefaultsWithAppLocation:(NSURL*)location {
_contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
_appLocation = location;
_limitsNavigationsToAppBoundDomains = FALSE;
_cordovaConfiguration = [[CDVConfigParser alloc] init];
// _cordovaConfiguration = [[CDVConfigParser alloc] init];
_warnings = 0;
if (location == nil) {
_warnings |= CAPInstanceWarningMissingAppDir;
Expand Down
20 changes: 2 additions & 18 deletions ios/Capacitor/Capacitor/CAPInstanceDescriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,6 @@ internal extension InstanceDescriptor {
warnings.update(with: .missingFile)
}

// parse the cordova configuration
var configParser: XMLParser?
if let cordovaURL = cordovaURL,
FileManager.default.fileExists(atPath: cordovaURL.path, isDirectory: &isDirectory),
isDirectory.boolValue == false {
configParser = XMLParser(contentsOf: cordovaURL)
} else {
warnings.update(with: .missingCordovaFile)
// we don't want to break up string literals
// swiftlint:disable:next line_length
if let cordovaXML = "<?xml version='1.0' encoding='utf-8'?><widget version=\"1.0.0\" xmlns=\"http://www.w3.org/ns/widgets\" xmlns:cdv=\"http://cordova.apache.org/ns/1.0\"><access origin=\"*\" /></widget>".data(using: .utf8) {
configParser = XMLParser(data: cordovaXML)
}
}
configParser?.delegate = cordovaConfiguration
configParser?.parse()

// extract our configuration values
if let config = config {
// to be removed
Expand Down Expand Up @@ -149,7 +132,8 @@ internal extension InstanceDescriptor {

extension InstanceDescriptor {
@objc public var cordovaDeployDisabled: Bool {
return (cordovaConfiguration.settings?["DisableDeploy".lowercased()] as? NSString)?.boolValue ?? false
return false
//return (cordovaConfiguration.settings?["DisableDeploy".lowercased()] as? NSString)?.boolValue ?? false
}

@objc public func normalize() {
Expand Down
Loading