From 9d1cb7c76175a85954650a7541c21dbb3d0c5415 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Fri, 2 Aug 2024 13:27:46 +0200 Subject: [PATCH 01/10] Added DeviceRendererFactory typing --- README.md | 2 +- index.d.ts | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 3 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 index.d.ts diff --git a/README.md b/README.md index 79b23ae8..7f08df9d 100644 --- a/README.md +++ b/README.md @@ -544,7 +544,7 @@ Enables or disables the identifiers widget. This widget can be used to set the i Enables or disables the phone widget. This widget can be used to send SMS or phone call the Android virtual device. -### `Baseband` +### `baseband` ... diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 00000000..6d0c07af --- /dev/null +++ b/index.d.ts @@ -0,0 +1,136 @@ +type KeyEffectDistance = { + distanceX: number; + distanceY: number; +}; + +interface KeyEffect { + initialX: number; + initialY: number; + name?: string; + description?: string; +} + +interface KeyMap { + keys: Record; + name?: string; + description?: string; +} + +interface KeyMappingConfig { + dpad?: KeyMap[]; + tap?: KeyMap[]; + swipe?: KeyMap[]; +} + +type DeviceRendererKeyMapping = { + enable(isEnable: boolean): void; + setConfig(config: KeyMappingConfig): void; + activeKeyMappingDebug(isTraceActivate?: boolean, isGridActivate?: boolean): void; +}; + +type VmEvent = 'beforeunload' | 'fingerprint' | 'gps' | 'BATTERY_LEVEL' | string // TODO Provide an exhaustive list + +type VmCommunication = { + disconnect(): void; + addEventListener(event: VmEvent, callback: (msg: string) => void): void; // TODO Verify if msg is always string + sendData(data: { channel: string; messages: string[] }): void; // TODO Verify typing +}; + +type RegisteredFunctionDoc = { + apiName: string, + apiDescription: string, +} + +type Utils = { + getRegisteredFunctions(): RegisteredFunctionDoc[]; +}; + +type Media = { + mute(): void; + unmute(): void; +}; + +type Video = { + fullscreen: () => void; +}; + +type Template = 'bootstrap' + | 'fullscreen' + | 'fullwindow' + | 'renderer' + | 'renderer_minimal' + | 'renderer_no_toolbar' + | 'renderer_partial'; + +interface Options { + baseband?: boolean; // Default: false + battery?: boolean; // Default: true + biometrics?: boolean; // Default: true + camera?: boolean; // Default: true + capture?: boolean; // Default: true + clipboard?: boolean; // Default: true + connectionFailedURL?: string; + diskIO?: boolean; // Default: true + fileUpload?: boolean; // Default: true + fileUploadUrl?: string; + fullscreen?: boolean; // Default: true + gamepad?: boolean; // Default: true + giveFeedbackLink?: string; + gps?: boolean; // Default: true + gpsSpeedSupport?: boolean; // Default: false + i18n?: Record; + identifiers?: boolean; // Default: true + keyboard?: boolean; // Default: true + keyboardMapping?: boolean; // Default: true + microphone?: boolean; // Default: false + mobilethrottling?: boolean; // Default: false + mouse?: boolean; // Default: true + navbar?: boolean; // Default: true + network?: boolean; // Default: true + phone?: boolean; // Default: true + power?: boolean; // Default: true + rotation?: boolean; // Default: true + streamBitrate?: boolean; // Default: false + streamResolution?: boolean; // Default: true + stun?: { urls?: string[] }; + template?: Template; // Default: 'renderer' + token?: string; + touch?: boolean; // Default: true + translateHomeKey?: boolean; // Default: false + turn?: { + urls?: string[]; + username?: string; + credential?: string; + default?: boolean; // Default: false + }; + volume?: boolean; // Default: true +} + +type DefaultTrue = B extends void +? T // Key is not presnet +: B extends true | undefined + ? T // Key is true or undefined + : B extends false + ? undefined // Key is false + : T | undefined; // Key is true, false or undefined (we cannot infer anything) + +type ExtractKey = O extends { [P in K]: infer T } ? T : void; + +type DeviceRendererApi = { +keyMapping: DefaultTrue, DeviceRendererKeyMapping>; +media: Media; +utils: Utils; +video?: Video; // Available if any plugin (e.g. fullscreen) using it is enabled. +VM_communication: VmCommunication; +}; + +declare class DeviceRendererFactory { +constructor(); +setupRenderer( + targetElement: HTMLDivElement, + webrtcAddress: string, + options?: O, +): DeviceRendererApi; +} + +export { DeviceRendererApi, DeviceRendererFactory, KeyMappingConfig } diff --git a/package.json b/package.json index 661c3298..6f036e69 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "files": [ "dist" ], + "types": "dist/index.d.ts", "engines": { "node": ">=16" }, From 0055d514df18c89d49739c8be6e2db514f12ca85 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Fri, 2 Aug 2024 13:35:20 +0200 Subject: [PATCH 02/10] typo --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 6d0c07af..92044009 100644 --- a/index.d.ts +++ b/index.d.ts @@ -107,7 +107,7 @@ interface Options { } type DefaultTrue = B extends void -? T // Key is not presnet +? T // Key is not present : B extends true | undefined ? T // Key is true or undefined : B extends false From 7e8be17f934c2679de0e20b6d07eac3cc0518496 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Fri, 2 Aug 2024 13:36:17 +0200 Subject: [PATCH 03/10] uncessary undefined --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 92044009..4d4d5325 100644 --- a/index.d.ts +++ b/index.d.ts @@ -116,7 +116,7 @@ type DefaultTrue = B extends void type ExtractKey = O extends { [P in K]: infer T } ? T : void; -type DeviceRendererApi = { +type DeviceRendererApi = { keyMapping: DefaultTrue, DeviceRendererKeyMapping>; media: Media; utils: Utils; From ae5830305dde88cac675ffe1ecb8ef5363b9aa6f Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Fri, 2 Aug 2024 13:54:28 +0200 Subject: [PATCH 04/10] export RendererSetupOptions --- index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 4d4d5325..8acc5058 100644 --- a/index.d.ts +++ b/index.d.ts @@ -62,7 +62,7 @@ type Template = 'bootstrap' | 'renderer_no_toolbar' | 'renderer_partial'; -interface Options { +export interface RendererSetupOptions { baseband?: boolean; // Default: false battery?: boolean; // Default: true biometrics?: boolean; // Default: true @@ -116,7 +116,7 @@ type DefaultTrue = B extends void type ExtractKey = O extends { [P in K]: infer T } ? T : void; -type DeviceRendererApi = { +type DeviceRendererApi = { keyMapping: DefaultTrue, DeviceRendererKeyMapping>; media: Media; utils: Utils; @@ -126,7 +126,7 @@ VM_communication: VmCommunication; declare class DeviceRendererFactory { constructor(); -setupRenderer( +setupRenderer( targetElement: HTMLDivElement, webrtcAddress: string, options?: O, From fcc558a6d7eaeb27e1c8bf0b9816011234fe4080 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Fri, 2 Aug 2024 13:54:44 +0200 Subject: [PATCH 05/10] RendererSetupOptions --- index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 8acc5058..09efc76a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -62,7 +62,7 @@ type Template = 'bootstrap' | 'renderer_no_toolbar' | 'renderer_partial'; -export interface RendererSetupOptions { +interface RendererSetupOptions { baseband?: boolean; // Default: false battery?: boolean; // Default: true biometrics?: boolean; // Default: true @@ -133,4 +133,4 @@ setupRenderer( ): DeviceRendererApi; } -export { DeviceRendererApi, DeviceRendererFactory, KeyMappingConfig } +export { DeviceRendererApi, DeviceRendererFactory, RendererSetupOptions, KeyMappingConfig } From a8f439037ed6d81db5bcbcba07a5e9daf692ee11 Mon Sep 17 00:00:00 2001 From: jparez Date: Fri, 2 Aug 2024 16:30:55 +0200 Subject: [PATCH 06/10] update gulpfile to ship declarations TS file *.d.ts --- gulpfile.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 9e08812b..763db1fb 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -72,12 +72,12 @@ function getTemplatesStream() { } // Clean dist dir -gulp.task('clean', function(cb) { +gulp.task('clean', function (cb) { del([PATHS.DEST.BASE + ' --force']).then( - function() { + function () { cb(); }, - function(err) { + function (err) { cb(err); }, ); @@ -105,6 +105,11 @@ gulp.task('app-styles', function () { .pipe(gulp.dest(PATHS.DEST.ASSETS.CSS)); }); +// TS declaration files +gulp.task('app-dts', function () { + return gulp.src(PATHS.SRC.BASE + './../*.d.ts').pipe(gulp.dest(PATHS.DEST.BASE)); +}); + gulp.task('app-templates', function () { return getTemplatesStream().pipe( tap(function (file) { @@ -119,6 +124,14 @@ gulp.task('app-templates', function () { ); }); +function setupBrowserify() { + return browserify({ + entries: [PATHS.SRC.BASE + '/' + PATHS.SRC.APP], + standalone: 'genyDeviceWebPlayer', + debug: true, + }).transform(graspify, ['#GEN_TEMPLATES', templates]); +} + function getBundler() { return new Promise((resolve) => { if (!templates) { @@ -131,14 +144,6 @@ function getBundler() { }); } -function setupBrowserify() { - return browserify({ - entries: [PATHS.SRC.BASE + '/' + PATHS.SRC.APP], - standalone: 'genyDeviceWebPlayer', - debug: true, - }).transform(graspify, ['#GEN_TEMPLATES', templates]); -} - gulp.task('app-js', async function () { const bundler = await getBundler(); return merge2(bundler.bundle().pipe(source(PATHS.SRC.APP)), {end: true}) @@ -196,7 +201,7 @@ gulp.task( gulp.series( 'clean', 'app-templates', - gulp.parallel('app-partials', 'app-styles', 'app-js'), + gulp.parallel('app-partials', 'app-styles', 'app-js', 'app-dts'), 'inject', function (cb) { cb(); From 7313c6e09b9eb672464c73219b04bfd119d44186 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Fri, 2 Aug 2024 16:42:32 +0200 Subject: [PATCH 07/10] added typescript as dev dep --- package.json | 1 + yarn.lock | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/package.json b/package.json index 6f036e69..83e96770 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,7 @@ "prettier": "^3.3.2", "sass": "^1.53.0", "through2": "^4.0.2", + "typescript": "^5.5.4", "vinyl": "^2.2.1", "vinyl-source-stream": "^2.0.0" }, diff --git a/yarn.lock b/yarn.lock index a674a9a2..088ca194 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8794,6 +8794,11 @@ typescript@^4.6.2: resolved "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz" integrity sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ== +typescript@^5.5.4: + version "5.5.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.4.tgz#d9852d6c82bad2d2eda4fd74a5762a8f5909e9ba" + integrity sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q== + ua-parser-js@1.0.2: version "1.0.2" resolved "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-1.0.2.tgz" From 81c2be95a6dbdf2d9e87b7f21a0196b15678b17d Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Fri, 2 Aug 2024 16:48:17 +0200 Subject: [PATCH 08/10] added events, removed todos --- index.d.ts | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 09efc76a..27390f55 100644 --- a/index.d.ts +++ b/index.d.ts @@ -28,12 +28,36 @@ type DeviceRendererKeyMapping = { activeKeyMappingDebug(isTraceActivate?: boolean, isGridActivate?: boolean): void; }; -type VmEvent = 'beforeunload' | 'fingerprint' | 'gps' | 'BATTERY_LEVEL' | string // TODO Provide an exhaustive list +type VmEvent = + | 'ANDROID_ID' + | 'baseband' + | 'BATTERY_LEVEL' + | 'BATTERY_LEVEL' + | 'BATTERY_STATUS' + | 'battery' + | 'beforeunload' + | 'BLK' + | 'CLIPBOARD' + | 'diskio' + | 'fingerprint' + | 'fingerprint' + | 'framework' + | 'gps' + | 'gps' + | 'IMEI' + | 'network_profile' + | 'NETWORK' + | 'settings' + | 'SYSTEM_PATCHER_LAST_RESULT' + | 'SYSTEM_PATCHER_STATUS' + | 'systempatcher' + | 'vinput' + | string // This list is not exhaustive and should be completed type VmCommunication = { disconnect(): void; - addEventListener(event: VmEvent, callback: (msg: string) => void): void; // TODO Verify if msg is always string - sendData(data: { channel: string; messages: string[] }): void; // TODO Verify typing + addEventListener(event: VmEvent, callback: (msg: string) => void): void; + sendData(data: { channel: string; messages: string[] }): void; }; type RegisteredFunctionDoc = { From d8b3e655a2004f64058e450819ed85fe6add9caf Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Fri, 2 Aug 2024 16:53:36 +0200 Subject: [PATCH 09/10] removed duplicates --- index.d.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 27390f55..cf8d16ff 100644 --- a/index.d.ts +++ b/index.d.ts @@ -32,7 +32,6 @@ type VmEvent = | 'ANDROID_ID' | 'baseband' | 'BATTERY_LEVEL' - | 'BATTERY_LEVEL' | 'BATTERY_STATUS' | 'battery' | 'beforeunload' @@ -40,10 +39,8 @@ type VmEvent = | 'CLIPBOARD' | 'diskio' | 'fingerprint' - | 'fingerprint' | 'framework' | 'gps' - | 'gps' | 'IMEI' | 'network_profile' | 'NETWORK' From 46c0fe4b1fc827a0c5c3442635f41acd97c03f36 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Fri, 2 Aug 2024 16:55:45 +0200 Subject: [PATCH 10/10] indent --- index.d.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/index.d.ts b/index.d.ts index cf8d16ff..498ef9b1 100644 --- a/index.d.ts +++ b/index.d.ts @@ -138,20 +138,20 @@ type DefaultTrue = B extends void type ExtractKey = O extends { [P in K]: infer T } ? T : void; type DeviceRendererApi = { -keyMapping: DefaultTrue, DeviceRendererKeyMapping>; -media: Media; -utils: Utils; -video?: Video; // Available if any plugin (e.g. fullscreen) using it is enabled. -VM_communication: VmCommunication; + keyMapping: DefaultTrue, DeviceRendererKeyMapping>; + media: Media; + utils: Utils; + video?: Video; // Available if any plugin (e.g. fullscreen) using it is enabled. + VM_communication: VmCommunication; }; declare class DeviceRendererFactory { -constructor(); -setupRenderer( - targetElement: HTMLDivElement, - webrtcAddress: string, - options?: O, -): DeviceRendererApi; + constructor(); + setupRenderer( + targetElement: HTMLDivElement, + webrtcAddress: string, + options?: O, + ): DeviceRendererApi; } export { DeviceRendererApi, DeviceRendererFactory, RendererSetupOptions, KeyMappingConfig }