mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-19 14:17:40 +00:00
refactor(web): merge device-detect with web/src/engine/main
This change moves `web/src/engine/device-detect/` → `web/src/engine/main/` and renames the `Device` class to `DeviceDetector`. Fixes: #12388
This commit is contained in:
parent
b20d7f1eb4
commit
f52a1209c8
23 changed files with 35 additions and 118 deletions
|
|
@ -116,8 +116,6 @@ graph TD;
|
|||
|
||||
subgraph ClassicWeb["`**ClassicWeb**
|
||||
Intermediate-level engine modules`"]
|
||||
Device["/web/src/engine/device-detect"];
|
||||
Device----->WebUtils;
|
||||
Elements["/web/src/engine/element-wrappers"];
|
||||
Elements-->JSProc;
|
||||
KeyboardStorage["/web/src/engine/keyboard-storage"];
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ builder_describe "Builds engine modules for Keyman Engine for Web (KMW)." \
|
|||
":app/webview A puppetable version of KMW designed for use in a host app's WebView" \
|
||||
":app/ui Builds KMW's desktop form-factor keyboard-selection UI modules" \
|
||||
":engine/attachment Subset used for detecting valid page contexts for use in text editing " \
|
||||
":engine/device-detect Subset used for device-detection " \
|
||||
":engine/dom-utils A common subset of function used for DOM calculations, layout, etc" \
|
||||
":engine/events Specialized classes utilized to support KMW API events" \
|
||||
":engine/element-wrappers Subset used to integrate with website elements" \
|
||||
|
|
@ -56,7 +55,6 @@ builder_describe_outputs \
|
|||
build:app/webview "/web/build/app/webview/${config}/keymanweb-webview.js" \
|
||||
build:app/ui "/web/build/app/ui/${config}/kmwuitoggle.js" \
|
||||
build:engine/attachment "/web/build/engine/attachment/lib/index.mjs" \
|
||||
build:engine/device-detect "/web/build/engine/device-detect/lib/index.mjs" \
|
||||
build:engine/dom-utils "/web/build/engine/dom-utils/obj/index.js" \
|
||||
build:engine/events "/web/build/engine/events/lib/index.mjs" \
|
||||
build:engine/element-wrappers "/web/build/engine/element-wrappers/lib/index.mjs" \
|
||||
|
|
@ -146,7 +144,6 @@ coverage_action() {
|
|||
cd web
|
||||
}
|
||||
|
||||
builder_run_child_actions build:engine/device-detect
|
||||
builder_run_child_actions build:engine/dom-utils
|
||||
|
||||
builder_run_child_actions build:engine/keyboard
|
||||
|
|
@ -164,7 +161,7 @@ builder_run_child_actions build:engine/attachment
|
|||
# Uses engine/interfaces (due to resource-path config interface)
|
||||
builder_run_child_actions build:engine/keyboard-storage
|
||||
|
||||
# Uses engine/interfaces, engine/device-detect, engine/keyboard-storage, & engine/osk
|
||||
# Uses engine/interfaces, engine/keyboard-storage, & engine/osk
|
||||
builder_run_child_actions build:engine/main
|
||||
|
||||
# Uses all but engine/element-wrappers and engine/attachment
|
||||
|
|
|
|||
|
|
@ -17,11 +17,6 @@
|
|||
"types": "./build/engine/interfaces/obj/index.d.ts",
|
||||
"import": "./build/engine/interfaces/obj/index.js"
|
||||
},
|
||||
"./engine/device-detect": {
|
||||
"es6-bundling": "./src/engine/device-detect/src/index.ts",
|
||||
"types": "./build/engine/device-detect/obj/index.d.ts",
|
||||
"import": "./build/engine/device-detect/obj/index.js"
|
||||
},
|
||||
"./engine/dom-utils": {
|
||||
"es6-bundling": "./src/engine/dom-utils/src/index.ts",
|
||||
"types": "./build/engine/dom-utils/obj/index.d.ts",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import { KeymanEngine as KeymanEngineBase } from 'keyman/engine/main';
|
||||
import { Device as DeviceDetector } from 'keyman/engine/device-detect';
|
||||
import { KeymanEngine as KeymanEngineBase, DeviceDetector } from 'keyman/engine/main';
|
||||
import { getAbsoluteY } from 'keyman/engine/dom-utils';
|
||||
import { OutputTarget } from 'keyman/engine/element-wrappers';
|
||||
import {
|
||||
|
|
|
|||
|
|
@ -1,49 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
## START STANDARD BUILD SCRIPT INCLUDE
|
||||
# adjust relative paths as necessary
|
||||
THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")"
|
||||
. "${THIS_SCRIPT%/*}/../../../../resources/build/builder.inc.sh"
|
||||
## END STANDARD BUILD SCRIPT INCLUDE
|
||||
|
||||
SUBPROJECT_NAME=engine/device-detect
|
||||
. "$KEYMAN_ROOT/web/common.inc.sh"
|
||||
. "$KEYMAN_ROOT/resources/shellHelperFunctions.sh"
|
||||
|
||||
# ################################ Main script ################################
|
||||
|
||||
builder_describe "Builds the device-detection component of Keyman Engine for Web (KMW)." \
|
||||
"@/common/web/keyman-version" \
|
||||
"@/web/src/engine/common/web-utils" \
|
||||
"clean" \
|
||||
"configure" \
|
||||
"build" \
|
||||
"test" \
|
||||
"--ci+ Set to utilize CI-based test configurations & reporting."
|
||||
|
||||
# Possible TODO?
|
||||
# "upload-symbols Uploads build product to Sentry for error report symbolification. Only defined for $DOC_BUILD_EMBED_WEB" \
|
||||
|
||||
builder_describe_outputs \
|
||||
configure /node_modules \
|
||||
build /web/build/$SUBPROJECT_NAME/lib/index.mjs
|
||||
|
||||
builder_parse "$@"
|
||||
|
||||
#### Build action definitions ####
|
||||
|
||||
do_build () {
|
||||
compile $SUBPROJECT_NAME
|
||||
|
||||
$BUNDLE_CMD "${KEYMAN_ROOT}/web/build/${SUBPROJECT_NAME}/obj/index.js" \
|
||||
--out "${KEYMAN_ROOT}/web/build/${SUBPROJECT_NAME}/lib/index.mjs" \
|
||||
--format esm
|
||||
}
|
||||
|
||||
builder_run_action configure verify_npm_setup
|
||||
builder_run_action clean rm -rf "$KEYMAN_ROOT/web/build/$SUBPROJECT_NAME"
|
||||
builder_run_action build do_build
|
||||
builder_run_action test
|
||||
|
||||
# No headless tests for this child project. Currently, DOM-based unit &
|
||||
# integrated tests are run solely by the top-level $KEYMAN_ROOT/web project.
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
## engine/device-detect
|
||||
|
||||
This submodule provides the subset of the main engine's Web-oriented code that's used to detect
|
||||
the user's device in isolation from the rest of KMW code. Fortunately, it doesn't have any
|
||||
cross-references with other top-level KMW code, so it was possible to modularize in the form
|
||||
seen here.
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
{
|
||||
"extends": "../../tsconfig.dom.json",
|
||||
|
||||
"compilerOptions": {
|
||||
"baseUrl": "./",
|
||||
"outDir": "../../../build/engine/device-detect/obj/",
|
||||
"tsBuildInfoFile": "../../../build/engine/device-detect/obj/tsconfig.tsbuildinfo",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
|
||||
"include": [ "**/*.ts" ],
|
||||
|
||||
"references": [
|
||||
{ "path": "../../../../common/web/keyman-version" },
|
||||
{ "path": "../common/web-utils" }
|
||||
]
|
||||
}
|
||||
|
|
@ -16,7 +16,6 @@ builder_describe "Builds the Keyman Engine for Web's common top-level base class
|
|||
"@/common/web/keyman-version" \
|
||||
"@/web/src/engine/keyboard" \
|
||||
"@/web/src/engine/interfaces build" \
|
||||
"@/web/src/engine/device-detect build" \
|
||||
"@/web/src/engine/js-processor build" \
|
||||
"@/web/src/engine/keyboard-storage build" \
|
||||
"@/web/src/engine/osk build" \
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { EventEmitter } from "eventemitter3";
|
|||
import { DeviceSpec, KeyboardProperties, ManagedPromise, physicalKeyDeviceAlias, SpacebarText } from "keyman/engine/keyboard";
|
||||
import { OutputTarget, RuleBehavior } from 'keyman/engine/js-processor';
|
||||
import { PathConfiguration, PathOptionDefaults, PathOptionSpec } from "keyman/engine/interfaces";
|
||||
import { Device } from "keyman/engine/device-detect";
|
||||
import { DeviceDetector } from "./headless/deviceDetector.js";
|
||||
import { KeyboardStub } from "keyman/engine/keyboard-storage";
|
||||
|
||||
interface EventMap {
|
||||
|
|
@ -31,7 +31,7 @@ export class EngineConfiguration extends EventEmitter<EventMap> {
|
|||
super();
|
||||
|
||||
if(!device) {
|
||||
const deviceDetector = new Device();
|
||||
const deviceDetector = new DeviceDetector();
|
||||
deviceDetector.detect();
|
||||
|
||||
device = deviceDetector.coreSpec;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
/*
|
||||
* Keyman is copyright (C) SIL International. MIT License.
|
||||
*
|
||||
* Detect the user's device.
|
||||
*/
|
||||
import StyleConstants from './utils/styleConstants.js';
|
||||
import { DeviceSpec, Version } from "@keymanapp/web-utils";
|
||||
|
||||
// The Device object definition -------------------------------------------------
|
||||
|
||||
export class Device {
|
||||
export class DeviceDetector {
|
||||
// These correspond directly to the properties & parameters for `DeviceSpec`.
|
||||
touchable: boolean;
|
||||
OS: string;
|
||||
|
|
@ -203,5 +206,3 @@ export class Device {
|
|||
return new DeviceSpec(this.browser, this.formFactor, this.OS, this.touchable);
|
||||
}
|
||||
}
|
||||
|
||||
export default Device;
|
||||
|
|
@ -7,4 +7,5 @@ export { LegacyAPIEvents } from './legacyAPIEvents.js';
|
|||
export { VariableStoreCookieSerializer } from './variableStoreCookieSerializer.js';
|
||||
export { LanguageProcessor } from './headless/languageProcessor.js';
|
||||
export { TranscriptionCache } from './headless/transcriptionCache.js';
|
||||
export { InputProcessor } from './headless/inputProcessor.js';
|
||||
export { InputProcessor } from './headless/inputProcessor.js';
|
||||
export { DeviceDetector } from './headless/deviceDetector.js';
|
||||
|
|
@ -11,7 +11,6 @@
|
|||
"include": [ "src/**/*.ts" ],
|
||||
|
||||
"references": [
|
||||
{ "path": "../device-detect" },
|
||||
{ "path": "../osk" },
|
||||
{ "path": "../keyboard-storage" },
|
||||
{ "path": "../interfaces" },
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import * as KeymanOSK from 'keyman/engine/osk';
|
||||
import Device from 'keyman/engine/device-detect';
|
||||
import { DeviceDetector } from 'keyman/engine/main';
|
||||
|
||||
import { loadKeyboardsFromStubs } from '../../kbdLoader.js';
|
||||
import { timedPromise } from '@keymanapp/web-utils';
|
||||
|
|
@ -7,7 +7,7 @@ import { timedPromise } from '@keymanapp/web-utils';
|
|||
import { assert } from 'chai';
|
||||
import { DEFAULT_BROWSER_TIMEOUT } from '@keymanapp/common-test-resources/test-timeouts.mjs';
|
||||
|
||||
const device = new Device();
|
||||
const device = new DeviceDetector();
|
||||
device.detect();
|
||||
|
||||
const TestResources = {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import * as KeymanOSK from 'keyman/engine/osk';
|
||||
import Device from 'keyman/engine/device-detect';
|
||||
import { DeviceDetector } from 'keyman/engine/main';
|
||||
|
||||
import { loadKeyboardsFromStubs } from '../../kbdLoader.js';
|
||||
import { timedPromise } from '@keymanapp/web-utils';
|
||||
|
|
@ -9,7 +9,7 @@ import sinon from 'sinon';
|
|||
import { assert } from 'chai';
|
||||
import { DEFAULT_BROWSER_TIMEOUT } from '@keymanapp/common-test-resources/test-timeouts.mjs';
|
||||
|
||||
const device = new Device();
|
||||
const device = new DeviceDetector();
|
||||
device.detect();
|
||||
|
||||
const TestResources = {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// We'll let things break after this reports, since this will likely signal a LOT of other failures.
|
||||
import { assert } from 'chai';
|
||||
|
||||
import Device from 'keyman/engine/device-detect';
|
||||
import { DeviceDetector } from 'keyman/engine/main';
|
||||
|
||||
/* Note - we still have to prevent errors setting up test resources;
|
||||
* Karma will fail to report errors for affected browsers otherwise.
|
||||
|
|
@ -17,7 +17,7 @@ describe('Test Initialization', function() {
|
|||
|
||||
it("Detects device without JS errors", function() {
|
||||
try {
|
||||
const device = new Device();
|
||||
const device = new DeviceDetector();
|
||||
device.detect();
|
||||
|
||||
console.log("Detected platform: " + device.browser + " on " + device.OS + " with form factor " + device.formFactor);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { assert } from 'chai';
|
||||
|
||||
import { DEVICE_DETECT_FAILURE, setupKMW, teardownKMW } from "../test_utils.js";
|
||||
import { Device } from "keyman/engine/device-detect";
|
||||
import { DeviceDetector } from "keyman/engine/main";
|
||||
import { KeymanEngine } from "keyman/app/browser";
|
||||
|
||||
const baseTimeout = 5000;
|
||||
|
|
@ -49,7 +49,7 @@ describe('Basic KeymanWeb', function() {
|
|||
});
|
||||
});
|
||||
|
||||
const device = new Device();
|
||||
const device = new DeviceDetector();
|
||||
device.detect();
|
||||
if(!device.touchable) {
|
||||
describe('Basic Toggle UI', function() {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// We'll let things break after this reports, since this will likely signal a LOT of other failures.
|
||||
import { assert } from 'chai';
|
||||
|
||||
import Device from 'keyman/engine/device-detect';
|
||||
import { DeviceDetector } from 'keyman/engine/main';
|
||||
|
||||
/* Note - we still have to prevent errors setting up test resources;
|
||||
* Karma will fail to report errors for affected browsers otherwise.
|
||||
|
|
@ -16,9 +16,9 @@ describe('Test Initialization', function() {
|
|||
this.timeout(15000);
|
||||
|
||||
it("Detects device without JS errors", function() {
|
||||
let device: Device;
|
||||
let device: DeviceDetector;
|
||||
try {
|
||||
device = new Device();
|
||||
device = new DeviceDetector();
|
||||
device.detect();
|
||||
|
||||
console.log("Detected platform: " + device.browser + " on " + device.OS + " with form factor " + device.formFactor);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// // KeymanWeb test suite - processing of the Karma configuration's client.args parameter.
|
||||
// KeymanWeb test suite - processing of the Karma configuration's client.args parameter.
|
||||
|
||||
import Device from 'keyman/engine/device-detect';
|
||||
import { DeviceDetector } from 'keyman/engine/main';
|
||||
import * as KMWRecorder from '#recorder';
|
||||
import { type BrowserInitOptionSpec, type KeymanEngine } from 'keyman/app/browser';
|
||||
import { ErrorStub, type KeyboardAPISpec, type KeyboardStub } from 'keyman/engine/keyboard-storage';
|
||||
|
|
@ -17,7 +17,7 @@ const domain = `${loc.protocol}/${loc.host}`
|
|||
|
||||
// If we've set things up to support Device dection without loading KMW...
|
||||
try {
|
||||
const device = new Device();
|
||||
const device = new DeviceDetector();
|
||||
device.detect();
|
||||
} catch (err) {
|
||||
// Sets a warning flag that unit-test files can use to disable themselves.
|
||||
|
|
@ -233,7 +233,7 @@ export async function runKeyboardTestFromJSON(jsonPath: any, params: any, assert
|
|||
const testJSON = await jsonResponse.json();
|
||||
|
||||
const testSpec = new KMWRecorder.KeyboardTest(testJSON);
|
||||
const device = new Device();
|
||||
const device = new DeviceDetector();
|
||||
device.detect();
|
||||
|
||||
// @ts-ignore // Types are a bit messy here.
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import * as KeymanOSK from '../../../../../../build/engine/osk/lib/index.mjs';
|
||||
import Device from '../../../../../../build/engine/device-detect/lib/index.mjs';
|
||||
import { DeviceDetector } from '../../../../../../build/engine/main/lib/index.mjs';
|
||||
import { loadKeyboardFromPath, loadKeyboardsFromStubs } from '../kbdLoader.mjs';
|
||||
|
||||
// NOTE: we must actually set these in this manner to have accessibility outside of
|
||||
// this script tag!
|
||||
window.modules = {
|
||||
osk: KeymanOSK,
|
||||
device: Device
|
||||
device: DeviceDetector
|
||||
};
|
||||
|
||||
let prefix = '../../';
|
||||
|
|
@ -22,7 +22,7 @@ window.keyboards = loadKeyboardsFromStubs(stubs).then((keyboards) => {
|
|||
window.keyboards = keyboards;
|
||||
});
|
||||
|
||||
let device = new Device();
|
||||
let device = new DeviceDetector();
|
||||
device.detect();
|
||||
|
||||
if(device.formFactor == 'phone') {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// Includes KeymanWeb's Device class, as it's quite a useful resource for KMW-related projects.
|
||||
import { Device } from 'keyman/engine/device-detect';
|
||||
import { DeviceDetector } from 'keyman/engine/main';
|
||||
import { type DeviceSpec } from '@keymanapp/web-utils';
|
||||
|
||||
import type { KeymanEngine } from 'keyman/app/browser';
|
||||
|
|
@ -243,7 +243,7 @@ export class BatchRenderer {
|
|||
|
||||
fillDeviceNotes() {
|
||||
let description = document.createElement('p');
|
||||
let device = new Device();
|
||||
let device = new DeviceDetector();
|
||||
device.detect();
|
||||
|
||||
description.appendChild(document.createTextNode('Browser: ' + device.browser));
|
||||
|
|
|
|||
|
|
@ -14,6 +14,6 @@
|
|||
|
||||
"references": [
|
||||
{ "path": "../../../app/browser" },
|
||||
{ "path": "../../../engine/device-detect" }
|
||||
{ "path": "../../../engine/main" }
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import * as KMWRecorder from '../../../../build/tools/testing/recorder/lib/index.mjs';
|
||||
import { Device } from '../../../../build/engine/device-detect/lib/index.mjs';
|
||||
import { DeviceDetector } from '../../../../build/engine/main/lib/index.mjs';
|
||||
|
||||
import { getResourcePathPrefix } from './recorder_KeyboardScripts.js';
|
||||
|
||||
|
|
@ -124,7 +124,7 @@ window.errorUpdate = () => {
|
|||
|
||||
window.initDevice = () => {
|
||||
// From KMW.
|
||||
var device = new Device();
|
||||
var device = new DeviceDetector();
|
||||
device.detect();
|
||||
|
||||
document.getElementById("activeFormFactor").textContent = device.formFactor;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue