Skip to content

Commit 8b692df

Browse files
committed
Fix MenuReplaceOperations being added and run synchronously
1 parent 809f48c commit 8b692df

6 files changed

Lines changed: 26 additions & 22 deletions

File tree

examples/js/hello-sdl/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152

153153
const cellList = [mainCell1, mainCell2];
154154

155-
screenManager.setMenu(cellList);
155+
await screenManager.setMenu(cellList);
156156
}
157157

158158
async _onHmiStatusListener (onHmiStatus) {

examples/node/hello-sdl-tcp/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class AppClient {
147147

148148
const cellList = [mainCell1, mainCell2];
149149

150-
screenManager.setMenu(cellList);
150+
await screenManager.setMenu(cellList);
151151
}
152152

153153
async _onHmiStatusListener (onHmiStatus) {

examples/node/hello-sdl/AppClient.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ class AppClient {
105105
this._isButtonSubscriptionRequested = false;
106106
}
107107

108-
_onConnected () {
108+
async _onConnected () {
109109
this._managersReady = true;
110110
this._checkReadyState();
111111
const screenManager = this._sdlManager.getScreenManager();
112-
112+
113113
// add menus
114114
const menuListener = new SDL.manager.screen.menu.MenuSelectionListener()
115115
.setOnTriggered(triggerSource => {
@@ -135,7 +135,7 @@ class AppClient {
135135

136136
const cellList = [mainCell1, mainCell2];
137137

138-
screenManager.setMenu(cellList);
138+
await screenManager.setMenu(cellList);
139139
}
140140

141141
_onHmiStatusListener (onHmiStatus) {

examples/webengine/hello-sdl/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157

158158
const cellList = [mainCell1, mainCell2];
159159

160-
screenManager.setMenu(cellList);
160+
await screenManager.setMenu(cellList);
161161
}
162162

163163
async _onSystemCapabilityUpdatedRpcListener (capabilityMessage) {

lib/js/src/manager/screen/_ScreenManagerBase.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,8 @@ class _ScreenManagerBase extends _SubManagerBase {
666666
* Note: the manager will store a deep copy the menuCells internally to be able to handle future updates correctly
667667
* @param {MenuCell[]} menuCells - The menu cells that are to be sent to the head unit, including their sub-cells.
668668
*/
669-
setMenu (menuCells) {
670-
this._menuManagerBase._setMenuCells(menuCells);
669+
async setMenu (menuCells) {
670+
await this._menuManagerBase._setMenuCells(menuCells);
671671
}
672672

673673
/**

lib/js/src/manager/screen/menu/_MenuManagerBase.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -142,34 +142,38 @@ class _MenuManagerBase extends _SubManagerBase {
142142
/**
143143
* Creates and sends all associated Menu RPCs
144144
* @param {MenuCell[]} cells - The menu cells that are to be sent to the head unit, including their sub-cells.
145+
* @returns {Promise} - A Promise that resolves to whether the operation was successful
145146
*/
146147
_setMenuCells (cells = []) {
147148
if (cells === null) {
148149
console.error('MenuManagerBase - Cells list is null. Skipping...');
149-
return;
150+
return Promise.resolve(true);
150151
}
151152

152153
if (!this._menuCellsAreUnique(cells, [])) {
153154
console.error('MenuManagerBase - Not all set menu cells are unique, but that is required');
154-
return;
155+
return Promise.resolve(false);
155156
}
156157

157158
// Create a deep copy of the list so future changes by developers don't affect the algorithm logic
158159
this._menuCells = cells.map(cell => cell.clone());
159160
const isDynamicMenuUpdateActiveBoolean = this._isDynamicMenuUpdateActive(this._dynamicMenuUpdatesMode, this._displayType);
160161

161-
const operation = new _MenuReplaceOperation(this._lifecycleManager, this._fileManager, this._windowCapability,
162-
this._currentMenuConfiguration, this._currentMenuCells, this._menuCells, isDynamicMenuUpdateActiveBoolean, new _MenuManagerCompletionListener()
163-
.setOnComplete((success, currentMenuCells) => {
164-
this._currentMenuCells = currentMenuCells;
165-
this._updateMenuReplaceOperationsWithNewCurrentMenu();
166-
console.log('MenuManagerBase - Finished updating menu');
167-
})
168-
);
169-
170-
// Cancel previous MenuReplaceOperations
171-
this._cancelAllTasks('MenuReplaceOperation');
172-
this._addTask(operation);
162+
return new Promise((resolve) => {
163+
const operation = new _MenuReplaceOperation(this._lifecycleManager, this._fileManager, this._windowCapability,
164+
this._currentMenuConfiguration, this._currentMenuCells, this._menuCells, isDynamicMenuUpdateActiveBoolean, new _MenuManagerCompletionListener()
165+
.setOnComplete((success, currentMenuCells) => {
166+
this._currentMenuCells = currentMenuCells;
167+
this._updateMenuReplaceOperationsWithNewCurrentMenu();
168+
console.log('MenuManagerBase - Finished updating menu');
169+
resolve(success);
170+
})
171+
);
172+
173+
// Cancel previous MenuReplaceOperations
174+
this._cancelAllTasks('MenuReplaceOperation');
175+
this._addTask(operation);
176+
});
173177
}
174178

175179
/**

0 commit comments

Comments
 (0)