Skip to content

Commit

Permalink
Provide graphics options, auto-append user agent, & use generated -Sw…
Browse files Browse the repository at this point in the history
…ift.h
  • Loading branch information
tzachari committed Aug 16, 2019
1 parent e4dbb3e commit 92113f7
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 187 deletions.
3 changes: 1 addition & 2 deletions XRViewer/ARKController/ARKController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#import <AVFoundation/AVFoundation.h>
#import <Accelerate/Accelerate.h>
#import "Compression.h"
// #import "XRViewer-Swift.h"
#import "arish-Swift.h"
#import "XRViewer-Swift.h"

@interface ARKController () {
}
Expand Down
6 changes: 5 additions & 1 deletion XRViewer/WebController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,11 @@ class WebController: NSObject, WKUIDelegate, WKNavigationDelegate, WKScriptMessa
let userScript = WKUserScript(source: scriptContent ?? "", injectionTime: .atDocumentStart, forMainFrameOnly: true)
self.contentController = wv.configuration.userContentController
self.contentController?.addUserScript(userScript)


wv.evaluateJavaScript("navigator.userAgent", completionHandler: { ( base, error ) in
wv.customUserAgent = (base as? String ?? "") + " Mobile WebXRViewer/1.17"
})

wv.configuration.preferences.setValue(true, forKey: "allowFileAccessFromFileURLs")
wv.navigationDelegate = self
wv.uiDelegate = self
Expand Down
3 changes: 2 additions & 1 deletion XRViewer/WebXRPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ class WebXRPlugin : CDVPlugin {

weak var blockSelf: WebXRPlugin? = self

arkController = ARKController(type: UserDefaults.standard.bool(forKey: Constant.useMetalForARKey()) ? .metal : .sceneKit, rootView: arkLayerView)
let frameworkString = self.commandDelegate.settings["graphicsframework"] as? String
arkController = ARKController(type: frameworkString == "metal" ? .metal : .sceneKit, rootView: arkLayerView)

arkController?.didUpdate = { c in
guard let shouldSendNativeTime = blockSelf?.stateController.shouldSendNativeTime() else { return }
Expand Down
179 changes: 0 additions & 179 deletions XRViewer/XRViewer-Swift.h

This file was deleted.

4 changes: 3 additions & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
<platform name="ios">
<preference name="CAMERA_USAGE_DESCRIPTION" default="This app uses the camera for augmented reality"/>
<preference name="WEBXR_AUTHORIZATION" default="minimal" />
<preference name="GRAPHICS_FRAMEWORK" default="sceneKit" />
<preference name="PRODUCT_MODULE_NAME" default=" " />

<config-file target="config.xml" parent="/widget">
<feature name="WebXRPlugin">
<param name="ios-package" value="WebXRPlugin" onload="true"/>
</feature>
<preference name="WebXRAuthorization" value="$WEBXR_AUTHORIZATION" />
<preference name="AppendUserAgent" value="Mobile WebXRViewer" />
<preference name="GraphicsFramework" value="$GRAPHICS_FRAMEWORK" />
</config-file>

<config-file target="*-Info.plist" parent="NSCameraUsageDescription">
Expand Down
13 changes: 10 additions & 3 deletions prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ const fs = require( 'fs' );
const path = require( 'path' );

module.exports = function( ctx ) {
var rootdir = path.join( ctx.opts.plugin.dir, 'XRViewer' );
var CP = ctx.requireCordovaModule('cordova-common/src/ConfigParser/ConfigParser');
var rootDir = path.join( ctx.opts.plugin.dir, 'XRViewer' );

var projectName = ctx.opts.plugin.pluginInfo.getPreferences( 'ios' ).PRODUCT_MODULE_NAME;
if ( projectName == " " ) {
projectName = new CP( path.join( ctx.opts.projectRoot, 'config.xml' ) ).name();
}

var replaceInDir = dir => {
fs.readdirSync( dir ).forEach( f => {
var file = path.join( dir, f );
Expand All @@ -13,6 +19,7 @@ module.exports = function( ctx ) {
data = data.replace( /^.*(XCGLogger).*$/mg, '' );
data = data.replace( /func appDelegate[^}]*\n}/, '' );
data = data.replace( /= .fade/, '= kCATransitionFade' );
data = data.replace( /\w+-Swift/, projectName.replace(' ','_') + '-Swift' )
fs.writeFileSync( file, data, 'utf8' );
}
} else {
Expand All @@ -21,7 +28,7 @@ module.exports = function( ctx ) {
} )
}

if ( rootdir ) {
replaceInDir( rootdir );
if ( rootDir ) {
replaceInDir( rootDir );
}
}

0 comments on commit 92113f7

Please sign in to comment.