From 2c72e4a5424e5abf1bc0ccf2d452d3ab1cca3a78 Mon Sep 17 00:00:00 2001 From: Zak Barbuto Date: Wed, 13 Jun 2018 08:52:04 +0930 Subject: [PATCH 1/4] Add com.wikitude.phonegap.wikitudeplugin types --- ....wikitude.phonegap.wikitudeplugin-tests.ts | 33 ++++++++ .../index.d.ts | 81 +++++++++++++++++++ .../tsconfig.json | 24 ++++++ .../tslint.json | 79 ++++++++++++++++++ 4 files changed, 217 insertions(+) create mode 100644 types/com.wikitude.phonegap.wikitudeplugin/com.wikitude.phonegap.wikitudeplugin-tests.ts create mode 100644 types/com.wikitude.phonegap.wikitudeplugin/index.d.ts create mode 100644 types/com.wikitude.phonegap.wikitudeplugin/tsconfig.json create mode 100644 types/com.wikitude.phonegap.wikitudeplugin/tslint.json diff --git a/types/com.wikitude.phonegap.wikitudeplugin/com.wikitude.phonegap.wikitudeplugin-tests.ts b/types/com.wikitude.phonegap.wikitudeplugin/com.wikitude.phonegap.wikitudeplugin-tests.ts new file mode 100644 index 0000000000..00ee01f175 --- /dev/null +++ b/types/com.wikitude.phonegap.wikitudeplugin/com.wikitude.phonegap.wikitudeplugin-tests.ts @@ -0,0 +1,33 @@ +const startupConfiguration: any = { camera_position: 'back' }; + +// Some code samples from the wikitude ionic starter +WikitudePlugin.loadARchitectWorld( + function(success) { + console.log('ARchitect World loaded successfully.'); + }, + function(fail) { + console.log('Failed to load ARchitect World!'); + }, + 'www/assets/07_3dModels_6_3dModelAtGeoLocation/index.html', + ['geo'], + startupConfiguration +); + +WikitudePlugin.setOnUrlInvokeCallback(function(url) { + if (url.indexOf('captureScreen') > -1) { + WikitudePlugin.captureScreen( + absoluteFilePath => { + WikitudePlugin.callJavaScript( + "World.testFunction('Screenshot saved at: " + absoluteFilePath + "');" + ); + }, + errorMessage => { + console.log(errorMessage); + }, + true, + null + ); + } else { + alert(url + 'not handled'); + } +}); diff --git a/types/com.wikitude.phonegap.wikitudeplugin/index.d.ts b/types/com.wikitude.phonegap.wikitudeplugin/index.d.ts new file mode 100644 index 0000000000..cfa1a82a4c --- /dev/null +++ b/types/com.wikitude.phonegap.wikitudeplugin/index.d.ts @@ -0,0 +1,81 @@ +// Type definitions for com.wikitude.phonegap.wikitudeplugin 7.2.0 +// Project: https://github.com/Wikitude/wikitude-cordova-plugin +// Definitions by: zbarbuto +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +// The following types are taken directly (unmodified) from the wikitude-ionic-3-starter-app +// https://github.com/pbreuss/wikitude-ionic-3-starter-app +// Latest commit at time of writing was 647cd546f6d1805765c4cee725566e246ca6259d + +/** + * Wrapper for the Wikitude SDK Phonegap Plugin - to use with IONIC2 + * (c) 2016 Schneeweis.Technology + */ +interface WikitudePlugin { + isDeviceSupported( + successCallback: (success: string) => void, + errorCallback: (message: string) => void, + requiredFeatures: [string] + ): void; + + loadARchitectWorld( + successCallback: (success: string) => void, + errorCallback: (message: string) => void, + architectWorldPath: string, + requiredFeatures: [string], + startupConfiguration: JSON | Object + ): void; + + close(): void; + + hide(): void; + + show(): void; + + // test type ok? + callJavaScript(js: any): void; + + setOnUrlInvokeCallback(onUrlInvokeCallback: (success: string) => void): void; + + setLocation(latitude: any, longitude: any, altitude: any, accuracy: any): void; + + captureScreen( + successCallback: (success: string) => void, + errorCallback: (message: string) => void, + includeWebView: boolean, + imagePathInBundleOrNullForPhotoLibrary: string | null + ): void; + + setErrorHandler(errorHandler: (message: string) => void): void; + + setDeviceSensorsNeedCalibrationHandler( + startCalibrationHandler: (message: string) => void + ): void; + + setDeviceSensorsFinishedCalibrationHandler( + finishedCalibrationHandler: (message: string) => void + ): void; + + setBackButtonCallback(onBackButtonCallback: (message: string) => void): void; + + /* Lifecycle updates */ + + onResume(): void; + onBackButton(): void; + onPause(): void; + + onWikitudeOK(): void; + onWikitudeError(): void; + + _sdkKey: string; + FeatureGeo: string; + Feature2DTracking: string; + CameraPositionUndefined: number; + CameraPositionFront: number; + CameraPositionBack: number; + CameraFocusRangeNone: number; + CameraFocusRangeNear: number; + CameraFocusRangeFar: number; +} + +declare var WikitudePlugin: WikitudePlugin; diff --git a/types/com.wikitude.phonegap.wikitudeplugin/tsconfig.json b/types/com.wikitude.phonegap.wikitudeplugin/tsconfig.json new file mode 100644 index 0000000000..ed0ce7783e --- /dev/null +++ b/types/com.wikitude.phonegap.wikitudeplugin/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "com.wikitude.phonegap.wikitudeplugin-tests.ts" + ] +} diff --git a/types/com.wikitude.phonegap.wikitudeplugin/tslint.json b/types/com.wikitude.phonegap.wikitudeplugin/tslint.json new file mode 100644 index 0000000000..a41bf5d19a --- /dev/null +++ b/types/com.wikitude.phonegap.wikitudeplugin/tslint.json @@ -0,0 +1,79 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "adjacent-overload-signatures": false, + "array-type": false, + "arrow-return-shorthand": false, + "ban-types": false, + "callable-types": false, + "comment-format": false, + "dt-header": false, + "eofline": false, + "export-just-namespace": false, + "import-spacing": false, + "interface-name": false, + "interface-over-type-literal": false, + "jsdoc-format": false, + "max-line-length": false, + "member-access": false, + "new-parens": false, + "no-any-union": false, + "no-boolean-literal-compare": false, + "no-conditional-assignment": false, + "no-consecutive-blank-lines": false, + "no-construct": false, + "no-declare-current-package": false, + "no-duplicate-imports": false, + "no-duplicate-variable": false, + "no-empty-interface": false, + "no-for-in-array": false, + "no-inferrable-types": false, + "no-internal-module": false, + "no-irregular-whitespace": false, + "no-mergeable-namespace": false, + "no-misused-new": false, + "no-namespace": false, + "no-object-literal-type-assertion": false, + "no-padding": false, + "no-redundant-jsdoc": false, + "no-redundant-jsdoc-2": false, + "no-redundant-undefined": false, + "no-reference-import": false, + "no-relative-import-in-test": false, + "no-self-import": false, + "no-single-declare-module": false, + "no-string-throw": false, + "no-unnecessary-callback-wrapper": false, + "no-unnecessary-class": false, + "no-unnecessary-generics": false, + "no-unnecessary-qualifier": false, + "no-unnecessary-type-assertion": false, + "no-useless-files": false, + "no-var-keyword": false, + "no-var-requires": false, + "no-void-expression": false, + "no-trailing-whitespace": false, + "object-literal-key-quotes": false, + "object-literal-shorthand": false, + "one-line": false, + "one-variable-per-declaration": false, + "only-arrow-functions": false, + "prefer-conditional-expression": false, + "prefer-const": false, + "prefer-declare-function": false, + "prefer-for-of": false, + "prefer-method-signature": false, + "prefer-template": false, + "radix": false, + "semicolon": false, + "space-before-function-paren": false, + "space-within-parens": false, + "strict-export-declare-modifiers": false, + "trim-file": false, + "triple-equals": false, + "typedef-whitespace": false, + "unified-signatures": false, + "void-return": false, + "whitespace": false + } +} From 2aad365dd95677bbd89a0847ee6393a7ff570a21 Mon Sep 17 00:00:00 2001 From: Zak Barbuto Date: Thu, 14 Jun 2018 09:19:03 +0930 Subject: [PATCH 2/4] Cleanup tslint to only extend dt.json --- .../tslint.json | 78 +------------------ 1 file changed, 1 insertion(+), 77 deletions(-) diff --git a/types/com.wikitude.phonegap.wikitudeplugin/tslint.json b/types/com.wikitude.phonegap.wikitudeplugin/tslint.json index a41bf5d19a..f93cf8562a 100644 --- a/types/com.wikitude.phonegap.wikitudeplugin/tslint.json +++ b/types/com.wikitude.phonegap.wikitudeplugin/tslint.json @@ -1,79 +1,3 @@ { - "extends": "dtslint/dt.json", - "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, - "ban-types": false, - "callable-types": false, - "comment-format": false, - "dt-header": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, - "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, - "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, - "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false - } + "extends": "dtslint/dt.json" } From 1873b123c38261fae76265213eb51eb377e717a6 Mon Sep 17 00:00:00 2001 From: Zak Barbuto Date: Thu, 14 Jun 2018 09:25:24 +0930 Subject: [PATCH 3/4] Fix lint errors --- .../com.wikitude.phonegap.wikitudeplugin-tests.ts | 10 +++++----- types/com.wikitude.phonegap.wikitudeplugin/index.d.ts | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/types/com.wikitude.phonegap.wikitudeplugin/com.wikitude.phonegap.wikitudeplugin-tests.ts b/types/com.wikitude.phonegap.wikitudeplugin/com.wikitude.phonegap.wikitudeplugin-tests.ts index 00ee01f175..c46d48d563 100644 --- a/types/com.wikitude.phonegap.wikitudeplugin/com.wikitude.phonegap.wikitudeplugin-tests.ts +++ b/types/com.wikitude.phonegap.wikitudeplugin/com.wikitude.phonegap.wikitudeplugin-tests.ts @@ -2,23 +2,23 @@ const startupConfiguration: any = { camera_position: 'back' }; // Some code samples from the wikitude ionic starter WikitudePlugin.loadARchitectWorld( - function(success) { + success => { console.log('ARchitect World loaded successfully.'); }, - function(fail) { + fail => { console.log('Failed to load ARchitect World!'); }, 'www/assets/07_3dModels_6_3dModelAtGeoLocation/index.html', ['geo'], - startupConfiguration + startupConfiguration ); -WikitudePlugin.setOnUrlInvokeCallback(function(url) { +WikitudePlugin.setOnUrlInvokeCallback(url => { if (url.indexOf('captureScreen') > -1) { WikitudePlugin.captureScreen( absoluteFilePath => { WikitudePlugin.callJavaScript( - "World.testFunction('Screenshot saved at: " + absoluteFilePath + "');" + `World.testFunction('Screenshot saved at: ${absoluteFilePath}');` ); }, errorMessage => { diff --git a/types/com.wikitude.phonegap.wikitudeplugin/index.d.ts b/types/com.wikitude.phonegap.wikitudeplugin/index.d.ts index cfa1a82a4c..02c5d99ad9 100644 --- a/types/com.wikitude.phonegap.wikitudeplugin/index.d.ts +++ b/types/com.wikitude.phonegap.wikitudeplugin/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for com.wikitude.phonegap.wikitudeplugin 7.2.0 +// Type definitions for com.wikitude.phonegap.wikitudeplugin 7.2 // Project: https://github.com/Wikitude/wikitude-cordova-plugin // Definitions by: zbarbuto // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -23,7 +23,7 @@ interface WikitudePlugin { errorCallback: (message: string) => void, architectWorldPath: string, requiredFeatures: [string], - startupConfiguration: JSON | Object + startupConfiguration: JSON | object ): void; close(): void; From 0f3c654f30b5e6096f98504131bd1bb8a0401936 Mon Sep 17 00:00:00 2001 From: Zak Barbuto Date: Thu, 14 Jun 2018 09:39:28 +0930 Subject: [PATCH 4/4] Add typescript version 2.2 to header --- types/com.wikitude.phonegap.wikitudeplugin/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/com.wikitude.phonegap.wikitudeplugin/index.d.ts b/types/com.wikitude.phonegap.wikitudeplugin/index.d.ts index 02c5d99ad9..50307d57c8 100644 --- a/types/com.wikitude.phonegap.wikitudeplugin/index.d.ts +++ b/types/com.wikitude.phonegap.wikitudeplugin/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/Wikitude/wikitude-cordova-plugin // Definitions by: zbarbuto // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 // The following types are taken directly (unmodified) from the wikitude-ionic-3-starter-app // https://github.com/pbreuss/wikitude-ionic-3-starter-app