From c8f7a4cdf4a3d01fe5cbbcc74ff930c7212a37df Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Thu, 24 Jun 2021 13:02:49 +0700 Subject: [PATCH] fix(web): Use util.internalAlert() wrapper --- web/source/keyboards/kmwkeyboards.ts | 18 +++++------------- web/source/kmwutils.ts | 12 ++++++++++++ web/source/osk/oskManager.ts | 4 +--- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/web/source/keyboards/kmwkeyboards.ts b/web/source/keyboards/kmwkeyboards.ts index ed62d5f296..d8bd6ec15d 100644 --- a/web/source/keyboards/kmwkeyboards.ts +++ b/web/source/keyboards/kmwkeyboards.ts @@ -570,11 +570,9 @@ namespace com.keyman.keyboards { // Thanks, Closure errors. if(!this.keymanweb.isEmbedded) { util.wait(false); - if (this.keymanweb.options.useAlerts) { - util.alert(altString || msg, function() { + util.internalAlert(altString || msg, function() { this.keymanweb['setActiveKeyboard'](''); // The API call! - }.bind(this)); - } + }.bind(this)); } switch(msgType) { // in case we extend this later. @@ -949,9 +947,7 @@ namespace com.keyman.keyboards { if(typeof(x[i]['filename']) == 'string') { if(!this.addStub(x[i])) { - if (this.keymanweb.options.useAlerts) { - this.keymanweb.util.alert('To use a custom keyboard, you must specify file name, keyboard name, language, language code and region code.'); - } + this.keymanweb.util.internalAlert('To use a custom keyboard, you must specify file name, keyboard name, language, language code and region code.'); } } else { if(x[i]['language']) { @@ -1331,9 +1327,7 @@ namespace com.keyman.keyboards { private alertLanguageUnavailable(languageName: string): string { let msg = 'No keyboards are available for '+ languageName + '. ' +'Does it have another language name?'; - if (this.keymanweb.options.useAlerts) { - this.keymanweb.util.alert(msg); - } + this.keymanweb.util.internalAlert(msg); return msg; } @@ -1344,9 +1338,7 @@ namespace com.keyman.keyboards { * **/ private serverUnavailable(cmd) { - if (this.keymanweb.options.useAlerts) { - this.keymanweb.util.alert(cmd == '' ? 'Unable to connect to Keyman Cloud server!' : cmd); - } + this.keymanweb.util.internalAlert(cmd == '' ? 'Unable to connect to Keyman Cloud server!' : cmd); this.keymanweb.warned=true; } diff --git a/web/source/kmwutils.ts b/web/source/kmwutils.ts index 1915d8f119..36f6f7211c 100644 --- a/web/source/kmwutils.ts +++ b/web/source/kmwutils.ts @@ -971,6 +971,18 @@ namespace com.keyman { } + /** + * Customized internal alert. This is enabled/disabled by the option flag 'useAlerts' + * + * @param {string} s alert text + * @param {function()=} fn function to call when alert dismissed + */ + internalAlert(s: string, fn?: () => void): void { + if (this.keyman.options.useAlerts) { + this.alert(s, fn); + } + } + /** * Prepare the background and keyboard loading wait message box * Should not be called before options are defined during initialization diff --git a/web/source/osk/oskManager.ts b/web/source/osk/oskManager.ts index 4cbea24ba2..04f089ac6c 100644 --- a/web/source/osk/oskManager.ts +++ b/web/source/osk/oskManager.ts @@ -465,10 +465,8 @@ namespace com.keyman.osk { */ showBuild() { let keymanweb = com.keyman.singleton; - if (keymanweb.options.useAlerts) { - keymanweb.util.alert('KeymanWeb Version '+keymanweb['version']+'.'+keymanweb['build']+'

' + keymanweb.util.internalAlert('KeymanWeb Version '+keymanweb['version']+'.'+keymanweb['build']+'

' +'Copyright © 2017 SIL International'); - } } /**