From 40a466e969aa763236f7d4eaeb647254ba3344a5 Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Tue, 25 Mar 2025 10:24:46 -0400 Subject: [PATCH 01/61] (fix:android) furthet investigation of applyKeyboardHeight() Since Keyboard Height is actually set on Action-Up and only frame height is set onBackPressed() in existing code, this should have no effect in KMAPro but "complete" the API in KMEA, --- .../kmapro/AdjustKeyboardHeightActivity.java | 13 +------------ .../src/main/java/com/keyman/engine/KMManager.java | 9 +++++++++ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java b/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java index de4530fe3a..66a777f6f9 100644 --- a/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java +++ b/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java @@ -107,11 +107,7 @@ public class AdjustKeyboardHeightActivity extends BaseActivity { break; case MotionEvent.ACTION_UP: // Save the currentHeight when the user releases - int orientation = KMManager.getOrientation(context); - String keyboardHeightKey = (orientation == Configuration.ORIENTATION_LANDSCAPE) ? - KMManager.KMKey_KeyboardHeightLandscape : KMManager.KMKey_KeyboardHeightPortrait; - editor.putInt(keyboardHeightKey, currentHeight); - editor.commit(); + KMManager.applyKeyboardHeight(this, currentHeight); break; } return true; @@ -139,12 +135,5 @@ public class AdjustKeyboardHeightActivity extends BaseActivity { refreshSampleKeyboard(this); } - @Override - public void onBackPressed() { - // Apply the adjusted height on exit - KMManager.applyKeyboardHeight(this, currentHeight); - - super.onBackPressed(); - } } \ No newline at end of file diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 39fba8db8b..f8fab40149 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2232,6 +2232,15 @@ public final class KMManager { } public static void applyKeyboardHeight(Context context, int height) { + SharedPreferences prefs = context.getSharedPreferences("KMAPreferences", Context.MODE_PRIVATE); + SharedPreferences.Editor editor = prefs.edit(); + int orientation = getOrientation(context); + if (orientation == Configuration.ORIENTATION_LANDSCAPE) { + editor.putInt(KMManager.KMKey_KeyboardHeightLandscape, height); + editor.commit(); + } else if (orientation == Configuration.ORIENTATION_PORTRAIT) { + editor.putInt(KMManager.KMKey_KeyboardHeightPortrait, height); + editor.commit(); if (isKeyboardLoaded(KeyboardType.KEYBOARD_TYPE_INAPP)) { InAppKeyboard.loadJavascript(KMString.format("setOskHeight('%s')", height)); RelativeLayout.LayoutParams params = getKeyboardLayoutParams(); From c09df23fbce499080ee7f1c315252aa644ef5034 Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Tue, 25 Mar 2025 10:51:24 -0400 Subject: [PATCH 02/61] update docs for applyKeyboardHeight() --- android/docs/engine/KMManager/applyKeyboardHeight.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/docs/engine/KMManager/applyKeyboardHeight.md b/android/docs/engine/KMManager/applyKeyboardHeight.md index 2830519c62..b3520fc094 100644 --- a/android/docs/engine/KMManager/applyKeyboardHeight.md +++ b/android/docs/engine/KMManager/applyKeyboardHeight.md @@ -3,7 +3,7 @@ title: KMManager.applyKeyboardHeight() --- ## Summary -The **applyKeyboardHeight()** method sets the height of the keyboard frame for +The **applyKeyboardHeight()** method sets the height of the keyboard and frame for the device's current [screen orientation](https://developer.android.com/training/multiscreen/screensizes#TaskUseOriQuali) (portrait vs landscape). From d84901fdc1f5f0f48335bed6cfb73003b8b3f08b Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Tue, 25 Mar 2025 20:27:19 -0400 Subject: [PATCH 03/61] Update android/docs/engine/KMManager/applyKeyboardHeight.md Co-authored-by: Marc Durdin --- android/docs/engine/KMManager/applyKeyboardHeight.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/docs/engine/KMManager/applyKeyboardHeight.md b/android/docs/engine/KMManager/applyKeyboardHeight.md index b3520fc094..2830519c62 100644 --- a/android/docs/engine/KMManager/applyKeyboardHeight.md +++ b/android/docs/engine/KMManager/applyKeyboardHeight.md @@ -3,7 +3,7 @@ title: KMManager.applyKeyboardHeight() --- ## Summary -The **applyKeyboardHeight()** method sets the height of the keyboard and frame for +The **applyKeyboardHeight()** method sets the height of the keyboard frame for the device's current [screen orientation](https://developer.android.com/training/multiscreen/screensizes#TaskUseOriQuali) (portrait vs landscape). From a0da0e18f51e921b9b5b0d1c7ef7737a0bdee0c4 Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Tue, 25 Mar 2025 22:00:31 -0400 Subject: [PATCH 04/61] Fixing Bracket, Adding applyKeyboardHeight(context, 0) --- .../kmapro/AdjustKeyboardHeightActivity.java | 8 +--- .../java/com/keyman/engine/KMManager.java | 40 +++++++++++++------ 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java b/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java index 66a777f6f9..c72dc06626 100644 --- a/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java +++ b/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java @@ -34,7 +34,6 @@ public class AdjustKeyboardHeightActivity extends BaseActivity { private static ImageView sampleKeyboard = null; // Keeps track of the adjusted keyboard height for saving - private static SharedPreferences.Editor editor = null; private static int currentHeight = 0; private static ViewGroup.LayoutParams layoutParams; @@ -65,9 +64,6 @@ public class AdjustKeyboardHeightActivity extends BaseActivity { adjustKeyboardHeightActivityTitle.setTextColor(ContextCompat.getColor(this, R.color.ms_white)); adjustKeyboardHeightActivityTitle.setText(titleStr); - SharedPreferences prefs = context.getSharedPreferences(context.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE); - editor = prefs.edit(); - sampleKeyboard = (ImageView) findViewById(R.id.sample_keyboard); layoutParams = sampleKeyboard.getLayoutParams(); currentHeight = KMManager.getKeyboardHeight(context); @@ -77,9 +73,7 @@ public class AdjustKeyboardHeightActivity extends BaseActivity { resetButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Clear the keyboard height preferences to reset - editor.remove(KMManager.KMKey_KeyboardHeightPortrait); - editor.remove(KMManager.KMKey_KeyboardHeightLandscape); - editor.commit(); + KMManager.applyKeyboardHeight(this, 0); // Restore default height currentHeight = KMManager.getKeyboardHeight(context); diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index f8fab40149..0ed54f99d9 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -292,8 +292,8 @@ public final class KMManager { public static final String KMKey_KMPInstall_Mode = "kmpInstallMode"; public static final String KMKey_KeyboardModified = "lastModified"; public static final String KMKey_KeyboardRTL = "rtl"; - public static final String KMKey_KeyboardHeightPortrait = "keyboardHeightPortrait"; - public static final String KMKey_KeyboardHeightLandscape = "keyboardHeightLandscape"; + private static final String KMKey_KeyboardHeightPortrait = "keyboardHeightPortrait"; + private static final String KMKey_KeyboardHeightLandscape = "keyboardHeightLandscape"; public static final String KMKey_LongpressDelay = "longpressDelay"; @@ -2218,16 +2218,19 @@ public final class KMManager { } public static int getKeyboardHeight(Context context) { + int orientation = getOrientation(context); // Default behavior + return getKeyboardHeight(context, orientation); // Delegate to the overloaded method + } + + // Overloaded method with an additional orientation parameter + public static int getKeyboardHeight(Context context, int orientation) { int defaultHeight = (int) context.getResources().getDimension(R.dimen.keyboard_height); SharedPreferences prefs = context.getSharedPreferences(context.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE); - - int orientation = getOrientation(context); if (orientation == Configuration.ORIENTATION_PORTRAIT) { - return prefs.getInt(KMManager.KMKey_KeyboardHeightPortrait, defaultHeight); + return prefs.getInt(KMManager.KMKey_KeyboardHeightPortrait, defaultHeight); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { - return prefs.getInt(KMManager.KMKey_KeyboardHeightLandscape, defaultHeight); + return prefs.getInt(KMManager.KMKey_KeyboardHeightLandscape, defaultHeight); } - return defaultHeight; } @@ -2235,12 +2238,25 @@ public final class KMManager { SharedPreferences prefs = context.getSharedPreferences("KMAPreferences", Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); int orientation = getOrientation(context); - if (orientation == Configuration.ORIENTATION_LANDSCAPE) { - editor.putInt(KMManager.KMKey_KeyboardHeightLandscape, height); - editor.commit(); - } else if (orientation == Configuration.ORIENTATION_PORTRAIT) { - editor.putInt(KMManager.KMKey_KeyboardHeightPortrait, height); + if (height == 0) { + // Passing 0 will reset both stored heights + editor.putInt(KMManager.KMKey_KeyboardHeightLandscape, getKeyboardHeight(context, Configuration.ORIENTATION_LANDSCAPE)); + editor.putInt(KMManager.KMKey_KeyboardHeightPortrait, getKeyboardHeight(context, Configuration.ORIENTATION_PORTRAIT)); editor.commit(); + + int height = (orientation == Configuration.ORIENTATION_PORTRAIT) ? getKeyboardHeight(context, Configuration.ORIENTATION_PORTRAIT) : getKeyboardHeight(context, Configuration.ORIENTATION_LANDSCAPE); + } + else: { + // Store the new height based on the current orientation + if (orientation == Configuration.ORIENTATION_LANDSCAPE) { + editor.putInt(KMManager.KMKey_KeyboardHeightLandscape, height); + editor.commit(); + } else if (orientation == Configuration.ORIENTATION_PORTRAIT) { + editor.putInt(KMManager.KMKey_KeyboardHeightPortrait, height); + editor.commit(); + } + } + // Confirm new LayoutParams for in-app or system keyboards if (isKeyboardLoaded(KeyboardType.KEYBOARD_TYPE_INAPP)) { InAppKeyboard.loadJavascript(KMString.format("setOskHeight('%s')", height)); RelativeLayout.LayoutParams params = getKeyboardLayoutParams(); From b548f6356620f53334c50ecee1b9d02ba826c678 Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Tue, 25 Mar 2025 22:26:13 -0400 Subject: [PATCH 05/61] Update android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java Co-authored-by: Darcy Wong --- .../com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java b/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java index c72dc06626..6240f3888f 100644 --- a/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java +++ b/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java @@ -73,7 +73,7 @@ public class AdjustKeyboardHeightActivity extends BaseActivity { resetButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Clear the keyboard height preferences to reset - KMManager.applyKeyboardHeight(this, 0); + KMManager.applyKeyboardHeight(context, 0); // Restore default height currentHeight = KMManager.getKeyboardHeight(context); From a014141d626dbebdc22936db4362c97003475a27 Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Tue, 25 Mar 2025 22:33:55 -0400 Subject: [PATCH 06/61] minor cleanups. --- .../KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 0ed54f99d9..6571ba504a 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2244,9 +2244,9 @@ public final class KMManager { editor.putInt(KMManager.KMKey_KeyboardHeightPortrait, getKeyboardHeight(context, Configuration.ORIENTATION_PORTRAIT)); editor.commit(); - int height = (orientation == Configuration.ORIENTATION_PORTRAIT) ? getKeyboardHeight(context, Configuration.ORIENTATION_PORTRAIT) : getKeyboardHeight(context, Configuration.ORIENTATION_LANDSCAPE); + height = (orientation == Configuration.ORIENTATION_PORTRAIT) ? getKeyboardHeight(context, Configuration.ORIENTATION_PORTRAIT) : getKeyboardHeight(context, Configuration.ORIENTATION_LANDSCAPE); } - else: { + else { // Store the new height based on the current orientation if (orientation == Configuration.ORIENTATION_LANDSCAPE) { editor.putInt(KMManager.KMKey_KeyboardHeightLandscape, height); From f0d0784719310033c792f24ad896b449fa33619c Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Tue, 25 Mar 2025 22:35:46 -0400 Subject: [PATCH 07/61] Update android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java Co-authored-by: Darcy Wong --- .../com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java b/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java index 6240f3888f..475d1ba7bd 100644 --- a/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java +++ b/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java @@ -101,7 +101,7 @@ public class AdjustKeyboardHeightActivity extends BaseActivity { break; case MotionEvent.ACTION_UP: // Save the currentHeight when the user releases - KMManager.applyKeyboardHeight(this, currentHeight); + KMManager.applyKeyboardHeight(context, currentHeight); break; } return true; From 75856683d4769186cd3552443f242ee4490c9c8f Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Tue, 25 Mar 2025 23:44:29 -0400 Subject: [PATCH 08/61] Fixing Reset Button Reverting change to getKeyboardHeight, adding getDefaultKeyboardHeightByOrientation. --- .../java/com/keyman/engine/KMManager.java | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 6571ba504a..40e7ae7c20 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -25,6 +25,7 @@ import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.res.AssetManager; import android.content.res.Configuration; +import android.content.res.Resources; import android.graphics.Point; import android.graphics.Typeface; import android.inputmethodservice.InputMethodService; @@ -2217,13 +2218,9 @@ public final class KMManager { return bannerHeight; } - public static int getKeyboardHeight(Context context) { - int orientation = getOrientation(context); // Default behavior - return getKeyboardHeight(context, orientation); // Delegate to the overloaded method - } - // Overloaded method with an additional orientation parameter - public static int getKeyboardHeight(Context context, int orientation) { + public static int getKeyboardHeight(Context context) { + int orientation = getOrientation(context); int defaultHeight = (int) context.getResources().getDimension(R.dimen.keyboard_height); SharedPreferences prefs = context.getSharedPreferences(context.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE); if (orientation == Configuration.ORIENTATION_PORTRAIT) { @@ -2240,11 +2237,13 @@ public final class KMManager { int orientation = getOrientation(context); if (height == 0) { // Passing 0 will reset both stored heights - editor.putInt(KMManager.KMKey_KeyboardHeightLandscape, getKeyboardHeight(context, Configuration.ORIENTATION_LANDSCAPE)); - editor.putInt(KMManager.KMKey_KeyboardHeightPortrait, getKeyboardHeight(context, Configuration.ORIENTATION_PORTRAIT)); + int defaultPortraitHeight = getDefaultKeyboardHeightByOrientation(context, Configuration.ORIENTATION_PORTRAIT); + int defaultLandscapeHeight = getDefaultKeyboardHeightByOrientation(context, Configuration.ORIENTATION_LANDSCAPE); + editor.putInt(KMManager.KMKey_KeyboardHeightLandscape, defaultLandscapeHeight); + editor.putInt(KMManager.KMKey_KeyboardHeightPortrait, defaultPortraitHeight); editor.commit(); - height = (orientation == Configuration.ORIENTATION_PORTRAIT) ? getKeyboardHeight(context, Configuration.ORIENTATION_PORTRAIT) : getKeyboardHeight(context, Configuration.ORIENTATION_LANDSCAPE); + height = (orientation == Configuration.ORIENTATION_PORTRAIT) ? defaultPortraitHeight : defaultLandscapeHeight; } else { // Store the new height based on the current orientation @@ -2269,6 +2268,22 @@ public final class KMManager { } } + private static int getDefaultKeyboardHeightByOrientation(Context context, int orientation) { + Resources resources = context.getResources(); + Configuration originalConfig = resources.getConfiguration(); + Configuration newConfig = new Configuration(originalConfig); + newConfig.orientation = orientation; + + // Create a new context with the updated configuration + Context newContext = context.createConfigurationContext(newConfig); + Resources newResources = newContext.getResources(); + + // Get the default keyboard height for the new orientation + int defaultHeight = (int) newResources.getDimension(R.dimen.keyboard_height); + + return defaultHeight; +} + /** * Get the size of the area the window would occupy. * API 30+ From 8e523aff893dd0d43499ce6f3a3604675088a03c Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Wed, 26 Mar 2025 00:34:11 -0400 Subject: [PATCH 09/61] Reverting to removing height values. --- android/docs/engine/KMManager/applyKeyboardHeight.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/android/docs/engine/KMManager/applyKeyboardHeight.md b/android/docs/engine/KMManager/applyKeyboardHeight.md index 2830519c62..190073dd4a 100644 --- a/android/docs/engine/KMManager/applyKeyboardHeight.md +++ b/android/docs/engine/KMManager/applyKeyboardHeight.md @@ -18,7 +18,7 @@ KMManager.applyKeyboardHeight(Context context, int height) : The context `height` -: The height of the keyboard frame in *density-independent pixels (dp)* +: The height of the keyboard frame in *density-independent pixels (dp)*. Pass 0 to reset the keyboard height (portrait and landscape) to device-specific defaults. ## Description Use this method when you want to increase or decrease the keyboard height for @@ -50,5 +50,12 @@ The following script illustrates the use of `applyKeyboardHeight()`: KMManager.applyKeyboardHeight(this, newKeyboardHeight); ``` +The following script illustrates the use of `applyKeyboardHeight()` to reset keyboard height to default: + +```java + // Reset keyboard to default height + KMManager.applyKeyboardHeight(this, 0); +``` + ## See also * [getKeyboardHeight()](getKeyboardHeight) From fc5374282177e0d191f2ce1dacf2a15c77f2f44a Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Wed, 26 Mar 2025 00:49:34 -0400 Subject: [PATCH 10/61] Setting 0 for heights. Gating inputs --- .../java/com/keyman/engine/KMManager.java | 33 +++++++------------ 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 40e7ae7c20..0d291e9d20 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -25,7 +25,6 @@ import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.res.AssetManager; import android.content.res.Configuration; -import android.content.res.Resources; import android.graphics.Point; import android.graphics.Typeface; import android.inputmethodservice.InputMethodService; @@ -2237,15 +2236,20 @@ public final class KMManager { int orientation = getOrientation(context); if (height == 0) { // Passing 0 will reset both stored heights - int defaultPortraitHeight = getDefaultKeyboardHeightByOrientation(context, Configuration.ORIENTATION_PORTRAIT); - int defaultLandscapeHeight = getDefaultKeyboardHeightByOrientation(context, Configuration.ORIENTATION_LANDSCAPE); - editor.putInt(KMManager.KMKey_KeyboardHeightLandscape, defaultLandscapeHeight); - editor.putInt(KMManager.KMKey_KeyboardHeightPortrait, defaultPortraitHeight); + editor.remove(KMManager.KMKey_KeyboardHeightLandscape); + editor.remove(KMManager.KMKey_KeyboardHeightPortrait); editor.commit(); - - height = (orientation == Configuration.ORIENTATION_PORTRAIT) ? defaultPortraitHeight : defaultLandscapeHeight; + } else { + // Applying gating to 50%-200% of default height (following Keyman) + int defaultHeight = (int) context.getResources().getDimension(R.dimen.keyboard_height); + if (height < (defaultHeight / 2)) { + height = (int) (defaultHeight / 2); + } else if (height > (defaultHeight * 2)) { + height = (int) (defaultHeight * 2); + } + // Store the new height based on the current orientation if (orientation == Configuration.ORIENTATION_LANDSCAPE) { editor.putInt(KMManager.KMKey_KeyboardHeightLandscape, height); @@ -2268,21 +2272,6 @@ public final class KMManager { } } - private static int getDefaultKeyboardHeightByOrientation(Context context, int orientation) { - Resources resources = context.getResources(); - Configuration originalConfig = resources.getConfiguration(); - Configuration newConfig = new Configuration(originalConfig); - newConfig.orientation = orientation; - - // Create a new context with the updated configuration - Context newContext = context.createConfigurationContext(newConfig); - Resources newResources = newContext.getResources(); - - // Get the default keyboard height for the new orientation - int defaultHeight = (int) newResources.getDimension(R.dimen.keyboard_height); - - return defaultHeight; -} /** * Get the size of the area the window would occupy. From 621d15aa6d7e9cc228bf9e447b1764e70f3f780c Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Wed, 26 Mar 2025 01:42:56 -0400 Subject: [PATCH 11/61] Update android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java Co-authored-by: Marc Durdin --- android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 0d291e9d20..32afea2b11 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2223,7 +2223,7 @@ public final class KMManager { int defaultHeight = (int) context.getResources().getDimension(R.dimen.keyboard_height); SharedPreferences prefs = context.getSharedPreferences(context.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE); if (orientation == Configuration.ORIENTATION_PORTRAIT) { - return prefs.getInt(KMManager.KMKey_KeyboardHeightPortrait, defaultHeight); + return prefs.getInt(KMManager.KMKey_KeyboardHeightPortrait, defaultHeight); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { return prefs.getInt(KMManager.KMKey_KeyboardHeightLandscape, defaultHeight); } From d4e7d060349d3f87cd126e614d3bf46adeb1e363 Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Wed, 26 Mar 2025 01:45:34 -0400 Subject: [PATCH 12/61] Update android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java Co-authored-by: Marc Durdin --- .../KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 32afea2b11..f742637b51 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2253,10 +2253,8 @@ public final class KMManager { // Store the new height based on the current orientation if (orientation == Configuration.ORIENTATION_LANDSCAPE) { editor.putInt(KMManager.KMKey_KeyboardHeightLandscape, height); - editor.commit(); - } else if (orientation == Configuration.ORIENTATION_PORTRAIT) { + } else /* orientation == Configuration.ORIENTATION_PORTRAIT */ { editor.putInt(KMManager.KMKey_KeyboardHeightPortrait, height); - editor.commit(); } } // Confirm new LayoutParams for in-app or system keyboards From 459c948a97d1bb336d89fc2c52eb5d979f7a67fb Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Wed, 26 Mar 2025 01:54:21 -0400 Subject: [PATCH 13/61] Update android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java Co-authored-by: Marc Durdin --- android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index f742637b51..febf41014b 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2225,7 +2225,7 @@ public final class KMManager { if (orientation == Configuration.ORIENTATION_PORTRAIT) { return prefs.getInt(KMManager.KMKey_KeyboardHeightPortrait, defaultHeight); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { - return prefs.getInt(KMManager.KMKey_KeyboardHeightLandscape, defaultHeight); + return prefs.getInt(KMManager.KMKey_KeyboardHeightLandscape, defaultHeight); } return defaultHeight; } From ca2101800dd41afc7267771ca7c19f948df354aa Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Wed, 26 Mar 2025 02:06:01 -0400 Subject: [PATCH 14/61] Adding variable. --- .../KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 0d291e9d20..9de6090e4e 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -342,6 +342,9 @@ public final class KMManager { public static final int KMMinimum_LongpressDelay = 300; public static final int KMMaximum_LongpressDelay = 1500; + // Default keyboard height + public static final int KeyboardHeight_Default = 0; + // Default prediction/correction setting public static final int KMDefault_Suggestion = SuggestionType.PREDICTIONS_WITH_CORRECTIONS.toInt(); From 7cd219d0973939ed1b58e575c7dff5aaa9ec6e76 Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Wed, 26 Mar 2025 02:08:10 -0400 Subject: [PATCH 15/61] Update android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java Co-authored-by: Marc Durdin --- android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index ef58e7ee88..3f88362fb5 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2237,7 +2237,7 @@ public final class KMManager { SharedPreferences prefs = context.getSharedPreferences("KMAPreferences", Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); int orientation = getOrientation(context); - if (height == 0) { + if (height == KMManager.DEFAULT_KEYBOARD_HEIGHT) { // Passing 0 will reset both stored heights editor.remove(KMManager.KMKey_KeyboardHeightLandscape); editor.remove(KMManager.KMKey_KeyboardHeightPortrait); From 18fc24cb05e060529eb3d2a6e4257143687c5fa0 Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Wed, 26 Mar 2025 02:08:30 -0400 Subject: [PATCH 16/61] Update android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java Co-authored-by: Marc Durdin --- .../KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 3f88362fb5..4dd43b0a5f 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2243,8 +2243,7 @@ public final class KMManager { editor.remove(KMManager.KMKey_KeyboardHeightPortrait); editor.commit(); - } - else { + } else { // Applying gating to 50%-200% of default height (following Keyman) int defaultHeight = (int) context.getResources().getDimension(R.dimen.keyboard_height); if (height < (defaultHeight / 2)) { From f7c0e4eaac69bce9ae73296a897a1c3ad84925ea Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Wed, 26 Mar 2025 02:10:11 -0400 Subject: [PATCH 17/61] Update android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java Co-authored-by: Marc Durdin --- android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 4dd43b0a5f..e8f7bd6d10 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2259,6 +2259,7 @@ public final class KMManager { editor.putInt(KMManager.KMKey_KeyboardHeightPortrait, height); } } + editor.commit(); // Confirm new LayoutParams for in-app or system keyboards if (isKeyboardLoaded(KeyboardType.KEYBOARD_TYPE_INAPP)) { InAppKeyboard.loadJavascript(KMString.format("setOskHeight('%s')", height)); From 2bade43b5416f7366962bfe622112ac6848859eb Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Wed, 26 Mar 2025 02:25:41 -0400 Subject: [PATCH 18/61] Adding overloads for getKeyboardHeight and applyKeyboardHeight for alternate orientations. --- .../java/com/keyman/engine/KMManager.java | 53 ++++++++++++++----- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index e8f7bd6d10..6b240e04fa 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2220,36 +2220,63 @@ public final class KMManager { return bannerHeight; } - // Overloaded method with an additional orientation parameter + // Original method remains unchanged public static int getKeyboardHeight(Context context) { - int orientation = getOrientation(context); + int orientation = getOrientation(context); // Default behavior + return getKeyboardHeight(context, orientation); // Delegate to the overloaded method + } + + // Overloaded method with an additional orientation parameter + public static int getKeyboardHeight(Context context, int orientation) { int defaultHeight = (int) context.getResources().getDimension(R.dimen.keyboard_height); SharedPreferences prefs = context.getSharedPreferences(context.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE); + if (orientation == Configuration.ORIENTATION_PORTRAIT) { - return prefs.getInt(KMManager.KMKey_KeyboardHeightPortrait, defaultHeight); + return prefs.getInt(KMManager.KMKey_KeyboardHeightPortrait, defaultHeight); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { - return prefs.getInt(KMManager.KMKey_KeyboardHeightLandscape, defaultHeight); + return prefs.getInt(KMManager.KMKey_KeyboardHeightLandscape, defaultHeight); } + return defaultHeight; } + /** + * Apply the keyboard height for the current orientation and store it in SharedPreferences. + * If height is KMManager.DEFAULT_KEYBOARD_HEIGHT, remove the stored height for that orientation. + * @param context Context + * @param height int - keyboard height in dp + */ public static void applyKeyboardHeight(Context context, int height) { + int orientation = getOrientation(context); // Default behavior + return getKeyboardHeight(context, height, orientation); // Delegate to the overloaded method + } + + /** + * Apply the keyboard height for the current orientation and store it in SharedPreferences. + * If height is KMManager.DEFAULT_KEYBOARD_HEIGHT, remove the stored height for that orientation. + * @param context Context + * @param height int - keyboard height in dp + * @param orientation int - Configuration.ORIENTATION_PORTRAIT or Configuration.ORIENTATION_LANDSCAPE + */ + public static void applyKeyboardHeight(Context context, int height, int orientation) { SharedPreferences prefs = context.getSharedPreferences("KMAPreferences", Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); - int orientation = getOrientation(context); + int defaultHeightForContext = (int) context.getResources().getDimension(R.dimen.keyboard_height); if (height == KMManager.DEFAULT_KEYBOARD_HEIGHT) { - // Passing 0 will reset both stored heights - editor.remove(KMManager.KMKey_KeyboardHeightLandscape); - editor.remove(KMManager.KMKey_KeyboardHeightPortrait); + // Passing 0 will reset the stored height for this orientation. + if (orientation == Configuration.ORIENTATION_LANDSCAPE) { + editor.remove(KMManager.KMKey_KeyboardHeightLandscape); + } else if (orientation == Configuration.ORIENTATION_PORTRAIT) { + editor.remove(KMManager.KMKey_KeyboardHeightPortrait); + } editor.commit(); } else { // Applying gating to 50%-200% of default height (following Keyman) - int defaultHeight = (int) context.getResources().getDimension(R.dimen.keyboard_height); - if (height < (defaultHeight / 2)) { - height = (int) (defaultHeight / 2); - } else if (height > (defaultHeight * 2)) { - height = (int) (defaultHeight * 2); + if (height < (defaultHeightForContext / 2)) { + height = (int) (defaultHeightForContext / 2); + } else if (height > (defaultHeightForContext * 2)) { + height = (int) (defaultHeightForContext * 2); } // Store the new height based on the current orientation From 79f8918346af29cefb5c98dcc550825cb78b377d Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Wed, 26 Mar 2025 02:52:01 -0400 Subject: [PATCH 19/61] adding Varables and GetDefaultKeyboardHeight Function. I still need to figure out when to call this for initialization. --- android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 6b240e04fa..279d560904 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -25,6 +25,7 @@ import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.res.AssetManager; import android.content.res.Configuration; +import android.content.res.Resources; import android.graphics.Point; import android.graphics.Typeface; import android.inputmethodservice.InputMethodService; From 1215f93f8760f6c57f2b3ed806a3a6906818e3ad Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Wed, 26 Mar 2025 08:09:10 -0400 Subject: [PATCH 20/61] getDefaultKeyboardHeight() --- .../java/com/keyman/engine/KMManager.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 279d560904..db1af3b30b 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -343,8 +343,10 @@ public final class KMManager { public static final int KMMinimum_LongpressDelay = 300; public static final int KMMaximum_LongpressDelay = 1500; - // Default keyboard height - public static final int KeyboardHeight_Default = 0; + // Default keyboard heights + public static final int KeyboardHeight_Default = 0; // Zero value for constructor + public static final int KeyboardHeight_Context_Portrait_Default = 0; // Default portrait height + public static final int KeyboardHeight_Context_Landscape_Default = 0; // Default landscape height // Default prediction/correction setting public static final int KMDefault_Suggestion = SuggestionType.PREDICTIONS_WITH_CORRECTIONS.toInt(); @@ -499,6 +501,9 @@ public final class KMManager { migrateCloudKeyboards(appContext); CloudDownloadMgr.getInstance().initialize(appContext); + + KeyboardHeight_Context_Portrait_Default = getDefaultKeyboardHeight(context, Configuration.ORIENTATION_PORTRAI); + KeyboardHeight_Context_Landscape_Default = getDefaultKeyboardHeight(context, Configuration.ORIENTATION_LANDSCAPE); } public static void executeResourceUpdate(Context aContext) @@ -2301,6 +2306,26 @@ public final class KMManager { } } + public static int getDefaultKeyboardHeight(Context context) { + int orientation = getOrientation(context); // Default behavior + return getDefaultKeyboardHeight(Context context, int orientation) + } + + public static int getDefaultKeyboardHeight(Context context, int orientation) { + Resources resources = context.getResources(); + Configuration originalConfig = resources.getConfiguration(); + Configuration newConfig = new Configuration(originalConfig); + newConfig.orientation = orientation; + + // Create a new context with the updated configuration + Context newContext = context.createConfigurationContext(newConfig); + Resources newResources = newContext.getResources(); + + // Get the default keyboard height for the new orientation + int defaultHeight = (int) newResources.getDimension(R.dimen.keyboard_height); + + return defaultHeight; + } /** * Get the size of the area the window would occupy. From b36dc677f5398242c408b4328e5a79ec73ab8998 Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Wed, 26 Mar 2025 19:44:13 -0400 Subject: [PATCH 21/61] Using new variables --- .../java/com/keyman/engine/KMManager.java | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index db1af3b30b..c3c1e5d122 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2226,24 +2226,17 @@ public final class KMManager { return bannerHeight; } - // Original method remains unchanged public static int getKeyboardHeight(Context context) { - int orientation = getOrientation(context); // Default behavior - return getKeyboardHeight(context, orientation); // Delegate to the overloaded method + return getKeyboardHeight(context, getOrientation(context)); } - // Overloaded method with an additional orientation parameter public static int getKeyboardHeight(Context context, int orientation) { - int defaultHeight = (int) context.getResources().getDimension(R.dimen.keyboard_height); SharedPreferences prefs = context.getSharedPreferences(context.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE); - if (orientation == Configuration.ORIENTATION_PORTRAIT) { - return prefs.getInt(KMManager.KMKey_KeyboardHeightPortrait, defaultHeight); + return prefs.getInt(KMManager.KMKey_KeyboardHeightPortrait, this.KeyboardHeight_Context_Portrait_Default); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { - return prefs.getInt(KMManager.KMKey_KeyboardHeightLandscape, defaultHeight); + return prefs.getInt(KMManager.KMKey_KeyboardHeightLandscape, this.KeyboardHeight_Context_Landscape_Default); } - - return defaultHeight; } /** @@ -2253,8 +2246,7 @@ public final class KMManager { * @param height int - keyboard height in dp */ public static void applyKeyboardHeight(Context context, int height) { - int orientation = getOrientation(context); // Default behavior - return getKeyboardHeight(context, height, orientation); // Delegate to the overloaded method + return getKeyboardHeight(context, height, getOrientation(context)); } /** @@ -2267,7 +2259,8 @@ public final class KMManager { public static void applyKeyboardHeight(Context context, int height, int orientation) { SharedPreferences prefs = context.getSharedPreferences("KMAPreferences", Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); - int defaultHeightForContext = (int) context.getResources().getDimension(R.dimen.keyboard_height); + int defaultHeightForContext = orientation == Configuration.ORIENTATION_PORTRAIT ? + KeyboardHeight_Context_Portrait_Default: KeyboardHeight_Context_Landscape_Default; if (height == KMManager.DEFAULT_KEYBOARD_HEIGHT) { // Passing 0 will reset the stored height for this orientation. if (orientation == Configuration.ORIENTATION_LANDSCAPE) { @@ -2283,7 +2276,7 @@ public final class KMManager { height = (int) (defaultHeightForContext / 2); } else if (height > (defaultHeightForContext * 2)) { height = (int) (defaultHeightForContext * 2); - } + } // Store the new height based on the current orientation if (orientation == Configuration.ORIENTATION_LANDSCAPE) { @@ -2307,8 +2300,7 @@ public final class KMManager { } public static int getDefaultKeyboardHeight(Context context) { - int orientation = getOrientation(context); // Default behavior - return getDefaultKeyboardHeight(Context context, int orientation) + return getDefaultKeyboardHeight(context, getOrientation(context)) } public static int getDefaultKeyboardHeight(Context context, int orientation) { From 5f069c35d825a95e580dc741797eb59b18ecec8d Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Wed, 26 Mar 2025 19:53:32 -0400 Subject: [PATCH 22/61] Reset Variable --- .../com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java b/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java index 475d1ba7bd..f29a85ba61 100644 --- a/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java +++ b/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java @@ -73,7 +73,7 @@ public class AdjustKeyboardHeightActivity extends BaseActivity { resetButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Clear the keyboard height preferences to reset - KMManager.applyKeyboardHeight(context, 0); + KMManager.applyKeyboardHeight(context, KMManager.KeyboardHeight_Reset); // Restore default height currentHeight = KMManager.getKeyboardHeight(context); From a8da8e7b5e7346c7e805811a90386c96a2452b2f Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Wed, 26 Mar 2025 20:59:37 -0400 Subject: [PATCH 23/61] Finalizing --- .../java/com/keyman/engine/KMManager.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index c3c1e5d122..fd45e4a2d6 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -344,9 +344,9 @@ public final class KMManager { public static final int KMMaximum_LongpressDelay = 1500; // Default keyboard heights - public static final int KeyboardHeight_Default = 0; // Zero value for constructor - public static final int KeyboardHeight_Context_Portrait_Default = 0; // Default portrait height - public static final int KeyboardHeight_Context_Landscape_Default = 0; // Default landscape height + public static final int KeyboardHeight_Reset = 0; // Zero value for constructor + public static int KeyboardHeight_Context_Portrait_Default = 0; // Default portrait height + public static int KeyboardHeight_Context_Landscape_Default = 0; // Default landscape height // Default prediction/correction setting public static final int KMDefault_Suggestion = SuggestionType.PREDICTIONS_WITH_CORRECTIONS.toInt(); @@ -502,7 +502,7 @@ public final class KMManager { CloudDownloadMgr.getInstance().initialize(appContext); - KeyboardHeight_Context_Portrait_Default = getDefaultKeyboardHeight(context, Configuration.ORIENTATION_PORTRAI); + KeyboardHeight_Context_Portrait_Default = getDefaultKeyboardHeight(context, Configuration.ORIENTATION_PORTRAIT); KeyboardHeight_Context_Landscape_Default = getDefaultKeyboardHeight(context, Configuration.ORIENTATION_LANDSCAPE); } @@ -2227,15 +2227,16 @@ public final class KMManager { } public static int getKeyboardHeight(Context context) { - return getKeyboardHeight(context, getOrientation(context)); + int orientation = getOrientation(context); + return getKeyboardHeight(context, orientation); } public static int getKeyboardHeight(Context context, int orientation) { SharedPreferences prefs = context.getSharedPreferences(context.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE); if (orientation == Configuration.ORIENTATION_PORTRAIT) { - return prefs.getInt(KMManager.KMKey_KeyboardHeightPortrait, this.KeyboardHeight_Context_Portrait_Default); - } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { - return prefs.getInt(KMManager.KMKey_KeyboardHeightLandscape, this.KeyboardHeight_Context_Landscape_Default); + return prefs.getInt(KMManager.KMKey_KeyboardHeightPortrait, KMManager.KeyboardHeight_Context_Portrait_Default); + } else /*(orientation == Configuration.ORIENTATION_LANDSCAPE) */ { + return prefs.getInt(KMManager.KMKey_KeyboardHeightLandscape, KMManager.KeyboardHeight_Context_Landscape_Default); } } @@ -2246,7 +2247,8 @@ public final class KMManager { * @param height int - keyboard height in dp */ public static void applyKeyboardHeight(Context context, int height) { - return getKeyboardHeight(context, height, getOrientation(context)); + int orientation = getOrientation(context); + applyKeyboardHeight(context, height, orientation); } /** @@ -2261,7 +2263,7 @@ public final class KMManager { SharedPreferences.Editor editor = prefs.edit(); int defaultHeightForContext = orientation == Configuration.ORIENTATION_PORTRAIT ? KeyboardHeight_Context_Portrait_Default: KeyboardHeight_Context_Landscape_Default; - if (height == KMManager.DEFAULT_KEYBOARD_HEIGHT) { + if (height == KMManager.KeyboardHeight_Reset) { // Passing 0 will reset the stored height for this orientation. if (orientation == Configuration.ORIENTATION_LANDSCAPE) { editor.remove(KMManager.KMKey_KeyboardHeightLandscape); @@ -2300,7 +2302,8 @@ public final class KMManager { } public static int getDefaultKeyboardHeight(Context context) { - return getDefaultKeyboardHeight(context, getOrientation(context)) + int orientation = getOrientation(context); + return getDefaultKeyboardHeight(context, orientation); } public static int getDefaultKeyboardHeight(Context context, int orientation) { From 18db5ec1390f7b1e6552d60740aa4f566b4e6d68 Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Wed, 26 Mar 2025 21:10:19 -0400 Subject: [PATCH 24/61] removing sharedprefs import --- .../com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java b/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java index f29a85ba61..45503b60b4 100644 --- a/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java +++ b/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java @@ -4,7 +4,6 @@ package com.tavultesoft.kmapro; import android.content.Context; -import android.content.SharedPreferences; import android.content.res.Configuration; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; From 287acfbd36a85a34dc30ce4888d238019efe0ed2 Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Wed, 26 Mar 2025 23:21:11 -0400 Subject: [PATCH 25/61] removing duplicate commit() --- android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index fd45e4a2d6..7fe40aba70 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2270,8 +2270,6 @@ public final class KMManager { } else if (orientation == Configuration.ORIENTATION_PORTRAIT) { editor.remove(KMManager.KMKey_KeyboardHeightPortrait); } - editor.commit(); - } else { // Applying gating to 50%-200% of default height (following Keyman) if (height < (defaultHeightForContext / 2)) { From 063a91d019fe69ffb1b7e0f7f625b6269d4d0f17 Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Thu, 27 Mar 2025 00:30:04 -0400 Subject: [PATCH 26/61] updating variable name --- .../KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 7fe40aba70..c3cab51e06 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2242,7 +2242,7 @@ public final class KMManager { /** * Apply the keyboard height for the current orientation and store it in SharedPreferences. - * If height is KMManager.DEFAULT_KEYBOARD_HEIGHT, remove the stored height for that orientation. + * If height is KMManager.KeyboardHeight_Reset, remove the stored height for that orientation. * @param context Context * @param height int - keyboard height in dp */ @@ -2253,7 +2253,7 @@ public final class KMManager { /** * Apply the keyboard height for the current orientation and store it in SharedPreferences. - * If height is KMManager.DEFAULT_KEYBOARD_HEIGHT, remove the stored height for that orientation. + * If height is KMManager.KeyboardHeight_Reset, remove the stored height for that orientation. * @param context Context * @param height int - keyboard height in dp * @param orientation int - Configuration.ORIENTATION_PORTRAIT or Configuration.ORIENTATION_LANDSCAPE From 8cd1518e24cc0a5af96b2f279d33f2e3a1af53fe Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Thu, 27 Mar 2025 09:00:39 -0400 Subject: [PATCH 27/61] Update android/docs/engine/KMManager/applyKeyboardHeight.md Co-authored-by: Marc Durdin --- android/docs/engine/KMManager/applyKeyboardHeight.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/docs/engine/KMManager/applyKeyboardHeight.md b/android/docs/engine/KMManager/applyKeyboardHeight.md index 190073dd4a..8276ceb0a9 100644 --- a/android/docs/engine/KMManager/applyKeyboardHeight.md +++ b/android/docs/engine/KMManager/applyKeyboardHeight.md @@ -18,7 +18,7 @@ KMManager.applyKeyboardHeight(Context context, int height) : The context `height` -: The height of the keyboard frame in *density-independent pixels (dp)*. Pass 0 to reset the keyboard height (portrait and landscape) to device-specific defaults. +: The height of the keyboard frame in *density-independent pixels (dp)*. Pass `KMManager.KeyboardHeight_Reset` to reset the keyboard height (for current orientation) to device-specific defaults. ## Description Use this method when you want to increase or decrease the keyboard height for From 426846f08a7aecbdc119b335b4ef43e3bd13babd Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Thu, 27 Mar 2025 09:05:11 -0400 Subject: [PATCH 28/61] Update android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java Co-authored-by: Marc Durdin --- .../KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index c3cab51e06..e8c23dc49b 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2267,9 +2267,10 @@ public final class KMManager { // Passing 0 will reset the stored height for this orientation. if (orientation == Configuration.ORIENTATION_LANDSCAPE) { editor.remove(KMManager.KMKey_KeyboardHeightLandscape); - } else if (orientation == Configuration.ORIENTATION_PORTRAIT) { + } else /* orientation == Configuration.ORIENTATION_PORTRAIT */ { editor.remove(KMManager.KMKey_KeyboardHeightPortrait); } + height = defaultHeightForContext; } else { // Applying gating to 50%-200% of default height (following Keyman) if (height < (defaultHeightForContext / 2)) { From 0bfefa11cdd2ddd94c82ce0c3688e27244ca4958 Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Thu, 27 Mar 2025 09:06:33 -0400 Subject: [PATCH 29/61] Update android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java Co-authored-by: Marc Durdin --- .../KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index e8c23dc49b..47e028bab1 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2261,8 +2261,9 @@ public final class KMManager { public static void applyKeyboardHeight(Context context, int height, int orientation) { SharedPreferences prefs = context.getSharedPreferences("KMAPreferences", Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); - int defaultHeightForContext = orientation == Configuration.ORIENTATION_PORTRAIT ? - KeyboardHeight_Context_Portrait_Default: KeyboardHeight_Context_Landscape_Default; + int defaultHeightForContext = orientation == Configuration.ORIENTATION_PORTRAIT + ? KeyboardHeight_Context_Portrait_Default + : KeyboardHeight_Context_Landscape_Default; if (height == KMManager.KeyboardHeight_Reset) { // Passing 0 will reset the stored height for this orientation. if (orientation == Configuration.ORIENTATION_LANDSCAPE) { From 908d17099ecffcd2f968dd03813a02b1a86b3e3b Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Thu, 27 Mar 2025 09:59:15 -0400 Subject: [PATCH 30/61] Drafting docs for overloads. --- .../engine/KMManager/applyKeyboardHeight.md | 29 +++++++++++++++---- .../engine/KMManager/getKeyboardHeight.md | 15 ++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/android/docs/engine/KMManager/applyKeyboardHeight.md b/android/docs/engine/KMManager/applyKeyboardHeight.md index 8276ceb0a9..cd9bb3fbd0 100644 --- a/android/docs/engine/KMManager/applyKeyboardHeight.md +++ b/android/docs/engine/KMManager/applyKeyboardHeight.md @@ -5,12 +5,17 @@ title: KMManager.applyKeyboardHeight() ## Summary The **applyKeyboardHeight()** method sets the height of the keyboard frame for the device's current [screen orientation](https://developer.android.com/training/multiscreen/screensizes#TaskUseOriQuali) -(portrait vs landscape). +(portrait vs landscape) or a specified orientation. ## Syntax ```java KMManager.applyKeyboardHeight(Context context, int height) ``` +or + +```java +KMManager.applyKeyboardHeight(Context context, int height, int orientation) +``` ### Parameters @@ -20,6 +25,9 @@ KMManager.applyKeyboardHeight(Context context, int height) `height` : The height of the keyboard frame in *density-independent pixels (dp)*. Pass `KMManager.KeyboardHeight_Reset` to reset the keyboard height (for current orientation) to device-specific defaults. +`orientation` _(Optional)_ +: Accepts a [screen orientation](https://developer.android.com/training/multiscreen/screensizes#TaskUseOriQuali) value. This is most useful if you want to change the size of the keyboard in the other (non-current) orientation. If `orientation` is not defined, keyboard height is set for the current device orientation. + ## Description Use this method when you want to increase or decrease the keyboard height for the device in the current screen orientation. This height is independent from @@ -30,11 +38,11 @@ For reference, here's a table of the default Keyman keyboard heights for various Device Type and Screen Orientation | Default height (dp) | |-----------------------------------|---------------------| | Default handset in portrait | 205 | -| Default handset in landscape | 150 | +| Default handset in landscape | 100 | | 7" tablet in portrait | 305 | -| 7" tablet in landscape | 200 | +| 7" tablet in landscape | 140 | | 10" tablet in portrait | 405 | -| 10" tablet in landscape | 300 | +| 10" tablet in landscape | 200 | **Note:** This new keyboard height would be applied for all platforms, so an adjusted keyboard height for a phone would appear too small for a tablet. @@ -50,11 +58,22 @@ The following script illustrates the use of `applyKeyboardHeight()`: KMManager.applyKeyboardHeight(this, newKeyboardHeight); ``` +or + +```java + import android.content.res.Configuration; + ... + // Increase the Keyman keyboard height for landscape mode to 250dp (default Keyman value for most phones is 100dp) + int newKeyboardHeight = 250; + KMManager.applyKeyboardHeight(this, newKeyboardHeight, Configuration.ORIENTATION_LANDSCAPE); +``` + + The following script illustrates the use of `applyKeyboardHeight()` to reset keyboard height to default: ```java // Reset keyboard to default height - KMManager.applyKeyboardHeight(this, 0); + KMManager.applyKeyboardHeight(this, KMManager.KeyboardHeight_Reset); ``` ## See also diff --git a/android/docs/engine/KMManager/getKeyboardHeight.md b/android/docs/engine/KMManager/getKeyboardHeight.md index c459e45ddb..5a8efc052f 100644 --- a/android/docs/engine/KMManager/getKeyboardHeight.md +++ b/android/docs/engine/KMManager/getKeyboardHeight.md @@ -12,12 +12,19 @@ frame. ``` javascript KMManager.getKeyboardHeight(Context context) ``` +or +``` javascript +KMManager.getKeyboardHeight(Context context, int orientation) +``` ### Parameters `context` : The context. +`orientation` _(Optional)_ +: Accepts a [screen orientation](https://developer.android.com/training/multiscreen/screensizes#TaskUseOriQuali) value. This is most useful if you want to get the size of the keyboard in the other (non-current) orientation. If `orientation` is not defined, keyboard height is returned for the current device orientation. + ### Returns Returns the height of the keyboard frame in *density-independent pixels @@ -36,6 +43,14 @@ The following script illustrate the use of `getKeyboardHeight()`: ``` javascript int keyboardHeight = KMManager.getKeyboardHeight(this); ``` +or +```java + import android.content.res.Configuration; + ... + // Get the current Keyman keyboard height for landscape mode. + + int keyboardHeightLandscape = KMManager.getKeyboardHeight(this, Configuration.ORIENTATION_LANDSCAPE); +``` ## See also From 05625d598381e7a982508c216b337c3965be50bd Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Thu, 27 Mar 2025 19:00:45 -0400 Subject: [PATCH 31/61] Bypassing dynamic height for tests --- .../KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 47e028bab1..f125dc0c31 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2307,6 +2307,10 @@ public final class KMManager { } public static int getDefaultKeyboardHeight(Context context, int orientation) { + if (isTestMode()) { + // Keyboard height not needed for unit tests #13578 + return KeyboardHeight_Context_Portrait_Default; + } Resources resources = context.getResources(); Configuration originalConfig = resources.getConfiguration(); Configuration newConfig = new Configuration(originalConfig); From 0cb5a17971372e2d42729cc188ee9d8761f07b6a Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Thu, 27 Mar 2025 23:21:43 -0400 Subject: [PATCH 32/61] Updating docs for Adjust Keyboard Height feature --- android/docs/help/basic/config/adjust-keyboard-height.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/docs/help/basic/config/adjust-keyboard-height.md b/android/docs/help/basic/config/adjust-keyboard-height.md index fcc459a5e5..6b18c5dc2a 100644 --- a/android/docs/help/basic/config/adjust-keyboard-height.md +++ b/android/docs/help/basic/config/adjust-keyboard-height.md @@ -6,11 +6,11 @@ title: Adjust Keyboard Height - Keyman for Android Help This menu is used to adjust the height of the on-screen keyboard (OSK), which does not include the suggestion banner. -Drag the blank OSK at the bottom of the screen to increase or decrease the keyboard height for the device's current orientation (portrait vs landscape). The adjusted keyboard heights are automatically saved when the blank OSK is released. +Drag the blank OSK at the bottom of the screen to increase or decrease the keyboard height for the device's current orientation (portrait vs landscape). Turn the device 90 degrees to the alternate orientation and repeat the process. The adjusted keyboard heights are automatically saved when the blank OSK is released. ![](../../android_images/blank-osk.png) ### Reset to Default Height -Press the button to reset the OSK height to the default values. +Press the button to reset the OSK height (for the current orientation) to the default device-specific height. ![](../../android_images/reset-to-default.png) From e7440af715f7da40e8d8052149333694b73290bb Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Fri, 28 Mar 2025 13:15:35 -0400 Subject: [PATCH 33/61] Handle undefined/invalid orientations Responding to Marc's message about undefined orientations. This shouldn't affect the user tests. It's handling an edge case. --- .../main/java/com/keyman/engine/KMManager.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index f125dc0c31..1b6cc9538d 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2235,8 +2235,10 @@ public final class KMManager { SharedPreferences prefs = context.getSharedPreferences(context.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE); if (orientation == Configuration.ORIENTATION_PORTRAIT) { return prefs.getInt(KMManager.KMKey_KeyboardHeightPortrait, KMManager.KeyboardHeight_Context_Portrait_Default); - } else /*(orientation == Configuration.ORIENTATION_LANDSCAPE) */ { + } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { return prefs.getInt(KMManager.KMKey_KeyboardHeightLandscape, KMManager.KeyboardHeight_Context_Landscape_Default); + } else { + return KMManager.KeyboardHeight_Reset; // Invalid orientation, return reset value } } @@ -2264,13 +2266,16 @@ public final class KMManager { int defaultHeightForContext = orientation == Configuration.ORIENTATION_PORTRAIT ? KeyboardHeight_Context_Portrait_Default : KeyboardHeight_Context_Landscape_Default; + if (orientation != Configuration.ORIENTATION_PORTRAIT && orientation != Configuration.ORIENTATION_LANDSCAPE) { + return; // Invalid orientation, do nothing + } if (height == KMManager.KeyboardHeight_Reset) { // Passing 0 will reset the stored height for this orientation. if (orientation == Configuration.ORIENTATION_LANDSCAPE) { editor.remove(KMManager.KMKey_KeyboardHeightLandscape); - } else /* orientation == Configuration.ORIENTATION_PORTRAIT */ { + } else /* (orientation == Configuration.ORIENTATION_PORTRAIT) */{ editor.remove(KMManager.KMKey_KeyboardHeightPortrait); - } + } height = defaultHeightForContext; } else { // Applying gating to 50%-200% of default height (following Keyman) @@ -2283,9 +2288,9 @@ public final class KMManager { // Store the new height based on the current orientation if (orientation == Configuration.ORIENTATION_LANDSCAPE) { editor.putInt(KMManager.KMKey_KeyboardHeightLandscape, height); - } else /* orientation == Configuration.ORIENTATION_PORTRAIT */ { + } else /* (orientation == Configuration.ORIENTATION_PORTRAIT) */ { editor.putInt(KMManager.KMKey_KeyboardHeightPortrait, height); - } + } } editor.commit(); // Confirm new LayoutParams for in-app or system keyboards @@ -2311,6 +2316,9 @@ public final class KMManager { // Keyboard height not needed for unit tests #13578 return KeyboardHeight_Context_Portrait_Default; } + if (orientation != Configuration.ORIENTATION_PORTRAIT && orientation != Configuration.ORIENTATION_LANDSCAPE) { + return KeyboardHeight_Reset; // Invalid orientation, return reset value + } Resources resources = context.getResources(); Configuration originalConfig = resources.getConfiguration(); Configuration newConfig = new Configuration(originalConfig); From f4b9d6a6f5c9e828c7f8447fa55d0df76141309a Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Fri, 28 Mar 2025 19:12:35 -0400 Subject: [PATCH 34/61] Update android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java Co-authored-by: Marc Durdin --- .../KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 1b6cc9538d..96ee6994ac 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2226,6 +2226,9 @@ public final class KMManager { return bannerHeight; } + /** + * Returns the current keyboard height in dp for the current device orientation + */ public static int getKeyboardHeight(Context context) { int orientation = getOrientation(context); return getKeyboardHeight(context, orientation); From 11cf9d8dbf85dc31e99b7270766b0d46b146634e Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Fri, 28 Mar 2025 19:13:20 -0400 Subject: [PATCH 35/61] Update android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java Co-authored-by: Marc Durdin --- .../KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 96ee6994ac..9fb81aa04d 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -344,7 +344,8 @@ public final class KMManager { public static final int KMMaximum_LongpressDelay = 1500; // Default keyboard heights - public static final int KeyboardHeight_Reset = 0; // Zero value for constructor + public static final int KeyboardHeight_Reset = 0; // To reset to default, applyKeyboardHeight + public static final int KeyboardHeight_Invalid = -1; // If invalid orientation passed to functions public static int KeyboardHeight_Context_Portrait_Default = 0; // Default portrait height public static int KeyboardHeight_Context_Landscape_Default = 0; // Default landscape height From b43d8659898167523f4fd39f1a411ad701cf74a6 Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Fri, 28 Mar 2025 19:13:51 -0400 Subject: [PATCH 36/61] Update android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java Co-authored-by: Marc Durdin --- .../KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 9fb81aa04d..932b5d3d82 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -503,8 +503,8 @@ public final class KMManager { CloudDownloadMgr.getInstance().initialize(appContext); - KeyboardHeight_Context_Portrait_Default = getDefaultKeyboardHeight(context, Configuration.ORIENTATION_PORTRAIT); - KeyboardHeight_Context_Landscape_Default = getDefaultKeyboardHeight(context, Configuration.ORIENTATION_LANDSCAPE); + KeyboardHeight_Context_Portrait_Default = calculateDefaultKeyboardHeight(context, Configuration.ORIENTATION_PORTRAIT); + KeyboardHeight_Context_Landscape_Default = calculateDefaultKeyboardHeight(context, Configuration.ORIENTATION_LANDSCAPE); } public static void executeResourceUpdate(Context aContext) From ca0507e3d7c44b27cedec18089f15e52dbb02c20 Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Fri, 28 Mar 2025 19:14:22 -0400 Subject: [PATCH 37/61] Update android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java Co-authored-by: Marc Durdin --- .../KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 932b5d3d82..9be0eea0a3 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2235,6 +2235,10 @@ public final class KMManager { return getKeyboardHeight(context, orientation); } + /** + * Returns the current keyboard height in dp for the specified device + * orientation + */ public static int getKeyboardHeight(Context context, int orientation) { SharedPreferences prefs = context.getSharedPreferences(context.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE); if (orientation == Configuration.ORIENTATION_PORTRAIT) { From eaa42a4e83fb25731c65e3a0427e9667430109b4 Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Fri, 28 Mar 2025 19:14:41 -0400 Subject: [PATCH 38/61] Update android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java Co-authored-by: Marc Durdin --- android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 9be0eea0a3..11d41b863f 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2246,7 +2246,7 @@ public final class KMManager { } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { return prefs.getInt(KMManager.KMKey_KeyboardHeightLandscape, KMManager.KeyboardHeight_Context_Landscape_Default); } else { - return KMManager.KeyboardHeight_Reset; // Invalid orientation, return reset value + return KMManager.KeyboardHeight_Invalid; // Invalid orientation } } From 3637ddc7f980b14466c828a4024ea5de9d7110d7 Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Fri, 28 Mar 2025 19:15:12 -0400 Subject: [PATCH 39/61] Update android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java Co-authored-by: Marc Durdin --- .../KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 11d41b863f..b32e84d3bf 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2252,7 +2252,8 @@ public final class KMManager { /** * Apply the keyboard height for the current orientation and store it in SharedPreferences. - * If height is KMManager.KeyboardHeight_Reset, remove the stored height for that orientation. + * If height is KMManager.KeyboardHeight_Reset, remove the stored height for that + * orientation, resetting to the default height for the device/orientation. * @param context Context * @param height int - keyboard height in dp */ From 34ee802106f8cf4856f3d3e805ff4ea199f2d492 Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Fri, 28 Mar 2025 19:15:24 -0400 Subject: [PATCH 40/61] Update android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java Co-authored-by: Marc Durdin --- android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index b32e84d3bf..c0e8688549 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2263,7 +2263,7 @@ public final class KMManager { } /** - * Apply the keyboard height for the current orientation and store it in SharedPreferences. + * Apply the keyboard height for the specified orientation and store it in SharedPreferences. * If height is KMManager.KeyboardHeight_Reset, remove the stored height for that orientation. * @param context Context * @param height int - keyboard height in dp From 20eae1cfc9a590d06a13104fc72e5f7c42523b86 Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Fri, 28 Mar 2025 19:15:50 -0400 Subject: [PATCH 41/61] Update android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java Co-authored-by: Marc Durdin --- .../KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index c0e8688549..16f7e561fe 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2272,9 +2272,7 @@ public final class KMManager { public static void applyKeyboardHeight(Context context, int height, int orientation) { SharedPreferences prefs = context.getSharedPreferences("KMAPreferences", Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); - int defaultHeightForContext = orientation == Configuration.ORIENTATION_PORTRAIT - ? KeyboardHeight_Context_Portrait_Default - : KeyboardHeight_Context_Landscape_Default; + int defaultHeightForContext = getDefaultKeyboardHeight(orientation); if (orientation != Configuration.ORIENTATION_PORTRAIT && orientation != Configuration.ORIENTATION_LANDSCAPE) { return; // Invalid orientation, do nothing } From 1638b211150e1b5ef4b8c27f65c827952675c42c Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Fri, 28 Mar 2025 19:16:04 -0400 Subject: [PATCH 42/61] Update android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java Co-authored-by: Marc Durdin --- .../KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 16f7e561fe..89c9d5650b 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2313,6 +2313,10 @@ public final class KMManager { } } + /** + * Returns the default keyboard height in dp for the current device + * and orientation + */ public static int getDefaultKeyboardHeight(Context context) { int orientation = getOrientation(context); return getDefaultKeyboardHeight(context, orientation); From 7b32908721fe7a8d5c51acf52811ab8e8d7303b1 Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Fri, 28 Mar 2025 19:16:36 -0400 Subject: [PATCH 43/61] Update android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java Co-authored-by: Marc Durdin --- android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 89c9d5650b..397cd8fc45 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2319,7 +2319,7 @@ public final class KMManager { */ public static int getDefaultKeyboardHeight(Context context) { int orientation = getOrientation(context); - return getDefaultKeyboardHeight(context, orientation); + return getDefaultKeyboardHeight(orientation); } public static int getDefaultKeyboardHeight(Context context, int orientation) { From a010865a573c4fc58fd68d7c16759c9ad12a34aa Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Fri, 28 Mar 2025 19:17:21 -0400 Subject: [PATCH 44/61] Update android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java Co-authored-by: Marc Durdin --- .../main/java/com/keyman/engine/KMManager.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 397cd8fc45..4d1dfb3b02 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2322,7 +2322,21 @@ public final class KMManager { return getDefaultKeyboardHeight(orientation); } - public static int getDefaultKeyboardHeight(Context context, int orientation) { + /** + * Returns the current keyboard height in dp for the specified orientation + * for the current device + */ + public static int getDefaultKeyboardHeight(int orientation) { + if (orientation == Configuration.ORIENTATION_PORTRAIT) { + return KMManager.KeyboardHeight_Context_Portrait_Default; + } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { + return KMManager.KeyboardHeight_Context_Landscape_Default; + } else { + return KMManager.KeyboardHeight_Invalid; // Invalid orientation + } + } + + private static int calculateDefaultKeyboardHeight(Context context, int orientation) { if (isTestMode()) { // Keyboard height not needed for unit tests #13578 return KeyboardHeight_Context_Portrait_Default; From 49c83f5f84a647603844d7ecc0711059795b350a Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Fri, 28 Mar 2025 19:17:54 -0400 Subject: [PATCH 45/61] Update android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java Co-authored-by: Marc Durdin --- android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 4d1dfb3b02..1c129c4d73 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2339,7 +2339,7 @@ public final class KMManager { private static int calculateDefaultKeyboardHeight(Context context, int orientation) { if (isTestMode()) { // Keyboard height not needed for unit tests #13578 - return KeyboardHeight_Context_Portrait_Default; + return 0; } if (orientation != Configuration.ORIENTATION_PORTRAIT && orientation != Configuration.ORIENTATION_LANDSCAPE) { return KeyboardHeight_Reset; // Invalid orientation, return reset value From be4f97e3283b84f4d213bc36ad00b5a6fd879337 Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Fri, 28 Mar 2025 19:21:04 -0400 Subject: [PATCH 46/61] Update android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java Co-authored-by: Marc Durdin --- android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 1c129c4d73..52a3dd3d63 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2342,7 +2342,7 @@ public final class KMManager { return 0; } if (orientation != Configuration.ORIENTATION_PORTRAIT && orientation != Configuration.ORIENTATION_LANDSCAPE) { - return KeyboardHeight_Reset; // Invalid orientation, return reset value + return KeyboardHeight_Invalid; // Invalid orientation } Resources resources = context.getResources(); Configuration originalConfig = resources.getConfiguration(); From 61ec797597e79200402f8bd439b6b981f42c0f90 Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Fri, 28 Mar 2025 19:22:13 -0400 Subject: [PATCH 47/61] Update android/docs/engine/KMManager/getKeyboardHeight.md Co-authored-by: Marc Durdin --- android/docs/engine/KMManager/getKeyboardHeight.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/docs/engine/KMManager/getKeyboardHeight.md b/android/docs/engine/KMManager/getKeyboardHeight.md index 5a8efc052f..036e886796 100644 --- a/android/docs/engine/KMManager/getKeyboardHeight.md +++ b/android/docs/engine/KMManager/getKeyboardHeight.md @@ -23,7 +23,7 @@ KMManager.getKeyboardHeight(Context context, int orientation) : The context. `orientation` _(Optional)_ -: Accepts a [screen orientation](https://developer.android.com/training/multiscreen/screensizes#TaskUseOriQuali) value. This is most useful if you want to get the size of the keyboard in the other (non-current) orientation. If `orientation` is not defined, keyboard height is returned for the current device orientation. +: Accepts a [screen orientation](https://developer.android.com/training/multiscreen/screensizes#TaskUseOriQuali) value. This is most useful if you want to get the size of the keyboard in the other (non-current) orientation. If `orientation` parameter is not passed in, keyboard height is returned for the current device orientation. ### Returns From 776bb381ff51b848661defc9ec2e638ae411660b Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Fri, 28 Mar 2025 20:19:45 -0400 Subject: [PATCH 48/61] Docs for getDefaultKeyboardHeight() --- .../KMManager/getDefaultKeyboardHeight.md | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 android/docs/engine/KMManager/getDefaultKeyboardHeight.md diff --git a/android/docs/engine/KMManager/getDefaultKeyboardHeight.md b/android/docs/engine/KMManager/getDefaultKeyboardHeight.md new file mode 100644 index 0000000000..56705cae7b --- /dev/null +++ b/android/docs/engine/KMManager/getDefaultKeyboardHeight.md @@ -0,0 +1,55 @@ +--- +title: KMManager.getDefaultKeyboardHeight() +--- + +## Summary + +The **`getDefaultKeyboardHeight()`** method returns the default height of the keyboard frame for the current or specefied orientation. + +## Syntax + +``` javascript +KMManager.getDefaultKeyboardHeight(Context context) +``` +or +``` javascript +KMManager.getDefaultKeyboardHeight(int orientation) +``` + +### Parameters (Choose One) + +`context` _(Alternate)_ +: The context. + +`orientation` _(Alternate)_ +: Accepts a [screen orientation](https://developer.android.com/training/multiscreen/screensizes#TaskUseOriQuali) value. This is most useful if you want to get the size of the keyboard in the other (non-current) orientation. If `orientation` parameter is not passed in, keyboard height is returned for the current device orientation. + +### Returns + +Returns the default height of the keyboard frame in *density-independent pixels (dp)*. + +## Description + +Use this method to get the default height of the keyboard frame. + +## Examples + +### Example: Using `getDefaultKeyboardHeight()` + +The following script illustrate the use of `getDefaultKeyboardHeight()`: + +``` javascript + int keyboardHeight = KMManager.getDefaultKeyboardHeight(this); +``` +or +```java + import android.content.res.Configuration; + ... + // Get the current Keyman keyboard height for landscape mode. + + int keyboardHeightLandscape = KMManager.getDefaultKeyboardHeight( Configuration.ORIENTATION_LANDSCAPE); +``` + +## See also + +- [applyKeyboardHeight()](applyKeyboardHeight) From 527f8e0d7a543cb638236c623832cff5e852e07a Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Fri, 28 Mar 2025 21:01:30 -0400 Subject: [PATCH 49/61] Current Height Refactor Avoiding multiple calls to system prefs. --- .../src/main/java/com/keyman/engine/KMManager.java | 12 +++++++++--- android/docs/engine/KMManager/getKeyboardHeight.md | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 52a3dd3d63..2b373795aa 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -348,6 +348,8 @@ public final class KMManager { public static final int KeyboardHeight_Invalid = -1; // If invalid orientation passed to functions public static int KeyboardHeight_Context_Portrait_Default = 0; // Default portrait height public static int KeyboardHeight_Context_Landscape_Default = 0; // Default landscape height + public static int KeyboardHeight_Context_Portrait_Current = 0; // Current portrait height + public static int KeyboardHeight_Context_Landscape_Current = 0; // Current landscape height // Default prediction/correction setting public static final int KMDefault_Suggestion = SuggestionType.PREDICTIONS_WITH_CORRECTIONS.toInt(); @@ -504,7 +506,11 @@ public final class KMManager { CloudDownloadMgr.getInstance().initialize(appContext); KeyboardHeight_Context_Portrait_Default = calculateDefaultKeyboardHeight(context, Configuration.ORIENTATION_PORTRAIT); - KeyboardHeight_Context_Landscape_Default = calculateDefaultKeyboardHeight(context, Configuration.ORIENTATION_LANDSCAPE); + KeyboardHeight_Context_Landscape_Default = calculateDefaultKeyboardHeight(context, Configuration.ORIENTATION_LANDSCAPE); + SharedPreferences prefs = context.getSharedPreferences(context.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE); + KeyboardHeight_Context_Portrait_Current = prefs.getInt(KMManager.KMKey_KeyboardHeightPortrait, KMManager.KeyboardHeight_Context_Portrait_Default); + KeyboardHeight_Context_Landscape_Current = prefs.getInt(KMManager.KMKey_KeyboardHeightLandscape, KMManager.KeyboardHeight_Context_Landscape_Default); + } public static void executeResourceUpdate(Context aContext) @@ -2242,9 +2248,9 @@ public final class KMManager { public static int getKeyboardHeight(Context context, int orientation) { SharedPreferences prefs = context.getSharedPreferences(context.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE); if (orientation == Configuration.ORIENTATION_PORTRAIT) { - return prefs.getInt(KMManager.KMKey_KeyboardHeightPortrait, KMManager.KeyboardHeight_Context_Portrait_Default); + return KMManager.KeyboardHeight_Context_Portrait_Current; } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { - return prefs.getInt(KMManager.KMKey_KeyboardHeightLandscape, KMManager.KeyboardHeight_Context_Landscape_Default); + return KMManager.KeyboardHeight_Context_Landscape_Current; } else { return KMManager.KeyboardHeight_Invalid; // Invalid orientation } diff --git a/android/docs/engine/KMManager/getKeyboardHeight.md b/android/docs/engine/KMManager/getKeyboardHeight.md index 036e886796..fb8efb2b96 100644 --- a/android/docs/engine/KMManager/getKeyboardHeight.md +++ b/android/docs/engine/KMManager/getKeyboardHeight.md @@ -54,4 +54,4 @@ or ## See also -- [applyKeyboardHeight](applyKeyboardHeight) +- [applyKeyboardHeight()](applyKeyboardHeight) From fa65ccb90172ca07bba47464c05c012e1240b6ab Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Mon, 31 Mar 2025 11:54:40 -0400 Subject: [PATCH 50/61] Making KMEngine_PrefsKey a constant. --- .../main/java/com/keyman/engine/KMManager.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 2b373795aa..2f16f94ce3 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -271,6 +271,8 @@ public final class KMManager { // will be blocked. private static boolean maySendCrashReport = true; + private final static String KMEngine_PrefsKey = "KMAPreferences"; + // Keyman public keys public static final String KMKey_ID = "id"; public static final String KMKey_Name = "name"; @@ -507,7 +509,7 @@ public final class KMManager { KeyboardHeight_Context_Portrait_Default = calculateDefaultKeyboardHeight(context, Configuration.ORIENTATION_PORTRAIT); KeyboardHeight_Context_Landscape_Default = calculateDefaultKeyboardHeight(context, Configuration.ORIENTATION_LANDSCAPE); - SharedPreferences prefs = context.getSharedPreferences(context.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE); + SharedPreferences prefs = context.getSharedPreferences(KMManager.KMEngine_PrefsKey, Context.MODE_PRIVATE); KeyboardHeight_Context_Portrait_Current = prefs.getInt(KMManager.KMKey_KeyboardHeightPortrait, KMManager.KeyboardHeight_Context_Portrait_Default); KeyboardHeight_Context_Landscape_Current = prefs.getInt(KMManager.KMKey_KeyboardHeightLandscape, KMManager.KeyboardHeight_Context_Landscape_Default); @@ -1452,7 +1454,7 @@ public final class KMManager { * @param suggestType SuggestionType */ public static void setMaySuggest(String languageID, SuggestionType suggestType) { - SharedPreferences prefs = appContext.getSharedPreferences(appContext.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE); + SharedPreferences prefs = appContext.getSharedPreferences(KMManager.KMEngine_PrefsKey, Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); editor.putInt(KMManager.getLanguageAutoCorrectionPreferenceKey(languageID), suggestType.toInt()); editor.commit(); @@ -1571,7 +1573,7 @@ public final class KMManager { model = model.replaceAll("\"", "'"); // When entering password field, maySuggest should override to disabled - SharedPreferences prefs = appContext.getSharedPreferences(appContext.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE); + SharedPreferences prefs = appContext.getSharedPreferences(KMManager.KMEngine_PrefsKey, Context.MODE_PRIVATE); int maySuggest = mayPredictOverride ? SuggestionType.SUGGESTIONS_DISABLED.toInt() : prefs.getInt(getLanguageAutoCorrectionPreferenceKey(languageID), KMDefault_Suggestion); @@ -2180,7 +2182,7 @@ public final class KMManager { */ public static int getLongpressDelay() { SharedPreferences prefs = appContext.getSharedPreferences( - appContext.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE); + KMManager.KMEngine_PrefsKey, Context.MODE_PRIVATE); return prefs.getInt(KMKey_LongpressDelay, KMDefault_LongpressDelay); } @@ -2197,7 +2199,7 @@ public final class KMManager { } SharedPreferences prefs = appContext.getSharedPreferences( - appContext.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE); + KMManager.KMEngine_PrefsKey, Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); editor.putInt(KMKey_LongpressDelay, longpressDelay); editor.commit(); @@ -2246,7 +2248,7 @@ public final class KMManager { * orientation */ public static int getKeyboardHeight(Context context, int orientation) { - SharedPreferences prefs = context.getSharedPreferences(context.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE); + SharedPreferences prefs = context.getSharedPreferences(KMManager.KMEngine_PrefsKey, Context.MODE_PRIVATE); if (orientation == Configuration.ORIENTATION_PORTRAIT) { return KMManager.KeyboardHeight_Context_Portrait_Current; } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { @@ -2394,7 +2396,7 @@ public final class KMManager { } protected static void setPersistentShouldShowHelpBubble(boolean flag) { - SharedPreferences prefs = appContext.getSharedPreferences(appContext.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE); + SharedPreferences prefs = appContext.getSharedPreferences(KMManager.KMEngine_PrefsKey, Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean(KMManager.KMKey_ShouldShowHelpBubble, flag); editor.commit(); From 99033cf1ec313eb862bcf648ce5e6ed8360ca4a5 Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Mon, 31 Mar 2025 12:00:50 -0400 Subject: [PATCH 51/61] Update android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java Co-authored-by: Marc Durdin --- .../java/com/keyman/engine/KMManager.java | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 2f16f94ce3..e3390ed390 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2344,27 +2344,28 @@ public final class KMManager { } } - private static int calculateDefaultKeyboardHeight(Context context, int orientation) { + private static void calculateDefaultKeyboardHeights(Context context, int orientation) { if (isTestMode()) { // Keyboard height not needed for unit tests #13578 - return 0; - } - if (orientation != Configuration.ORIENTATION_PORTRAIT && orientation != Configuration.ORIENTATION_LANDSCAPE) { - return KeyboardHeight_Invalid; // Invalid orientation - } + KeyboardHeight_Context_Portrait_Default = 0; + KeyboardHeight_Context_Landscape_Default = 0; + return; + } + Resources resources = context.getResources(); Configuration originalConfig = resources.getConfiguration(); - Configuration newConfig = new Configuration(originalConfig); - newConfig.orientation = orientation; - // Create a new context with the updated configuration + Configuration newConfig = new Configuration(originalConfig); + newConfig.orientation = Configuration.ORIENTATION_PORTRAIT; Context newContext = context.createConfigurationContext(newConfig); Resources newResources = newContext.getResources(); + KeyboardHeight_Context_Portrait_Default = (int) newResources.getDimension(R.dimen.keyboard_height); - // Get the default keyboard height for the new orientation - int defaultHeight = (int) newResources.getDimension(R.dimen.keyboard_height); - - return defaultHeight; + newConfig = new Configuration(originalConfig); + newConfig.orientation = Configuration.ORIENTATION_LANDSCAPE; + newContext = context.createConfigurationContext(newConfig); + newResources = newContext.getResources(); + KeyboardHeight_Context_Landscape_Default = (int) newResources.getDimension(R.dimen.keyboard_height); } /** From 7b16d81eaf8a2445cb9f172ab510795f780705e8 Mon Sep 17 00:00:00 2001 From: Keyman Build Agent Date: Mon, 31 Mar 2025 14:01:07 -0400 Subject: [PATCH 52/61] auto: increment master version to 19.0.20 --- HISTORY.md | 4 ++++ VERSION.md | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index dc0b6a7594..74ad0f284b 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,9 @@ # Keyman Version History +## 19.0.19 alpha 2025-03-31 + +* chore: merge beta to master B18S4 (#13606) + ## 19.0.18 alpha 2025-03-25 * chore(developer): improve ldml code coverage (#13516) diff --git a/VERSION.md b/VERSION.md index 9dcade37d9..e2ac71704b 100644 --- a/VERSION.md +++ b/VERSION.md @@ -1 +1 @@ -19.0.19 +19.0.20 \ No newline at end of file From 54d6f374d9d9007df5028158ef9bb133f59be104 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Tue, 1 Apr 2025 01:05:51 +0200 Subject: [PATCH 53/61] chore(android): use constant instead of string --- android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index fe68c487f5..d079283b15 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -2327,7 +2327,7 @@ public final class KMManager { * @param orientation int - Configuration.ORIENTATION_PORTRAIT or Configuration.ORIENTATION_LANDSCAPE */ public static void applyKeyboardHeight(Context context, int height, int orientation) { - SharedPreferences prefs = context.getSharedPreferences("KMAPreferences", Context.MODE_PRIVATE); + SharedPreferences prefs = context.getSharedPreferences(KMManager.KMEngine_PrefsKey, Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); int defaultHeightForContext = getDefaultKeyboardHeight(orientation); if (orientation != Configuration.ORIENTATION_PORTRAIT && orientation != Configuration.ORIENTATION_LANDSCAPE) { From 7999677cd60c48217133d001819d4d5af989447c Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Tue, 1 Apr 2025 08:48:13 +0200 Subject: [PATCH 54/61] Apply suggestions from code review --- .../KMEA/app/src/main/java/com/keyman/engine/KMManager.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index d079283b15..95a99d635b 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -510,8 +510,7 @@ public final class KMManager { CloudDownloadMgr.getInstance().initialize(appContext); - KeyboardHeight_Context_Portrait_Default = calculateDefaultKeyboardHeight(context, Configuration.ORIENTATION_PORTRAIT); - KeyboardHeight_Context_Landscape_Default = calculateDefaultKeyboardHeight(context, Configuration.ORIENTATION_LANDSCAPE); + calculateDefaultKeyboardHeights(context); SharedPreferences prefs = context.getSharedPreferences(KMManager.KMEngine_PrefsKey, Context.MODE_PRIVATE); KeyboardHeight_Context_Portrait_Current = prefs.getInt(KMManager.KMKey_KeyboardHeightPortrait, KMManager.KeyboardHeight_Context_Portrait_Default); KeyboardHeight_Context_Landscape_Current = prefs.getInt(KMManager.KMKey_KeyboardHeightLandscape, KMManager.KeyboardHeight_Context_Landscape_Default); @@ -2393,7 +2392,7 @@ public final class KMManager { } } - private static void calculateDefaultKeyboardHeights(Context context, int orientation) { + private static void calculateDefaultKeyboardHeights(Context context) { if (isTestMode()) { // Keyboard height not needed for unit tests #13578 KeyboardHeight_Context_Portrait_Default = 0; From 724613cc8f4eb062609b41c5fc4c5f81d3ea886f Mon Sep 17 00:00:00 2001 From: Keyman Build Agent Date: Tue, 1 Apr 2025 14:01:24 -0400 Subject: [PATCH 55/61] auto: increment master version to 19.0.21 --- HISTORY.md | 4 ++++ VERSION.md | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 74ad0f284b..ea82962795 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,9 @@ # Keyman Version History +## 19.0.20 alpha 2025-04-01 + +* fix(android): move responsibility for setting keyboard height preference into `applyKeyboardHeight()` (#13578) + ## 19.0.19 alpha 2025-03-31 * chore: merge beta to master B18S4 (#13606) diff --git a/VERSION.md b/VERSION.md index e2ac71704b..13ec463b7b 100644 --- a/VERSION.md +++ b/VERSION.md @@ -1 +1 @@ -19.0.20 \ No newline at end of file +19.0.21 \ No newline at end of file From ac6eb0b76775ebd8e273d3fd6c8ec4187eddffbc Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Thu, 3 Apr 2025 07:58:15 +0700 Subject: [PATCH 56/61] chore: use explicit `node:` prefix for node imports This makes it easier for us to enumerate modules that have node dependencies. There may be others I have not yet picked up. --- common/tools/hextobin/index.ts | 4 ++-- common/tools/sourcemap-path-remapper/src/index.ts | 4 ++-- core/tools/api-header-extractor/src/index.ts | 4 ++-- .../src/common/web/test-helpers/TestCompilerCallbacks.ts | 4 ++-- developer/src/common/web/utils/test/helpers/index.ts | 6 +++--- .../src/kmc-model/tools/create-override-script-regexp.ts | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/common/tools/hextobin/index.ts b/common/tools/hextobin/index.ts index b53b2d734a..168ccb0539 100644 --- a/common/tools/hextobin/index.ts +++ b/common/tools/hextobin/index.ts @@ -1,5 +1,5 @@ -import * as fs from 'fs'; -import * as rd from 'readline'; +import * as fs from 'node:fs'; +import * as rd from 'node:readline'; export default async function hextobin(inputFilename: string, outputFilename?: string, options?: {silent?: boolean}): Promise { diff --git a/common/tools/sourcemap-path-remapper/src/index.ts b/common/tools/sourcemap-path-remapper/src/index.ts index fca96c3b14..af1f184698 100644 --- a/common/tools/sourcemap-path-remapper/src/index.ts +++ b/common/tools/sourcemap-path-remapper/src/index.ts @@ -1,5 +1,5 @@ -import * as fs from 'fs'; -import path from 'path'; +import * as fs from 'node:fs'; +import path from 'node:path'; import convertSourceMap from 'convert-source-map'; // Transforms sourcemaps among various common formats. // Base64, stringified-JSON, end-of-file comment... diff --git a/core/tools/api-header-extractor/src/index.ts b/core/tools/api-header-extractor/src/index.ts index e0c6cab918..76498044df 100644 --- a/core/tools/api-header-extractor/src/index.ts +++ b/core/tools/api-header-extractor/src/index.ts @@ -1,5 +1,5 @@ -import * as fs from 'fs'; -import * as path from 'path'; +import * as fs from 'node:fs'; +import * as path from 'node:path'; // TODO: support multiple infiles to generate from multiple headers diff --git a/developer/src/common/web/test-helpers/TestCompilerCallbacks.ts b/developer/src/common/web/test-helpers/TestCompilerCallbacks.ts index fad1dd646f..04e5734f18 100644 --- a/developer/src/common/web/test-helpers/TestCompilerCallbacks.ts +++ b/developer/src/common/web/test-helpers/TestCompilerCallbacks.ts @@ -1,5 +1,5 @@ -import * as fs from 'fs'; -import * as path from 'path'; +import * as fs from 'node:fs'; +import * as path from 'node:path'; import { CompilerEvent, CompilerCallbacks, CompilerPathCallbacks, CompilerFileSystemCallbacks, CompilerError, CompilerNetAsyncCallbacks, DefaultCompilerFileSystemAsyncCallbacks, CompilerFileSystemAsyncCallbacks, diff --git a/developer/src/common/web/utils/test/helpers/index.ts b/developer/src/common/web/utils/test/helpers/index.ts index e36d07429b..25fd6856c7 100644 --- a/developer/src/common/web/utils/test/helpers/index.ts +++ b/developer/src/common/web/utils/test/helpers/index.ts @@ -1,9 +1,9 @@ /** * Helpers and utilities for the Mocha tests. */ -import * as path from 'path'; -import * as fs from "fs"; -import { fileURLToPath } from 'url'; +import * as path from 'node:path'; +import * as fs from "node:fs"; +import { fileURLToPath } from 'node:url'; /** * Builds a path to the fixture with the given path components. diff --git a/developer/src/kmc-model/tools/create-override-script-regexp.ts b/developer/src/kmc-model/tools/create-override-script-regexp.ts index 38f6ade0a6..63c39aeea5 100644 --- a/developer/src/kmc-model/tools/create-override-script-regexp.ts +++ b/developer/src/kmc-model/tools/create-override-script-regexp.ts @@ -9,8 +9,8 @@ * If you need to add more Unicode blocks, customize SPACELESS_SCRIPT_BLOCKS. */ -import {readFileSync} from "fs"; -import * as path from "path"; +import {readFileSync} from "node:fs"; +import * as path from "node:path"; // Where to find UnicodeData.txt and Blocks.txt const UCD_DIR = path.join("..", "..", "..", "..", "resources", "standards-data", "unicode-character-database"); From cafa5031245af2c8833d9d5a344d56b36052f537 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Thu, 3 Apr 2025 08:10:50 +0700 Subject: [PATCH 57/61] chore: use explicit `node:` prefix on more module imports --- resources/build/version/src/fixupHistory.ts | 2 +- resources/build/version/src/incrementVersion.ts | 4 ++-- resources/build/version/src/index.ts | 2 +- .../keyboard-storage/src/nodeCloudRequester.ts | 6 +++--- .../wordbreakers/tools/data-compiler/index.ts | 4 ++-- .../worker-main/src/node/mappedWorker.ts | 12 ++++++------ web/src/tools/building/sourcemap-root/index.ts | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/resources/build/version/src/fixupHistory.ts b/resources/build/version/src/fixupHistory.ts index 1d6a290957..884e9c5557 100644 --- a/resources/build/version/src/fixupHistory.ts +++ b/resources/build/version/src/fixupHistory.ts @@ -3,7 +3,7 @@ import { } from '@actions/core'; import { GitHub } from '@actions/github'; -import { readFileSync, writeFileSync } from 'fs'; +import { readFileSync, writeFileSync } from 'node:fs'; import { gt } from 'semver'; import { reportHistory } from './reportHistory.js'; import { spawnChild } from './util/spawnAwait.js'; diff --git a/resources/build/version/src/incrementVersion.ts b/resources/build/version/src/incrementVersion.ts index 6183b7f9c4..2d7ea67ab6 100644 --- a/resources/build/version/src/incrementVersion.ts +++ b/resources/build/version/src/incrementVersion.ts @@ -1,11 +1,11 @@ -import { readFileSync, writeFileSync } from 'fs'; +import { readFileSync, writeFileSync } from 'node:fs'; // ------------------------------------------------------------------------------------ // incrementVersion // ------------------------------------------------------------------------------------ export const incrementVersion = () => { - // 1. + // 1. const version = readFileSync('./VERSION.md', 'utf8'); const triplet = version.split('.'); const patch = parseInt(triplet[2], 10) + 1; diff --git a/resources/build/version/src/index.ts b/resources/build/version/src/index.ts index ea0b12e7e7..f1fb2cc6a0 100644 --- a/resources/build/version/src/index.ts +++ b/resources/build/version/src/index.ts @@ -5,7 +5,7 @@ import { sendCommentToPullRequestAndRelatedIssues, fixupHistory } from './fixupH import { incrementVersion } from './incrementVersion.js'; import yargs from 'yargs'; import { hideBin } from 'yargs/helpers'; -import { readFileSync } from 'fs'; +import { readFileSync } from 'node:fs'; import { reportHistory } from './reportHistory.js'; const argv = await yargs(hideBin(process.argv)) diff --git a/web/src/engine/keyboard-storage/src/nodeCloudRequester.ts b/web/src/engine/keyboard-storage/src/nodeCloudRequester.ts index e8461ff20d..334cc570cf 100644 --- a/web/src/engine/keyboard-storage/src/nodeCloudRequester.ts +++ b/web/src/engine/keyboard-storage/src/nodeCloudRequester.ts @@ -7,9 +7,9 @@ import { default as CloudQueryEngine } from './cloud/queryEngine.js'; -import fs from 'fs'; -import https from 'https'; -import vm from 'vm'; +import fs from 'node:fs'; +import https from 'node:https'; +import vm from 'node:vm'; export default class NodeCloudRequester implements CloudRequesterInterface { private static QUERY_SEED = 1; diff --git a/web/src/engine/predictive-text/wordbreakers/tools/data-compiler/index.ts b/web/src/engine/predictive-text/wordbreakers/tools/data-compiler/index.ts index 7feb16e5b1..15ca018fd4 100644 --- a/web/src/engine/predictive-text/wordbreakers/tools/data-compiler/index.ts +++ b/web/src/engine/predictive-text/wordbreakers/tools/data-compiler/index.ts @@ -2,8 +2,8 @@ // Original version found at: https://github.com/eddieantonio/unicode-default-word-boundary/blob/master/libexec/compile-word-break.js -import fs from 'fs'; -import path from 'path'; +import fs from 'node:fs'; +import path from 'node:path'; import { createRequire } from 'module'; const require = createRequire(import.meta.url); diff --git a/web/src/engine/predictive-text/worker-main/src/node/mappedWorker.ts b/web/src/engine/predictive-text/worker-main/src/node/mappedWorker.ts index aafbba5232..d588a19562 100644 --- a/web/src/engine/predictive-text/worker-main/src/node/mappedWorker.ts +++ b/web/src/engine/predictive-text/worker-main/src/node/mappedWorker.ts @@ -3,17 +3,17 @@ /// // Defines types related to Node workers. -import * as worker from 'worker_threads'; -import { Buffer } from 'buffer'; -import { URL } from 'url'; +import * as worker from 'node:worker_threads'; +import { Buffer } from 'node:buffer'; +import { URL } from 'node:url'; /** * Defines mappings from Node Worker signatures to WebWorker signatures */ const nodeWorkerToWebWorkerMappingSource = ` -import { parentPort } from 'worker_threads'; -import fs from 'fs'; -import vm from 'vm'; +import { parentPort } from 'node:worker_threads'; +import fs from 'node:fs'; +import vm from 'node:vm'; function postMessage(...args) { parentPort.postMessage.call(parentPort, args); diff --git a/web/src/tools/building/sourcemap-root/index.ts b/web/src/tools/building/sourcemap-root/index.ts index c99c0c4e5c..9f87f2cae5 100644 --- a/web/src/tools/building/sourcemap-root/index.ts +++ b/web/src/tools/building/sourcemap-root/index.ts @@ -1,7 +1,7 @@ import SourcemapRemapper from "@keymanapp/sourcemap-path-remapper" import convertSourceMap from 'convert-source-map'; // Transforms sourcemaps among various common formats. // Base64, stringified-JSON, end-of-file comment... -import fs from 'fs'; +import fs from 'node:fs'; function displayHelp() { console.log("KeymanWeb's sourcemap-cleansing tool. This tool is designed to produce clean filepaths"); From 70838ff1ac16eefd91d933c0982232e2f891b4aa Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Thu, 3 Apr 2025 09:23:58 +0700 Subject: [PATCH 58/61] refactor(developer): rename to developer-utils-messages.ts Renames common-messages.ts to developer-utils-messages.ts. This was split from /common/web/types, but the messages module retained the old name, which was confusing (two modules with same name). --- .../web/utils/src/compiler-interfaces.ts | 5 +++-- ...messages.ts => developer-utils-messages.ts} | 14 +++++++------- developer/src/common/web/utils/src/index.ts | 2 +- .../web/utils/src/types/kps/kps-file-reader.ts | 4 ++-- .../ldml-keyboard/ldml-keyboard-xml-reader.ts | 18 +++++++++--------- .../utils/test/kps/kps-file-reader.tests.ts | 4 ++-- .../ldml/ldml-keyboard-xml-reader.tests.ts | 16 ++++++++-------- .../src/compiler/package-compiler-messages.ts | 4 ++-- .../src/kmc/src/messages/messageNamespaces.ts | 6 +++--- 9 files changed, 37 insertions(+), 36 deletions(-) rename developer/src/common/web/utils/src/{common-messages.ts => developer-utils-messages.ts} (86%) diff --git a/developer/src/common/web/utils/src/compiler-interfaces.ts b/developer/src/common/web/utils/src/compiler-interfaces.ts index 869e0165da..18b93d9c88 100644 --- a/developer/src/common/web/utils/src/compiler-interfaces.ts +++ b/developer/src/common/web/utils/src/compiler-interfaces.ts @@ -233,9 +233,10 @@ export enum CompilerErrorNamespace { */ LdmlKeyboardCompiler = 0x0000, /** - * common/web/types errors between 0x1000…0x1FFF + * common/web/utils errors between 0x1000…0x1FFF + * was previously called CommonTypes */ - CommonTypes = 0x1000, + DeveloperUtils = 0x1000, /** * kmc-kmn errors between 0x2000…0x2FFF; these map to * the base codes found in kmn_compiler_errors.h, exclusive severity flags diff --git a/developer/src/common/web/utils/src/common-messages.ts b/developer/src/common/web/utils/src/developer-utils-messages.ts similarity index 86% rename from developer/src/common/web/utils/src/common-messages.ts rename to developer/src/common/web/utils/src/developer-utils-messages.ts index 6eca08d37c..eb69e42385 100644 --- a/developer/src/common/web/utils/src/common-messages.ts +++ b/developer/src/common/web/utils/src/developer-utils-messages.ts @@ -4,14 +4,14 @@ import { CompilerErrorNamespace, CompilerErrorSeverity, CompilerMessageDef as def, CompilerMessageSpec as m } from './compiler-interfaces.js'; import { constants } from '@keymanapp/ldml-keyboard-constants'; -const CommonTypesErrMask = CompilerErrorNamespace.CommonTypes; -// const SevInfo = CompilerErrorSeverity.Info | CommonTypesErrMask; -// const SevHint = CompilerErrorSeverity.Hint | CommonTypesErrMask; -// const SevWarn = CompilerErrorSeverity.Warn | CommonTypesErrMask; -const SevError = CompilerErrorSeverity.Error | CommonTypesErrMask; -// const SevFatal = CompilerErrorSeverity.Fatal | CommonTypesErrMask; +const DeveloperUtilsErrMask = CompilerErrorNamespace.DeveloperUtils; +// const SevInfo = CompilerErrorSeverity.Info | DeveloperUtilsErrMask; +// const SevHint = CompilerErrorSeverity.Hint | DeveloperUtilsErrMask; +// const SevWarn = CompilerErrorSeverity.Warn | DeveloperUtilsErrMask; +const SevError = CompilerErrorSeverity.Error | DeveloperUtilsErrMask; +// const SevFatal = CompilerErrorSeverity.Fatal | DeveloperUtilsErrMask; -export class CommonTypesMessages { +export class DeveloperUtilsMessages { // structured Ajv validation error static ERROR_SchemaValidationError = SevError | 0x0001; static Error_SchemaValidationError = (o:{instancePath:string, keyword:string, message: string, params: string}) => m(this.ERROR_SchemaValidationError, diff --git a/developer/src/common/web/utils/src/index.ts b/developer/src/common/web/utils/src/index.ts index f3e23e79f2..5a435a577e 100644 --- a/developer/src/common/web/utils/src/index.ts +++ b/developer/src/common/web/utils/src/index.ts @@ -63,7 +63,7 @@ export { defaultCompilerOptions, CompilerBaseOptions, CompilerOptions, CompilerE export { UrlSubpathCompilerCallback } from './utils/UrlSubpathCompilerCallback.js'; -export { CommonTypesMessages } from './common-messages.js'; +export { DeveloperUtilsMessages } from './developer-utils-messages.js'; export * as SourceFilenamePatterns from './source-filename-patterns.js'; export { KeymanXMLType, KeymanXMLWriter, KeymanXMLReader } from './xml-utils.js'; diff --git a/developer/src/common/web/utils/src/types/kps/kps-file-reader.ts b/developer/src/common/web/utils/src/types/kps/kps-file-reader.ts index 73f2280ebc..c41a30ebb4 100644 --- a/developer/src/common/web/utils/src/types/kps/kps-file-reader.ts +++ b/developer/src/common/web/utils/src/types/kps/kps-file-reader.ts @@ -9,7 +9,7 @@ import { util } from '@keymanapp/common-types'; import boxXmlArray = util.boxXmlArray; -import { CommonTypesMessages } from "../../common-messages.js"; +import { DeveloperUtilsMessages } from "../../developer-utils-messages.js"; import { CompilerCallbacks } from "../../compiler-callbacks.js"; import { KeymanXMLReader } from "../../xml-utils.js"; import { KpsPackage } from "./kps-file.js"; @@ -29,7 +29,7 @@ export class KpsFileReader { a = new KeymanXMLReader('kps') .parse(data) as KpsPackage; } catch(e) { - this.callbacks.reportMessage(CommonTypesMessages.Error_InvalidPackageFile({e})); + this.callbacks.reportMessage(DeveloperUtilsMessages.Error_InvalidPackageFile({e})); } return a; })(); diff --git a/developer/src/common/web/utils/src/types/ldml-keyboard/ldml-keyboard-xml-reader.ts b/developer/src/common/web/utils/src/types/ldml-keyboard/ldml-keyboard-xml-reader.ts index 0a5abf6355..c8bbbe40dd 100644 --- a/developer/src/common/web/utils/src/types/ldml-keyboard/ldml-keyboard-xml-reader.ts +++ b/developer/src/common/web/utils/src/types/ldml-keyboard/ldml-keyboard-xml-reader.ts @@ -4,7 +4,7 @@ * Reads a LDML XML keyboard file into JS object tree and resolves imports */ import { SchemaValidators, util } from '@keymanapp/common-types'; -import { CommonTypesMessages } from '../../common-messages.js'; +import { DeveloperUtilsMessages } from '../../developer-utils-messages.js'; import { CompilerCallbacks } from "../../compiler-callbacks.js"; import { LDMLKeyboardXMLSourceFile, LKImport, ImportStatus } from './ldml-keyboard-xml.js'; import { constants } from '@keymanapp/ldml-keyboard-constants'; @@ -219,7 +219,7 @@ export class LDMLKeyboardXMLSourceFileReader { const { base, path } = asImport; // If base is not an empty string (or null/undefined), then it must be 'cldr' if (base && base !== constants.cldr_import_base) { - this.callbacks.reportMessage(CommonTypesMessages.Error_ImportInvalidBase({base, path, subtag})); + this.callbacks.reportMessage(DeveloperUtilsMessages.Error_ImportInvalidBase({base, path, subtag})); return false; } let importData: Uint8Array; @@ -228,7 +228,7 @@ export class LDMLKeyboardXMLSourceFileReader { // CLDR import const paths = path.split('/'); if (paths[0] == '' || paths[1] == '' || paths.length !== 2) { - this.callbacks.reportMessage(CommonTypesMessages.Error_ImportInvalidPath({base, path, subtag})); + this.callbacks.reportMessage(DeveloperUtilsMessages.Error_ImportInvalidPath({base, path, subtag})); return false; } if (constants.treatAsLatest(paths[0])) { @@ -241,7 +241,7 @@ export class LDMLKeyboardXMLSourceFileReader { importData = this.readLocalImportFile(path); } if (!importData || !importData.length) { - this.callbacks.reportMessage(CommonTypesMessages.Error_ImportReadFail({base, path, subtag})); + this.callbacks.reportMessage(DeveloperUtilsMessages.Error_ImportReadFail({base, path, subtag})); return false; } const importXml: any = this.loadUnboxed(importData); // TODO-LDML: have to load as any because it is an arbitrary part @@ -249,7 +249,7 @@ export class LDMLKeyboardXMLSourceFileReader { // importXml will have one property: the root element. if (!importRootNode) { - this.callbacks.reportMessage(CommonTypesMessages.Error_ImportWrongRoot({base, path, subtag})); + this.callbacks.reportMessage(DeveloperUtilsMessages.Error_ImportWrongRoot({base, path, subtag})); return false; } // pull all children of importXml[subtag] into obj @@ -259,7 +259,7 @@ export class LDMLKeyboardXMLSourceFileReader { if (!Array.isArray(subsubval)) { // This is somewhat of an internal error, indicating that a non-mergeable XML file was imported // Not exercisable with the standard LDML imports. - this.callbacks.reportMessage(CommonTypesMessages.Error_ImportMergeFail({base, path, subtag, subsubtag})); + this.callbacks.reportMessage(DeveloperUtilsMessages.Error_ImportMergeFail({base, path, subtag, subsubtag})); return false; } // Mark all children as an import @@ -286,7 +286,7 @@ export class LDMLKeyboardXMLSourceFileReader { public validate(source: LDMLKeyboardXMLSourceFile | LDMLKeyboardTestDataXMLSourceFile): boolean { if(!SchemaValidators.default.ldmlKeyboard3(source)) { for (const err of (SchemaValidators.default.ldmlKeyboard3).errors) { - this.callbacks.reportMessage(CommonTypesMessages.Error_SchemaValidationError({ + this.callbacks.reportMessage(DeveloperUtilsMessages.Error_SchemaValidationError({ instancePath: err.instancePath, keyword: err.keyword, message: err.message || 'Unknown AJV Error', // docs say 'message' is optional if 'messages:false' in options @@ -318,7 +318,7 @@ export class LDMLKeyboardXMLSourceFileReader { try { source = this.loadUnboxed(file); } catch(e) { - this.callbacks.reportMessage(CommonTypesMessages.Error_InvalidXml({e})); + this.callbacks.reportMessage(DeveloperUtilsMessages.Error_InvalidXml({e})); return null; } @@ -359,7 +359,7 @@ export class LDMLKeyboardXMLSourceFileReader { } else if (r.length === 1) { return r[0]; } else { - this.callbacks.reportMessage(CommonTypesMessages.Error_TestDataUnexpectedArray({subtag})); + this.callbacks.reportMessage(DeveloperUtilsMessages.Error_TestDataUnexpectedArray({subtag})); return null; // ERROR } } diff --git a/developer/src/common/web/utils/test/kps/kps-file-reader.tests.ts b/developer/src/common/web/utils/test/kps/kps-file-reader.tests.ts index 1b809f39d0..ddf6ec48a9 100644 --- a/developer/src/common/web/utils/test/kps/kps-file-reader.tests.ts +++ b/developer/src/common/web/utils/test/kps/kps-file-reader.tests.ts @@ -14,7 +14,7 @@ import { makePathToFixture } from '../helpers/index.js'; import { KpsFileReader } from "../../src/types/kps/kps-file-reader.js"; import { KpsFileWriter } from '../../src/types/kps/kps-file-writer.js'; -import { CommonTypesMessages } from '../../src/common-messages.js'; +import { DeveloperUtilsMessages } from '../../src/developer-utils-messages.js'; const callbacks = new TestCompilerCallbacks(); @@ -80,6 +80,6 @@ describe('kps-file-reader', function () { assert.isNull(kps); assert.lengthOf(callbacks.messages, 1); - assert.isTrue(callbacks.hasMessage(CommonTypesMessages.ERROR_InvalidPackageFile)); + assert.isTrue(callbacks.hasMessage(DeveloperUtilsMessages.ERROR_InvalidPackageFile)); }); }); diff --git a/developer/src/common/web/utils/test/ldml/ldml-keyboard-xml-reader.tests.ts b/developer/src/common/web/utils/test/ldml/ldml-keyboard-xml-reader.tests.ts index dc6f3021ae..d2dfb86370 100644 --- a/developer/src/common/web/utils/test/ldml/ldml-keyboard-xml-reader.tests.ts +++ b/developer/src/common/web/utils/test/ldml/ldml-keyboard-xml-reader.tests.ts @@ -1,7 +1,7 @@ import 'mocha'; import {assert} from 'chai'; +import { DeveloperUtilsMessages } from '../../src/developer-utils-messages.js'; import { Constants } from '@keymanapp/common-types'; -import { CommonTypesMessages } from '../../src/common-messages.js'; import { LKKey, ImportStatus } from '../../src/types/ldml-keyboard/ldml-keyboard-xml.js'; import { testReaderCases } from '../helpers/reader-callback-test.js'; @@ -19,7 +19,7 @@ describe('ldml keyboard xml reader tests', function () { testReaderCases([ { subpath: 'invalid-structure-per-dtd.xml', - errors: [CommonTypesMessages.Error_SchemaValidationError({ + errors: [DeveloperUtilsMessages.Error_SchemaValidationError({ instancePath: '/keyboard3', keyword: 'required', message: `must have required property 'info'`, @@ -28,7 +28,7 @@ describe('ldml keyboard xml reader tests', function () { }, { subpath: 'invalid-conforms-to.xml', - errors: [CommonTypesMessages.Error_SchemaValidationError({ + errors: [DeveloperUtilsMessages.Error_SchemaValidationError({ instancePath: '/keyboard3/conformsTo', keyword: 'enum', message: `must be equal to one of the allowed values`, @@ -150,7 +150,7 @@ describe('ldml keyboard xml reader tests', function () { subpath: 'invalid-import-base.xml', loadfail: true, errors: [ - CommonTypesMessages.Error_ImportInvalidBase({ + DeveloperUtilsMessages.Error_ImportInvalidBase({ base: 'SOME_INVALID_BASE', path: 'B', subtag: 'C' @@ -161,7 +161,7 @@ describe('ldml keyboard xml reader tests', function () { subpath: 'invalid-import-local.xml', loadfail: true, errors: [ - CommonTypesMessages.Error_ImportReadFail({ + DeveloperUtilsMessages.Error_ImportReadFail({ base: undefined, path: 'keys-Zyyy-DOESNOTEXIST.xml', subtag: 'keys' @@ -172,7 +172,7 @@ describe('ldml keyboard xml reader tests', function () { subpath: 'invalid-import-path.xml', loadfail: true, errors: [ - CommonTypesMessages.Error_ImportInvalidPath({ + DeveloperUtilsMessages.Error_ImportInvalidPath({ base: 'cldr', path: '45/too/many/slashes/leading/to/nothing-Zxxx-does-not-exist.xml', subtag: null, @@ -183,7 +183,7 @@ describe('ldml keyboard xml reader tests', function () { subpath: 'invalid-import-readfail.xml', loadfail: true, errors: [ - CommonTypesMessages.Error_ImportReadFail({ + DeveloperUtilsMessages.Error_ImportReadFail({ base: 'cldr', path: '45/none-Zxxx-does-not-exist.xml', subtag: null, @@ -194,7 +194,7 @@ describe('ldml keyboard xml reader tests', function () { subpath: 'invalid-import-wrongroot.xml', loadfail: true, errors: [ - CommonTypesMessages.Error_ImportWrongRoot({ + DeveloperUtilsMessages.Error_ImportWrongRoot({ base: null, path: '45/keys-Zyyy-punctuation.xml', subtag: 'flicks', diff --git a/developer/src/kmc-package/src/compiler/package-compiler-messages.ts b/developer/src/kmc-package/src/compiler/package-compiler-messages.ts index 5a088be128..d98ff747e0 100644 --- a/developer/src/kmc-package/src/compiler/package-compiler-messages.ts +++ b/developer/src/kmc-package/src/compiler/package-compiler-messages.ts @@ -144,7 +144,7 @@ export class PackageCompilerMessages { `The source file '${def(o.filename)}' should not be included in the package; instead include the compiled result.` ); - // 0x001E was ERROR_InvalidPackageFile, now CommonTypesMessages.Error_InvalidPackageFile + // 0x001E was ERROR_InvalidPackageFile, now DeveloperUtilsMessages.Error_InvalidPackageFile static ERROR_FileRecordIsMissingName = SevError | 0x001F; static Error_FileRecordIsMissingName = (o:{description:string}) => m(this.ERROR_FileRecordIsMissingName, @@ -191,7 +191,7 @@ export class PackageCompilerMessages { `The format for version numbers should be number[.number[.number]]. Each number component should be an integer, without leading zeroes.` ); - + static ERROR_PackageMustNotContainItself = SevError | 0x0028; static Error_PackageMustNotContainItself = (o:{outputFilename: string}) => m( this.ERROR_PackageMustNotContainItself, `The package may not include a .kmp file of the same name '${def(o.outputFilename)}'.`, ` diff --git a/developer/src/kmc/src/messages/messageNamespaces.ts b/developer/src/kmc/src/messages/messageNamespaces.ts index 3918d7183d..792acffd19 100644 --- a/developer/src/kmc/src/messages/messageNamespaces.ts +++ b/developer/src/kmc/src/messages/messageNamespaces.ts @@ -1,4 +1,4 @@ -import { CommonTypesMessages, CompilerErrorNamespace } from '@keymanapp/developer-utils'; +import { DeveloperUtilsMessages, CompilerErrorNamespace } from '@keymanapp/developer-utils'; import { AnalyzerMessages } from '@keymanapp/kmc-analyze'; import { CopierMessages } from '@keymanapp/kmc-copy'; import { GeneratorMessages } from '@keymanapp/kmc-generate'; @@ -13,7 +13,7 @@ import { InfrastructureMessages } from './infrastructureMessages.js'; // Maps every compiler error namespace to the corresponding implementation const messageNamespaces: Record = { [CompilerErrorNamespace.LdmlKeyboardCompiler]: LdmlCompilerMessages, - [CompilerErrorNamespace.CommonTypes]: CommonTypesMessages, + [CompilerErrorNamespace.DeveloperUtils]: DeveloperUtilsMessages, [CompilerErrorNamespace.KmnCompiler]: KmnCompilerMessages, [CompilerErrorNamespace.ModelCompiler]: ModelCompilerMessages, [CompilerErrorNamespace.PackageCompiler]: PackageCompilerMessages, @@ -38,7 +38,7 @@ export type CompilerMessageSource = { // TODO: consolidate with messageNamespaces above export const messageSources: Record = { [CompilerErrorNamespace.LdmlKeyboardCompiler]: { module: 'kmc-ldml', class: LdmlCompilerMessages }, - [CompilerErrorNamespace.CommonTypes]: { module: 'common-types', class: CommonTypesMessages }, + [CompilerErrorNamespace.DeveloperUtils]: { module: 'developer-utils', class: DeveloperUtilsMessages }, [CompilerErrorNamespace.KmnCompiler]: { module: 'kmc-kmn', class: KmnCompilerMessages }, [CompilerErrorNamespace.ModelCompiler]: { module: 'kmc-model', class: ModelCompilerMessages }, [CompilerErrorNamespace.PackageCompiler]: { module: 'kmc-package', class: PackageCompilerMessages }, From cf16c378695cd31a8524e5c31ec9a28b4610b46e Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Thu, 3 Apr 2025 08:15:59 +0700 Subject: [PATCH 59/61] refactor(developer): move sentry and developer options into console apps Move the sentry dependency out of developer-utils and into the console apps kmc and server, in process of making sure that developer-utils has no node dependencies. Also copy the options.ts module into kmc and server, for the same reason. This first step duplicates two units, options.ts and KeymanSentry.ts. We do need to refactor this again later to avoid this duplication (maybe via yet another internal package?) --- developer/src/common/web/utils/package.json | 1 - developer/src/common/web/utils/src/index.ts | 2 - .../src/commands/buildClasses/BuildProject.ts | 2 +- developer/src/kmc/src/kmc.ts | 3 +- developer/src/kmc/src/util/KeymanSentry.ts | 104 ++++++++++++++++++ .../src/kmc/src/util/NodeCompilerCallbacks.ts | 2 +- .../src/kmc/src/util/TestKeymanSentry.ts | 2 +- .../src/kmc/src/util/kmcSentryOptions.ts | 2 +- .../src/utils => kmc/src/util}/options.ts | 0 developer/src/kmc/src/util/sysexits.ts | 2 +- developer/src/kmc/test/build.tests.ts | 2 +- .../kmc/test/infrastructureMessages.tests.ts | 2 +- developer/src/kmc/test/project-build.tests.ts | 2 +- .../src/utils => server/src}/KeymanSentry.ts | 1 + developer/src/server/src/index.ts | 3 +- developer/src/server/src/load-json-file.ts | 2 +- developer/src/server/src/options.ts | 96 ++++++++++++++++ developer/src/server/src/shutdown.ts | 2 +- 18 files changed, 215 insertions(+), 15 deletions(-) create mode 100644 developer/src/kmc/src/util/KeymanSentry.ts rename developer/src/{common/web/utils/src/utils => kmc/src/util}/options.ts (100%) rename developer/src/{common/web/utils/src/utils => server/src}/KeymanSentry.ts (98%) create mode 100644 developer/src/server/src/options.ts diff --git a/developer/src/common/web/utils/package.json b/developer/src/common/web/utils/package.json index 05cba553bb..caff2e23a5 100644 --- a/developer/src/common/web/utils/package.json +++ b/developer/src/common/web/utils/package.json @@ -10,7 +10,6 @@ ], "dependencies": { "@keymanapp/common-types": "*", - "@sentry/node": "^7.57.0", "eventemitter3": "^5.0.0", "fast-xml-parser": "^5.0.9", "path-browserify": "^1.0.1", diff --git a/developer/src/common/web/utils/src/index.ts b/developer/src/common/web/utils/src/index.ts index 5a435a577e..2477442bd4 100644 --- a/developer/src/common/web/utils/src/index.ts +++ b/developer/src/common/web/utils/src/index.ts @@ -3,8 +3,6 @@ */ export { validateMITLicense } from './utils/validate-mit-license.js'; -export { KeymanSentry, SentryNodeOptions } from './utils/KeymanSentry.js'; -export { getOption, loadOptions, clearOptions } from './utils/options.js'; export { escapeMarkdownChar } from './utils/markdown.js'; export { KeymanUrls } from './utils/keyman-urls.js'; diff --git a/developer/src/kmc/src/commands/buildClasses/BuildProject.ts b/developer/src/kmc/src/commands/buildClasses/BuildProject.ts index 4ae9f8d9ce..249261cd0d 100644 --- a/developer/src/kmc/src/commands/buildClasses/BuildProject.ts +++ b/developer/src/kmc/src/commands/buildClasses/BuildProject.ts @@ -8,7 +8,7 @@ import { buildActivities, buildKeyboardInfoActivity, buildModelInfoActivity } fr import { InfrastructureMessages } from '../../messages/infrastructureMessages.js'; import { loadProject } from '../../util/projectLoader.js'; import { ExtendedCompilerOptions } from '../../util/extendedCompilerOptions.js'; -import { getOption } from '@keymanapp/developer-utils'; +import { getOption } from '../../util/options.js'; export class BuildProject extends BuildActivity { public get name(): string { return 'Project'; } diff --git a/developer/src/kmc/src/kmc.ts b/developer/src/kmc/src/kmc.ts index f4c28aa68c..d569621163 100644 --- a/developer/src/kmc/src/kmc.ts +++ b/developer/src/kmc/src/kmc.ts @@ -6,7 +6,8 @@ import { Command, Option } from 'commander'; import { declareBuild } from './commands/build.js'; import { declareAnalyze } from './commands/analyze.js'; -import { KeymanSentry, loadOptions } from '@keymanapp/developer-utils'; +import { loadOptions } from './util/options.js'; +import { KeymanSentry } from './util/KeymanSentry.js'; import KEYMAN_VERSION from "@keymanapp/keyman-version"; import { TestKeymanSentry } from './util/TestKeymanSentry.js'; import { exitProcess } from './util/sysexits.js'; diff --git a/developer/src/kmc/src/util/KeymanSentry.ts b/developer/src/kmc/src/util/KeymanSentry.ts new file mode 100644 index 0000000000..9ee05ecb7f --- /dev/null +++ b/developer/src/kmc/src/util/KeymanSentry.ts @@ -0,0 +1,104 @@ +// TODO: this is duplicated in server.js +import Sentry from "@sentry/node"; +import KEYMAN_VERSION from "@keymanapp/keyman-version"; +import { getOption } from "./options.js"; + +export type SentryNodeOptions = Sentry.NodeOptions; + +/** + * Maximum delay on shutdown of process to send pending events + * to Sentry, in msec + */ +const CLOSE_TIMEOUT = 2000; + +let isInit = false; + +export class KeymanSentry { + + static isEnabled() { + if(process.argv.includes('--no-error-reporting')) { + return false; + } + if(process.argv.includes('--error-reporting')) { + return true; + } + + return getOption('automatically report errors', true); + } + + static init(options?: SentryNodeOptions) { + options = options ?? {}; + Sentry.init({ + ...options, + dsn: 'https://39b25a09410349a58fe12aaf721565af@o1005580.ingest.sentry.io/5983519', // Keyman Developer + environment: KEYMAN_VERSION.VERSION_ENVIRONMENT, + release: KEYMAN_VERSION.VERSION_GIT_TAG, + }); + isInit = true; + } + + private static writeSentryMessage(eventId: string) { + process.stderr.write(` + This error has been automatically reported to the Keyman team. + Identifier: ${eventId} + Application: Keyman Developer + Reported at: https://sentry.io/organizations/keyman/projects/keyman-developer/events/${eventId}/ + `); + } + + static async reportException(e: any, silent: boolean = true) { + if(isInit) { + const eventId = await Sentry.captureException(e); + if(!silent) { + this.writeSentryMessage(eventId); + } + return eventId; + } + return null; + } + + static captureMessage(message: string) { + if(isInit) { + return Sentry.captureMessage(message); + } else { + return null; + } + } + + /** + * capture an exception for Sentry; note that in local environments, this will normally + * throw the exception rather than sending to Sentry + * @param e + * @param force if true, reports to Sentry even in local environments + */ + static async captureException(e: any, force?: boolean): Promise { + if(isInit) { + // For local development, we don't want to bury the trace; we need the cast to avoid + // TS2367 (comparison appears to be unintentional) + if(!force && (KEYMAN_VERSION.VERSION_ENVIRONMENT as string) == 'local') { + throw e; + } + + const eventId = Sentry.captureException(e); + process.stderr.write(` + Fatal error: ${(e??'').toString()} + `); + this.writeSentryMessage(eventId); + await this.close(); + + process.exit(1); + } else { + throw e; + } + } + + static async close() { + if(isInit) { + try { + await Sentry.close(CLOSE_TIMEOUT); + } catch(e) { + // ignore any errors here + } + } + } +} \ No newline at end of file diff --git a/developer/src/kmc/src/util/NodeCompilerCallbacks.ts b/developer/src/kmc/src/util/NodeCompilerCallbacks.ts index 94465d4413..98b62a8bad 100644 --- a/developer/src/kmc/src/util/NodeCompilerCallbacks.ts +++ b/developer/src/kmc/src/util/NodeCompilerCallbacks.ts @@ -13,7 +13,7 @@ import { CompilerCallbacks, CompilerEvent, import { InfrastructureMessages } from '../messages/infrastructureMessages.js'; import chalk from 'chalk'; import supportsColor from 'supports-color'; -import { KeymanSentry } from '@keymanapp/developer-utils'; +import { KeymanSentry } from './KeymanSentry.js'; import { fileURLToPath } from 'url'; const color = chalk.default; diff --git a/developer/src/kmc/src/util/TestKeymanSentry.ts b/developer/src/kmc/src/util/TestKeymanSentry.ts index b8572516bd..34e41e64d3 100644 --- a/developer/src/kmc/src/util/TestKeymanSentry.ts +++ b/developer/src/kmc/src/util/TestKeymanSentry.ts @@ -1,6 +1,6 @@ import { KmnCompiler } from "@keymanapp/kmc-kmn"; import { NodeCompilerCallbacks } from "./NodeCompilerCallbacks.js"; -import { KeymanSentry, SentryNodeOptions } from '@keymanapp/developer-utils'; +import { KeymanSentry, SentryNodeOptions } from './KeymanSentry.js'; const cli = process.argv.join(' '); diff --git a/developer/src/kmc/src/util/kmcSentryOptions.ts b/developer/src/kmc/src/util/kmcSentryOptions.ts index c6c47f732f..b0def8be66 100644 --- a/developer/src/kmc/src/util/kmcSentryOptions.ts +++ b/developer/src/kmc/src/util/kmcSentryOptions.ts @@ -1,6 +1,6 @@ import Sentry from "@sentry/node"; import * as process from "node:process"; -import { SentryNodeOptions } from "@keymanapp/developer-utils"; +import { SentryNodeOptions } from "./KeymanSentry.js"; Sentry.setContext('Command Line', { // obfusate parameters with longer paths e.g. from 'c:/users/name/a/b' to diff --git a/developer/src/common/web/utils/src/utils/options.ts b/developer/src/kmc/src/util/options.ts similarity index 100% rename from developer/src/common/web/utils/src/utils/options.ts rename to developer/src/kmc/src/util/options.ts diff --git a/developer/src/kmc/src/util/sysexits.ts b/developer/src/kmc/src/util/sysexits.ts index b656d538e4..7256dd4e77 100644 --- a/developer/src/kmc/src/util/sysexits.ts +++ b/developer/src/kmc/src/util/sysexits.ts @@ -1,4 +1,4 @@ -import { KeymanSentry } from "@keymanapp/developer-utils"; +import { KeymanSentry } from './KeymanSentry.js'; /** * Exit codes defined in : diff --git a/developer/src/kmc/test/build.tests.ts b/developer/src/kmc/test/build.tests.ts index 5bb382efc3..f8356db54b 100644 --- a/developer/src/kmc/test/build.tests.ts +++ b/developer/src/kmc/test/build.tests.ts @@ -1,5 +1,5 @@ import { TestCompilerCallbacks } from '@keymanapp/developer-test-helpers'; -import { clearOptions } from '@keymanapp/developer-utils'; +import { clearOptions } from '../src/util/options.js'; import { assert } from 'chai'; import 'mocha'; import { BuildProject } from '../src/commands/buildClasses/BuildProject.js'; diff --git a/developer/src/kmc/test/infrastructureMessages.tests.ts b/developer/src/kmc/test/infrastructureMessages.tests.ts index 225742bd92..d187075deb 100644 --- a/developer/src/kmc/test/infrastructureMessages.tests.ts +++ b/developer/src/kmc/test/infrastructureMessages.tests.ts @@ -8,7 +8,7 @@ import { NodeCompilerCallbacks } from '../src/util/NodeCompilerCallbacks.js'; import { KeymanFileTypes } from '@keymanapp/common-types'; import { unitTestEndpoints } from '../src/commands/build.js'; import { KmnCompilerMessages } from '@keymanapp/kmc-kmn'; -import { clearOptions } from '@keymanapp/developer-utils'; +import { clearOptions } from '../src/util/options.js'; import { loadProject } from '../src/util/projectLoader.js'; import { CompilerErrorNamespace, CompilerEvent, defaultCompilerOptions, CompilerOptions} from '@keymanapp/developer-utils'; import { analyzeUnitTestEndpoints } from '../src/commands/analyze.js'; diff --git a/developer/src/kmc/test/project-build.tests.ts b/developer/src/kmc/test/project-build.tests.ts index 3b10d8857c..f094afb79d 100644 --- a/developer/src/kmc/test/project-build.tests.ts +++ b/developer/src/kmc/test/project-build.tests.ts @@ -4,7 +4,7 @@ import 'mocha'; import { BuildProject } from '../src/commands/buildClasses/BuildProject.js'; import { makePathToFixture } from './helpers/index.js'; import { InfrastructureMessages } from '../src/messages/infrastructureMessages.js'; -import { clearOptions } from '@keymanapp/developer-utils'; +import { clearOptions } from '../src/util/options.js'; const callbacks = new TestCompilerCallbacks(); diff --git a/developer/src/common/web/utils/src/utils/KeymanSentry.ts b/developer/src/server/src/KeymanSentry.ts similarity index 98% rename from developer/src/common/web/utils/src/utils/KeymanSentry.ts rename to developer/src/server/src/KeymanSentry.ts index dfe62bfa3d..9dba30a0d4 100644 --- a/developer/src/common/web/utils/src/utils/KeymanSentry.ts +++ b/developer/src/server/src/KeymanSentry.ts @@ -1,3 +1,4 @@ +// TODO: this is duplicated in kmc! import Sentry from "@sentry/node"; import KEYMAN_VERSION from "@keymanapp/keyman-version"; import { getOption } from "./options.js"; diff --git a/developer/src/server/src/index.ts b/developer/src/server/src/index.ts index 677c5a7cd5..85de2fcce6 100644 --- a/developer/src/server/src/index.ts +++ b/developer/src/server/src/index.ts @@ -5,12 +5,13 @@ import chalk from 'chalk'; import express from 'express'; import multer from 'multer'; import * as ws from 'ws'; -import { KeymanSentry, loadOptions } from '@keymanapp/developer-utils'; +import { KeymanSentry } from './KeymanSentry.js'; import { configuration } from './config.js'; import { environment } from './environment.js'; import setupRoutes from './routes.js'; import { shutdown } from './shutdown.js'; import { initTray } from './tray.js'; +import { loadOptions } from './options.js'; const options = { ngrokLog: false, // Set this to true if you need to see ngrok logs in the console diff --git a/developer/src/server/src/load-json-file.ts b/developer/src/server/src/load-json-file.ts index 28916cd83b..174a22a650 100644 --- a/developer/src/server/src/load-json-file.ts +++ b/developer/src/server/src/load-json-file.ts @@ -1,4 +1,4 @@ -import { KeymanSentry } from '@keymanapp/developer-utils'; +import { KeymanSentry } from './KeymanSentry.js'; import { readFileSync, existsSync } from 'fs'; export function loadJsonFile(filename: string): any { diff --git a/developer/src/server/src/options.ts b/developer/src/server/src/options.ts new file mode 100644 index 0000000000..45799ba5f2 --- /dev/null +++ b/developer/src/server/src/options.ts @@ -0,0 +1,96 @@ +// TODO: this is duplicated in kmc +import * as os from 'node:os'; +import * as fs from 'node:fs'; +import * as path from 'node:path'; + +export interface KeymanDeveloperOptions { + "use tab char"?: boolean; + "link font sizes"?: boolean; + "indent size"?: number; + "use old debugger"?: boolean; + "editor theme"?: string; + "debugger break when exiting line"?: boolean; + "debugger single step after break"?: boolean; + "debugger show store offset"?: boolean; + "debugger recompile with debug info"?: boolean; + "debugger auto reset before compilng"?: boolean; + "auto save before compiling"?: boolean; + "osk auto save before importing"?: boolean; + "web host port"?: number; + "server keep alive"?: boolean; + "server use local addresses"?: boolean; + "server ngrok token"?: string; + "server ngrok region"?: string; + "server use ngrok"?: boolean; + "server show console window"?: boolean; + "char map disable database lookups"?: boolean; + "char map auto lookup"?: boolean; + "open keyboard files in source view"?: boolean; + "display theme"?: string; + "external editor path"?: string; + "smtp server"?: string; + "test email addresses"?: string; + "web ladder length"?: number; + "default project path"?: string; + "automatically report errors"?: boolean; + "automatically report usage"?: boolean; + "toolbar visible"?: boolean; + "active project"?: string; + "prompt to upgrade projects"?: boolean; +}; + +type KeymanDeveloperOption = keyof KeymanDeveloperOptions; + +// Default has no options set, and unit tests will use the defaults (won't call +// `loadOptions()`) +let options: KeymanDeveloperOptions = {}; + +// We only load the options from disk once on first use +let optionsLoaded = false; + +export async function loadOptions(): Promise { + if(optionsLoaded) { + return options; + } + + options = {}; + try { + const optionsFile = path.join(os.homedir(), '.keymandeveloper', 'options.json'); + if(fs.existsSync(optionsFile)) { + for(let i = 0; i < 5; i++) { + try { + const data = JSON.parse(fs.readFileSync(optionsFile, 'utf-8')); + if(typeof data == 'object') { + options = data; + } + break; + } catch(e) { + if(e?.code == 'EBUSY') { + await new Promise(resolve => setTimeout(resolve, 500)); + } else { + // give up, nothing to report here + break; + } + } + } + } + } catch(e) { + // Nothing to report here, sadly -- because we cannot rely on Sentry at this + // low level. + options = {}; + } + optionsLoaded = true; + return options; +} + +export function getOption(valueName: T, defaultValue: KeymanDeveloperOptions[T]): KeymanDeveloperOptions[T] { + return options[valueName] ?? defaultValue; +} + +/** + * unit tests will clear options before running, for consistency + */ +export function clearOptions() { + options = {}; + optionsLoaded = true; +} \ No newline at end of file diff --git a/developer/src/server/src/shutdown.ts b/developer/src/server/src/shutdown.ts index d33b035bfc..13f0c15349 100644 --- a/developer/src/server/src/shutdown.ts +++ b/developer/src/server/src/shutdown.ts @@ -1,4 +1,4 @@ -import { KeymanSentry } from '@keymanapp/developer-utils'; +import { KeymanSentry } from './KeymanSentry.js'; export async function shutdown(code?: number): Promise { await KeymanSentry.close(); From 838aea52ed8c62825030395af6e7ae47f9357cfb Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Thu, 3 Apr 2025 11:37:54 +0700 Subject: [PATCH 60/61] refactor(developer): consolidate project loader Consolidates project loading code from kmc and kmc-copy, in preparation for kmc-test epic. This leaves open a change we need to make to CompilerCallbacks, to consolidate the fsAsync and net callbacks into CompilerCallbacks as a first-class part of CompilerCallbacks. We will then need to start to move all the fs and net callback interactions to the async model across all kmc modules, at some point. --- .../web/utils/src/developer-utils-messages.ts | 18 ++++++++ developer/src/common/web/utils/src/index.ts | 2 + .../common/web/utils/src/project-loader.ts | 34 ++++++++++++++ .../src/kmc-copy/src/KeymanProjectCopier.ts | 45 ++++++++----------- developer/src/kmc-copy/src/copier-messages.ts | 19 ++------ developer/src/kmc-copy/tsconfig.json | 2 + .../src/messages/infrastructureMessages.ts | 8 +--- developer/src/kmc/src/util/projectLoader.ts | 22 +-------- .../kmc/test/infrastructureMessages.tests.ts | 10 ++--- 9 files changed, 86 insertions(+), 74 deletions(-) create mode 100644 developer/src/common/web/utils/src/project-loader.ts diff --git a/developer/src/common/web/utils/src/developer-utils-messages.ts b/developer/src/common/web/utils/src/developer-utils-messages.ts index eb69e42385..d5bf1cd64a 100644 --- a/developer/src/common/web/utils/src/developer-utils-messages.ts +++ b/developer/src/common/web/utils/src/developer-utils-messages.ts @@ -58,4 +58,22 @@ export class DeveloperUtilsMessages { this.ERROR_InvalidPackageFile, `Package source file is invalid: ${(o.e ?? 'unknown error').toString()}` ); + + static ERROR_InvalidProjectFile = SevError | 0x000A; + static Error_InvalidProjectFile = (o:{message:string}) => m( + this.ERROR_InvalidProjectFile, + `Project file is not valid: ${def(o.message)}`, + ); + + static ERROR_UnsupportedProjectVersion = SevError | 0x0013; + static Error_UnsupportedProjectVersion = (o:{version:string}) => m( + this.ERROR_UnsupportedProjectVersion, + `Project version ${def(o.version)} is not supported by this version of Keyman Developer.`, + ); + + static ERROR_ProjectFileCouldNotBeRead = SevError | 0x0014; + static Error_ProjectFileCouldNotBeRead = () => m( + this.ERROR_ProjectFileCouldNotBeRead, + `Project file could not be read` + ); }; diff --git a/developer/src/common/web/utils/src/index.ts b/developer/src/common/web/utils/src/index.ts index 2477442bd4..7ed873905f 100644 --- a/developer/src/common/web/utils/src/index.ts +++ b/developer/src/common/web/utils/src/index.ts @@ -71,3 +71,5 @@ export * as CloudUrls from './cloud-urls.js'; export { getFontFamily, getFontFamilySync } from './font-family.js'; export * as ValidIds from './valid-ids.js'; + +export * as ProjectLoader from './project-loader.js'; \ No newline at end of file diff --git a/developer/src/common/web/utils/src/project-loader.ts b/developer/src/common/web/utils/src/project-loader.ts new file mode 100644 index 0000000000..a62545e877 --- /dev/null +++ b/developer/src/common/web/utils/src/project-loader.ts @@ -0,0 +1,34 @@ +import { KeymanDeveloperProject } from "./types/kpj/keyman-developer-project.js"; +import { KPJFileReader } from "./types/kpj/kpj-file-reader.js"; +import { CompilerAsyncCallbacks, CompilerCallbacks } from "./compiler-callbacks.js"; +import { DeveloperUtilsMessages } from "./developer-utils-messages.js"; + +// TODO-KMC-TEST: refactor asyncCallbacks, make it a first-class part of CompilerCallbacks +export async function loadProjectFromFile(infile: string, callbacks: CompilerCallbacks, asyncCallbacks: CompilerAsyncCallbacks = null): Promise { + const kpjData = await (asyncCallbacks ?? callbacks).fsAsync.readFile(infile); + if(!kpjData) { + callbacks.reportMessage(DeveloperUtilsMessages.Error_ProjectFileCouldNotBeRead()); + return null; + } + const reader = new KPJFileReader(callbacks); + let kpj = null; + try { + kpj = reader.read(kpjData); + if(!kpj) { + callbacks.reportMessage(DeveloperUtilsMessages.Error_ProjectFileCouldNotBeRead()); + return null; + } + + if(kpj.KeymanDeveloperProject?.Options?.Version && kpj.KeymanDeveloperProject.Options.Version != "1.0" && kpj.KeymanDeveloperProject.Options.Version != "2.0") { + callbacks.reportMessage(DeveloperUtilsMessages.Error_UnsupportedProjectVersion({version: kpj.KeymanDeveloperProject.Options.Version})); + return null; + } + reader.validate(kpj); + } catch(e) { + callbacks.reportMessage(DeveloperUtilsMessages.Error_InvalidProjectFile({message: (e??'').toString()})); + return null; + } + const project = await reader.transform(infile, kpj); + return project; +} + diff --git a/developer/src/kmc-copy/src/KeymanProjectCopier.ts b/developer/src/kmc-copy/src/KeymanProjectCopier.ts index a751e46731..545163aded 100644 --- a/developer/src/kmc-copy/src/KeymanProjectCopier.ts +++ b/developer/src/kmc-copy/src/KeymanProjectCopier.ts @@ -4,7 +4,23 @@ * Copy a keyboard or lexical model project */ -import { CloudUrls, GitHubUrls, CompilerCallbacks, KeymanCompiler, KeymanCompilerArtifact, KeymanCompilerArtifacts, KeymanCompilerResult, KeymanDeveloperProject, KeymanDeveloperProjectOptions, KPJFileReader, KPJFileWriter, KpsFileReader, KpsFileWriter, ValidIds, CompilerBaseOptions } from "@keymanapp/developer-utils"; +import { + CloudUrls, + GitHubUrls, + CompilerCallbacks, + KeymanCompiler, + KeymanCompilerArtifact, + KeymanCompilerArtifacts, + KeymanCompilerResult, + KeymanDeveloperProject, + KeymanDeveloperProjectOptions, + ProjectLoader, + KPJFileWriter, + KpsFileReader, + KpsFileWriter, + ValidIds, + CompilerBaseOptions, +} from "@keymanapp/developer-utils"; import { KeymanFileTypes } from "@keymanapp/common-types"; import { CopierMessages } from "./copier-messages.js"; @@ -124,7 +140,7 @@ export class KeymanProjectCopier implements KeymanCompiler { this.sourceId = this.callbacks.path.basename(projectSource, KeymanFileTypes.Source.Project); // copy project file - const project = await this.loadProjectFromFile(projectSource); + const project = await ProjectLoader.loadProjectFromFile(projectSource, this.callbacks, this.asyncCallbacks); if(!project) { // loadProjectFromFile already reported errors return null; @@ -637,31 +653,6 @@ export class KeymanProjectCopier implements KeymanCompiler { return this.callbacks.path.join(this.outPath, 'source'); } - private async loadProjectFromFile(filename: string): Promise { - const kpjData = await this.asyncCallbacks.fsAsync.readFile(filename); - const reader = new KPJFileReader(this.asyncCallbacks); - let kpj = null; - try { - kpj = reader.read(kpjData); - if(!kpj) { - this.callbacks.reportMessage(CopierMessages.Error_ProjectFileCouldNotBeRead({filename})); - return null; - } - - if(kpj.KeymanDeveloperProject?.Options?.Version && kpj.KeymanDeveloperProject.Options.Version != "1.0" && kpj.KeymanDeveloperProject.Options.Version != "2.0") { - this.callbacks.reportMessage(CopierMessages.Error_UnsupportedProjectVersion({filename, version: kpj.KeymanDeveloperProject.Options.Version})); - return null; - } - reader.validate(kpj); - } catch(e) { - this.callbacks.reportMessage(CopierMessages.Error_InvalidProjectFile({filename, message: (e ?? '').toString()})); - return null; - } - const project = await reader.transform(filename, kpj); - - return project; - } - /** * Write artifacts from a successful compile to disk, via callbacks methods. * The artifacts written will include all files from the project, across diff --git a/developer/src/kmc-copy/src/copier-messages.ts b/developer/src/kmc-copy/src/copier-messages.ts index 976002a35f..cb8d0c83de 100644 --- a/developer/src/kmc-copy/src/copier-messages.ts +++ b/developer/src/kmc-copy/src/copier-messages.ts @@ -92,22 +92,9 @@ export class CopierMessages { `The package source file '${def(o.filename)}' could not be loaded. The file may have an invalid format` ); - static ERROR_UnsupportedProjectVersion = SevError | 0x000D; - static Error_UnsupportedProjectVersion = (o:{filename: string, version: string}) => m(this.ERROR_UnsupportedProjectVersion, - `Project version ${def(o.version)} for '${def(o.filename)}' is not supported by this version of Keyman Developer` - ); - - static ERROR_InvalidProjectFile = SevError | 0x000E; - static Error_InvalidProjectFile = (o:{filename: string, message: string}) => m( - this.ERROR_InvalidProjectFile, - `Project file '${def(o.filename)}' is not valid: ${def(o.message)}` - ); - - static ERROR_ProjectFileCouldNotBeRead = SevError | 0x000F; - static Error_ProjectFileCouldNotBeRead = (o:{filename: string}) => m( - this.ERROR_ProjectFileCouldNotBeRead, - `Project file '${def(o.filename)}' could not be read` - ); + // 0x000D ERROR_UnsupportedProjectVersion: moved to developer-utils-messages + // 0x000E ERROR_InvalidProjectFile: moved to developer-utils-messages + // 0x000F ERROR_ProjectFileCouldNotBeRead: moved to developer-utils-messages static INFO_DryRun = SevInfo | 0x0010; static Info_DryRun = (o:{outPath: string}) => m( diff --git a/developer/src/kmc-copy/tsconfig.json b/developer/src/kmc-copy/tsconfig.json index 1fc0a249be..e54ad9adaa 100644 --- a/developer/src/kmc-copy/tsconfig.json +++ b/developer/src/kmc-copy/tsconfig.json @@ -9,6 +9,7 @@ "paths": { "@keymanapp/keyman-version": ["../../../common/web/keyman-version/keyman-version.mts"], "@keymanapp/common-types": ["../../../common/web/types/src/main"], + "@keymanapp/developer-utils": ["../common/web/utils"], }, }, @@ -21,5 +22,6 @@ "references": [ { "path": "../../../common/web/keyman-version" }, { "path": "../../../common/web/types/" }, + { "path": "../common/web/utils/" }, ] } diff --git a/developer/src/kmc/src/messages/infrastructureMessages.ts b/developer/src/kmc/src/messages/infrastructureMessages.ts index 3e1f4f30c6..d384aa7d86 100644 --- a/developer/src/kmc/src/messages/infrastructureMessages.ts +++ b/developer/src/kmc/src/messages/infrastructureMessages.ts @@ -38,9 +38,7 @@ export class InfrastructureMessages { static Info_FileNotBuiltSuccessfully = (o:{filename:string,relativeFilename:string}) => ({filename:o.filename, ...m(this.INFO_FileNotBuiltSuccessfully, `${def(o.relativeFilename)} failed to build.`)}); - static ERROR_InvalidProjectFile = SevError | 0x0008; - static Error_InvalidProjectFile = (o:{message:string}) => m(this.ERROR_InvalidProjectFile, - `Project file is not valid: ${def(o.message)}`); + // 0x0008: ERROR_InvalidProjectFile moved to DeveloperUtilsMessages static HINT_FilenameHasDifferingCase = SevHint | 0x0009; static Hint_FilenameHasDifferingCase = (o:{reference:string, filename:string}) => m(this.HINT_FilenameHasDifferingCase, @@ -84,9 +82,7 @@ export class InfrastructureMessages { static Error_InvalidProjectFolder = (o:{folderName:string}) => m(this.ERROR_InvalidProjectFolder, `The folder ${def(o.folderName)} does not appear to be a Keyman Developer project.`); - static ERROR_UnsupportedProjectVersion = SevError | 0x0013; - static Error_UnsupportedProjectVersion = (o:{version:string}) => m(this.ERROR_UnsupportedProjectVersion, - `Project version ${def(o.version)} is not supported by this version of Keyman Developer.`); + // 0x0013: ERROR_UnsupportedProjectVersion moved to developer-utils-messages static HINT_ProjectIsVersion10 = SevHint | 0x0014; static Hint_ProjectIsVersion10 = () => m(this.HINT_ProjectIsVersion10, diff --git a/developer/src/kmc/src/util/projectLoader.ts b/developer/src/kmc/src/util/projectLoader.ts index 1cd944397f..b870a9fd68 100644 --- a/developer/src/kmc/src/util/projectLoader.ts +++ b/developer/src/kmc/src/util/projectLoader.ts @@ -2,7 +2,7 @@ import * as path from 'path'; import * as fs from 'fs'; import { KeymanFileTypes } from "@keymanapp/common-types"; -import { CompilerCallbacks, KeymanDeveloperProject, KPJFileReader } from "@keymanapp/developer-utils"; +import { CompilerCallbacks, KeymanDeveloperProject, ProjectLoader } from "@keymanapp/developer-utils"; import { InfrastructureMessages } from "../messages/infrastructureMessages.js"; export const isProject = (filename: string): boolean => @@ -26,7 +26,7 @@ export async function loadProject(infile: string, callbacks: CompilerCallbacks) } const project = callbacks.fs.existsSync(infile) ? - await loadProjectFromFile(infile, callbacks) : + await ProjectLoader.loadProjectFromFile(infile, callbacks) : await loadDefaultProjectFromFolder(infile, callbacks); return project; @@ -42,21 +42,3 @@ async function loadDefaultProjectFromFolder(infile: string, callbacks: CompilerC return project; } -async function loadProjectFromFile(infile: string, callbacks: CompilerCallbacks): Promise { - const kpjData = await callbacks.fsAsync.readFile(infile); - const reader = new KPJFileReader(callbacks); - let kpj = null; - try { - kpj = reader.read(kpjData); - if(kpj.KeymanDeveloperProject?.Options?.Version && kpj.KeymanDeveloperProject.Options.Version != "1.0" && kpj.KeymanDeveloperProject.Options.Version != "2.0") { - callbacks.reportMessage(InfrastructureMessages.Error_UnsupportedProjectVersion({version: kpj.KeymanDeveloperProject.Options.Version})); - return null; - } - reader.validate(kpj); - } catch(e) { - callbacks.reportMessage(InfrastructureMessages.Error_InvalidProjectFile({message: (e??'').toString()})); - return null; - } - const project = await reader.transform(infile, kpj); - return project; -} diff --git a/developer/src/kmc/test/infrastructureMessages.tests.ts b/developer/src/kmc/test/infrastructureMessages.tests.ts index d187075deb..68edaa7a10 100644 --- a/developer/src/kmc/test/infrastructureMessages.tests.ts +++ b/developer/src/kmc/test/infrastructureMessages.tests.ts @@ -10,7 +10,7 @@ import { unitTestEndpoints } from '../src/commands/build.js'; import { KmnCompilerMessages } from '@keymanapp/kmc-kmn'; import { clearOptions } from '../src/util/options.js'; import { loadProject } from '../src/util/projectLoader.js'; -import { CompilerErrorNamespace, CompilerEvent, defaultCompilerOptions, CompilerOptions} from '@keymanapp/developer-utils'; +import { CompilerErrorNamespace, CompilerEvent, defaultCompilerOptions, CompilerOptions, DeveloperUtilsMessages} from '@keymanapp/developer-utils'; import { analyzeUnitTestEndpoints } from '../src/commands/analyze.js'; import { BuildKeyboardInfo } from '../src/commands/buildClasses/BuildKeyboardInfo.js'; import { BuildModelInfo } from '../src/commands/buildClasses/BuildModelInfo.js'; @@ -71,12 +71,12 @@ describe('InfrastructureMessages', function () { 'ERROR_OutFileNotValidForProjects not generated, instead got: '+JSON.stringify(ncb.messages,null,2)); }); - // ERROR_InvalidProjectFile + // ERROR_InvalidProjectFile - test stays here for now though referencing developer-messages it('should generate ERROR_InvalidProjectFile if a project file is invalid', async function() { const ncb = new NodeCompilerCallbacks({logLevel: 'silent'}); await unitTestEndpoints.build(makePathToFixture('invalid-projects', 'error_invalid_project_file.kpj'), null, ncb, {}); - assert.isTrue(ncb.hasMessage(InfrastructureMessages.ERROR_InvalidProjectFile), + assert.isTrue(ncb.hasMessage(DeveloperUtilsMessages.ERROR_InvalidProjectFile), 'ERROR_InvalidProjectFile not generated, instead got: '+JSON.stringify(ncb.messages,null,2)); }); @@ -202,14 +202,14 @@ describe('InfrastructureMessages', function () { assertMessagesEqual(ncb.messages, expectedMessages); }); - // ERROR_UnsupportedProjectVersion + // ERROR_UnsupportedProjectVersion (test stays here for now though referencing developer-utils) it('should generate ERROR_UnsupportedProjectVersion if a project file with an unsupported version is loaded', async function() { const ncb = new NodeCompilerCallbacks({logLevel: 'silent'}); const filename = makePathToFixture('invalid-projects', 'error_unsupported_project_version.kpj'); const expectedMessages = [ InfrastructureMessages.INFO_BuildingFile, - InfrastructureMessages.ERROR_UnsupportedProjectVersion, + DeveloperUtilsMessages.ERROR_UnsupportedProjectVersion, InfrastructureMessages.INFO_ProjectNotBuiltSuccessfully ]; await unitTestEndpoints.build(filename, null, ncb, {compilerWarningsAsErrors: true}); From e68acd8b98d1eb88e61efaf55b7e92094239103c Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Thu, 3 Apr 2025 12:35:52 +0700 Subject: [PATCH 61/61] chore(linux): cleanup c++ for updated compiler --- linux/mcompile/keymap/mc_kmxfile.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/linux/mcompile/keymap/mc_kmxfile.cpp b/linux/mcompile/keymap/mc_kmxfile.cpp index 674da61fa1..039ae075f1 100644 --- a/linux/mcompile/keymap/mc_kmxfile.cpp +++ b/linux/mcompile/keymap/mc_kmxfile.cpp @@ -346,7 +346,7 @@ LPKMX_KEYBOARD CopyKeyboard(PKMX_BYTE bufp, PKMX_BYTE base) { * @return pointer to the keyboard */ LPKMX_KEYBOARD KMX_FixupKeyboard(PKMX_BYTE bufp, PKMX_BYTE base, KMX_DWORD dwFileSize) { - UNREFERENCED_PARAMETER(dwFileSize); + // UNREFERENCED_PARAMETER(dwFileSize); KMX_DWORD i, j; PCOMP_KEYBOARD ckbp = (PCOMP_KEYBOARD)base; @@ -369,9 +369,9 @@ LPKMX_KEYBOARD KMX_FixupKeyboard(PKMX_BYTE bufp, PKMX_BYTE base, KMX_DWORD dwFil for (gp = kbp->dpGroupArray, cgp = (PCOMP_GROUP)gp, i = 0; i < kbp->cxGroupArray; i++, gp++, cgp++) { gp->dpName = KMX_StringOffset(base, cgp->dpName); gp->dpKeyArray = (LPKMX_KEY)(base + cgp->dpKeyArray); - if (cgp->dpMatch != NULL) + if (cgp->dpMatch != 0) gp->dpMatch = (PKMX_WCHAR)(base + cgp->dpMatch); - if (cgp->dpNoMatch != NULL) + if (cgp->dpNoMatch != 0) gp->dpNoMatch = (PKMX_WCHAR)(base + cgp->dpNoMatch); for (kp = gp->dpKeyArray, ckp = (PCOMP_KEY)kp, j = 0; j < gp->cxKeyArray; j++, kp++, ckp++) {