Skip to content

Commit ec9182b

Browse files
authored
Merge pull request #568 from smartdevicelink/release/1.8.0_RC
JavaScript_Suite - Release/1.8.0
2 parents c56738a + 88818d9 commit ec9182b

15 files changed

+3497
-3816
lines changed

lib/js/src/manager/SystemCapabilityManager.js

Lines changed: 218 additions & 14 deletions
Large diffs are not rendered by default.

lib/js/src/manager/file/filetypes/SdlArtwork.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ class SdlArtwork extends SdlFile {
125125
clone () {
126126
const clonedParams = Object.assign({}, this); // shallow copy
127127

128-
if (clonedParams._imageRPC !== null) {
129-
clonedParams._imageRPC = Object.assign(new Image(), clonedParams._imageRPC);
130-
}
128+
// do not clone the _imageRPC parameter. let getImageRPC regenerate the property if the manager needs it
129+
delete clonedParams._imageRPC;
130+
131131
return Object.assign(new SdlArtwork(), clonedParams);
132132
}
133133
}

lib/js/src/manager/screen/_TextAndGraphicManagerBase.js

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
*/
3232

3333
import { _SubManagerBase } from '../_SubManagerBase.js';
34-
import { _Task } from '../_Task.js';
3534
import { _TextAndGraphicUpdateOperation } from './_TextAndGraphicUpdateOperation.js';
3635
import { _TextAndGraphicState } from './_TextAndGraphicState.js';
3736

@@ -67,7 +66,6 @@ class _TextAndGraphicManagerBase extends _SubManagerBase {
6766
this._textField4Type = null;
6867
this._isDirty = false;
6968
this._updateOperation = null;
70-
this._currentOperationListener = null;
7169
this._templateConfiguration = null;
7270

7371
this._handleDisplayCapabilityUpdates();
@@ -108,7 +106,6 @@ class _TextAndGraphicManagerBase extends _SubManagerBase {
108106
this._textField4Type = null;
109107
this._isDirty = false;
110108
this._updateOperation = null;
111-
this._currentOperationListener = null;
112109

113110
this._handleDisplayCapabilityUpdates();
114111
this._handleTaskQueue();
@@ -125,7 +122,7 @@ class _TextAndGraphicManagerBase extends _SubManagerBase {
125122
resolve(false);
126123
}
127124
if (this._isDirty) {
128-
this._sdlUpdate(true, resolve);
125+
this._sdlUpdate(resolve);
129126
} else {
130127
resolve(true);
131128
}
@@ -135,36 +132,23 @@ class _TextAndGraphicManagerBase extends _SubManagerBase {
135132
/**
136133
* Determines what needs to be done to send a valid Show method
137134
* @private
138-
* @param {Boolean} supersedePreviousOperations - Whether this update should have priority over previous updates
139135
* @param {function} listener - A function to invoke when the update task is complete once it runs
140136
*/
141-
_sdlUpdate (supersedePreviousOperations, listener) {
142-
if (this._updateOperation !== null && this._updateOperation.getState() === _Task.READY && supersedePreviousOperations) {
143-
this._updateOperation.switchStates(_Task.CANCELED);
144-
if (typeof this._currentOperationListener === 'function') {
145-
this._currentOperationListener(false);
146-
}
147-
}
148-
149-
if (this._updateOperation !== null && this._updateOperation.getState() === _Task.IN_PROGRESS && supersedePreviousOperations) {
150-
this._updateOperation.switchStates(_Task.CANCELED);
151-
}
152-
153-
this._currentOperationListener = listener;
154-
137+
_sdlUpdate (listener) {
155138
const currentScreenDataUpdateListener = (asyncListener) => {
156139
asyncListener().then((newScreenData) => {
157140
if (newScreenData !== null) {
158141
this._currentScreenData = newScreenData;
159142
this._updatePendingOperationsWithNewScreenData();
160143
}
161-
}).catch((err) => {
144+
}).catch((errorState) => {
162145
this._resetFieldsToCurrentScreenData();
146+
this._updatePendingOperationsWithFailedScreenState(errorState);
163147
});
164148
};
165149

166150
this._updateOperation = new _TextAndGraphicUpdateOperation(this._lifecycleManager, this._fileManager, this._defaultMainWindowCapability,
167-
this._currentScreenData, this._currentState(), this._currentOperationListener, currentScreenDataUpdateListener.bind(this));
151+
this._currentScreenData, this._currentState(), listener, currentScreenDataUpdateListener.bind(this));
168152
this._addTask(this._updateOperation);
169153
}
170154

@@ -189,11 +173,25 @@ class _TextAndGraphicManagerBase extends _SubManagerBase {
189173
this._templateConfiguration = this._currentScreenData.getTemplateConfiguration();
190174
}
191175

176+
/**
177+
* Updates all pending tasks in the queue with the failed screen state
178+
* @param {_TextAndGraphicState} errorState - The _TextAndGraphicState when the error occured
179+
* @private
180+
*/
181+
_updatePendingOperationsWithFailedScreenState (errorState) {
182+
for (const task of this._getTasks()) {
183+
if (!(task instanceof _TextAndGraphicUpdateOperation)) {
184+
continue;
185+
}
186+
task._updateTargetStateWithErrorState(errorState);
187+
}
188+
}
189+
192190
/**
193191
* Updates all pending tasks in the queue with the current screen data
194192
*/
195193
_updatePendingOperationsWithNewScreenData () {
196-
for (const task in this._getTasks()) {
194+
for (const task of this._getTasks()) {
197195
if (!(task instanceof _TextAndGraphicUpdateOperation)) {
198196
continue;
199197
}
@@ -235,7 +233,7 @@ class _TextAndGraphicManagerBase extends _SubManagerBase {
235233
setTextAlignment (textAlignment) {
236234
this._textAlignment = textAlignment;
237235
if (!this._batchingUpdates) {
238-
this._sdlUpdate(true, null);
236+
this._sdlUpdate(null);
239237
} else {
240238
this._isDirty = true;
241239
}
@@ -258,7 +256,7 @@ class _TextAndGraphicManagerBase extends _SubManagerBase {
258256
setMediaTrackTextField (mediaTrackTextField) {
259257
this._mediaTrackTextField = mediaTrackTextField;
260258
if (!this._batchingUpdates) {
261-
this._sdlUpdate(true, null);
259+
this._sdlUpdate(null);
262260
} else {
263261
this._isDirty = true;
264262
}
@@ -281,7 +279,7 @@ class _TextAndGraphicManagerBase extends _SubManagerBase {
281279
setTextField1 (textField1) {
282280
this._textField1 = textField1;
283281
if (!this._batchingUpdates) {
284-
this._sdlUpdate(true, null);
282+
this._sdlUpdate(null);
285283
} else {
286284
this._isDirty = true;
287285
}
@@ -304,7 +302,7 @@ class _TextAndGraphicManagerBase extends _SubManagerBase {
304302
setTextField2 (textField2) {
305303
this._textField2 = textField2;
306304
if (!this._batchingUpdates) {
307-
this._sdlUpdate(true, null);
305+
this._sdlUpdate(null);
308306
} else {
309307
this._isDirty = true;
310308
}
@@ -327,7 +325,7 @@ class _TextAndGraphicManagerBase extends _SubManagerBase {
327325
setTextField3 (textField3) {
328326
this._textField3 = textField3;
329327
if (!this._batchingUpdates) {
330-
this._sdlUpdate(true, null);
328+
this._sdlUpdate(null);
331329
} else {
332330
this._isDirty = true;
333331
}
@@ -350,7 +348,7 @@ class _TextAndGraphicManagerBase extends _SubManagerBase {
350348
setTextField4 (textField4) {
351349
this._textField4 = textField4;
352350
if (!this._batchingUpdates) {
353-
this._sdlUpdate(true, null);
351+
this._sdlUpdate(null);
354352
} else {
355353
this._isDirty = true;
356354
}
@@ -373,7 +371,7 @@ class _TextAndGraphicManagerBase extends _SubManagerBase {
373371
setTextField1Type (textField1Type) {
374372
this._textField1Type = textField1Type;
375373
if (!this._batchingUpdates) {
376-
this._sdlUpdate(true, null);
374+
this._sdlUpdate(null);
377375
} else {
378376
this._isDirty = true;
379377
}
@@ -396,7 +394,7 @@ class _TextAndGraphicManagerBase extends _SubManagerBase {
396394
setTextField2Type (textField2Type) {
397395
this._textField2Type = textField2Type;
398396
if (!this._batchingUpdates) {
399-
this._sdlUpdate(true, null);
397+
this._sdlUpdate(null);
400398
} else {
401399
this._isDirty = true;
402400
}
@@ -419,7 +417,7 @@ class _TextAndGraphicManagerBase extends _SubManagerBase {
419417
setTextField3Type (textField3Type) {
420418
this._textField3Type = textField3Type;
421419
if (!this._batchingUpdates) {
422-
this._sdlUpdate(true, null);
420+
this._sdlUpdate(null);
423421
} else {
424422
this._isDirty = true;
425423
}
@@ -442,7 +440,7 @@ class _TextAndGraphicManagerBase extends _SubManagerBase {
442440
setTextField4Type (textField4Type) {
443441
this._textField4Type = textField4Type;
444442
if (!this._batchingUpdates) {
445-
this._sdlUpdate(true, null);
443+
this._sdlUpdate(null);
446444
} else {
447445
this._isDirty = true;
448446
}
@@ -465,7 +463,7 @@ class _TextAndGraphicManagerBase extends _SubManagerBase {
465463
setTitle (title) {
466464
this._title = title;
467465
if (!this._batchingUpdates) {
468-
this._sdlUpdate(true, null);
466+
this._sdlUpdate(null);
469467
} else {
470468
this._isDirty = true;
471469
}
@@ -488,7 +486,7 @@ class _TextAndGraphicManagerBase extends _SubManagerBase {
488486
setPrimaryGraphic (primaryGraphic) {
489487
this._primaryGraphic = primaryGraphic;
490488
if (!this._batchingUpdates) {
491-
this._sdlUpdate(true, null);
489+
this._sdlUpdate(null);
492490
} else {
493491
this._isDirty = true;
494492
}
@@ -511,7 +509,7 @@ class _TextAndGraphicManagerBase extends _SubManagerBase {
511509
setSecondaryGraphic (secondaryGraphic) {
512510
this._secondaryGraphic = secondaryGraphic;
513511
if (!this._batchingUpdates) {
514-
this._sdlUpdate(true, null);
512+
this._sdlUpdate(null);
515513
} else {
516514
this._isDirty = true;
517515
}
@@ -534,7 +532,7 @@ class _TextAndGraphicManagerBase extends _SubManagerBase {
534532
changeLayout (templateConfiguration, listener) {
535533
this.setTemplateConfiguration(templateConfiguration);
536534
if (!this._batchingUpdates) {
537-
this._sdlUpdate(true, listener);
535+
this._sdlUpdate(listener);
538536
} else {
539537
this._isDirty = true;
540538
}

lib/js/src/manager/screen/_TextAndGraphicUpdateOperation.js

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class _TextAndGraphicUpdateOperation extends _Task {
8787
this._fullShow = this._assembleLayout(this._fullShow);
8888

8989
if (this._showRpcSupportsTemplateConfiguration()) {
90-
this._updateGraphicsAndShow(this._fullShow);
90+
await this._updateGraphicsAndShow(this._fullShow);
9191
} else {
9292
if (this._shouldUpdateTemplateConfig()) {
9393
const success = await this._sendSetDisplayLayoutWithTemplateConfiguration(this._updatedState.getTemplateConfiguration());
@@ -96,9 +96,9 @@ class _TextAndGraphicUpdateOperation extends _Task {
9696
this._finishOperation(false);
9797
return;
9898
}
99-
this._updateGraphicsAndShow(this._fullShow);
99+
await this._updateGraphicsAndShow(this._fullShow);
100100
} else {
101-
this._updateGraphicsAndShow(this._fullShow);
101+
await this._updateGraphicsAndShow(this._fullShow);
102102
}
103103
}
104104
}
@@ -146,14 +146,14 @@ class _TextAndGraphicUpdateOperation extends _Task {
146146
} else {
147147
console.info('Text and Graphic Show failed');
148148
this._currentScreenDataUpdateListener(async () => {
149-
throw new Error('Text and Graphic Show failed');
149+
throw this._updatedState; // send the errored state back to the manager
150150
});
151151
}
152152
return response.getSuccess();
153153
} else {
154154
console.info('LifecycleManager is null, Text and Graphic update failed');
155155
this._currentScreenDataUpdateListener(async () => {
156-
throw new Error('LifecycleManager is null, Text and Graphic update failed');
156+
throw this._updatedState; // send the errored state back to the manager
157157
});
158158
this._finishOperation(false);
159159
return;
@@ -176,14 +176,14 @@ class _TextAndGraphicUpdateOperation extends _Task {
176176
} else {
177177
console.info('Text and Graphic SetDisplayLayout failed');
178178
this._currentScreenDataUpdateListener(async () => {
179-
throw new Error('Text and Graphic SetDisplayLayout failed');
179+
throw this._updatedState; // send the errored state back to the manager
180180
});
181181
}
182182
return response.getSuccess();
183183
} else {
184184
console.info('LifecycleManager is null, Text and Graphic update failed');
185185
this._currentScreenDataUpdateListener(async () => {
186-
throw new Error('LifecycleManager is null, Text and Graphic update failed');
186+
throw this._updatedState; // send the errored state back to the manager
187187
});
188188
this._finishOperation(false);
189189
return;
@@ -665,6 +665,9 @@ class _TextAndGraphicUpdateOperation extends _Task {
665665
if (show.getSecondaryGraphic() !== null && show.getSecondaryGraphic() !== undefined) {
666666
this._currentScreenData.setSecondaryGraphic(this._updatedState.getSecondaryGraphic());
667667
}
668+
if (show.getTemplateConfiguration() !== null && show.getTemplateConfiguration() !== undefined) {
669+
this._currentScreenData.setTemplateConfiguration(this._updatedState.getTemplateConfiguration());
670+
}
668671
if (typeof this._currentScreenDataUpdateListener === 'function') {
669672
this._currentScreenDataUpdateListener(async () => {
670673
return this._currentScreenData;
@@ -860,6 +863,66 @@ class _TextAndGraphicUpdateOperation extends _Task {
860863
}
861864
this.onFinished();
862865
}
866+
867+
/**
868+
* Applies changes to the _TextAndGraphicState with that of the error state
869+
* @private
870+
* @param {_TextAndGraphicState} errorState - The _TextAndGraphicState when the error occured
871+
*/
872+
_updateTargetStateWithErrorState (errorState) {
873+
if (errorState.getTextField1() === this._updatedState.getTextField1()) {
874+
this._updatedState.setTextField1(this._currentScreenData.getTextField1());
875+
}
876+
if (errorState.getTextField2() === this._updatedState.getTextField2()) {
877+
this._updatedState.setTextField2(this._currentScreenData.getTextField2());
878+
}
879+
if (errorState.getTextField3() === this._updatedState.getTextField3()) {
880+
this._updatedState.setTextField3(this._currentScreenData.getTextField3());
881+
}
882+
if (errorState.getTextField4() === this._updatedState.getTextField4()) {
883+
this._updatedState.setTextField4(this._currentScreenData.getTextField4());
884+
}
885+
if (errorState.getMediaTrackTextField() === this._updatedState.getMediaTrackTextField()) {
886+
this._updatedState.setMediaTrackTextField(this._currentScreenData.getMediaTrackTextField());
887+
}
888+
if (errorState.getTitle() === this._updatedState.getTitle()) {
889+
this._updatedState.setTitle(this._currentScreenData.getTitle());
890+
}
891+
892+
const errorPrimary = errorState.getPrimaryGraphic();
893+
const updatedPrimary = this._updatedState.getPrimaryGraphic();
894+
if ((errorPrimary === null && updatedPrimary === null)
895+
|| (errorPrimary !== null && errorPrimary.equals(updatedPrimary) && errorPrimary.isTemplateImage() === updatedPrimary.isTemplateImage())) { // for safe null check
896+
this._updatedState.setPrimaryGraphic(this._currentScreenData.getPrimaryGraphic());
897+
}
898+
899+
const errorSecondary = errorState.getSecondaryGraphic();
900+
const updatedSecondary = this._updatedState.getSecondaryGraphic();
901+
if ((errorSecondary === null && updatedSecondary === null)
902+
|| (errorSecondary !== null && errorSecondary.equals(updatedSecondary) && errorSecondary.isTemplateImage() === updatedSecondary.isTemplateImage())) { // for safe null check
903+
this._updatedState.setPrimaryGraphic(this._currentScreenData.getPrimaryGraphic());
904+
}
905+
906+
if (errorState.getTextAlignment() === this._updatedState.getTextAlignment()) {
907+
this._updatedState.setTextAlignment(this._currentScreenData.getTextAlignment());
908+
}
909+
if (errorState.getTextField1Type() === this._updatedState.getTextField1Type()) {
910+
this._updatedState.setTextField1Type(this._currentScreenData.getTextField1Type());
911+
}
912+
if (errorState.getTextField2Type() === this._updatedState.getTextField2Type()) {
913+
this._updatedState.setTextField2Type(this._currentScreenData.getTextField2Type());
914+
}
915+
if (errorState.getTextField3Type() === this._updatedState.getTextField3Type()) {
916+
this._updatedState.setTextField3Type(this._currentScreenData.getTextField3Type());
917+
}
918+
if (errorState.getTextField4Type() === this._updatedState.getTextField4Type()) {
919+
this._updatedState.setTextField4Type(this._currentScreenData.getTextField4Type());
920+
}
921+
if ((errorState.getTemplateConfiguration() === null && this._updatedState.getTemplateConfiguration() === null)
922+
|| (errorState.getTemplateConfiguration() !== null && errorState.getTemplateConfiguration().getParameters() === this._updatedState.getTemplateConfiguration().getParameters())) { // for safe null check
923+
this._updatedState.setTemplateConfiguration(this._currentScreenData.getTemplateConfiguration());
924+
}
925+
}
863926
}
864927

865928
export { _TextAndGraphicUpdateOperation };

lib/js/src/manager/screen/_VoiceCommandManagerBase.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class _VoiceCommandManagerBase extends _SubManagerBase {
152152
* @returns {Boolean} - indicate whether all voice commands are unique
153153
*/
154154
_arePendingVoiceCommandsUnique (voiceCommands) {
155-
const allVoiceCommands = voiceCommands.map(voiceCommand => voiceCommand.getVoiceCommands()).flat();
155+
const allVoiceCommands = voiceCommands.reduce((array, voiceCommand) => array.concat(voiceCommand.getVoiceCommands()), []);
156156
return new Set(allVoiceCommands).size === allVoiceCommands.length;
157157
}
158158

0 commit comments

Comments
 (0)